-
Notifications
You must be signed in to change notification settings - Fork 323
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
Refactor how messages are processed #129
Conversation
Codecov Report
@@ Coverage Diff @@
## master #129 +/- ##
===========================================
+ Coverage 19.58% 32.01% +12.42%
===========================================
Files 15 13 -2
Lines 2783 2271 -512
===========================================
+ Hits 545 727 +182
+ Misses 2211 1493 -718
- Partials 27 51 +24
Continue to review full report at Codecov.
|
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.
This is a pretty hefty change for this repo, and is essentially a rewrite of how the app handles messages. Sorry ahead of time for cramming all this into a single PR, but the larger important changes are all dependent upon each other.
Before this PR, the app had a separate Tx type called TxSignedTransactionDataPayForMessage
, whose purpose is to pay for messages submitted to celestia. This has been replaced by a standard authsigning.Tx
. There also used to be a message that TxSignedTransactionDataPayForMessage
wrapped, called MsgSignedTransactionDataPayForMessage
. This message has been simplified into MsgPayForMessage
.
https://github.com/celestiaorg/lazyledger-app/blob/4eda3ddb92071fb7e29d2233bc397b448cd384b9/proto/payment/tx.proto#L38-L46
Before, we had to stick things like nonce and fees into the message portion, now we keep sequence, gas limit, and gas price in the standard sdk authsigning.Tx
. This allows us to plug into the sdk in a much more conventional way.
A similar treatment has been applied to what used to be called MsgWirePayForMessage
, portions of the struct have been moved to a standard sdk authsigning.Tx
, and only the minimal fields are left. This was first suggested by Ismail in this comment.
https://github.com/celestiaorg/lazyledger-app/blob/4eda3ddb92071fb7e29d2233bc397b448cd384b9/proto/payment/tx.proto#L18-L26
Most of the rest of the changes introduced in this PR surround these two changes.
There’s also a few overdue code quality changes.
app/abci.go
Outdated
coreMsg, signedTx, err := app.processMsg(msg) | ||
coreMsg, unsignedPFM, sig, err := types.ProcessWirePayForMessage(wireMsg, app.SquareSize()) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
signedTx, err := types.BuildPayForMessageTxFromWireTx(authTx, app.txConfig.NewTxBuilder(), sig, unsignedPFM) | ||
if err != nil { | ||
// todo(evan): log all of these potential errors | ||
continue | ||
} |
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.
Here we are building a new MsgPayForMessage
into a standard sdk.Tx
by using one of the signatures included in MsgWirePayForMessage
, but using the same fees, gas price, and sequence of the transaction that contains the MsgWirePayForMessage
.
This differs from the previous approach, which created a an entirely new transaction that was reliant upon a separate fee struct for fees.
this is closer to how the sdk expects transactions to be created/used
// makeEncodingConfig is copied here so that we don't have to have an | ||
// import cycle. if possible, use cosmoscmd.MakeEncodingConfig | ||
func makeEncodingConfig() cosmoscmd.EncodingConfig { | ||
amino := codec.NewLegacyAmino() | ||
interfaceRegistry := codectypes.NewInterfaceRegistry() | ||
RegisterInterfaces(interfaceRegistry) | ||
marshaler := codec.NewProtoCodec(interfaceRegistry) | ||
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) | ||
|
||
return cosmoscmd.EncodingConfig{ | ||
InterfaceRegistry: interfaceRegistry, | ||
Marshaler: marshaler, | ||
TxConfig: txCfg, | ||
Amino: amino, | ||
} | ||
} |
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.
The newer version of the sdk registers proto interfaces for us using the app
package’s ModuleBasics
struct when we create encoding configs. This works for most use cases, but we need to handle building new transactions manually in the types
package, so this had to be copied here.
x/payment/keeper/keeper.go
Outdated
func (k Keeper) PayForMessage(goCtx context.Context, msg *types.MsgPayForMessage) (*types.MsgPayForMessageResponse, error) { | ||
// @liamsi here's where we can use the bank keeper to burn fees | ||
return &types.MsgPayForMessageResponse{}, nil | ||
} |
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.
@liamsi I think spoke about this briefly during the sprint planning session. If we end up being able to move away from deferred execution, and could get burning fraud provable, then I think we would be able to burn fees here
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.
TBH, I think if we adopt fee burning, we should adopt it for all Txs and not just for PayForMessage. So it would still be in the auth module (or a modification of that) instead IMO. I think @marbar3778 had a diff laying around somewhere that implemented general fee-burning. We can just use that instead.
Also, I really think we should talk with the SDK and tendermint team about immediate execution. If there is a strong point to adopt immediate exec by default in the baseapp (which I think there is), than we should support that implementation directly upstream first IMO.
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.
https://github.com/marbar3778/fee/blob/main/app/feeParam.go
i never finished the burning but its a simple change in the ante handler
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 see, that would be a separate module. I think that is also good. I just do not think we should implement feeburning only for PayForMessage (if at all) but if it should be applied to all Txs.
TokenDenomination = "token" | ||
TokenDenomination = "tia" |
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.
Idk what the token denomination will actually be and am not attached to this name whatsoever, just thought we wouldn't use plain old "token".
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 like tia.
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.
wen tia
// Multiple versions are signed and included, each version creates a commitment for a | ||
// specific square size. | ||
message MsgPayForMessage { | ||
string signer = 1; |
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.
adding the signer or "creator" as the bech32 address of the key that signed is a new default in starport, so I figured we could keep it. Happy to remove.
message MsgWirePayForMessage { | ||
TransactionFee fee = 1; | ||
uint64 nonce = 2; | ||
bytes message_name_space_id = 3; // assume this is 8 bytes! | ||
uint64 message_size = 4; | ||
bytes message = 5; | ||
string signer = 1; | ||
bytes message_name_space_id = 2; // assume this is 8 bytes! | ||
uint64 message_size = 3; | ||
bytes message = 4; | ||
repeated ShareCommitAndSignature message_share_commitment = 6 [(gogoproto.nullable) = false]; | ||
bytes public_key = 7; | ||
} |
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.
simplified wire message
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.
First pass looks good. So finally the fees get actually payed by deleting a bunch of code 👏🏼
} | ||
|
||
// WirePayForMessage describes the format of data that is sent over the wire for | ||
// MsgWirePayForMessage describes the format of data that is sent over the wire for | ||
// each PayForMessage | ||
message MsgWirePayForMessage { |
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.
Is the naming inspired by the specs? What is with the Msg*Message
? cc @adlerjohn
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, the Msg prefix is just an sdk suggested syntax thing (ie MsgCreatePool), and the second Message is referring to a core.Message
like the specs do. It is annoying, but I think it also makes sense. 🤷
@@ -264,7 +136,7 @@ func CreateCommitment(k uint64, namespace, message []byte) ([]byte, error) { | |||
// create the commits by pushing each leaf set onto an nmt | |||
subTreeRoots := make([][]byte, len(leafSets)) | |||
for i, set := range leafSets { | |||
// create the nmt | |||
// create the nmt todo(evan) use nmt wrapper |
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.
So the nmt wrapper will be used here and in the celestia-node. And potenially to verify inclusion in other clients. We should move that code into another repo too probably. (cc @renaynay)
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.
|
||
// ensure that a reserved namespace is not used | ||
if bytes.Compare(msg.GetMessageNameSpaceId(), consts.MaxReservedNamespace) < 1 { | ||
return errors.New("message is not valid: uses a reserved namesapce ID") |
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 need to document this pretty well somewhere for people building rollups.
it seems there are some unrelated changes in this PR. Are they coming from upstream? Could updates be pulled into a separate PR? it will be easier to track commits and revert items if nessecary. |
app/export.go
Outdated
@@ -4,7 +4,7 @@ import ( | |||
"encoding/json" | |||
"log" | |||
|
|||
tmproto "github.com/celestiaorg/celestia-core/proto/tendermint/types" | |||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" |
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.
revert?
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.
The gomod name is now back to tendermint/tendermint: https://github.com/celestiaorg/celestia-core/blob/c2df2c4ce0942b8e974fd2b530355f2a58139926/go.mod#L1
And pointing to the fork is now done via a replace
directive here: https://github.com/celestiaorg/lazyledger-app/blob/215166853ebaccc266fd3755599d3ca5450b5136/go.mod#L129
Anything wrong with that?
app/abci.go
Outdated
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/pkg/consts" | ||
core "github.com/tendermint/tendermint/proto/tendermint/types" |
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.
celestia?
I cant find where this changed. I dont see the ante handler being touched, so i could be looking in the wrong place |
@marbar3778 the idea was to simply use the default underlying fee deduction mechanism assuming that the included messages' gas simply gets metered by bytes. I thought the auth module (or its ante handlers) would provide this. |
brief summary with chat with marko:
Let's just make sure that if the base-fee is non-zero, we pay more if the blob/msg the payformessage commits to gets larger. Every other aspect around fees is not important right now! |
OK, this is apparently out of scope for this PR and paying for the blob will be handled in another PR. |
Co-authored-by: Ismail Khoffi <[email protected]>
Co-authored-by: Ismail Khoffi <[email protected]>
Co-authored-by: Ismail Khoffi <[email protected]>
2151668
to
43b1303
Compare
Co-authored-by: John Adler <[email protected]>
Co-authored-by: John Adler <[email protected]>
Yeah, sorry we merged the branch that this PR was based off of #127 last evening and I didn't rebase this branch until today. Hopefully this is better. There are still a few minor code quality changes and some additions to tests that were orthogonal to this PR and definitely should have been in a separate PR.
This PR doesn't change how the fees are getting handled. I miscommunicated that by including #59 and #48 in this PR's description! I think I was going to handle those issues when this was a draft PR by burning the fees in the payment keeper, but then removed that later as it is not the best mechanism and this PR was already too big. This PR only changes the way we handle messages (comment) . Fees for |
Co-authored-by: John Adler <[email protected]>
…r-app into evan/refactor-wpfm
@liamsi @adlerjohn is there anything else needed to merge this PR? it's not blocking anything AFAIK, so no rush or anything |
Yes, this one! #129 (comment) |
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 think this looks good! Looking forward to the followup PR that further deducts fees for the included message-blob too.
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.
Description
This PR follows what was outlined in this #33 (comment) , where we utilize a more standard sdk.Tx instead of creating a custom one for
SignedTxPayForMessage
, which let's us plug into the cosmos sdk in a less hacky/more traditional way.closes: #28, #33
blocked by #127