-
Notifications
You must be signed in to change notification settings - Fork 521
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
Add runtime API ConvertTransactionRuntime API
#559
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ members = [ | |
"primitives/self-contained", | ||
"template/node", | ||
"template/runtime", | ||
] | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,8 +177,26 @@ sp_api::decl_runtime_apis! { | |
/// Return the elasticity multiplier. | ||
fn elasticity() -> Option<Permill>; | ||
} | ||
|
||
#[api_version(2)] | ||
pub trait ConvertTransactionRuntimeApi { | ||
fn convert_transaction(transaction: ethereum::TransactionV2) -> <Block as BlockT>::Extrinsic; | ||
#[changed_in(2)] | ||
fn convert_transaction(transaction: ethereum::TransactionV0) -> <Block as BlockT>::Extrinsic; | ||
} | ||
} | ||
|
||
pub trait ConvertTransaction<E> { | ||
fn convert_transaction(&self, transaction: ethereum::TransactionV2) -> E; | ||
} | ||
|
||
// `NoTransactionConverter` is a non-instantiable type (an enum with no variants), | ||
// so we are guaranteed at compile time that `NoTransactionConverter` can never be instantiated. | ||
pub enum NoTransactionConverter {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this actually used? Do we actually have a situation where transaction conversion is just not possible or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have this type, then why do you still have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I get it. I use this only as a type parameter. and use |
||
impl<E> ConvertTransaction<E> for NoTransactionConverter { | ||
// `convert_transaction` is a method taking `&self` as a parameter, so it can only be called via an instance of type Self, | ||
// so we are guaranteed at compile time that this method can never be called. | ||
fn convert_transaction(&self, _transaction: ethereum::TransactionV2) -> E { | ||
unreachable!() | ||
} | ||
} |
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.
Consider changing this to with RLPVec<u8>
as input, and returnOption<Extrinsic>
whereNone
indicates that the conversion failed.Ethereum transaction's RLP encoding is backward and future compatible, but not really the SCALE encoding, as that's internal. Doing the above ensures that when runtime updates to support a new transaction type, you can immediately use it without waiting for old nodes to update. With this you can also remove the versioning.
Also, is there a particular reason that this isn't put into
EthereumRuntimeRPCApi
?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.
Hmm I realized that our
EthereumRuntimeRPCApi
is not forward compatible anyway, so the above (using RLPVec<u8>
as input) may not provide much benefits.The other points still stands -- maybe consider moving this to
EthereumRuntimeRPCApi
.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 decided to have it in a separate trait so that the client can ask if the API is present or not.
Indeed, substrate does not allow to ask if a particular method of a runtime api is present or not.