-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnteDecorator #5006
Merged
Merged
AnteDecorator #5006
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
1960993
start decorator changes
AdityaSripal 12244c5
start replacing ante logic with decorators
AdityaSripal 5a46ceb
Fix build errors
AdityaSripal bdcf294
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ad…
AdityaSripal ac19f18
fix some tests
AdityaSripal 9a0eac7
fix baseapp tests
AdityaSripal 725f5cf
fix auth tests
AdityaSripal ff5f1f7
start individual decorator tests
AdityaSripal 73e2739
add signature tests
AdityaSripal 77bc7c6
complete sig tests
AdityaSripal baf5bfb
fix all test errors
AdityaSripal 71e07ce
remove unnecessary &
AdityaSripal 3b3a74f
fix linter errors
AdityaSripal 6303bec
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ad…
AdityaSripal e52e89d
interface all decorators except sigs
AdityaSripal ac8209d
check signer lenght in sigverify
AdityaSripal b93ca36
Apply suggestions from bez code review
AdityaSripal 5825e81
complete bez suggestions
AdityaSripal 441c050
fix merge conflicts
AdityaSripal 2f22251
create sigTx interface
AdityaSripal 975ad0e
linting
AdityaSripal c5ede73
finish linting except TODO
AdityaSripal 9a5cb61
make auth tx interfaces extend sdk.Tx
AdityaSripal e7ec478
Merge branch 'master' into aditya/ante-decorator
alexanderbez 634c1aa
test docs, replace FeeCoins with GetFee
AdityaSripal 66144bf
Merge branch 'aditya/ante-decorator' of https://github.com/cosmos/cos…
AdityaSripal 0c39cd9
Apply suggestions from fede code review
AdityaSripal 29e85bf
address tim comments
AdityaSripal f1964cf
Merge branch 'aditya/ante-decorator' of https://github.com/cosmos/cos…
AdityaSripal b6d9166
Merge branch 'master' into aditya/ante-decorator
fedekunze 0fd1234
add order comments
AdityaSripal aad9673
Add Schwarzenegger art
AdityaSripal 5ce99da
add assertions that StdTx implements all necessary decorator interfaces
AdityaSripal bd79e58
Merge branch 'aditya/ante-decorator' of https://github.com/cosmos/cos…
AdityaSripal 2f54876
documentation and CHANGELOG
AdityaSripal a4ef3ec
Run goimports
alexanderbez 33cc17a
Update ChainAnteDecorators godoc
alexanderbez 882fac5
Changelog entries cleanup
alexanderbez 163da7f
Changelog entries cleanup
alexanderbez 492cf0d
Merge branch 'master' into aditya/ante-decorator
alexanderbez 1b1a779
Fix formatter
alexanderbez 440a05c
Merge branch 'master' into aditya/ante-decorator
alexanderbez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,62 @@ type Handler func(ctx Context, msg Msg) Result | |
|
||
// AnteHandler authenticates transactions, before their internal messages are handled. | ||
// If newCtx.IsZero(), ctx is used instead. | ||
type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, result Result, abort bool) | ||
type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, err error) | ||
|
||
// AnteDecorator wraps the next AnteHandler to perform custom pre- and post-processing. | ||
type AnteDecorator interface { | ||
AnteHandle(ctx Context, tx Tx, simulate bool, next AnteHandler) (newCtx Context, err error) | ||
} | ||
|
||
// ChainDecorator chains AnteDecorators together with each AnteDecorator | ||
// wrapping over the decorators further along chain and returns a single AnteHandler. | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// NOTE: The first element is outermost decorator, while the last element is innermost | ||
// decorator. Decorator ordering is critical since some decorators will expect | ||
// certain checks and updates to be performed (e.g. the Context) before the decorator | ||
// is run. These expectations should be documented clearly in a CONTRACT docline | ||
// in the decorator's godoc. | ||
// | ||
// NOTE: Any application that uses GasMeter to limit transaction processing cost | ||
// MUST set GasMeter with the FIRST AnteDecorator. Failing to do so will cause | ||
// transactions to be processed with an infinite gasmeter and open a DOS attack vector. | ||
// Use `ante.SetUpContextDecorator` or a custom Decorator with similar functionality. | ||
func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler { | ||
if (chain[len(chain)-1] != Terminator{}) { | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
chain = append(chain, Terminator{}) | ||
} | ||
|
||
if len(chain) == 1 { | ||
return func(ctx Context, tx Tx, simulate bool) (Context, error) { | ||
return chain[0].AnteHandle(ctx, tx, simulate, nil) | ||
} | ||
} | ||
|
||
return func(ctx Context, tx Tx, simulate bool) (Context, error) { | ||
return chain[0].AnteHandle(ctx, tx, simulate, ChainAnteDecorators(chain[1:]...)) | ||
} | ||
} | ||
|
||
// Terminator AnteDecorator will get added to the chain to simplify decorator code | ||
// Don't need to check if next == nil further up the chain | ||
AdityaSripal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// ______ | ||
// <((((((\\\ | ||
// / . }\ | ||
// ;--..--._|} | ||
// (\ '--/\--' ) | ||
// \\ | '-' :'| | ||
// \\ . -==- .-| | ||
// \\ \.__.' \--._ | ||
// [\\ __.--| // _/'--. | ||
// \ \\ .'-._ ('-----'/ __/ \ | ||
// \ \\ / __>| | '--. | | ||
// \ \\ | \ | / / / | ||
// \ '\ / \ | | _/ / | ||
// \ \ \ | | / / | ||
// snd \ \ \ / | ||
type Terminator struct{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lololol |
||
|
||
// Simply return provided Context and nil error | ||
func (t Terminator) AnteHandle(ctx Context, _ Tx, _ bool, _ AnteHandler) (Context, error) { | ||
return ctx, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this is not specific to this PR, but I've always felt that
GasRequired
would be a better name thanGasWanted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! Think it should be a separate PR tho