-
Notifications
You must be signed in to change notification settings - Fork 903
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
Replace Tree generic with Arc<dyn TreeViewer> #7615
Comments
May I? |
assigned |
Hello! I just started working on this issue and noticed the following structures: impl<DB, Tree> BlockchainTreeEngine for BlockchainProvider<DB, Tree>
where
DB: Send + Sync,
Tree: BlockchainTreeEngine,
{
// ...
}
impl<DB, Tree> BlockchainTreePendingStateProvider for BlockchainProvider<DB, Tree>
where
DB: Send + Sync,
Tree: BlockchainTreePendingStateProvider,
{
fn find_pending_state_provider(
&self,
block_hash: BlockHash,
) -> Option<Box<dyn BundleStateDataProvider>> {
self.tree.find_pending_state_provider(block_hash)
}
}
impl<DB, Tree> CanonStateSubscriptions for BlockchainProvider<DB, Tree>
where
DB: Send + Sync,
Tree: CanonStateSubscriptions,
{
fn subscribe_to_canonical_state(&self) -> CanonStateNotifications {
self.tree.subscribe_to_canonical_state()
}
} If we intend to change to #[derive(Clone, Debug)]
pub struct BlockchainProvider<DB> {
/// Provider type used to access the database.
database: ProviderFactory<DB>,
/// The blockchain tree instance.
tree: Arc<dyn BlockchainTreeViewer>,
/// Tracks the chain info wrt forkchoice updates
chain_info: ChainInfoTracker,
} Correct me if I'm wrong. From what I can see: The The Maybe I need to create a new trait, UPD: And yeah, a tree viewer should definitely not contain cc @mattsse |
this is a good point, I think what we want is a trait that unifies all the functions we need for the BlockchainProvider so that we have a single trait we can use as dyn |
Got it, so I'll proceed with the creation of a unified trait But what do we do with |
sg!
if unused can be removed |
@KyrylR just checking in this will become a blocker shortly |
Hello, sorry for the delay |
cool! |
I have a few more questions Right now I am heading in the direction with such a trait: pub trait TreeViewer:
BlockchainTreeViewer
+ BlockchainTreePendingStateProvider
+ CanonStateSubscriptions
+ BlockchainTreeEngine
{
} So, we have such a structure in the end: #[derive(Clone)]
#[allow(missing_debug_implementations)]
pub struct BlockchainProvider<DB> {
/// Provider type used to access the database.
database: ProviderFactory<DB>,
/// The blockchain tree instance.
tree: Arc<dyn TreeViewer>,
/// Tracks the chain info wrt forkchoice updates
chain_info: ChainInfoTracker,
} Is this the intended way? For me, it feels not right I am not a full-time Rust dev, so I could still miss some obvious details By the keyword I cannot define anything alongside
Are you referring to the TreeViewer that I intend to create? Off-topic: Is it okay to tag you when I have a question? Or is a simple message enough? cc @mattsse |
anytime, can also DM on tg @mattsse this looks okay, we need to combine all traits we use in the the impls, with a helper trait like you did, this is only a temporary solution but is what we want |
Got it, the last point where I encounter a problem is with pub struct ShareableBlockchainTree<DB, EF> {
/// BlockchainTree
pub tree: Arc<RwLock<BlockchainTree<DB, EF>>>,
} I am trying to reuse it like this: let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree));
// Set up the blockchain provider
let blockchain_db =
BlockchainProvider::new(provider_factory.clone(), blockchain_tree.clone())?; But the problem that I see is the structure of this code is Arc -> Arc -> BlockchainTree Is this ok? cc @mattsse |
Describe the feature
This generic doesn't have any performance benefits because it's just just for simple get calls, which will also be refactored shortly.
It would make the setup a lot more convenient if we'd use
Arc< dyn TreeViewer>
here instead. Treeviewer trait is object safe so this should be very simple.reth/crates/storage/provider/src/providers/mod.rs
Lines 74 to 75 in 041e293
This would let us cut down on a bunch of bloated types in the node-builder
reth/crates/node-builder/src/builder.rs
Lines 63 to 64 in 041e293
and allows us to be less constraint during the node-builder setup
Additional context
No response
The text was updated successfully, but these errors were encountered: