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

Helper for composing tx decoders #1922

Closed
4 tasks
notatestuser opened this issue Aug 6, 2018 · 5 comments
Closed
4 tasks

Helper for composing tx decoders #1922

notatestuser opened this issue Aug 6, 2018 · 5 comments

Comments

@notatestuser
Copy link

notatestuser commented Aug 6, 2018

Summary

Feature request: Add a helper for composing tx decoders

Problem Definition

Right now we can give baseapp a single decoder like so:

NewBaseApp(name, logger, db, txDecoder(cdc))

but it would be great if we could compose multiple decoders together:

NewBaseApp(name, logger, db, sdk.ComposeTxDecoders(cdc, txDecoderOne, txDecoderTwo, ...))

not sure what kind of magic would exist in this method but we should be able to add and remove decoders without affecting the implementations of the others.

This would make it easier to include the decoders in x plugins to plug them in as new tx types are coded up.

Disadvantages: Breaks existing API? maybe not depending on implementation

Proposal

NewBaseApp(name, logger, db, sdk.ComposeTxDecoders(cdc, txDecoderOne, txDecoderTwo, ...))

or

NewBaseApp(name, logger, db, cdc.ComposeTxDecoders(txDecoderOne, txDecoderTwo, ...))

This would require implementing ComposeTxDecoders and handling it

Later thought: There might be two behaviours here - one that "waterfalls" down from the top passing the result of each decoder to the next one in the list and another that tries each decoder until one returns a non-nil tx.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez
Copy link
Contributor

There might be two behaviours here - one that "waterfalls" down from the top passing the result of each decoder to the next one in the list and another that tries each decoder until one returns a non-nil tx.

Seems a bit dangerous here. There is a now an options argument you can pass to the app. Perhaps if/when we need this in the future, one of these options could be to "register" a tx decoder for a particular tx. That way a lookup could be done based on the tx.

@ValarDragon
Copy link
Contributor

This sort of composition doesn't seem like something we should apply globally. I think its better if the app just writes the custom composition logic they expect. (The cases where you want multiple tx decoders seems rare to me. We're working on an EVM module, so that decoding stuff will be handled within that module)

@notatestuser
Copy link
Author

notatestuser commented Aug 7, 2018

Currently have some txs coming through in a non standard format to test the performance implications. So I just use the multiple decoders to handle these. I suppose it’s not going to be a really common thing but wanted to suggest this anyway.

To address the other comment above the decoder sig could be changed so that there is a “next” function to pass control down to the next decoder in the stack. This avoids the need for a type to decoder mapping and that would work more like middleware.

@ValarDragon
Copy link
Contributor

ValarDragon commented Aug 8, 2018

I do think your right, there is a reasonable way to cascade this. I'm just not sure if this is api which is common enough to justify inclusion in every app. I could totally see having a separate module down the line for "baseapp helper methods", which aren't used in the default modules. (For cases like this where we don't expect many people to use it)

@jackzampolin
Copy link
Member

We currently only have 1 transaction decoder in the SDK and have not seen a feature request for additional decoders. I'm going to close this issue as out of scope.

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

No branches or pull requests

5 participants