-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
use core::fmt; | ||
|
||
use crate::{ | ||
FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, FullSignedTx, FullTxType, MaybeSerde, | ||
Block, BlockBody, BlockHeader, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, | ||
FullSignedTx, FullTxType, MaybeSerde, SignedTransaction, | ||
}; | ||
|
||
/// Configures all the primitive types of the node. | ||
|
@@ -77,46 +78,74 @@ impl NodePrimitives for () { | |
} | ||
|
||
/// Helper trait that sets trait bounds on [`NodePrimitives`]. | ||
pub trait FullNodePrimitives | ||
where | ||
Self: NodePrimitives< | ||
Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>, | ||
BlockHeader: FullBlockHeader, | ||
BlockBody: FullBlockBody<Transaction = Self::SignedTx>, | ||
SignedTx: FullSignedTx, | ||
TxType: FullTxType, | ||
Receipt: FullReceipt, | ||
> + Send | ||
+ Sync | ||
+ Unpin | ||
+ Clone | ||
+ Default | ||
+ fmt::Debug | ||
+ PartialEq | ||
+ Eq | ||
+ 'static, | ||
pub trait FullNodePrimitives: | ||
NodePrimitives< | ||
Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody> + 'static, | ||
BlockHeader: FullBlockHeader + 'static, | ||
BlockBody: FullBlockBody<Transaction = Self::SignedTx> + 'static, | ||
SignedTx: FullSignedTx + 'static, | ||
TxType: FullTxType + 'static, | ||
Receipt: FullReceipt + 'static, | ||
> | ||
{ | ||
} | ||
|
||
impl<T> FullNodePrimitives for T where | ||
T: NodePrimitives< | ||
Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>, | ||
BlockHeader: FullBlockHeader, | ||
BlockBody: FullBlockBody<Transaction = Self::SignedTx>, | ||
SignedTx: FullSignedTx, | ||
TxType: FullTxType, | ||
Receipt: FullReceipt, | ||
> + Send | ||
+ Sync | ||
+ Unpin | ||
+ Clone | ||
+ Default | ||
+ fmt::Debug | ||
+ PartialEq | ||
+ Eq | ||
+ 'static | ||
Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody> + 'static, | ||
BlockHeader: FullBlockHeader + 'static, | ||
BlockBody: FullBlockBody<Transaction = Self::SignedTx> + 'static, | ||
SignedTx: FullSignedTx + 'static, | ||
TxType: FullTxType + 'static, | ||
Receipt: FullReceipt + 'static, | ||
> | ||
{ | ||
} | ||
|
||
/// Helper adapter type for accessing [`NodePrimitives`] receipt type. | ||
pub type ReceiptTy<N> = <N as NodePrimitives>::Receipt; | ||
|
||
/// Helper trait that links [`NodePrimitives::Block`] to [`NodePrimitives::BlockHeader`], | ||
/// [`NodePrimitives::BlockBody`] and [`NodePrimitives::SignedTx`]. | ||
pub trait BlockPrimitives: | ||
Comment on lines
+108
to
+110
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. unclear what the benefit here is 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. it links the block type to the header, body and signed tx types. it should be used in places where |
||
NodePrimitives< | ||
Block: Block<Header = Self::BlockHeader, Body = Self::BlockBody>, | ||
BlockHeader: BlockHeader, | ||
BlockBody: BlockBody<Transaction = Self::SignedTx>, | ||
SignedTx: SignedTransaction, | ||
> | ||
{ | ||
} | ||
|
||
impl<T> BlockPrimitives for T where | ||
T: NodePrimitives< | ||
Block: Block<Header = T::BlockHeader, Body = T::BlockBody>, | ||
BlockHeader: BlockHeader, | ||
BlockBody: BlockBody<Transaction = T::SignedTx>, | ||
SignedTx: SignedTransaction, | ||
> | ||
{ | ||
} | ||
|
||
/// Helper trait like [`BlockPrimitives`], but with encoding trait bounds on | ||
/// [`NodePrimitives::Block`], [`NodePrimitives::BlockHeader`], [`NodePrimitives::BlockBody`] and | ||
/// [`NodePrimitives::SignedTx`]. | ||
pub trait FullBlockPrimitives: | ||
NodePrimitives< | ||
Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>, | ||
BlockHeader: FullBlockHeader, | ||
BlockBody: FullBlockBody<Transaction = Self::SignedTx>, | ||
SignedTx: FullSignedTx, | ||
> | ||
{ | ||
} | ||
|
||
impl<T> FullBlockPrimitives for T where | ||
T: NodePrimitives< | ||
Block: FullBlock<Header = T::BlockHeader, Body = T::BlockBody>, | ||
BlockHeader: FullBlockHeader, | ||
BlockBody: FullBlockBody<Transaction = T::SignedTx>, | ||
SignedTx: FullSignedTx, | ||
> | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
|
||
fn tx_hash(&self) -> &TxHash { | ||
self.hash_ref() | ||
|
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 toNodePrimitives
?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
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 ofBlockPrimitives
, is that in case it's needed, a trait impl usingBlockPrimitives
, can still return a receipt type, just not use the receipt functionality in its scopeThere 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 areFullNodePrimitives
so I don't think you will be able to test anything with such primitives implementationThere 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 usefulThere 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 useFullNodePrimitives
everywhere