Skip to content

Commit aa0fcf3

Browse files
authored
Merge pull request #4208 from ProvableHQ/feat/sync-log-fork-source
[Feature] Log where a fork originated (Router or Gateway)
2 parents 6aea8d9 + a2966f8 commit aa0fcf3

12 files changed

Lines changed: 49 additions & 22 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/bft/examples/simple_node.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use snarkos_node_bft::{
2828
};
2929
use snarkos_node_bft_ledger_service::TranslucentLedgerService;
3030
use snarkos_node_bft_storage_service::BFTMemoryService;
31+
use snarkos_node_network::ConnectionMode;
3132
use snarkos_node_sync::BlockSync;
3233
use snarkos_utilities::{NodeDataDir, SimpleStoppable};
3334

@@ -149,7 +150,7 @@ pub async fn start_bft(
149150
// Initialize the consensus receiver handler.
150151
consensus_handler(consensus_receiver);
151152
// Initialize the BFT instance.
152-
let block_sync = Arc::new(BlockSync::new(ledger.clone()));
153+
let block_sync = Arc::new(BlockSync::new(ledger.clone(), ConnectionMode::Gateway));
153154
let mut bft = BFT::<CurrentNetwork>::new(
154155
account,
155156
storage,
@@ -199,7 +200,7 @@ pub async fn start_primary(
199200
let trusted_validators = trusted_validators(node_id, num_nodes, peers);
200201
let trusted_peers_only = false;
201202
// Initialize the primary instance.
202-
let block_sync = Arc::new(BlockSync::new(ledger.clone()));
203+
let block_sync = Arc::new(BlockSync::new(ledger.clone(), ConnectionMode::Gateway));
203204
let primary = Primary::<CurrentNetwork>::new(
204205
account,
205206
storage,

node/bft/src/bft.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ mod tests {
890890
use snarkos_account::Account;
891891
use snarkos_node_bft_ledger_service::{LedgerService, MockLedgerService};
892892
use snarkos_node_bft_storage_service::BFTMemoryService;
893+
use snarkos_node_network::ConnectionMode;
893894
use snarkos_node_sync::BlockSync;
894895
use snarkos_utilities::NodeDataDir;
895896

@@ -948,7 +949,7 @@ mod tests {
948949
ledger: Arc<MockLedgerService<CurrentNetwork>>,
949950
) -> anyhow::Result<BFT<CurrentNetwork>> {
950951
// Create the block synchronization logic.
951-
let block_sync = Arc::new(BlockSync::new(ledger.clone()));
952+
let block_sync = Arc::new(BlockSync::new(ledger.clone(), ConnectionMode::Gateway));
952953
// Initialize the BFT.
953954
BFT::new(
954955
account.clone(),

node/bft/src/primary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ use crate::{
4545
use snarkos_account::Account;
4646
use snarkos_node_bft_events::PrimaryPing;
4747
use snarkos_node_bft_ledger_service::LedgerService;
48+
#[cfg(test)]
49+
use snarkos_node_network::ConnectionMode;
4850
use snarkos_node_network::PeerPoolHandling;
4951
use snarkos_node_sync::{BlockSync, DUMMY_SELF_IP, Ping};
5052
use snarkos_utilities::{CallbackHandle, NodeDataDir};
@@ -2082,7 +2084,7 @@ mod tests {
20822084

20832085
// Initialize the primary.
20842086
let account = accounts[account_index].1.clone();
2085-
let block_sync = Arc::new(BlockSync::new(ledger.clone()));
2087+
let block_sync = Arc::new(BlockSync::new(ledger.clone(), ConnectionMode::Gateway));
20862088
let primary =
20872089
Primary::new(account, storage, ledger, block_sync, None, &[], false, NodeDataDir::new_test(None), None)
20882090
.unwrap();

node/bft/src/sync/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ mod tests {
10991099
use crate::{BFT, helpers::now, ledger_service::CoreLedgerService, storage_service::BFTMemoryService};
11001100

11011101
use snarkos_account::Account;
1102+
use snarkos_node_network::ConnectionMode;
11021103
use snarkos_node_sync::BlockSync;
11031104
use snarkos_utilities::{NodeDataDir, SimpleStoppable};
11041105

@@ -1356,7 +1357,7 @@ mod tests {
13561357
)
13571358
.unwrap();
13581359

1359-
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone()));
1360+
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone(), ConnectionMode::Gateway));
13601361
let sync = Sync::new(gateway.clone(), syncing_storage.clone(), syncing_ledger.clone(), block_sync.clone());
13611362

13621363
let syncing_bft = BFT::new(
@@ -1425,7 +1426,7 @@ mod tests {
14251426
)
14261427
.unwrap();
14271428

1428-
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone()));
1429+
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone(), ConnectionMode::Gateway));
14291430
let sync = Sync::new(gateway.clone(), syncing_storage.clone(), syncing_ledger.clone(), block_sync.clone());
14301431

14311432
let syncing_bft = BFT::new(
@@ -1516,7 +1517,7 @@ mod tests {
15161517
)
15171518
.unwrap();
15181519

1519-
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone()));
1520+
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone(), ConnectionMode::Gateway));
15201521
let sync = Sync::new(gateway.clone(), syncing_storage.clone(), syncing_ledger.clone(), block_sync.clone());
15211522

15221523
let syncing_bft = BFT::new(
@@ -1601,7 +1602,7 @@ mod tests {
16011602
)
16021603
.unwrap();
16031604

1604-
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone()));
1605+
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone(), ConnectionMode::Gateway));
16051606
let sync = Sync::new(gateway.clone(), syncing_storage.clone(), syncing_ledger.clone(), block_sync.clone());
16061607

16071608
let syncing_bft = BFT::new(
@@ -1683,7 +1684,7 @@ mod tests {
16831684
)
16841685
.unwrap();
16851686

1686-
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone()));
1687+
let block_sync = Arc::new(BlockSync::new(syncing_ledger.clone(), ConnectionMode::Gateway));
16871688
let sync = Sync::new(gateway.clone(), syncing_storage.clone(), syncing_ledger.clone(), block_sync.clone());
16881689

16891690
let syncing_bft = BFT::new(

node/bft/tests/common/primary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use snarkos_node_bft::{
2828
helpers::{PrimarySender, Storage, init_primary_channels},
2929
};
3030
use snarkos_node_bft_storage_service::BFTMemoryService;
31-
use snarkos_node_network::PeerPoolHandling;
31+
use snarkos_node_network::{ConnectionMode, PeerPoolHandling};
3232
use snarkos_node_sync::BlockSync;
3333
use snarkos_utilities::{NodeDataDir, SimpleStoppable};
3434

@@ -171,7 +171,7 @@ impl TestNetwork {
171171
)
172172
.unwrap();
173173
// Initialize the block synchronization logic.
174-
let block_sync = Arc::new(BlockSync::new(ledger.clone()));
174+
let block_sync = Arc::new(BlockSync::new(ledger.clone(), ConnectionMode::Gateway));
175175
let (primary, bft) = if config.bft {
176176
let bft = BFT::<CurrentNetwork>::new(
177177
account,

node/network/src/peer.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::NodeType;
1717
use snarkvm::prelude::{Address, Network};
1818
use tracing::*;
1919

20-
use std::{net::SocketAddr, time::Instant};
20+
use std::{fmt, net::SocketAddr, time::Instant};
2121

2222
/// A peer of any connection status.
2323
#[derive(Clone, Debug)]
@@ -89,6 +89,15 @@ pub enum ConnectionMode {
8989
Router,
9090
}
9191

92+
impl fmt::Display for ConnectionMode {
93+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94+
match self {
95+
ConnectionMode::Gateway => write!(f, "Gateway"),
96+
ConnectionMode::Router => write!(f, "Router"),
97+
}
98+
}
99+
}
100+
92101
impl<N: Network> Peer<N> {
93102
/// Create a candidate peer.
94103
pub const fn new_candidate(listener_addr: SocketAddr, trusted: bool) -> Self {

node/src/client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
};
2323

2424
use snarkos_account::Account;
25-
use snarkos_node_network::NodeType;
25+
use snarkos_node_network::{ConnectionMode, NodeType};
2626
use snarkos_node_rest::Rest;
2727
use snarkos_node_router::{
2828
Heartbeat,
@@ -172,7 +172,7 @@ impl<N: Network, C: ConsensusStorage<N>> Client<N, C> {
172172
.await?;
173173

174174
// Initialize the sync module.
175-
let sync = Arc::new(BlockSync::new(ledger_service.clone()));
175+
let sync = Arc::new(BlockSync::new(ledger_service.clone(), ConnectionMode::Router));
176176

177177
// Set up the ping logic.
178178
let locators = sync.get_block_locators()?;

node/src/prover/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
};
2323

2424
use snarkos_account::Account;
25-
use snarkos_node_network::{NodeType, PeerPoolHandling};
25+
use snarkos_node_network::{ConnectionMode, NodeType, PeerPoolHandling};
2626
use snarkos_node_router::{
2727
Heartbeat,
2828
Inbound,
@@ -125,7 +125,7 @@ impl<N: Network, C: ConsensusStorage<N>> Prover<N, C> {
125125
.await?;
126126

127127
// Initialize the sync module.
128-
let sync = BlockSync::new(ledger_service.clone());
128+
let sync = BlockSync::new(ledger_service.clone(), ConnectionMode::Router);
129129

130130
// Set up the ping logic.
131131
let ping = Arc::new(Ping::new_nosync(router.clone()));

node/src/validator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use snarkos_account::Account;
2121
use snarkos_node_bft::{ledger_service::CoreLedgerService, spawn_blocking};
2222
use snarkos_node_cdn::CdnBlockSync;
2323
use snarkos_node_consensus::Consensus;
24-
use snarkos_node_network::{NodeType, PeerPoolHandling};
24+
use snarkos_node_network::{ConnectionMode, NodeType, PeerPoolHandling};
2525
use snarkos_node_rest::Rest;
2626
use snarkos_node_router::{
2727
Heartbeat,
@@ -121,7 +121,7 @@ impl<N: Network, C: ConsensusStorage<N>> Validator<N, C> {
121121
.await?;
122122

123123
// Initialize the block synchronization logic.
124-
let sync = Arc::new(BlockSync::new(ledger_service.clone()));
124+
let sync = Arc::new(BlockSync::new(ledger_service.clone(), ConnectionMode::Gateway));
125125
let locators = sync.get_block_locators()?;
126126
let ping = Arc::new(Ping::new(router.clone(), locators));
127127

0 commit comments

Comments
 (0)