Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add sync oracle to overseer
  • Loading branch information
tdimitrov committed Feb 9, 2023
commit ae29bb4d7d0d053361a4413e73746cbdca8c81e8
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/overseer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ orchestra = "0.0.4"
gum = { package = "tracing-gum", path = "../gum" }
lru = "0.9"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
async-trait = "0.1.57"
tikv-jemalloc-ctl = "0.5.0"

Expand Down
5 changes: 3 additions & 2 deletions node/overseer/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::{
prometheus::Registry, HeadSupportsParachains, InitializedOverseerBuilder, MetricsTrait,
Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnGlue,
prometheus::Registry, HeadSupportsParachains, InitializedOverseerBuilder, MajorSyncOracle,
MetricsTrait, Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnGlue,
KNOWN_LEAVES_CACHE_SIZE,
};
use lru::LruCache;
Expand Down Expand Up @@ -193,6 +193,7 @@ where
.leaves(Default::default())
.spawner(SpawnGlue(spawner))
.metrics(metrics)
.sync_oracle(MajorSyncOracle::new_dummy())
.supports_parachains(supports_parachains);
Ok(builder)
}
36 changes: 36 additions & 0 deletions node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ use polkadot_node_subsystem_types::messages::{
DisputeDistributionMessage, GossipSupportMessage, NetworkBridgeRxMessage,
NetworkBridgeTxMessage, ProvisionerMessage, RuntimeApiMessage, StatementDistributionMessage,
};
use sp_consensus::SyncOracle;

pub use polkadot_node_subsystem_types::{
errors::{SubsystemError, SubsystemResult},
Expand Down Expand Up @@ -330,6 +331,38 @@ pub async fn forward_events<P: BlockchainEvents<Block>>(client: Arc<P>, mut hand
}
}

/// Used to detect if the node is in major sync. This can happen only on startup so once syncing is
/// done the node is considered up to date and `finished_syncing` will always return `true`.
pub struct MajorSyncOracle {
sync_oracle: Option<Box<dyn SyncOracle + Send>>,
}

impl MajorSyncOracle {
/// Create `MajorSyncOracle` from `SyncOracle`
pub fn new(sync_oracle: Box<dyn SyncOracle + Send>) -> Self {
Self { sync_oracle: Some(sync_oracle) }
}

/// Create dummy `MajorSyncOracle` which always returns true for `finished_syncing`
pub fn new_dummy() -> Self {
Self { sync_oracle: None }
}

/// Check if node is in major sync
pub fn finished_syncing(&mut self) -> bool {
match &mut self.sync_oracle {
Some(sync_oracle) =>
if !sync_oracle.is_major_syncing() {
self.sync_oracle = None;
true
} else {
false
},
None => true,
}
}
}

/// Create a new instance of the [`Overseer`] with a fixed set of [`Subsystem`]s.
///
/// This returns the overseer along with an [`OverseerHandle`] which can
Expand Down Expand Up @@ -629,6 +662,9 @@ pub struct Overseer<SupportsParachains> {

/// Various Prometheus metrics.
pub metrics: OverseerMetrics,

/// SyncOracle is used to detect when initial full node sync is complete
pub sync_oracle: MajorSyncOracle,
}

/// Spawn the metrics metronome task.
Expand Down
3 changes: 2 additions & 1 deletion node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use {
polkadot_node_network_protocol::{
peer_set::PeerSetProtocolNames, request_response::ReqProtocolNames,
},
polkadot_overseer::BlockInfo,
polkadot_overseer::{BlockInfo, MajorSyncOracle},
sc_client_api::BlockBackend,
sp_core::traits::SpawnNamed,
sp_trie::PrefixedMemoryDB,
Expand Down Expand Up @@ -1091,6 +1091,7 @@ where
overseer_message_channel_capacity_override,
req_protocol_names,
peerset_protocol_names,
sync_oracle: MajorSyncOracle::new(Box::new(network.clone())),
},
)
.map_err(|e| {
Expand Down
8 changes: 6 additions & 2 deletions node/service/src/overseer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub use polkadot_overseer::{
HeadSupportsParachains,
};
use polkadot_overseer::{
metrics::Metrics as OverseerMetrics, BlockInfo, InitializedOverseerBuilder, MetricsTrait,
Overseer, OverseerConnector, OverseerHandle, SpawnGlue,
metrics::Metrics as OverseerMetrics, BlockInfo, InitializedOverseerBuilder, MajorSyncOracle,
MetricsTrait, Overseer, OverseerConnector, OverseerHandle, SpawnGlue,
};

use polkadot_primitives::runtime_api::ParachainHost;
Expand Down Expand Up @@ -125,6 +125,8 @@ where
pub req_protocol_names: ReqProtocolNames,
/// [`PeerSet`] protocol names to protocols mapping.
pub peerset_protocol_names: PeerSetProtocolNames,
/// SyncOracle is used to detect when initial full node sync is complete
pub sync_oracle: MajorSyncOracle,
}

/// Obtain a prepared `OverseerBuilder`, that is initialized
Expand Down Expand Up @@ -155,6 +157,7 @@ pub fn prepared_overseer_builder<Spawner, RuntimeClient>(
overseer_message_channel_capacity_override,
req_protocol_names,
peerset_protocol_names,
sync_oracle,
}: OverseerGenArgs<Spawner, RuntimeClient>,
) -> Result<
InitializedOverseerBuilder<
Expand Down Expand Up @@ -319,6 +322,7 @@ where
.supports_parachains(runtime_client)
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
.metrics(metrics)
.sync_oracle(sync_oracle)
.spawner(spawner);

if let Some(capacity) = overseer_message_channel_capacity_override {
Expand Down