Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
cargo build --release

run_multiple:
./run.sh

clean:
./stop.sh
9 changes: 9 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
> pids.txt

cargo build --release
for i in {1..50}
do
./target/release/snarkos --connect_to_beacon 95.217.56.71:4130 --dev $((i)) --rest_port
$((i + 11000)) --node 0.0.0.0:$((i+10000)) & echo "$!" >> pids.txt
done
4 changes: 4 additions & 0 deletions snarkos/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub struct CLI {
#[clap(long = "connect")]
pub connect: Option<String>,

/// Specify the rest API port for the node server.
#[clap(long = "rest_port")]
pub rest_port: Option<u16>,

/// Specify the IP address and port for the RPC server.
#[clap(default_value = "0.0.0.0:3033", long = "rpc")]
pub rpc: SocketAddr,
Expand Down
12 changes: 6 additions & 6 deletions snarkos/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Ledger<N: Network> {

impl<N: Network> Ledger<N> {
/// Initializes a new instance of the ledger.
pub(super) fn new_with_genesis(private_key: PrivateKey<N>, genesis_block: Block<N>, dev: Option<u16>) -> Result<Arc<Self>> {
pub(super) fn new_with_genesis(private_key: PrivateKey<N>, genesis_block: Block<N>, dev: Option<u16>, custom_port: Option<u16>) -> Result<Arc<Self>> {
// Initialize the ledger.
let ledger = match InternalLedger::new_with_genesis(&genesis_block, genesis_block.signature().to_address(), dev) {
Ok(ledger) => Arc::new(RwLock::new(ledger)),
Expand All @@ -70,19 +70,19 @@ impl<N: Network> Ledger<N> {
};

// Return the ledger.
Self::from(ledger, private_key)
Self::from(ledger, private_key, custom_port)
}

/// Opens an instance of the ledger.
pub fn load(private_key: PrivateKey<N>, dev: Option<u16>) -> Result<Arc<Self>> {
pub fn load(private_key: PrivateKey<N>, dev: Option<u16>, custom_port: Option<u16>) -> Result<Arc<Self>> {
// Initialize the ledger.
let ledger = Arc::new(RwLock::new(InternalLedger::open(dev)?));
// Return the ledger.
Self::from(ledger, private_key)
Self::from(ledger, private_key, custom_port)
}

/// Initializes a new instance of the ledger.
pub fn from(ledger: Arc<RwLock<InternalLedger<N>>>, private_key: PrivateKey<N>) -> Result<Arc<Self>> {
pub fn from(ledger: Arc<RwLock<InternalLedger<N>>>, private_key: PrivateKey<N>, custom_port: Option<u16>) -> Result<Arc<Self>> {
// Derive the view key and address.
let view_key = ViewKey::try_from(private_key)?;
let address = Address::try_from(&view_key)?;
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<N: Network> Ledger<N> {
};

// Initialize the server.
let server = InternalServer::<N>::start(ledger.clone(), Some(additional_routes), None)?;
let server = InternalServer::<N>::start(ledger.clone(), Some(additional_routes), custom_port)?;

// Return the ledger.
Ok(Arc::new(Self {
Expand Down
4 changes: 2 additions & 2 deletions snarkos/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<N: Network, E: Environment> Node<N, E> {
let ledger = match cli.dev {
None => {
// Initialize the ledger.
let ledger = Ledger::<N>::load(*account.private_key(), cli.dev)?;
let ledger = Ledger::<N>::load(*account.private_key(), cli.dev, cli.rest_port)?;
// Sync the ledger with the network.
ledger.initial_sync_with_network(cli.beacon_addr.ip()).await?;

Expand All @@ -52,7 +52,7 @@ impl<N: Network, E: Environment> Node<N, E> {
let genesis_block = request_genesis_block::<N>(cli.beacon_addr.ip()).await?;

// Initialize the ledger from the provided genesis block.
Ledger::<N>::new_with_genesis(*account.private_key(), genesis_block, cli.dev)?
Ledger::<N>::new_with_genesis(*account.private_key(), genesis_block, cli.dev, cli.rest_port)?
}
};

Expand Down
4 changes: 4 additions & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pkill -f snarkos
rm -rf .ledger-3-*