Skip to content

Commit

Permalink
Merge pull request #429 from contrun/configurable_active_passive_peers
Browse files Browse the repository at this point in the history
Make number of active/passive syncers configurable
  • Loading branch information
quake authored Jan 8, 2025
2 parents 81014d3 + d47ea23 commit 66886f0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/fiber/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ pub struct FiberConfig {
)]
pub(crate) gossip_store_maintenance_interval_ms: Option<u64>,

/// Gossip network num targeted active syncing peers. [default: None]
/// This is the number of peers to target for active syncing. This is the number of peers that we will
/// send GetBroadcastMessages message to obtain the gossip messages that we missed during the time we
/// were offiline. A larger number means more peers to receive updates from, but also more bandwidth usage.
/// If None, it will use the default value.
#[arg(
name = "FIBER_GOSSIP_NETWORK_NUM_TARGETED_ACTIVE_SYNCING_PEERS",
long = "fiber-gossip-network-num-targeted-active-syncing-peers",
env,
help = "Gossip network num targeted active syncing peers. [default: None]"
)]
pub(crate) gossip_network_num_targeted_active_syncing_peers: Option<usize>,

/// Gossip network num targeted outbound passive syncing peers. [default: None]
/// This is the number of peers to target for outbound passive syncing. This is the number of outbound peers
/// that we will send BroadcastMessageFilter to receive updates from them. A larger number means more
/// peers to receive updates from, but also more bandwidth usage. We only count the outbound peers here,
/// because outbound peers are less likely to be malicious, and we want to receive updates from them.
/// If None, it will use the default value.
#[arg(
name = "FIBER_GOSSIP_NETWORK_NUM_TARGETED_OUTBOUND_PASSIVE_SYNCING_PEERS",
long = "fiber-gossip-network-num-targeted-outbound-passive-syncing-peers",
env,
help = "Gossip network num targeted outbound passive syncing peers. [default: None]"
)]
pub(crate) gossip_network_num_targeted_outbound_passive_syncing_peers: Option<usize>,

/// Whether to sync the network graph from the network. [default: true]
#[arg(
name = "FIBER_SYNC_NETWORK_GRAPH",
Expand Down
19 changes: 15 additions & 4 deletions src/fiber/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,11 +1351,13 @@ pub enum ExtendedGossipMessageStoreMessage {
pub(crate) struct GossipActorState<S> {
store: ExtendedGossipMessageStore<S>,
control: ServiceAsyncControl,
num_targeted_active_syncing_peers: usize,
// The number of active syncing peers that we have finished syncing with.
// Together with the number of currect active syncing peers, this is
// Together with the number of current active syncing peers, this is
// used to determine if we should start a new active syncing peer.
num_finished_active_syncing_peers: usize,
// The number of targeted active syncing peers that we want to have.
// Currently we will only start this many active syncing peers.
num_targeted_active_syncing_peers: usize,
// The number of outbound passive syncing peers that we want to have.
// We only count outbound peers because the purpose of this number is to avoid eclipse attacks.
// By maintaining a certain number of outbound passive syncing peers, we can ensure that we are
Expand Down Expand Up @@ -2091,6 +2093,8 @@ impl GossipProtocolHandle {
gossip_network_maintenance_interval: Duration,
gossip_store_maintenance_interval: Duration,
announce_private_addr: bool,
num_targeted_active_syncing_peers: Option<usize>,
num_targeted_outbound_passive_syncing_peers: Option<usize>,
store: S,
chain_actor: ActorRef<CkbChainMessage>,
supervisor: ActorCell,
Expand All @@ -2110,6 +2114,9 @@ impl GossipProtocolHandle {
gossip_network_maintenance_interval,
gossip_store_maintenance_interval,
announce_private_addr,
num_targeted_active_syncing_peers.unwrap_or(MAX_NUM_OF_ACTIVE_SYNCING_PEERS),
num_targeted_outbound_passive_syncing_peers
.unwrap_or(MIN_NUM_OF_PASSIVE_SYNCING_PEERS),
store,
chain_actor,
),
Expand Down Expand Up @@ -2154,6 +2161,8 @@ where
Duration,
Duration,
bool,
usize,
usize,
S,
ActorRef<CkbChainMessage>,
);
Expand All @@ -2167,6 +2176,8 @@ where
network_maintenance_interval,
store_maintenance_interval,
announce_private_addr,
num_targeted_active_syncing_peers,
num_targeted_outbound_passive_syncing_peers,
store,
chain_actor,
): Self::Arguments,
Expand Down Expand Up @@ -2194,8 +2205,8 @@ where
let state = Self::State {
store,
control,
num_targeted_active_syncing_peers: MAX_NUM_OF_ACTIVE_SYNCING_PEERS,
num_targeted_outbound_passive_syncing_peers: MIN_NUM_OF_PASSIVE_SYNCING_PEERS,
num_targeted_active_syncing_peers,
num_targeted_outbound_passive_syncing_peers,
myself,
chain_actor,
next_request_id: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,8 @@ where
Duration::from_millis(config.gossip_network_maintenance_interval_ms()).into(),
Duration::from_millis(config.gossip_store_maintenance_interval_ms()).into(),
config.announce_private_addr(),
config.gossip_network_num_targeted_active_syncing_peers,
config.gossip_network_num_targeted_outbound_passive_syncing_peers,
self.store.clone(),
self.chain_actor.clone(),
myself.get_cell(),
Expand Down
2 changes: 2 additions & 0 deletions src/fiber/tests/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl GossipTestingContext {
Duration::from_millis(50).into(),
Duration::from_millis(50).into(),
true,
None,
None,
store.clone(),
chain_actor.clone(),
root_actor.get_cell(),
Expand Down

0 comments on commit 66886f0

Please sign in to comment.