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

x/payment/pfd.go: Add canonical PFD constructor/signer/submittor methods #352

Merged
merged 2 commits into from Apr 25, 2022

Conversation

renaynay
Copy link
Member

This PR adds 3 methods:

  • BuildPayForData
  • SignPayForData
  • SubmitPayForData

Celestia-node (and other repos depending on this message type) should import these methods from app.

Once this PR is merged, I will close celestiaorg/celestia-node#619 and reopen a PR that updates the celestia-app dep to the latest celestia-app release and uses these methods under the hood.

Copy link
Member

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

I think we should also create an issue to see if we can also reduce the exposed API after introducing these.

Only one suggested change, wish we would have thought to move this to the app after the dalc or even sooner. Really great work @renaynay . I think this will save countless headaches and foot guns.

x/payment/pfd.go Outdated
Comment on lines 85 to 89
// SignPayForData signs a PayForData transaction.
func SignPayForData(
signer *types.KeyringSigner,
pfd *types.MsgWirePayForData,
gasLimOption types.TxBuilderOption,
Copy link
Member

Choose a reason for hiding this comment

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

instead of doing only a gasLim option, do you think it makes sense to do ...types.TxBuilderOption?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

@evan-forbes does the gas lim get set by default if no TxBuilderOption is included for it?

Copy link
Member

Choose a reason for hiding this comment

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

not 100% sure, but I don't think so

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay can you check this commit to see how i've implemented it: 931fbd5

x/payment/pfd.go Outdated
Comment on lines 15 to 19
var (
// shareSizes includes all the possible share sizes of the given data
// that the signer must sign over.
shareSizes = []uint64{16, 32, 64, 128}
)
Copy link
Member

Choose a reason for hiding this comment

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

would prefer not to hardcode these, but I also think its ok to merge as is, considering that we have #239 and #236

x/payment/pfd.go Outdated
Comment on lines 21 to 51
// SubmitPayForData constructs, signs and synchronously submits a PayForData
// transaction, returning a sdk.TxResponse upon submission.
func SubmitPayForData(
ctx context.Context,
signer *types.KeyringSigner,
conn *grpc.ClientConn,
nID namespace.ID,
data []byte,
gasLim uint64,
) (*sdk.TxResponse, error) {
pfd, err := BuildPayForData(ctx, signer, conn, nID, data, gasLim)
if err != nil {
return nil, err
}

signed, err := SignPayForData(signer, pfd, types.SetGasLimit(gasLim))
if err != nil {
return nil, err
}

rawTx, err := signer.EncodeTx(signed)
if err != nil {
return nil, err
}

txResp, err := types.BroadcastTx(ctx, conn, sdk_tx.BroadcastMode_BROADCAST_MODE_BLOCK, rawTx)
if err != nil {
return nil, err
}
return txResp.TxResponse, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

finally, the prophesied good api for submitting a payForData has come 🙌

@evan-forbes
Copy link
Member

oh shoot, one last thing minor nit pick, I would prefer to name the file something else instead of the shorthand version, just to be consistent.

Copy link
Member

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

🏋️ 💯

@evan-forbes evan-forbes merged commit 56c82ec into celestiaorg:master Apr 25, 2022
@renaynay renaynay deleted the add-pfd-endpoint branch April 25, 2022 18:45
@adlerjohn adlerjohn added app enhancement New feature or request labels Apr 25, 2022
renaynay added a commit to renaynay/celestia-app that referenced this pull request Apr 27, 2022
…thods (celestiaorg#352)

* feat: add canonical PFD constructor/signer/submittor methods to payment module

* refactor: add types.TxBuilderOpts as param for SubmitPayForData | rename pfd.go to payfordata.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants