mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 22:57:59 -05:00
[consensus] y in is_lead fixed from commitment to hash, similar to the circuit
This commit is contained in:
@@ -71,6 +71,7 @@ circuit "Lead" {
|
||||
seed = poseidon_hash(PREFIX_SEED, c1_sk_root, c1_rho, ZERO);
|
||||
# y
|
||||
y = poseidon_hash(seed, mu_y);
|
||||
###
|
||||
constrain_instance(mu_y);
|
||||
constrain_instance(y);
|
||||
# rho
|
||||
|
||||
@@ -20,6 +20,7 @@ use lazy_static::lazy_static;
|
||||
|
||||
use crate::{consensus::Float10, util::time::Timestamp};
|
||||
|
||||
|
||||
lazy_static! {
|
||||
/// Genesis hash for the mainnet chain
|
||||
pub static ref MAINNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_mainnet");
|
||||
@@ -27,10 +28,10 @@ lazy_static! {
|
||||
// NOTE: On initial network bootstrap, genesis timestamp should be equal to boostrap timestamp.
|
||||
// On network restart only change bootstrap timestamp to schedule when nodes become active.
|
||||
/// Genesis timestamp for the mainnet chain
|
||||
pub static ref MAINNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1650887115);
|
||||
pub static ref MAINNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1773025405);
|
||||
|
||||
/// Bootstrap timestamp for the mainnet chain
|
||||
pub static ref MAINNET_BOOTSTRAP_TIMESTAMP: Timestamp = Timestamp(1650887115);
|
||||
pub static ref MAINNET_BOOTSTRAP_TIMESTAMP: Timestamp = Timestamp(1773025405);
|
||||
|
||||
/// Total sum of initial staking coins for the mainnet chain
|
||||
pub static ref MAINNET_INITIAL_DISTRIBUTION: u64 = 1000;
|
||||
@@ -39,10 +40,10 @@ lazy_static! {
|
||||
pub static ref TESTNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_testnet");
|
||||
|
||||
/// Genesis timestamp for the testnet chain
|
||||
pub static ref TESTNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1672785000);
|
||||
pub static ref TESTNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1673039000);
|
||||
|
||||
/// Bootstrap timestamp for the testnet chain
|
||||
pub static ref TESTNET_BOOTSTRAP_TIMESTAMP: Timestamp = Timestamp(1672785000);
|
||||
pub static ref TESTNET_BOOTSTRAP_TIMESTAMP: Timestamp = Timestamp(1673039000);
|
||||
|
||||
/// Total sum of initial staking coins for the testnet chain
|
||||
pub static ref TESTNET_INITIAL_DISTRIBUTION: u64 = 1000;
|
||||
@@ -61,12 +62,17 @@ lazy_static! {
|
||||
|
||||
|
||||
// Consensus parameters
|
||||
pub static ref DT: Float10 = Float10::try_from("0.1").unwrap();
|
||||
|
||||
pub static ref TI: Float10 = FLOAT10_ONE.clone();
|
||||
pub static ref TD: Float10 = FLOAT10_ONE.clone();
|
||||
//pid parameters
|
||||
//pub static ref KP: Float10 = Float10::from_str_native("-0.8").unwrap().with_precision(RADIX_BITS).value();
|
||||
//pub static ref KI: Float10 = Float10::from_str_native("0.6").unwrap().with_precision(RADIX_BITS).value();
|
||||
//pub static ref KD: Float10 = Float10::from_str_native("0.8").unwrap().with_precision(RADIX_BITS).value();
|
||||
// pid discrete parameters
|
||||
pub static ref KP: Float10 = Float10::from_str_native("0.5").unwrap().with_precision(RADIX_BITS).value();
|
||||
pub static ref KI: Float10 = Float10::from_str_native("0.8").unwrap().with_precision(RADIX_BITS).value();
|
||||
|
||||
pub static ref KP: Float10 = Float10::from_str_native("-0.8").unwrap().with_precision(RADIX_BITS).value();
|
||||
pub static ref KI: Float10 = Float10::from_str_native("0.6").unwrap().with_precision(RADIX_BITS).value();
|
||||
pub static ref KD: Float10 = Float10::from_str_native("0.8").unwrap().with_precision(RADIX_BITS).value();
|
||||
pub static ref PID_OUT_STEP: Float10 = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
|
||||
pub static ref MAX_DER: Float10 = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
|
||||
|
||||
@@ -305,16 +305,11 @@ impl LeadCoin {
|
||||
];
|
||||
let y_seed_hash = poseidon_hash(y_seed);
|
||||
let (y_mu, rho_mu) = Self::election_seeds(current_eta, current_slot);
|
||||
let y_coords = pedersen_commitment_base(y_seed_hash, mod_r_p(y_mu))
|
||||
.to_affine()
|
||||
.coordinates()
|
||||
.unwrap();
|
||||
|
||||
let y_coords = [*y_coords.x(), *y_coords.y()];
|
||||
let y = poseidon_hash(y_coords);
|
||||
let y_msg = [y_seed_hash, y_mu];
|
||||
let y = poseidon_hash(y_msg);
|
||||
|
||||
let value = pallas::Base::from(self.value);
|
||||
let target = sigma1 * value + sigma2 * value * value;
|
||||
let target = pallas::Base::one().neg() * (sigma1 * value + sigma2 * value * value);
|
||||
|
||||
info!(target: "consensus::leadcoin", "is_leader(): y = {:?}", y);
|
||||
info!(target: "consensus::leadcoin", "is_leader(): T = {:?}", target);
|
||||
|
||||
@@ -432,9 +432,11 @@ impl ConsensusState {
|
||||
let second_to_last = Float10::try_from(self.leaders_history[len - 2] as i64).unwrap();
|
||||
|
||||
let mut der =
|
||||
(Self::pid_error(second_to_last) - Self::pid_error(last)) / constants::DT.clone();
|
||||
(Self::pid_error(second_to_last) - Self::pid_error(last)) / constants::TD.clone();
|
||||
/*
|
||||
der = if der > constants::MAX_DER.clone() { constants::MAX_DER.clone() } else { der };
|
||||
der = if der < constants::MIN_DER.clone() { constants::MIN_DER.clone() } else { der };
|
||||
*/
|
||||
der
|
||||
}
|
||||
|
||||
@@ -503,7 +505,6 @@ impl ConsensusState {
|
||||
k1 * err.clone() +
|
||||
k2 * self.err_history[err_len-1].clone() +
|
||||
k3 * self.err_history[err_len-2].clone();
|
||||
self.f_history.push(ret.clone());
|
||||
self.err_history.push(err);
|
||||
ret
|
||||
}
|
||||
@@ -512,7 +513,7 @@ impl ConsensusState {
|
||||
fn win_inv_prob_with_full_stake(&mut self) -> Float10 {
|
||||
self.extend_leaders_history();
|
||||
//
|
||||
let f = self.discrete_pid();
|
||||
let mut f = self.discrete_pid();
|
||||
// log f history
|
||||
let file = File::options().append(true).open(constants::F_HISTORY_LOG).unwrap();
|
||||
{
|
||||
@@ -521,10 +522,10 @@ impl ConsensusState {
|
||||
let mut writer = BufWriter::new(file);
|
||||
writer.write(&f_history.into_bytes()).unwrap();
|
||||
}
|
||||
if f == constants::FLOAT10_ZERO.clone() {
|
||||
return constants::MIN_F.clone()
|
||||
if f <= constants::FLOAT10_ZERO.clone() {
|
||||
f = constants::MIN_F.clone()
|
||||
} else if f >= constants::FLOAT10_ONE.clone() {
|
||||
return constants::MAX_F.clone()
|
||||
f = constants::MAX_F.clone()
|
||||
}
|
||||
let hist_len = self.leaders_history.len();
|
||||
if hist_len > 3 &&
|
||||
@@ -533,8 +534,9 @@ impl ConsensusState {
|
||||
self.leaders_history[hist_len - 3] == 0
|
||||
//&& i == constants::FLOAT10_ZERO.clone()
|
||||
{
|
||||
return f * constants::DEG_RATE.clone().powf(self.zero_leads_len())
|
||||
f = f.clone() * constants::DEG_RATE.clone().powf(self.zero_leads_len());
|
||||
}
|
||||
self.f_history.push(f.clone());
|
||||
f
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user