This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Delay beefy worker initialization while network is on major sync #10705
Closed
Wizdave97
wants to merge
16
commits into
paritytech:master
from
Wizdave97:david/delay-beefy-on-major-sync
Closed
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f6eaef1
delay beefy start on major sync
Wizdave97 b7e28d4
fix conflicts
Wizdave97 ddea83b
use a future to wait on major sync
Wizdave97 befe3d2
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 e88d416
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 44ff51b
Merge branch 'paritytech:master' into david/delay-beefy-on-major-sync
Wizdave97 e104fd1
updated network parameter with sync oracle trait in beefy params
Wizdave97 31b04cb
use waker_by_ref as a tempaorary fix to wake up future
Wizdave97 ecdd381
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 8aca7a1
create a channel for major sync notifications
Wizdave97 65071ae
minor fix
Wizdave97 6ef365f
wrapper major sync sender in Arc
Wizdave97 e3395c6
Merge branch 'paritytech:master' into david/delay-beefy-on-major-sync
Wizdave97 16efe0f
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 0d2a0c7
make SyncOracle usable as trait object
Wizdave97 3675f3e
Merge branch 'david/delay-beefy-on-major-sync' of github.com:Wizdave9…
Wizdave97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -47,10 +47,10 @@ use crate::{ | |||||
metric_inc, metric_set, | ||||||
metrics::Metrics, | ||||||
notification::{BeefyBestBlockSender, BeefySignedCommitmentSender}, | ||||||
round, Client, | ||||||
round, Client, SyncOracle, | ||||||
}; | ||||||
|
||||||
pub(crate) struct WorkerParams<B, BE, C> | ||||||
pub(crate) struct WorkerParams<B, BE, C, SO> | ||||||
where | ||||||
B: Block, | ||||||
{ | ||||||
|
@@ -63,14 +63,16 @@ where | |||||
pub gossip_validator: Arc<GossipValidator<B>>, | ||||||
pub min_block_delta: u32, | ||||||
pub metrics: Option<Metrics>, | ||||||
pub sync_oracle: SO, | ||||||
} | ||||||
|
||||||
/// A BEEFY worker plays the BEEFY protocol | ||||||
pub(crate) struct BeefyWorker<B, C, BE> | ||||||
pub(crate) struct BeefyWorker<B, C, BE, SO> | ||||||
where | ||||||
B: Block, | ||||||
BE: Backend<B>, | ||||||
C: Client<B, BE>, | ||||||
SO: SyncOracle + Send + Sync + Clone + 'static, | ||||||
{ | ||||||
client: Arc<C>, | ||||||
backend: Arc<BE>, | ||||||
|
@@ -91,24 +93,27 @@ where | |||||
beefy_best_block_sender: BeefyBestBlockSender<B>, | ||||||
/// Validator set id for the last signed commitment | ||||||
last_signed_id: u64, | ||||||
/// Handle to the sync oracle | ||||||
sync_oracle: SO, | ||||||
// keep rustc happy | ||||||
_backend: PhantomData<BE>, | ||||||
} | ||||||
|
||||||
impl<B, C, BE> BeefyWorker<B, C, BE> | ||||||
impl<B, C, BE, SO> BeefyWorker<B, C, BE, SO> | ||||||
where | ||||||
B: Block + Codec, | ||||||
BE: Backend<B>, | ||||||
C: Client<B, BE>, | ||||||
C::Api: BeefyApi<B>, | ||||||
SO: SyncOracle + Send + Sync + Clone + 'static, | ||||||
{ | ||||||
/// Return a new BEEFY worker instance. | ||||||
/// | ||||||
/// Note that a BEEFY worker is only fully functional if a corresponding | ||||||
/// BEEFY pallet has been deployed on-chain. | ||||||
/// | ||||||
/// The BEEFY pallet is needed in order to keep track of the BEEFY authority set. | ||||||
pub(crate) fn new(worker_params: WorkerParams<B, BE, C>) -> Self { | ||||||
pub(crate) fn new(worker_params: WorkerParams<B, BE, C, SO>) -> Self { | ||||||
let WorkerParams { | ||||||
client, | ||||||
backend, | ||||||
|
@@ -119,6 +124,7 @@ where | |||||
gossip_validator, | ||||||
min_block_delta, | ||||||
metrics, | ||||||
sync_oracle, | ||||||
} = worker_params; | ||||||
|
||||||
BeefyWorker { | ||||||
|
@@ -136,17 +142,19 @@ where | |||||
best_beefy_block: None, | ||||||
last_signed_id: 0, | ||||||
beefy_best_block_sender, | ||||||
sync_oracle, | ||||||
_backend: PhantomData, | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
impl<B, C, BE> BeefyWorker<B, C, BE> | ||||||
impl<B, C, BE, SO> BeefyWorker<B, C, BE, SO> | ||||||
where | ||||||
B: Block, | ||||||
BE: Backend<B>, | ||||||
C: Client<B, BE>, | ||||||
C::Api: BeefyApi<B>, | ||||||
SO: SyncOracle + Send + Sync + Clone + 'static, | ||||||
{ | ||||||
/// Return `true`, if we should vote on block `number` | ||||||
fn should_vote_on(&self, number: NumberFor<B>) -> bool { | ||||||
|
@@ -400,6 +408,11 @@ where | |||||
)); | ||||||
|
||||||
loop { | ||||||
if self.sync_oracle.is_major_syncing() { | ||||||
debug!(target: "beefy", "Skipping initialization due to sync."); | ||||||
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 is not necessarily initialization, it is the main loop of the worker. I would rephrase to smth like:
Suggested change
|
||||||
continue | ||||||
} | ||||||
|
||||||
acatangiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
let engine = self.gossip_engine.clone(); | ||||||
let gossip_engine = future::poll_fn(|cx| engine.lock().poll_unpin(cx)); | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would these two ever be provided by different objects? If not, I think it would make sense to simply squash them together, they're both mandatory anyway...