Skip to content

Commit

Permalink
Merge branch 'staging' into feat/banned-peers
Browse files Browse the repository at this point in the history
  • Loading branch information
zkxuerb authored Nov 12, 2024
2 parents 2bdc60b + c6de459 commit ba70c75
Show file tree
Hide file tree
Showing 34 changed files with 741 additions and 450 deletions.
779 changes: 436 additions & 343 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ default-features = false
[workspace.dependencies.snarkvm] # If this is updated, the rev in `node/rest/Cargo.toml` must be updated as well.
#path = "../snarkVM"
git = "https://github.com/AleoNet/snarkVM.git"
rev = "dea322b"
rev = "4eb83d7"
#version = "=1.0.0"
features = [ "circuit", "console", "rocks" ]

Expand All @@ -58,6 +58,7 @@ path = "snarkos/main.rs"
[features]
metrics = [ "snarkos-node-metrics", "snarkos-node/metrics" ]
history = [ "snarkos-node/history" ]
test_targets = [ "snarkos-cli/test_targets" ]

[dependencies.anyhow]
version = "1.0.79"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ Please ensure ports `4130/tcp` and `3030/tcp` are open on your router and OS fir
| 9000/tcp | TCP | Allow | Internal VPC or VPN | Metrics export, should only be open within an internal VPC or VPN |
| 9090/tcp | TCP | Allow | Internal VPC or VPN | Prometheus metrics, should only be open within an internal VPC or VPN |

**Note:** Ensure that your open file limit is set to 16,384 or above.
For the recommended setting run:
```
# Increase the open file limit for the current user (replace <username> with your username)
echo "<username> - nofile 65536" | sudo tee -a /etc/security/limits.conf
# Increase the default system open file limit
sudo bash -c 'echo "DefaultLimitNOFILE=65536" >> /etc/systemd/system.conf'
```

## 3. Run an Aleo Node

## 3.1 Run an Aleo Client
Expand Down
3 changes: 3 additions & 0 deletions account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ categories = [ "cryptography", "cryptography::cryptocurrencies", "os" ]
license = "Apache-2.0"
edition = "2021"

[features]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.anyhow]
version = "1.0.79"

Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ edition = "2021"

[features]
default = [ "snarkos-node/metrics" ]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.aleo-std]
workspace = true
Expand Down
59 changes: 55 additions & 4 deletions cli/src/commands/developer/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub struct Execute {
pub network: u16,
/// The private key used to generate the execution.
#[clap(short, long)]
private_key: String,
private_key: Option<String>,
/// Specify the path to a file containing the account private key of the node
#[clap(long)]
private_key_file: Option<String>,
/// The endpoint to query node state from.
#[clap(short, long)]
query: String,
Expand All @@ -78,7 +81,9 @@ pub struct Execute {
impl Drop for Execute {
/// Zeroize the private key when the `Execute` struct goes out of scope.
fn drop(&mut self) {
self.private_key.zeroize();
if let Some(mut pk) = self.private_key.take() {
pk.zeroize()
}
}
}

Expand Down Expand Up @@ -106,7 +111,18 @@ impl Execute {
let query = Query::from(&self.query);

// Retrieve the private key.
let private_key = PrivateKey::from_str(&self.private_key)?;
let key_str = match (self.private_key.as_ref(), self.private_key_file.as_ref()) {
(Some(private_key), None) => private_key.to_owned(),
(None, Some(private_key_file)) => {
let path = private_key_file.parse::<PathBuf>().map_err(|e| anyhow!("Invalid path - {e}"))?;
std::fs::read_to_string(path)?.trim().to_string()
}
(None, None) => bail!("Missing the '--private-key' or '--private-key-file' argument"),
(Some(_), Some(_)) => {
bail!("Cannot specify both the '--private-key' and '--private-key-file' flags")
}
};
let private_key = PrivateKey::from_str(&key_str)?;

// Retrieve the program ID.
let program_id = ProgramID::from_str(&self.program_id)?;
Expand Down Expand Up @@ -238,7 +254,42 @@ mod tests {

if let Command::Developer(Developer::Execute(execute)) = cli.command {
assert_eq!(execute.network, 0);
assert_eq!(execute.private_key, "PRIVATE_KEY");
assert_eq!(execute.private_key, Some("PRIVATE_KEY".to_string()));
assert_eq!(execute.query, "QUERY");
assert_eq!(execute.priority_fee, Some(77));
assert_eq!(execute.record, Some("RECORD".into()));
assert_eq!(execute.program_id, "hello.aleo".to_string());
assert_eq!(execute.function, "hello".to_string());
assert_eq!(execute.inputs, vec!["1u32".to_string(), "2u32".to_string()]);
} else {
panic!("Unexpected result of clap parsing!");
}
}

#[test]
fn clap_snarkos_execute_pk_file() {
let arg_vec = vec![
"snarkos",
"developer",
"execute",
"--private-key-file",
"PRIVATE_KEY_FILE",
"--query",
"QUERY",
"--priority-fee",
"77",
"--record",
"RECORD",
"hello.aleo",
"hello",
"1u32",
"2u32",
];
let cli = CLI::parse_from(arg_vec);

if let Command::Developer(Developer::Execute(execute)) = cli.command {
assert_eq!(execute.network, 0);
assert_eq!(execute.private_key_file, Some("PRIVATE_KEY_FILE".to_string()));
assert_eq!(execute.query, "QUERY");
assert_eq!(execute.priority_fee, Some(77));
assert_eq!(execute.record, Some("RECORD".into()));
Expand Down
17 changes: 14 additions & 3 deletions cli/src/commands/developer/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#![allow(clippy::type_complexity)]

use crate::commands::CDN_BASE_URL;
use snarkvm::{
console::network::{CanaryV0, MainnetV0, Network, TestnetV0},
prelude::{Ciphertext, Field, FromBytes, Plaintext, PrivateKey, Record, ViewKey, block::Block},
Expand All @@ -31,8 +32,6 @@ use std::{
use zeroize::Zeroize;

const MAX_BLOCK_RANGE: u32 = 50;
// TODO (raychu86): This should be configurable based on network.
const CDN_ENDPOINT: &str = "https://s3.us-west-1.amazonaws.com/testnet3.blocks/phase3";

/// Scan the snarkOS node for records.
#[derive(Debug, Parser, Zeroize)]
Expand Down Expand Up @@ -172,6 +171,16 @@ impl Scan {
}
}

/// Returns the CDN to prefetch initial blocks from, from the given configurations.
fn parse_cdn<N: Network>() -> Result<String> {
match N::ID {
MainnetV0::ID => Ok(format!("{CDN_BASE_URL}/mainnet/v0")),
TestnetV0::ID => Ok(format!("{CDN_BASE_URL}/testnet/v0")),
CanaryV0::ID => Ok(format!("{CDN_BASE_URL}/canary/v0")),
_ => bail!("Unknown network ID ({})", N::ID),
}
}

/// Fetch owned ciphertext records from the endpoint.
fn fetch_records<N: Network>(
private_key: Option<PrivateKey<N>>,
Expand Down Expand Up @@ -215,11 +224,13 @@ impl Scan {
let mut request_start = match is_development_network {
true => start_height,
false => {
// Parse the CDN endpoint.
let cdn_endpoint = Self::parse_cdn::<N>()?;
// Scan the CDN first for records.
Self::scan_from_cdn(
start_height,
end_height,
CDN_ENDPOINT.to_string(),
cdn_endpoint,
endpoint.to_string(),
private_key,
*view_key,
Expand Down
20 changes: 13 additions & 7 deletions cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const DEVELOPMENT_MODE_RNG_SEED: u64 = 1234567890u64;
const DEVELOPMENT_MODE_NUM_GENESIS_COMMITTEE_MEMBERS: u16 = 4;

/// The CDN base url.
const CDN_BASE_URL: &str = "https://blocks.aleo.org";
pub(crate) const CDN_BASE_URL: &str = "https://blocks.aleo.org";

/// A mapping of `staker_address` to `(validator_address, withdrawal_address, amount)`.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
Expand Down Expand Up @@ -388,11 +388,10 @@ impl Start {
// Initialize the (fixed) RNG.
let mut rng = ChaChaRng::seed_from_u64(DEVELOPMENT_MODE_RNG_SEED);
// Initialize the development private keys.
let development_private_keys =
let dev_keys =
(0..num_committee_members).map(|_| PrivateKey::<N>::new(&mut rng)).collect::<Result<Vec<_>>>()?;
// Initialize the development addresses.
let development_addresses =
development_private_keys.iter().map(Address::<N>::try_from).collect::<Result<Vec<_>>>()?;
let development_addresses = dev_keys.iter().map(Address::<N>::try_from).collect::<Result<Vec<_>>>()?;

// Construct the committee based on the state of the bonded balances.
let (committee, bonded_balances) = match &self.dev_bonded_balances {
Expand Down Expand Up @@ -472,7 +471,7 @@ impl Start {
let public_balance_per_validator = remaining_balance.saturating_div(num_committee_members as u64);

// Construct the public balances with fairly equal distribution.
let mut public_balances = development_private_keys
let mut public_balances = dev_keys
.iter()
.map(|private_key| Ok((Address::try_from(private_key)?, public_balance_per_validator)))
.collect::<Result<indexmap::IndexMap<_, _>>>()?;
Expand All @@ -492,7 +491,7 @@ impl Start {
}

// Construct the genesis block.
load_or_compute_genesis(development_private_keys[0], committee, public_balances, bonded_balances, &mut rng)
load_or_compute_genesis(dev_keys[0], committee, public_balances, bonded_balances, self.dev, &mut rng)
} else {
// If the `dev_num_validators` flag is set, inform the user that it is ignored.
if self.dev_num_validators.is_some() {
Expand Down Expand Up @@ -520,6 +519,12 @@ impl Start {
// Print the welcome.
println!("{}", crate::helpers::welcome_message());

// Check if we are running with the lower coinbase and proof targets. This should only be
// allowed in --dev mode.
if cfg!(feature = "test_targets") && self.dev.is_none() {
bail!("The 'test_targets' feature is enabled, but the '--dev' flag is not set");
}

// Parse the trusted peers to connect to.
let mut trusted_peers = self.parse_trusted_peers()?;
// Parse the trusted validators to connect to.
Expand Down Expand Up @@ -667,6 +672,7 @@ fn load_or_compute_genesis<N: Network>(
committee: Committee<N>,
public_balances: indexmap::IndexMap<Address<N>, u64>,
bonded_balances: indexmap::IndexMap<Address<N>, (Address<N>, Address<N>, u64)>,
dev_id: Option<u16>,
rng: &mut ChaChaRng,
) -> Result<Block<N>> {
// Construct the preimage.
Expand Down Expand Up @@ -762,7 +768,7 @@ fn load_or_compute_genesis<N: Network>(
/* Otherwise, compute the genesis block and store it. */

// Initialize a new VM.
let vm = VM::from(ConsensusStore::<N, ConsensusMemory<N>>::open(Some(0))?)?;
let vm = VM::from(ConsensusStore::<N, ConsensusMemory<N>>::open(dev_id)?)?;
// Initialize the genesis block.
let block = vm.genesis_quorum(&genesis_private_key, committee, public_balances, bonded_balances, rng)?;
// Write the genesis block to the file.
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ metrics = [
"snarkos-node-tcp/metrics"
]
history = [ "snarkos-node-rest/history" ]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.aleo-std]
workspace = true
Expand Down
1 change: 1 addition & 0 deletions node/bft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ metrics = [
"snarkos-node-bft-events/metrics",
"snarkos-node-bft-ledger-service/metrics"
]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.aleo-std]
workspace = true
Expand Down
1 change: 1 addition & 0 deletions node/bft/events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ edition = "2021"
[features]
default = [ ]
metrics = [ "dep:metrics", "snarkvm/metrics" ]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.anyhow]
version = "1.0"
Expand Down
1 change: 1 addition & 0 deletions node/bft/ledger-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mock = [ "parking_lot", "tracing" ]
prover = [ ]
test = [ "mock", "translucent" ]
translucent = [ "ledger" ]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.async-trait]
version = "0.1"
Expand Down
7 changes: 7 additions & 0 deletions node/bft/storage-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ default = [ ]
memory = [ "parking_lot", "tracing" ]
persistent = [ ]
test = [ "memory" ]
test_targets = [ "snarkvm/test_targets" ]

[dependencies.aleo-std]
workspace = true

[dependencies.anyhow]
version = "1.0.79"

[dependencies.indexmap]
version = "2.1"
features = [ "serde", "rayon" ]

[dependencies.lru]
version = "0.12.1"

[dependencies.parking_lot]
version = "0.12"
optional = true
Expand Down
Loading

0 comments on commit ba70c75

Please sign in to comment.