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

chore(sdk): define helper trait BlockPrimitives #12721

Closed
wants to merge 2 commits into from
Closed

Conversation

emhane
Copy link
Member

@emhane emhane commented Nov 20, 2024

Based on #12647

  • Defines helper trait BlockPrimitives, which links NodePrimitives::Block to NodePrimitives::BlockHeader, NodePrimitives::BlockBody and NodePrimitives::SignedTransaction. This makes the trait bounds necessary on impl bodies much less verbose!
  • Makes NodePrimitives super trait of FullNodePrimitives, as it allows for the transition FullNodePrimitives -> 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 because FullNodeComponents 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.

@emhane emhane added C-debt A clean up/refactor of existing code A-sdk Related to reth's use as a library labels Nov 20, 2024
@emhane emhane changed the base branch from main to emhane/node-prims-block-parts November 20, 2024 22:35
@klkvr
Copy link
Member

klkvr commented Nov 20, 2024

  • Fixes bug in stages. Bug: writing compact encoded signed transaction instead of the unsigned transaction to db

I believe we've been always writing signed transaction to both static files and database?

pub fn append_transaction(
&mut self,
tx_num: TxNumber,
tx: &TransactionSignedNoHash,
) -> ProviderResult<TxNumber> {

table Transactions<Key = TxNumber, Value = TransactionSignedNoHash>;

@emhane
Copy link
Member Author

emhane commented Nov 20, 2024

  • Fixes bug in stages. Bug: writing compact encoded signed transaction instead of the unsigned transaction to db

I believe we've been always writing signed transaction to both static files and database?

pub fn append_transaction(
&mut self,
tx_num: TxNumber,
tx: &TransactionSignedNoHash,
) -> ProviderResult<TxNumber> {

table Transactions<Key = TxNumber, Value = TransactionSignedNoHash>;

TransactionSigned doesn't impl Compact though

@klkvr
Copy link
Member

klkvr commented Nov 20, 2024

It does since #12539

related discussion #12694 (comment)

@emhane
Copy link
Member Author

emhane commented Nov 20, 2024

then it should impl Compact, but it doesn't. before StaticFileProviderRW::append_transaction took TransactionSignedNoHash. @klkvr

@klkvr
Copy link
Member

klkvr commented Nov 20, 2024

then it should impl Compact, but it doesn't

It does impl Compact

impl reth_codecs::Compact for TransactionSigned {

before StaticFileProviderRW::append_transaction took TransactionSignedNoHash

yep, but now it takes anything that implements Compact (should probably change that to N::SignedTx given that we have primitives on StaticFileProvider now)

sorry for the confusion with the 2 storage types, I was expecting the TransactionSignedNoHash to be gone by now

@emhane
Copy link
Member Author

emhane commented Nov 20, 2024

ok nvm, switching between a lot of branches to shrink scope, my bad

@emhane
Copy link
Member Author

emhane commented Nov 20, 2024

re-request review @klkvr


/// Helper trait that links [`NodePrimitives::Block`] to [`NodePrimitives::BlockHeader`],
/// [`NodePrimitives::BlockBody`] and [`NodePrimitives::SignedTx`].
pub trait BlockPrimitives:
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

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

Base automatically changed from emhane/node-prims-block-parts to main November 21, 2024 17:18
@emhane emhane force-pushed the emhane/block-prims branch from 16c938d to 831a6da Compare November 24, 2024 09:09
Comment on lines +108 to +110
/// Helper trait that links [`NodePrimitives::Block`] to [`NodePrimitives::BlockHeader`],
/// [`NodePrimitives::BlockBody`] and [`NodePrimitives::SignedTx`].
pub trait BlockPrimitives:
Copy link
Collaborator

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?

Copy link
Member Author

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;
Copy link
Collaborator

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

@emhane emhane requested a review from mattsse November 25, 2024 09:00
@emhane
Copy link
Member Author

emhane commented Nov 25, 2024

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

@emhane emhane closed this Nov 25, 2024
@emhane emhane deleted the emhane/block-prims branch March 5, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sdk Related to reth's use as a library C-debt A clean up/refactor of existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants