mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 22:57:59 -05:00
consensus: created single-node mode for local testing
This commit is contained in:
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8340"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = false
|
consensus = false
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
#consensus_p2p_accept = ["tls://127.0.0.1:8341"]
|
#consensus_p2p_accept = ["tls://127.0.0.1:8341"]
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ struct Args {
|
|||||||
/// Participate in consensus
|
/// Participate in consensus
|
||||||
consensus: bool,
|
consensus: bool,
|
||||||
|
|
||||||
|
#[structopt(long)]
|
||||||
|
/// Enable single-node mode for local testing
|
||||||
|
single_node: bool,
|
||||||
|
|
||||||
#[structopt(long, default_value = "~/.config/darkfi/darkfid_wallet.db")]
|
#[structopt(long, default_value = "~/.config/darkfi/darkfid_wallet.db")]
|
||||||
/// Path to wallet database
|
/// Path to wallet database
|
||||||
wallet_path: String,
|
wallet_path: String,
|
||||||
@@ -327,6 +331,10 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
|||||||
faucet_pubkeys.push(pk);
|
faucet_pubkeys.push(pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args.single_node {
|
||||||
|
info!("Node is configured to tun in single-node mode!");
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize validator state
|
// Initialize validator state
|
||||||
let state = ValidatorState::new(
|
let state = ValidatorState::new(
|
||||||
&sled_db,
|
&sled_db,
|
||||||
@@ -337,6 +345,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
|||||||
wallet.clone(),
|
wallet.clone(),
|
||||||
faucet_pubkeys,
|
faucet_pubkeys,
|
||||||
args.consensus,
|
args.consensus,
|
||||||
|
args.single_node,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -574,6 +574,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
|||||||
wallet.clone(),
|
wallet.clone(),
|
||||||
faucet_pubkeys,
|
faucet_pubkeys,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8340"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8440"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8441"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8441"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8540"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8541"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8541"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8640"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8641"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8641"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8740"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8741"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8741"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8340"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = true
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8340"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8440"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8441"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8441"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8540"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = false
|
consensus = false
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
#consensus_p2p_accept = ["tcp://127.0.0.1:8541"]
|
#consensus_p2p_accept = ["tcp://127.0.0.1:8541"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8340"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8341"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8440"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = true
|
consensus = true
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
consensus_p2p_accept = ["tcp://127.0.0.1:8441"]
|
consensus_p2p_accept = ["tcp://127.0.0.1:8441"]
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ rpc_listen = "tcp://127.0.0.1:8540"
|
|||||||
# Participate in the consensus protocol
|
# Participate in the consensus protocol
|
||||||
consensus = false
|
consensus = false
|
||||||
|
|
||||||
|
# Enable single-node mode for local testing
|
||||||
|
single_node = false
|
||||||
|
|
||||||
# P2P accept addresses for the consensus protocol
|
# P2P accept addresses for the consensus protocol
|
||||||
#consensus_p2p_accept = ["tcp://127.0.0.1:8541"]
|
#consensus_p2p_accept = ["tcp://127.0.0.1:8541"]
|
||||||
|
|
||||||
|
|||||||
@@ -328,6 +328,7 @@ async fn generate(localnet: &str, name: &str) -> Result<()> {
|
|||||||
wallet,
|
wallet,
|
||||||
vec![],
|
vec![],
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let info = StateInfo::new(&*state.read().await);
|
let info = StateInfo::new(&*state.read().await);
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ pub struct ConsensusState {
|
|||||||
pub genesis_block: blake3::Hash,
|
pub genesis_block: blake3::Hash,
|
||||||
/// Total sum of initial staking coins
|
/// Total sum of initial staking coins
|
||||||
pub initial_distribution: u64,
|
pub initial_distribution: u64,
|
||||||
|
/// Flag to enable single-node mode
|
||||||
|
pub single_node: bool,
|
||||||
/// Slot the network was bootstrapped
|
/// Slot the network was bootstrapped
|
||||||
pub bootstrap_slot: u64,
|
pub bootstrap_slot: u64,
|
||||||
/// Participating start slot
|
/// Participating start slot
|
||||||
@@ -91,6 +93,7 @@ impl ConsensusState {
|
|||||||
genesis_ts: Timestamp,
|
genesis_ts: Timestamp,
|
||||||
genesis_data: blake3::Hash,
|
genesis_data: blake3::Hash,
|
||||||
initial_distribution: u64,
|
initial_distribution: u64,
|
||||||
|
single_node: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let genesis_block = Block::genesis_block(genesis_ts, genesis_data).blockhash();
|
let genesis_block = Block::genesis_block(genesis_ts, genesis_data).blockhash();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@@ -99,6 +102,7 @@ impl ConsensusState {
|
|||||||
genesis_ts,
|
genesis_ts,
|
||||||
genesis_block,
|
genesis_block,
|
||||||
initial_distribution,
|
initial_distribution,
|
||||||
|
single_node,
|
||||||
bootstrap_slot: 0,
|
bootstrap_slot: 0,
|
||||||
participating: None,
|
participating: None,
|
||||||
proposing: false,
|
proposing: false,
|
||||||
@@ -303,9 +307,10 @@ impl ConsensusState {
|
|||||||
// Temporarily, we compete with fixed stake.
|
// Temporarily, we compete with fixed stake.
|
||||||
// This stake should be based on how many nodes we want to run, and they all
|
// This stake should be based on how many nodes we want to run, and they all
|
||||||
// must sum to initial distribution total coins.
|
// must sum to initial distribution total coins.
|
||||||
//let stake = self.initial_distribution;
|
let stake = self.initial_distribution;
|
||||||
|
//let stake = 200;
|
||||||
let coin = LeadCoin::new(
|
let coin = LeadCoin::new(
|
||||||
200,
|
stake,
|
||||||
slot,
|
slot,
|
||||||
epoch_secrets.secret_keys[0].inner(),
|
epoch_secrets.secret_keys[0].inner(),
|
||||||
epoch_secrets.merkle_roots[0],
|
epoch_secrets.merkle_roots[0],
|
||||||
@@ -453,6 +458,12 @@ impl ConsensusState {
|
|||||||
self.forks[fork_index as usize].sequence.last().unwrap().coins.clone()
|
self.forks[fork_index as usize].sequence.last().unwrap().coins.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If on single-node mode, node always proposes by extending the
|
||||||
|
// single fork it holds.
|
||||||
|
if self.single_node {
|
||||||
|
return (true, fork_index, 0)
|
||||||
|
}
|
||||||
|
|
||||||
let mut won = false;
|
let mut won = false;
|
||||||
let mut highest_stake = 0;
|
let mut highest_stake = 0;
|
||||||
let mut highest_stake_idx = 0;
|
let mut highest_stake_idx = 0;
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ pub struct ValidatorState {
|
|||||||
pub verifying_keys: VerifyingKeyMap,
|
pub verifying_keys: VerifyingKeyMap,
|
||||||
/// Wallet interface
|
/// Wallet interface
|
||||||
pub wallet: WalletPtr,
|
pub wallet: WalletPtr,
|
||||||
|
/// Flag to enable single-node mode
|
||||||
|
pub single_node: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValidatorState {
|
impl ValidatorState {
|
||||||
@@ -98,6 +100,7 @@ impl ValidatorState {
|
|||||||
wallet: WalletPtr,
|
wallet: WalletPtr,
|
||||||
faucet_pubkeys: Vec<PublicKey>,
|
faucet_pubkeys: Vec<PublicKey>,
|
||||||
enable_participation: bool,
|
enable_participation: bool,
|
||||||
|
single_node: bool,
|
||||||
) -> Result<ValidatorStatePtr> {
|
) -> Result<ValidatorStatePtr> {
|
||||||
debug!(target: "consensus::validator", "Initializing ValidatorState");
|
debug!(target: "consensus::validator", "Initializing ValidatorState");
|
||||||
|
|
||||||
@@ -130,6 +133,7 @@ impl ValidatorState {
|
|||||||
genesis_ts,
|
genesis_ts,
|
||||||
genesis_data,
|
genesis_data,
|
||||||
initial_distribution,
|
initial_distribution,
|
||||||
|
single_node,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let unconfirmed_txs = vec![];
|
let unconfirmed_txs = vec![];
|
||||||
@@ -222,6 +226,7 @@ impl ValidatorState {
|
|||||||
subscribers,
|
subscribers,
|
||||||
verifying_keys: Arc::new(RwLock::new(verifying_keys)),
|
verifying_keys: Arc::new(RwLock::new(verifying_keys)),
|
||||||
wallet,
|
wallet,
|
||||||
|
single_node,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
@@ -458,59 +463,64 @@ impl ValidatorState {
|
|||||||
return Err(Error::ProposalHeadersMissmatchError)
|
return Err(Error::ProposalHeadersMissmatchError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify proposal leader proof
|
// Ignore node coin validations if we oporate in single-node mode
|
||||||
if let Err(e) = lf.proof.verify(&self.lead_verifying_key, &lf.public_inputs) {
|
if !self.single_node {
|
||||||
error!(target: "consensus::validator", "receive_proposal(): Error during leader proof verification: {}", e);
|
// Verify proposal leader proof
|
||||||
return Err(Error::LeaderProofVerification)
|
if let Err(e) = lf.proof.verify(&self.lead_verifying_key, &lf.public_inputs) {
|
||||||
};
|
error!(target: "consensus::validator", "receive_proposal(): Error during leader proof verification: {}", e);
|
||||||
info!(target: "consensus::validator", "receive_proposal(): Leader proof verified successfully!");
|
return Err(Error::LeaderProofVerification)
|
||||||
|
};
|
||||||
|
info!(target: "consensus::validator", "receive_proposal(): Leader proof verified successfully!");
|
||||||
|
|
||||||
// Validate proposal public value against coin creation slot checkpoint
|
// Validate proposal public value against coin creation slot checkpoint
|
||||||
let (mu_y, mu_rho) =
|
let (mu_y, mu_rho) = LeadCoin::election_seeds_u64(
|
||||||
LeadCoin::election_seeds_u64(self.consensus.get_eta(), self.consensus.current_slot());
|
self.consensus.get_eta(),
|
||||||
// y
|
self.consensus.current_slot(),
|
||||||
let prop_mu_y = lf.public_inputs[constants::PI_MU_Y_INDEX];
|
|
||||||
|
|
||||||
if mu_y != prop_mu_y {
|
|
||||||
error!(
|
|
||||||
target: "consensus::validator",
|
|
||||||
"receive_proposal(): Failed to verify mu_y: {:?}, proposed: {:?}",
|
|
||||||
mu_y, prop_mu_y
|
|
||||||
);
|
);
|
||||||
return Err(Error::ProposalPublicValuesMismatched)
|
// y
|
||||||
}
|
let prop_mu_y = lf.public_inputs[constants::PI_MU_Y_INDEX];
|
||||||
|
|
||||||
// rho
|
if mu_y != prop_mu_y {
|
||||||
let prop_mu_rho = lf.public_inputs[constants::PI_MU_RHO_INDEX];
|
error!(
|
||||||
|
target: "consensus::validator",
|
||||||
|
"receive_proposal(): Failed to verify mu_y: {:?}, proposed: {:?}",
|
||||||
|
mu_y, prop_mu_y
|
||||||
|
);
|
||||||
|
return Err(Error::ProposalPublicValuesMismatched)
|
||||||
|
}
|
||||||
|
|
||||||
if mu_rho != prop_mu_rho {
|
// rho
|
||||||
error!(
|
let prop_mu_rho = lf.public_inputs[constants::PI_MU_RHO_INDEX];
|
||||||
target: "consensus::validator",
|
|
||||||
"receive_proposal(): Failed to verify mu_rho: {:?}, proposed: {:?}",
|
|
||||||
mu_rho, prop_mu_rho
|
|
||||||
);
|
|
||||||
return Err(Error::ProposalPublicValuesMismatched)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate proposal coin sigmas against current slot checkpoint
|
if mu_rho != prop_mu_rho {
|
||||||
let checkpoint = self.consensus.get_slot_checkpoint(current)?;
|
error!(
|
||||||
// sigma1
|
target: "consensus::validator",
|
||||||
let prop_sigma1 = lf.public_inputs[constants::PI_SIGMA1_INDEX];
|
"receive_proposal(): Failed to verify mu_rho: {:?}, proposed: {:?}",
|
||||||
if checkpoint.sigma1 != prop_sigma1 {
|
mu_rho, prop_mu_rho
|
||||||
error!(
|
);
|
||||||
target: "consensus::validator",
|
return Err(Error::ProposalPublicValuesMismatched)
|
||||||
"receive_proposal(): Failed to verify public value sigma1: {:?}, to proposed: {:?}",
|
}
|
||||||
checkpoint.sigma1, prop_sigma1
|
|
||||||
);
|
// Validate proposal coin sigmas against current slot checkpoint
|
||||||
}
|
let checkpoint = self.consensus.get_slot_checkpoint(current)?;
|
||||||
// sigma2
|
// sigma1
|
||||||
let prop_sigma2 = lf.public_inputs[constants::PI_SIGMA2_INDEX];
|
let prop_sigma1 = lf.public_inputs[constants::PI_SIGMA1_INDEX];
|
||||||
if checkpoint.sigma2 != prop_sigma2 {
|
if checkpoint.sigma1 != prop_sigma1 {
|
||||||
error!(
|
error!(
|
||||||
target: "consensus::validator",
|
target: "consensus::validator",
|
||||||
"receive_proposal(): Failed to verify public value sigma2: {:?}, to proposed: {:?}",
|
"receive_proposal(): Failed to verify public value sigma1: {:?}, to proposed: {:?}",
|
||||||
checkpoint.sigma2, prop_sigma2
|
checkpoint.sigma1, prop_sigma1
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
// sigma2
|
||||||
|
let prop_sigma2 = lf.public_inputs[constants::PI_SIGMA2_INDEX];
|
||||||
|
if checkpoint.sigma2 != prop_sigma2 {
|
||||||
|
error!(
|
||||||
|
target: "consensus::validator",
|
||||||
|
"receive_proposal(): Failed to verify public value sigma2: {:?}, to proposed: {:?}",
|
||||||
|
checkpoint.sigma2, prop_sigma2
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create corresponding state checkpoint for validations
|
// Create corresponding state checkpoint for validations
|
||||||
|
|||||||
Reference in New Issue
Block a user