Skip to content
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

Merged
merged 39 commits into from
Oct 13, 2021
Merged

Refactor how messages are processed #129

merged 39 commits into from
Oct 13, 2021

Conversation

evan-forbes
Copy link
Member

@evan-forbes evan-forbes commented Oct 1, 2021

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

@evan-forbes evan-forbes self-assigned this Oct 1, 2021
@evan-forbes evan-forbes changed the title Evan/refactor wpfm Refactor the payment module Oct 1, 2021
@evan-forbes evan-forbes changed the base branch from master to evan/regenerate-app October 5, 2021 14:17
@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2021

Codecov Report

Merging #129 (cb9810a) into master (18e69b5) will increase coverage by 12.42%.
The diff coverage is 52.64%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
app/export.go 0.00% <ø> (ø)
x/payment/types/genesis.pb.go 1.69% <0.00%> (+0.02%) ⬆️
x/payment/types/keys.go 0.00% <ø> (ø)
x/payment/types/tx.pb.gw.go 0.00% <0.00%> (ø)
x/payment/types/tx.pb.go 16.49% <16.94%> (+15.45%) ⬆️
x/payment/types/payformessage.go 57.24% <30.43%> (-12.94%) ⬇️
x/payment/types/builder.go 42.60% <50.00%> (ø)
app/abci.go 61.01% <57.14%> (-4.46%) ⬇️
x/payment/types/wirepayformessage.go 68.46% <68.46%> (ø)
app/app.go 82.94% <83.63%> (+0.92%) ⬆️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d061ef0...cb9810a. Read the comment docs.

Copy link
Member Author

@evan-forbes evan-forbes left a 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
Comment on lines 54 to 70
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
}
Copy link
Member Author

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

Comment on lines +45 to +60
// 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,
}
}
Copy link
Member Author

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.

Comment on lines 40 to 43
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
}
Copy link
Member Author

@evan-forbes evan-forbes Oct 6, 2021

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

Copy link
Member

@liamsi liamsi Oct 6, 2021

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.

Copy link
Contributor

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

Copy link
Member

@liamsi liamsi Oct 8, 2021

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.

Comment on lines -16 to +15
TokenDenomination = "token"
TokenDenomination = "tia"
Copy link
Member Author

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".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like tia.

Copy link
Member

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;
Copy link
Member Author

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.

Comment on lines 20 to 26
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;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified wire message

@evan-forbes evan-forbes marked this pull request as ready for review October 6, 2021 03:53
@evan-forbes evan-forbes changed the title Refactor the payment module Refactor how messages are processed Oct 6, 2021
Copy link
Member

@liamsi liamsi left a 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 👏🏼

x/payment/types/wirepayformessage.go Outdated Show resolved Hide resolved
x/payment/types/wirepayformessage.go Outdated Show resolved Hide resolved
}

// 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 {
Copy link
Member

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

Copy link
Member Author

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. 🤷

x/payment/types/payformessage.go Show resolved Hide resolved
@@ -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
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x/payment/types/wirepayformessage.go Outdated Show resolved Hide resolved

// 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")
Copy link
Member

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.

@evan-forbes evan-forbes mentioned this pull request Oct 6, 2021
Base automatically changed from evan/regenerate-app to master October 7, 2021 13:18
@tac0turtle
Copy link
Contributor

tac0turtle commented Oct 8, 2021

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert?

Copy link
Member

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
Comment on lines 10 to 12
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/pkg/consts"
core "github.com/tendermint/tendermint/proto/tendermint/types"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

celestia?

@tac0turtle
Copy link
Contributor

So finally the fees get actually payed by deleting a bunch of code

I cant find where this changed. I dont see the ante handler being touched, so i could be looking in the wrong place

app/abci.go Show resolved Hide resolved
app/app.go Outdated Show resolved Hide resolved
app/export.go Outdated Show resolved Hide resolved
app/genesis.go Outdated Show resolved Hide resolved
x/payment/genesis.go Outdated Show resolved Hide resolved
x/payment/client/cli/tx_wire_pay_for_message.go Outdated Show resolved Hide resolved
x/payment/types/payformessage.go Outdated Show resolved Hide resolved
x/payment/types/payformessage.go Show resolved Hide resolved
x/payment/types/wirepayformessage.go Outdated Show resolved Hide resolved
@liamsi
Copy link
Member

liamsi commented Oct 8, 2021

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.

@liamsi
Copy link
Member

liamsi commented Oct 8, 2021

brief summary with chat with marko:

  • without custom fee logic, the default fee applies (which is locally set and could be zero and which is fine and part of the goal of this PR)
  • if custom logic is necessary just add it to the AnteHandler

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!

@liamsi
Copy link
Member

liamsi commented Oct 8, 2021

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.

OK, this is apparently out of scope for this PR and paying for the blob will be handled in another PR.

evan-forbes and others added 6 commits October 8, 2021 13:49
Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com>
Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com>
Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com>
evan-forbes and others added 3 commits October 8, 2021 14:49
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
@evan-forbes
Copy link
Member Author

evan-forbes commented Oct 8, 2021

it seems there are some unrelated changes in this PR. Are they coming from upstream?

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.

So finally the fees get actually payed by deleting a bunch of code

I cant find where this changed. I dont see the ante handler being touched, so i could be looking in the wrong place

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 MsgPayForMessage are still handled like a normal sdk.Msg, but the rollup data (core.Message) is not yet paid for.

@evan-forbes
Copy link
Member Author

evan-forbes commented Oct 12, 2021

@liamsi @adlerjohn is there anything else needed to merge this PR? it's not blocking anything AFAIK, so no rush or anything

@adlerjohn
Copy link
Member

@evan-forbes

is there anything else needed to merge this PR?

Yes, this one! #129 (comment)

Copy link
Member

@liamsi liamsi left a 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.

Copy link
Member

@adlerjohn adlerjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Redundant Signature Verification in WirePayForMessage
6 participants