-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: share SnapshotProvider
through ProviderFactory
#5249
Conversation
@@ -295,7 +295,9 @@ impl<Ext: RethCliExt> NodeCommand<Ext> { | |||
let head = self.lookup_head(Arc::clone(&db)).wrap_err("the head block is missing")?; | |||
|
|||
// setup the blockchain provider | |||
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain)); | |||
let (highest_snapshots_tx, highest_snapshots_rx) = watch::channel(None); | |||
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain)) |
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.
am i correct to understand that this will be shared across all components that might create providers?
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.
through blockchain_db
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.
yes
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's getting a bit harder for me to maintain an overview of all components and how they'll fit together.
we need a proper overview and docs.
The Snapshotter::new
needs more docs, unclear what the watch channel does.
after having a closer look at how the channel is currently used
do we care if the value changed or if is sufficient to just get the current highest snapshot?
because this is essentially an Rwlock that keeps track of changes
/// Snapshot Provider | ||
snapshot_provider: Option<Arc<SnapshotProvider>>, |
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 this is a reasonable location for the snapshot integration, otherwise we'd need to integrate it into the BlockchainProvider, which I guess would also be suitable.
ref #5270 <- overview docs |
It should be sufficient to get the current one. Even if a new one comes the moment i'm reading the old one, it just means that the new snapshot files were just created. Data hasn't been deleted yet, that's the |
@@ -1071,6 +1071,7 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> { | |||
let provider = DatabaseProvider::new_rw( | |||
self.externals.db.tx_mut()?, | |||
self.externals.chain_spec.clone(), | |||
None, |
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 don't like that this extra argument is now required
bin/reth/src/node/mod.rs
Outdated
@@ -295,7 +295,9 @@ impl<Ext: RethCliExt> NodeCommand<Ext> { | |||
let head = self.lookup_head(Arc::clone(&db)).wrap_err("the head block is missing")?; | |||
|
|||
// setup the blockchain provider | |||
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain)); | |||
let (highest_snapshots_tx, highest_snapshots_rx) = watch::channel(None); |
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.
where does the sender go here, looks unused now.
I think we should consider hiding this channel and move instantiation to the Snapshotter instead, it can keep both halfs and return a new receiver on demand
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.
Lines 469 to 474 in 113ef23
let _snapshotter = reth_snapshot::Snapshotter::new( | |
db, | |
self.chain.clone(), | |
self.chain.snapshot_block_interval, | |
highest_snapshots_tx, | |
); |
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 still makes sense to move it inside
|
||
/// SnapshotProvider | ||
#[derive(Debug, Default)] | ||
pub struct SnapshotProvider { | ||
/// Maintains a map which allows for concurrent access to different `NippyJars`, over different | ||
/// segments and ranges. | ||
map: DashMap<(BlockNumber, SnapshotSegment), LoadedJar>, | ||
/// Tracks the latest and highest snapshot of every segment. | ||
highest_tracker: Option<watch::Receiver<Option<HighestSnapshots>>>, |
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.
can we reuse HighestSnapshotsTracker
here?
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.
that would mean adding tokio as a dependency to primitives, and I didn't want to add that tbh
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.
that would mean adding tokio as a dependency to primitives
sorry I don't understand, HighestSnapshotsTracker
is in reth-snapshot
crate that we already use as a dependency in reth-provider
, no?
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
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.
suggesting to replace the watch channel with SnapshotTracker {Arc<Rwlock>}
wrapper type
let _ = self.highest_snapshots_notifier.send(Some(self.highest_snapshots)).map_err(|_| { | ||
warn!(target: "snapshot", "Highest snapshots channel closed"); | ||
}); | ||
} |
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 error can safely be ignored because it's kept open by having both as fields
highest_snapshots: HighestSnapshots, | ||
highest_snapshots_tracker: watch::Sender<Option<HighestSnapshots>>, | ||
/// Channel sender to notify other components of the new highest snapshots | ||
highest_snapshots_notifier: watch::Sender<Option<HighestSnapshots>>, |
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.
do we expect features that need to listen for changed snapshots?
if not perhaps we could just use an rwlock wrapper type? because a watch channel is also just an rwlock with some add ons.
if we need listeners for snapshots we can add this separately
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.
yeah, agree. i'll do it in a further PR if that's okay
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.
@@ -295,7 +295,9 @@ impl<Ext: RethCliExt> NodeCommand<Ext> { | |||
let head = self.lookup_head(Arc::clone(&db)).wrap_err("the head block is missing")?; | |||
|
|||
// setup the blockchain provider | |||
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain)); | |||
let (highest_snapshots_tx, highest_snapshots_rx) = watch::channel(None); | |||
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain)) |
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.
yes
SnapshotProvider
toProviderFactory
&DatabaseProvider