-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
R4R: Multimsg ante handler Jae's proposal #3787
Changes from 6 commits
c775602
ffbda5c
2907ef1
10af5c2
60890da
ddbe903
e27b979
c15322c
d2e9c5f
5255fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ const ( | |
appName = "GaiaApp" | ||
// DefaultKeyPass contains the default key password for genesis transactions | ||
DefaultKeyPass = "12345678" | ||
|
||
atomsToUatoms = 1000000 | ||
) | ||
|
||
// default home directories for expected binaries | ||
|
@@ -170,7 +172,30 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b | |
) | ||
app.SetInitChainer(app.initChainer) | ||
app.SetBeginBlocker(app.BeginBlocker) | ||
app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.feeCollectionKeeper)) | ||
|
||
authAnteHandler := auth.NewAnteHandler(app.accountKeeper, app.feeCollectionKeeper) | ||
|
||
filterAnteHandler := func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, result sdk.Result, abort bool) { | ||
newCtx, result, abort = authAnteHandler(ctx, tx, simulate) | ||
if abort == true { | ||
return | ||
} | ||
|
||
for _, msg := range tx.GetMsgs() { | ||
switch msg.(type) { | ||
case bank.MsgSend: | ||
// LCD tests requires this to be commented out | ||
// return ctx, bank.ErrSendDisabled(bank.DefaultCodespace).Result(), true | ||
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. Why? We should modify those tests, no? 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. This doesn't seem safe, now we'll allow sends (?) 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. Can I use the Makefile to set an environment variable or something that I can read from in the code? Is that safe? 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. we can't use an env variable but we can use a build flag, i'll do this. |
||
case bank.MsgMultiSend: | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !CheckTransferDisabledBurnMultiSend(msg.(bank.MsgMultiSend)) { | ||
sunnya97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ctx, bank.ErrSendDisabled(bank.DefaultCodespace).Result(), true | ||
} | ||
} | ||
} | ||
return | ||
} | ||
|
||
app.SetAnteHandler(filterAnteHandler) | ||
app.SetEndBlocker(app.EndBlocker) | ||
|
||
if loadLatest { | ||
|
@@ -183,6 +208,30 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b | |
return app | ||
} | ||
|
||
// CheckTransferDisabledBurnMultiSend | ||
func validateMultiSendTransfersDisabled(msg bank.MsgMultiSend) bool { | ||
nineAtoms := sdk.Coins{sdk.NewInt64Coin("uatom", 9*atomsToUatoms)} | ||
oneAtom := sdk.Coins{sdk.NewInt64Coin("uatom", 10*atomsToUatoms)} | ||
sunnya97 marked this conversation as resolved.
Show resolved
Hide resolved
sunnya97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if len(msg.Inputs) != 1 { | ||
return false | ||
} | ||
if len(msg.Outputs) != 2 { | ||
return false | ||
} | ||
|
||
if !msg.Outputs[0].Address.Equals(bank.BurnedCoinsAccAddr) { | ||
return false | ||
} | ||
if !msg.Outputs[0].Coins.IsEqual(nineAtoms) { | ||
return false | ||
} | ||
if !msg.Outputs[1].Coins.IsEqual(oneAtom) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// custom tx codec | ||
func MakeCodec() *codec.Codec { | ||
var cdc = codec.New() | ||
|
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.
Hmmm maybe I'm missing something glaringly obvious, but why must we have a "filterAnteHandler" in
app
? Why can't we just use the regular ante handler and have thesendEnabled
enabled check? Then we won't need any hacky build stuff for this. Yes, the ante handler would have to be provided a "keeper contract" that implementsGetSendEnabled
.What if a bunch of nodes choose to run without this build setup? What if this introduces a spam or DoS vector? (since the entire ante handler is executed first)
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.
Ohhh because it needs access to
x/bank
for message validation....sigh. I still think we can avoid this though.NewAnteHandler
can be passed a tx validator function (which is defined in bank, e.g.func(tx sdk.Tx) sdk.Result
) . Then we dont need any filter ante handler OR hacky build steps.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.
Because other people are using the bank module rn, and we don't want to add Hub specific functionality to the module. We wanted to isolate this functionality change to just the gaia package.
Really, the proper way to do this is to allow for rerouting subroutes. So the route of the bank module msgs would be:
bank/send
bank/multisend
And then in the router, we route
bank/*
to the bank module, butbank/multisend
to a special handler defined in the gaia folder.However, we don't have time to do this rn, as this would involve changes to the router functionality.
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.
I guess we could just temporarily fork the entire
bank
module and add it as a specialbank
module in the gaia folder. And then to enable transfers point it back to the SDK bank module. That's actually not a bad idea.....@cwgoes @jaekwon @zmanian
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.
Yeah anything to avoid involving the build pipeline would be an ideal solution. Seems trivial to do @sunnya97
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.
I have all of these same concerns about using the build pipeline. I think, while messy, that forking the
bank
module may be the best way to do this. Looking forward to continuing this discussion in the sdk meeting today.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.
Also this will be a very easy change to revert if we do that (just reimport the normal bank module into
app.go
)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.
we don't know how messy it will be, this is done, lets go with this.
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.
Alternative as suggested by @sunnya97: #3807
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.
It's not messy at all. I really don't think we should rely on the build process to enforce business logic (especially since it ties into consensus).