Skip to content

Commit

Permalink
Merge branch 'mainnet-staging' into update/devnet-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
raychu86 authored May 23, 2024
2 parents e7036de + 3d7b4d7 commit 286df20
Show file tree
Hide file tree
Showing 25 changed files with 284 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
wasm/Cargo.lock
**/build
**.ledger-*
**.current-proposal-cache-*
**.logs-*
validator-*
**.bft-storage-*/
Expand Down
139 changes: 80 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ default-features = false

[workspace.dependencies.snarkvm]
git = "https://github.com/AleoNet/snarkVM.git"
rev = "140ff26"
rev = "0bd71b5"
#version = "=0.16.18"
features = [ "circuit", "console", "rocks" ]

Expand Down
6 changes: 5 additions & 1 deletion cli/src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use snarkvm::{
console::{
account::{Address, PrivateKey, Signature},
network::{MainnetV0, Network, TestnetV0},
network::{CanaryV0, MainnetV0, Network, TestnetV0},
prelude::{Environment, Uniform},
program::{ToFields, Value},
types::Field,
Expand Down Expand Up @@ -113,12 +113,14 @@ impl Account {
Some(vanity) => match network {
MainnetV0::ID => Self::new_vanity::<MainnetV0>(vanity.as_str(), discreet),
TestnetV0::ID => Self::new_vanity::<TestnetV0>(vanity.as_str(), discreet),
CanaryV0::ID => Self::new_vanity::<CanaryV0>(vanity.as_str(), discreet),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
},
// Generate a seeded account for the specified network.
None => match network {
MainnetV0::ID => Self::new_seeded::<MainnetV0>(seed, discreet),
TestnetV0::ID => Self::new_seeded::<TestnetV0>(seed, discreet),
CanaryV0::ID => Self::new_seeded::<CanaryV0>(seed, discreet),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
},
}
Expand All @@ -140,6 +142,7 @@ impl Account {
match network {
MainnetV0::ID => Self::sign::<MainnetV0>(key, message, seed, raw),
TestnetV0::ID => Self::sign::<TestnetV0>(key, message, seed, raw),
CanaryV0::ID => Self::sign::<CanaryV0>(key, message, seed, raw),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand All @@ -148,6 +151,7 @@ impl Account {
match network {
MainnetV0::ID => Self::verify::<MainnetV0>(address, signature, message, raw),
TestnetV0::ID => Self::verify::<TestnetV0>(address, signature, message, raw),
CanaryV0::ID => Self::verify::<CanaryV0>(address, signature, message, raw),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/developer/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use snarkvm::{
console::{
network::{MainnetV0, Network, TestnetV0},
network::{CanaryV0, MainnetV0, Network, TestnetV0},
program::Ciphertext,
},
prelude::{Record, ViewKey},
Expand Down Expand Up @@ -45,6 +45,7 @@ impl Decrypt {
match self.network {
MainnetV0::ID => Self::decrypt_ciphertext::<MainnetV0>(&self.ciphertext, &self.view_key),
TestnetV0::ID => Self::decrypt_ciphertext::<TestnetV0>(&self.ciphertext, &self.view_key),
CanaryV0::ID => Self::decrypt_ciphertext::<CanaryV0>(&self.ciphertext, &self.view_key),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand Down
5 changes: 3 additions & 2 deletions cli/src/commands/developer/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

use super::Developer;
use snarkvm::{
circuit::{Aleo, AleoTestnetV0, AleoV0},
circuit::{Aleo, AleoCanaryV0, AleoTestnetV0, AleoV0},
console::{
network::{MainnetV0, Network, TestnetV0},
network::{CanaryV0, MainnetV0, Network, TestnetV0},
program::ProgramOwner,
},
prelude::{
Expand Down Expand Up @@ -93,6 +93,7 @@ impl Deploy {
match self.network {
MainnetV0::ID => self.construct_deployment::<MainnetV0, AleoV0>(),
TestnetV0::ID => self.construct_deployment::<TestnetV0, AleoTestnetV0>(),
CanaryV0::ID => self.construct_deployment::<CanaryV0, AleoCanaryV0>(),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/developer/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use super::Developer;
use snarkvm::{
console::network::{MainnetV0, Network, TestnetV0},
console::network::{CanaryV0, MainnetV0, Network, TestnetV0},
prelude::{
query::Query,
store::{helpers::memory::ConsensusMemory, ConsensusStore},
Expand Down Expand Up @@ -94,6 +94,7 @@ impl Execute {
match self.network {
MainnetV0::ID => self.construct_execution::<MainnetV0>(),
TestnetV0::ID => self.construct_execution::<TestnetV0>(),
CanaryV0::ID => self.construct_execution::<CanaryV0>(),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand Down
2 changes: 2 additions & 0 deletions cli/src/commands/developer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl Developer {
let network = match N::ID {
snarkvm::console::network::MainnetV0::ID => "mainnet",
snarkvm::console::network::TestnetV0::ID => "testnet",
snarkvm::console::network::CanaryV0::ID => "canary",
unknown_id => bail!("Unknown network ID ({unknown_id})"),
};

Expand Down Expand Up @@ -147,6 +148,7 @@ impl Developer {
let network = match N::ID {
snarkvm::console::network::MainnetV0::ID => "mainnet",
snarkvm::console::network::TestnetV0::ID => "testnet",
snarkvm::console::network::CanaryV0::ID => "canary",
unknown_id => bail!("Unknown network ID ({unknown_id})"),
};

Expand Down
6 changes: 5 additions & 1 deletion cli/src/commands/developer/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#![allow(clippy::type_complexity)]

use snarkvm::{
console::network::{MainnetV0, Network, TestnetV0},
console::network::{CanaryV0, MainnetV0, Network, TestnetV0},
prelude::{block::Block, Ciphertext, Field, FromBytes, Plaintext, PrivateKey, Record, ViewKey},
};

Expand Down Expand Up @@ -71,6 +71,7 @@ impl Scan {
match self.network {
MainnetV0::ID => self.scan_records::<MainnetV0>(),
TestnetV0::ID => self.scan_records::<TestnetV0>(),
CanaryV0::ID => self.scan_records::<CanaryV0>(),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand Down Expand Up @@ -135,6 +136,7 @@ impl Scan {
let network = match self.network {
MainnetV0::ID => "mainnet",
TestnetV0::ID => "testnet",
CanaryV0::ID => "canary",
unknown_id => bail!("Unknown network ID ({unknown_id})"),
};

Expand Down Expand Up @@ -186,6 +188,7 @@ impl Scan {
let network = match N::ID {
MainnetV0::ID => "mainnet",
TestnetV0::ID => "testnet",
CanaryV0::ID => "canary",
unknown_id => bail!("Unknown network ID ({unknown_id})"),
};

Expand Down Expand Up @@ -364,6 +367,7 @@ impl Scan {
let network = match N::ID {
MainnetV0::ID => "mainnet",
TestnetV0::ID => "testnet",
CanaryV0::ID => "canary",
unknown_id => bail!("Unknown network ID ({unknown_id})"),
};

Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/developer/transfer_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use super::Developer;
use snarkvm::{
console::network::{MainnetV0, Network, TestnetV0},
console::network::{CanaryV0, MainnetV0, Network, TestnetV0},
prelude::{
query::Query,
store::{helpers::memory::ConsensusMemory, ConsensusStore},
Expand Down Expand Up @@ -93,6 +93,7 @@ impl TransferPrivate {
match self.network {
MainnetV0::ID => self.construct_transfer_private::<MainnetV0>(),
TestnetV0::ID => self.construct_transfer_private::<TestnetV0>(),
CanaryV0::ID => self.construct_transfer_private::<CanaryV0>(),
unknown_id => bail!("Unknown network ID ({unknown_id})"),
}
}
Expand Down
11 changes: 10 additions & 1 deletion cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use snarkvm::{
console::{
account::{Address, PrivateKey},
algorithms::Hash,
network::{MainnetV0, Network, TestnetV0},
network::{CanaryV0, MainnetV0, Network, TestnetV0},
},
ledger::{
block::Block,
Expand Down Expand Up @@ -189,6 +189,15 @@ impl Start {
Display::start(node, log_receiver).expect("Failed to initialize the display");
}
}
CanaryV0::ID => {
// Parse the node from the configurations.
let node = cli.parse_node::<CanaryV0>(shutdown.clone()).await.expect("Failed to parse the node");
// If the display is enabled, render the display.
if !cli.nodisplay {
// Initialize the display.
Display::start(node, log_receiver).expect("Failed to initialize the display");
}
}
_ => panic!("Invalid network ID specified"),
};
// Note: Do not move this. The pending await must be here otherwise
Expand Down
2 changes: 1 addition & 1 deletion devnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ read -p "Enter the total number of clients (default: 2): " total_clients
total_clients=${total_clients:-2}

# Read the network ID from user or use a default value of 1
read -p "Enter the network ID (mainnet = 0, testnet = 1) (default: 1): " network_id
read -p "Enter the network ID (mainnet = 0, testnet = 1, canary = 2) (default: 1): " network_id
network_id=${network_id:-1}

# Ask the user if they want to run 'cargo install --locked --path .' or use a pre-installed binary
Expand Down
5 changes: 5 additions & 0 deletions node/bft/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,11 @@ impl<N: Network> Disconnect for Gateway<N> {
async fn handle_disconnect(&self, peer_addr: SocketAddr) {
if let Some(peer_ip) = self.resolver.get_listener(peer_addr) {
self.remove_connected_peer(peer_ip);

// We don't clear this map based on time but only on peer disconnect.
// This is sufficient to avoid infinite growth as the committee has a fixed number
// of members.
self.cache.clear_outbound_validators_requests(peer_ip);
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions node/bft/src/helpers/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ impl<N: Network> Cache<N> {
pub fn decrement_outbound_validators_requests(&self, peer_ip: SocketAddr) -> u32 {
Self::decrement_counter(&self.seen_outbound_validators_requests, peer_ip)
}

/// Clears the the IP's number of validator requests.
pub fn clear_outbound_validators_requests(&self, peer_ip: SocketAddr) {
self.seen_outbound_validators_requests.write().remove(&peer_ip);
}
}

impl<N: Network> Cache<N> {
Expand Down Expand Up @@ -293,4 +298,27 @@ mod tests {
outbound_certificate,
outbound_transmission
}

#[test]
fn test_seen_outbound_validators_requests() {
let cache = Cache::<CurrentNetwork>::default();
let input = Input::input();

// Check the map is empty.
assert!(!cache.contains_outbound_validators_request(input));

// Insert some requests.
for _ in 0..3 {
cache.increment_outbound_validators_requests(input);
assert!(cache.contains_outbound_validators_request(input));
}

// Remove a request.
cache.decrement_outbound_validators_requests(input);
assert!(cache.contains_outbound_validators_request(input));

// Clear all requests.
cache.clear_outbound_validators_requests(input);
assert!(!cache.contains_outbound_validators_request(input));
}
}
24 changes: 23 additions & 1 deletion node/bft/src/helpers/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ impl<T: Copy + Clone + PartialEq + Eq + Hash, V: Clone> Pending<T, V> {
self.pending.read().get(&item.into()).map_or(false, |peer_ips| peer_ips.contains_key(&peer_ip))
}

/// Returns `true` if the pending queue contains the specified `item` for the specified `peer IP` with a sent request.
pub fn contains_peer_with_sent_request(&self, item: impl Into<T>, peer_ip: SocketAddr) -> bool {
self.pending.read().get(&item.into()).map_or(false, |peer_ips| {
peer_ips
.get(&peer_ip)
.map(|callbacks| callbacks.iter().any(|(_, _, request_sent)| *request_sent))
.unwrap_or(false)
})
}

/// Returns the peer IPs for the specified `item`.
pub fn get_peers(&self, item: impl Into<T>) -> Option<HashSet<SocketAddr>> {
self.pending.read().get(&item.into()).map(|map| map.keys().cloned().collect())
Expand Down Expand Up @@ -254,24 +264,29 @@ mod tests {
let solution_id_1 = TransmissionID::Solution(rng.gen::<u64>().into());
let solution_id_2 = TransmissionID::Solution(rng.gen::<u64>().into());
let solution_id_3 = TransmissionID::Solution(rng.gen::<u64>().into());
let solution_id_4 = TransmissionID::Solution(rng.gen::<u64>().into());

// Initialize the SocketAddrs.
let addr_1 = SocketAddr::from(([127, 0, 0, 1], 1234));
let addr_2 = SocketAddr::from(([127, 0, 0, 1], 2345));
let addr_3 = SocketAddr::from(([127, 0, 0, 1], 3456));
let addr_4 = SocketAddr::from(([127, 0, 0, 1], 4567));

// Initialize the callbacks.
let (callback_sender_1, _) = oneshot::channel();
let (callback_sender_2, _) = oneshot::channel();
let (callback_sender_3, _) = oneshot::channel();
let (callback_sender_4, _) = oneshot::channel();

// Insert the solution IDs.
assert!(pending.insert(solution_id_1, addr_1, Some((callback_sender_1, true))));
assert!(pending.insert(solution_id_2, addr_2, Some((callback_sender_2, true))));
assert!(pending.insert(solution_id_3, addr_3, Some((callback_sender_3, true))));
// Add a callback without a sent request.
assert!(pending.insert(solution_id_4, addr_4, Some((callback_sender_4, false))));

// Check the number of SocketAddrs.
assert_eq!(pending.len(), 3);
assert_eq!(pending.len(), 4);
assert!(!pending.is_empty());

// Check the items.
Expand All @@ -282,20 +297,27 @@ mod tests {
let id = ids[i];
assert!(pending.contains(id));
assert!(pending.contains_peer(id, peers[i]));
assert!(pending.contains_peer_with_sent_request(id, peers[i]));
}
// Ensure the last item does not have a sent request.
assert!(pending.contains_peer(solution_id_4, addr_4));
assert!(!pending.contains_peer_with_sent_request(solution_id_4, addr_4));

let unknown_id = TransmissionID::Solution(rng.gen::<u64>().into());
assert!(!pending.contains(unknown_id));

// Check get.
assert_eq!(pending.get_peers(solution_id_1), Some(HashSet::from([addr_1])));
assert_eq!(pending.get_peers(solution_id_2), Some(HashSet::from([addr_2])));
assert_eq!(pending.get_peers(solution_id_3), Some(HashSet::from([addr_3])));
assert_eq!(pending.get_peers(solution_id_4), Some(HashSet::from([addr_4])));
assert_eq!(pending.get_peers(unknown_id), None);

// Check remove.
assert!(pending.remove(solution_id_1, None).is_some());
assert!(pending.remove(solution_id_2, None).is_some());
assert!(pending.remove(solution_id_3, None).is_some());
assert!(pending.remove(solution_id_4, None).is_some());
assert!(pending.remove(unknown_id, None).is_none());

// Check empty again.
Expand Down
1 change: 1 addition & 0 deletions node/bft/src/helpers/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ impl<N: Network> Storage<N> {
/// Inserts the given `certificate` into storage.
///
/// Note: Do NOT use this in production. This is for **testing only**.
#[cfg(test)]
#[doc(hidden)]
pub(crate) fn testing_only_insert_certificate_testing_only(&self, certificate: BatchCertificate<N>) {
// Retrieve the round.
Expand Down
Loading

0 comments on commit 286df20

Please sign in to comment.