Skip to content

Commit 0016265

Browse files
committed
fix: post-toolchain and snarkVM update alignment
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
1 parent e4a97d5 commit 0016265

File tree

6 files changed

+45
-39
lines changed

6 files changed

+45
-39
lines changed

node/bft/src/gateway.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,7 @@ impl<N: Network> Reading for Gateway<N> {
10721072
type Message = Event<N>;
10731073

10741074
/// The maximum queue depth of incoming messages for a single peer.
1075-
const MESSAGE_QUEUE_DEPTH: usize = 2
1076-
* BatchHeader::<N>::MAX_GC_ROUNDS
1077-
* N::LATEST_MAX_CERTIFICATES().unwrap() as usize
1078-
* BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH;
1075+
const MESSAGE_QUEUE_DEPTH: usize = 256_000;
10791076

10801077
/// Creates a [`Decoder`] used to interpret messages from the network.
10811078
/// The `side` param indicates the connection side **from the node's perspective**.
@@ -1107,10 +1104,7 @@ impl<N: Network> Writing for Gateway<N> {
11071104
type Message = Event<N>;
11081105

11091106
/// The maximum queue depth of outgoing messages for a single peer.
1110-
const MESSAGE_QUEUE_DEPTH: usize = 2
1111-
* BatchHeader::<N>::MAX_GC_ROUNDS
1112-
* N::LATEST_MAX_CERTIFICATES().unwrap() as usize
1113-
* BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH;
1107+
const MESSAGE_QUEUE_DEPTH: usize = 256_000;
11141108

11151109
/// Creates an [`Encoder`] used to write the outbound messages to the target stream.
11161110
/// The `side` parameter indicates the connection side **from the node's perspective**.
@@ -1254,7 +1248,7 @@ impl<N: Network> Gateway<N> {
12541248
peer_ip: Option<SocketAddr>,
12551249
restrictions_id: Field<N>,
12561250
stream: &'a mut TcpStream,
1257-
) -> io::Result<(SocketAddr, Framed<&mut TcpStream, EventCodec<N>>)> {
1251+
) -> io::Result<(SocketAddr, Framed<&'a mut TcpStream, EventCodec<N>>)> {
12581252
// This value is immediately guaranteed to be present, so it can be unwrapped.
12591253
let peer_ip = peer_ip.unwrap();
12601254

@@ -1319,7 +1313,7 @@ impl<N: Network> Gateway<N> {
13191313
peer_ip: &mut Option<SocketAddr>,
13201314
restrictions_id: Field<N>,
13211315
stream: &'a mut TcpStream,
1322-
) -> io::Result<(SocketAddr, Framed<&mut TcpStream, EventCodec<N>>)> {
1316+
) -> io::Result<(SocketAddr, Framed<&'a mut TcpStream, EventCodec<N>>)> {
13231317
// Construct the stream.
13241318
let mut framed = Framed::new(stream, EventCodec::<N>::handshake());
13251319

@@ -1453,7 +1447,10 @@ mod prop_tests {
14531447
use snarkos_account::Account;
14541448
use snarkos_node_bft_ledger_service::MockLedgerService;
14551449
use snarkos_node_bft_storage_service::BFTMemoryService;
1456-
use snarkos_node_tcp::P2P;
1450+
use snarkos_node_tcp::{
1451+
P2P,
1452+
protocols::{Reading, Writing},
1453+
};
14571454
use snarkvm::{
14581455
ledger::{
14591456
committee::{
@@ -1692,4 +1689,15 @@ mod prop_tests {
16921689
}
16931690
}
16941691
}
1692+
1693+
#[test]
1694+
fn ensure_sufficient_rw_queue_depth() {
1695+
let desired_rw_queue_depth = 2
1696+
* BatchHeader::<MainnetV0>::MAX_GC_ROUNDS
1697+
* MainnetV0::LATEST_MAX_CERTIFICATES().unwrap() as usize
1698+
* BatchHeader::<MainnetV0>::MAX_TRANSMISSIONS_PER_BATCH;
1699+
1700+
assert!(<Gateway<MainnetV0> as Reading>::MESSAGE_QUEUE_DEPTH >= desired_rw_queue_depth);
1701+
assert!(<Gateway<MainnetV0> as Writing>::MESSAGE_QUEUE_DEPTH >= desired_rw_queue_depth);
1702+
}
16951703
}

node/bft/src/helpers/pending.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use crate::MAX_FETCH_TIMEOUT_IN_MS;
1717
use snarkos_node_bft_ledger_service::LedgerService;
18-
use snarkvm::console::network::{consensus_config_value, Network};
18+
use snarkvm::console::network::{Network, consensus_config_value};
1919

2020
use parking_lot::RwLock;
2121
use std::{
@@ -34,14 +34,14 @@ pub(crate) const CALLBACK_EXPIRATION_IN_SECS: i64 = MAX_FETCH_TIMEOUT_IN_MS.div_
3434
/// Returns the maximum number of redundant requests for the number of validators in the specified round.
3535
pub fn max_redundant_requests<N: Network>(ledger: Arc<dyn LedgerService<N>>, round: u64) -> usize {
3636
// Determine the number of validators in the committee lookback for the given round.
37-
let num_validators = ledger
38-
.get_committee_lookback_for_round(round)
39-
.map(|committee| committee.num_members())
40-
.ok()
41-
.unwrap_or_else(|| {
42-
let max_committee_size = consensus_config_value!(N, MAX_CERTIFICATES, ledger.latest_block_height()).unwrap();
43-
max_committee_size as usize
44-
});
37+
let num_validators =
38+
ledger.get_committee_lookback_for_round(round).map(|committee| committee.num_members()).ok().unwrap_or_else(
39+
|| {
40+
let max_committee_size =
41+
consensus_config_value!(N, MAX_CERTIFICATES, ledger.latest_block_height()).unwrap();
42+
max_committee_size as usize
43+
},
44+
);
4545

4646
// Note: It is adequate to set this value to the availability threshold,
4747
// as with high probability one will respond honestly (in the best and worst case

node/bft/storage-service/src/persistent.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ impl<N: Network> BFTPersistentStorage<N> {
6161
/// Initializes a new BFT persistent storage service.
6262
pub fn open(storage_mode: StorageMode) -> Result<Self> {
6363
let max_committee_size = N::LATEST_MAX_CERTIFICATES().unwrap();
64-
let capacity = NonZeroUsize::new(
65-
(max_committee_size as usize) * (BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH) * 2,
66-
)
67-
.ok_or_else(|| anyhow!("Could not construct NonZeroUsize"))?;
64+
let capacity =
65+
NonZeroUsize::new((max_committee_size as usize) * (BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH) * 2)
66+
.ok_or_else(|| anyhow!("Could not construct NonZeroUsize"))?;
6867

6968
Ok(Self {
7069
transmissions: internal::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::BFT(BFTMap::Transmissions))?,
@@ -82,10 +81,9 @@ impl<N: Network> BFTPersistentStorage<N> {
8281
#[cfg(any(test, feature = "test"))]
8382
pub fn open_testing(temp_dir: std::path::PathBuf, dev: Option<u16>) -> Result<Self> {
8483
let max_committee_size = N::MAX_CERTIFICATES.last().unwrap().1;
85-
let capacity = NonZeroUsize::new(
86-
(max_committee_size as usize) * (BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH) * 2,
87-
)
88-
.ok_or_else(|| anyhow!("Could not construct NonZeroUsize"))?;
84+
let capacity =
85+
NonZeroUsize::new((max_committee_size as usize) * (BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH) * 2)
86+
.ok_or_else(|| anyhow!("Could not construct NonZeroUsize"))?;
8987

9088
Ok(Self {
9189
transmissions: internal::RocksDB::open_map_testing(

node/bft/tests/components/pending.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
use crate::common::{CurrentNetwork, primary::new_test_committee, utils::sample_ledger};
1717
use snarkos_node_bft::helpers::max_redundant_requests;
18-
use snarkvm::{ledger::committee::Committee, prelude::TestRng};
18+
use snarkvm::prelude::{Network, TestRng};
1919

2020
#[test]
2121
fn test_max_redundant_requests() {
22-
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;
22+
let num_nodes: u16 = CurrentNetwork::LATEST_MAX_CERTIFICATES().unwrap();
2323

2424
// Initialize the RNG.
2525
let mut rng = TestRng::default();
2626
// Initialize the accounts and the committee.
27-
let (accounts, committee) = new_test_committee(NUM_NODES, &mut rng);
27+
let (accounts, committee) = new_test_committee(num_nodes, &mut rng);
2828
// Sample a ledger.
2929
let ledger = sample_ledger(&accounts, &committee, &mut rng);
3030
// Ensure the maximum number of redundant requests is correct and consistent across iterations.

node/bft/tests/components/worker.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::common::{
2020
};
2121
use snarkos_node_bft::helpers::max_redundant_requests;
2222
use snarkvm::{
23-
ledger::{committee::Committee, narwhal::TransmissionID},
23+
ledger::narwhal::TransmissionID,
2424
prelude::{Network, TestRng},
2525
};
2626

@@ -29,12 +29,12 @@ use std::net::SocketAddr;
2929
#[tokio::test]
3030
#[rustfmt::skip]
3131
async fn test_resend_transmission_request() {
32-
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;
32+
let num_nodes: u16 = CurrentNetwork::LATEST_MAX_CERTIFICATES().unwrap();
3333

3434
// Initialize the RNG.
3535
let mut rng = TestRng::default();
3636
// Initialize the accounts and the committee.
37-
let (accounts, committee) = new_test_committee(NUM_NODES, &mut rng);
37+
let (accounts, committee) = new_test_committee(num_nodes, &mut rng);
3838
// Sample a ledger.
3939
let ledger = sample_ledger(&accounts, &committee, &mut rng);
4040
// Sample a worker.
@@ -111,12 +111,12 @@ async fn test_resend_transmission_request() {
111111
#[tokio::test]
112112
#[rustfmt::skip]
113113
async fn test_flood_transmission_requests() {
114-
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;
114+
let num_nodes: u16 = CurrentNetwork::LATEST_MAX_CERTIFICATES().unwrap();
115115

116116
// Initialize the RNG.
117117
let mut rng = TestRng::default();
118118
// Initialize the accounts and the committee.
119-
let (accounts, committee) = new_test_committee(NUM_NODES, &mut rng);
119+
let (accounts, committee) = new_test_committee(num_nodes, &mut rng);
120120
// Sample a ledger.
121121
let ledger = sample_ledger(&accounts, &committee, &mut rng);
122122
// Sample a worker.

node/router/src/handshake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<N: Network> Router<N> {
9090
peer_side: ConnectionSide,
9191
genesis_header: Header<N>,
9292
restrictions_id: Field<N>,
93-
) -> io::Result<(SocketAddr, Framed<&mut TcpStream, MessageCodec<N>>)> {
93+
) -> io::Result<(SocketAddr, Framed<&'a mut TcpStream, MessageCodec<N>>)> {
9494
// If this is an inbound connection, we log it, but don't know the listening address yet.
9595
// Otherwise, we can immediately register the listening address.
9696
let mut peer_ip = if peer_side == ConnectionSide::Initiator {
@@ -146,7 +146,7 @@ impl<N: Network> Router<N> {
146146
stream: &'a mut TcpStream,
147147
genesis_header: Header<N>,
148148
restrictions_id: Field<N>,
149-
) -> io::Result<(SocketAddr, Framed<&mut TcpStream, MessageCodec<N>>)> {
149+
) -> io::Result<(SocketAddr, Framed<&'a mut TcpStream, MessageCodec<N>>)> {
150150
// This value is immediately guaranteed to be present, so it can be unwrapped.
151151
let peer_ip = peer_ip.unwrap();
152152
// Construct the stream.
@@ -224,7 +224,7 @@ impl<N: Network> Router<N> {
224224
stream: &'a mut TcpStream,
225225
genesis_header: Header<N>,
226226
restrictions_id: Field<N>,
227-
) -> io::Result<(SocketAddr, Framed<&mut TcpStream, MessageCodec<N>>)> {
227+
) -> io::Result<(SocketAddr, Framed<&'a mut TcpStream, MessageCodec<N>>)> {
228228
// Construct the stream.
229229
let mut framed = Framed::new(stream, MessageCodec::<N>::handshake());
230230

0 commit comments

Comments
 (0)