-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: add capability to reformat Transactions before broadcasting #12936
Conversation
client/context.go
Outdated
@@ -18,6 +18,9 @@ import ( | |||
sdk "github.com/cosmos/cosmos-sdk/types" | |||
) | |||
|
|||
// ReformatTx allows chains to optionally reformat transactions before broadcasting | |||
type ReformatTxFn func(chainID string, key keyring.KeyType, tx TxBuilder) error |
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 function signature is very non-intuitive. How does the reformatting occur? Where is the tx itself? Why is the TxBuilder called tx? How is someone who wants to reformat a tx meant to express their transformation?
A reformatter should take one version of a thing, and return the reformatted version.
type ReformatTxFn func(txBytes []byte) ([]byte, error)
If you intend to take an abstract Tx interface, then this isn't a Reformatter, it's just a Formatter, I suppose?
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.
Do you have an example of such a function and/or it being used?
The SDK's txbuilder already has a |
Here is an example along the lines of what Evmos would use to reformat EIP-712-signed Ledger transactions for Cosmos. The context would use that function like this:
The main point is that higher level chains currently do not have access to the payload between generating, signing and broadcasting. With this PR, chains can apply custom logic to the |
Ah I see, it's like a client-side hook on when we generate the tx. SGTM, though agreed with #12936 (comment) about naming, maybe we can add the word "Hook" in there? Would like to see a test case in the SDK as well. |
Codecov Report
@@ Coverage Diff @@
## main #12936 +/- ##
==========================================
- Coverage 55.87% 53.36% -2.52%
==========================================
Files 646 648 +2
Lines 54895 55037 +142
==========================================
- Hits 30675 29372 -1303
- Misses 21762 23330 +1568
+ Partials 2458 2335 -123
|
@AmauryM Renamed and added test case |
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.
LGTM! Let's add a changelog and this is good to go
4855260
to
7099011
Compare
@AmauryM Updated with changelog entry |
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.
lgtm! Can you fix the linting errors (make lint-fix
might do it, otherwise manually)?
go.work.sum
Outdated
@@ -1 +1,517 @@ | |||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= |
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.
You should rebase, this file is in the .gitignore
.
@julienrbrt @AmauryM |
…smos#12936) ## Description Increase customized signing capabilities by: - Adding a hook to preprocess transactions before broadcasting This PR introduces the ability to preprocess transactions before broadcasting, a feature that provides the ability to add extensions, or otherwise customize the payload to satisfy a chain's requirements. For adaptability, the parameters include the keytype to allow differentiation between formatting transactions for Ledger vs. software keys. ## PR This PR introduces a hook to preprocess transactions, chiefly to add extensions, from a higher-level chain. Key changes and relevant files: - Add `PreprocessTxFn` type and fields to both `Context` and `Factory` - Instantiate the `Factory` with the `PreprocessTxFn` provided by the `Context` - Call `PreprocessTx` with the appropriate parameters after signing Closes: #XXXX --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
Description
Increase customized signing capabilities by:
This PR introduces the ability to preprocess transactions before broadcasting, a feature that provides the ability to add extensions, or otherwise customize the payload to satisfy a chain's requirements. For adaptability, the parameters include the keytype to allow differentiation between formatting transactions for Ledger vs. software keys.
PR
This PR introduces a hook to preprocess transactions, chiefly to add extensions, from a higher-level chain. Key changes and relevant files:
PreprocessTxFn
type and fields to bothContext
andFactory
Factory
with thePreprocessTxFn
provided by theContext
PreprocessTx
with the appropriate parameters after signingCloses: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change