-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
chore(sdk): define helper trait BlockPrimitives
#12721
Conversation
I believe we've been always writing signed transaction to both static files and database? reth/crates/storage/provider/src/providers/static_file/writer.rs Lines 543 to 547 in 166a234
reth/crates/storage/db/src/tables/mod.rs Line 295 in 166a234
|
|
It does since #12539 related discussion #12694 (comment) |
then it should impl |
It does impl reth/crates/primitives/src/transaction/mod.rs Line 1054 in e3702cf
yep, but now it takes anything that implements sorry for the confusion with the 2 storage types, I was expecting the TransactionSignedNoHash to be gone by now |
ok nvm, switching between a lot of branches to shrink scope, my bad |
c41edd0
to
ffad861
Compare
re-request review @klkvr |
|
||
/// Helper trait that links [`NodePrimitives::Block`] to [`NodePrimitives::BlockHeader`], | ||
/// [`NodePrimitives::BlockBody`] and [`NodePrimitives::SignedTx`]. | ||
pub trait BlockPrimitives: |
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.
unsure I understand why we need a separate trait for this? those bounds already exist for FullNodePrimitives
, and I believe we could also move them to NodePrimitives
?
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.
for the same reason we don't have the compact feature reth-codec
always enabled, cc @joshieDo . it makes testing more straight forward and it makes it more apparent to us how data flows in reth.
if you want to test for example consensus engine, you should just need an impl like
impl NodePrimitives for TestPrimitives {
type Block = Block;
type BlockHeader = Header;
type BlockBody = BlockBody;
type SignedTx = TransactionSigned;
type TxType = ();
type Receipt = ();
}
it's always misleading a weird for someone new to the code, to try and figure out how the code works by looking at the test, and then realise half way through that types are in scope, that are not used.
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.
nice side effect of having NodePrimitives
as super trait of BlockPrimitives
, is that in case it's needed, a trait impl using BlockPrimitives
, can still return a receipt type, just not use the receipt functionality in its scope
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.
ProviderFactory
won't work unless primitives are FullNodePrimitives
so I don't think you will be able to test anything with such primitives implementation
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.
I think it might make sense to move those bounds to NodePrimitives
but separate trait doesn't seem very useful
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.
provider is expected to use FullNodePrimitives
in some places. node builder is expected to use FullNodePrimitives
everywhere
16c938d
to
831a6da
Compare
/// Helper trait that links [`NodePrimitives::Block`] to [`NodePrimitives::BlockHeader`], | ||
/// [`NodePrimitives::BlockBody`] and [`NodePrimitives::SignedTx`]. | ||
pub trait BlockPrimitives: |
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.
unclear what the benefit here is
what does this unblock?
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.
it links the block type to the header, body and signed tx types. it should be used in places where FullNodePrimitives
is not needed, and simplifies having to specify the super trait of BlockPrimitives
everywhere, i.e. N: NodePrimitives<Block: Block<Header = N::BlockHeader, ..>, ..>
to link the blockparts and tx to the block type
@@ -1265,6 +1265,7 @@ impl TransactionSigned { | |||
|
|||
impl SignedTransaction for TransactionSigned { | |||
type Type = TxType; | |||
type Transaction = Transaction; |
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 was removed because this AT, didn't make much sense that a transaction defines a transaction
since we won't have access to a base trait without trait bounds on associated types since #12846, there is no need for this pr |
Based on #12647
BlockPrimitives
, which linksNodePrimitives::Block
toNodePrimitives::BlockHeader
,NodePrimitives::BlockBody
andNodePrimitives::SignedTransaction
. This makes the trait bounds necessary on impl bodies much less verbose!NodePrimitives
super trait ofFullNodePrimitives
, as it allows for the transitionFullNodePrimitives
->BlockPrimitives
->NodePrimitives
.NOTE: the reason I didn't do this in the first place is because I copied the pattern of
FullNodeComponents
->RpcNodeCore
used to simplify type definitions, introduced becauseFullNodeComponents
wasn't built from a base trait without trait bounds (and re-writing that would have been a too big change for the task). Here we have the opportunity to have a plain (trait unbound) super trait though since we're writing primitives from scratch.