constants.rs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use lazy_static::lazy_static;
  19. use crate::{consensus::Float10, util::time::Timestamp};
  20. lazy_static! {
  21. /// Genesis hash for the mainnet chain
  22. pub static ref MAINNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_mainnet");
  23. // NOTE: On initial network bootstrap, genesis timestamp should be equal to boostrap timestamp.
  24. // On network restart only change bootstrap timestamp to schedule when nodes become active.
  25. /// Genesis timestamp for the mainnet chain
  26. pub static ref MAINNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1650887115);
  27. /// Bootstrap timestamp for the mainnet chain
  28. pub static ref MAINNET_BOOTSTRAP_TIMESTAMP: Timestamp = Timestamp(1650887115);
  29. /// Total sum of initial staking coins for the mainnet chain
  30. pub static ref MAINNET_INITIAL_DISTRIBUTION: u64 = 1000;
  31. /// Genesis hash for the testnet chain
  32. pub static ref TESTNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_testnet");
  33. /// Genesis timestamp for the testnet chain
  34. pub static ref TESTNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1672785000);
  35. /// Bootstrap timestamp for the testnet chain
  36. pub static ref TESTNET_BOOTSTRAP_TIMESTAMP: Timestamp = Timestamp(1672785000);
  37. /// Total sum of initial staking coins for the testnet chain
  38. pub static ref TESTNET_INITIAL_DISTRIBUTION: u64 = 1000;
  39. // Commonly used Float10
  40. pub static ref FLOAT10_NEG_TWO: Float10 = Float10::try_from("-2").unwrap();
  41. pub static ref FLOAT10_NEG_ONE: Float10 = Float10::try_from("-1").unwrap();
  42. pub static ref FLOAT10_ZERO: Float10 = Float10::try_from("0").unwrap();
  43. pub static ref FLOAT10_ONE: Float10 = Float10::try_from("1").unwrap();
  44. pub static ref FLOAT10_TWO: Float10 = Float10::try_from("2").unwrap();
  45. pub static ref FLOAT10_THREE: Float10 = Float10::try_from("3").unwrap();
  46. pub static ref FLOAT10_FIVE: Float10 = Float10::try_from("5").unwrap();
  47. pub static ref FLOAT10_NINE: Float10 = Float10::try_from("9").unwrap();
  48. pub static ref FLOAT10_TEN: Float10 = Float10::try_from("10").unwrap();
  49. // Consensus parameters
  50. pub static ref KP: Float10 = Float10::try_from("0.18").unwrap();
  51. pub static ref KI: Float10 = Float10::try_from("0.02").unwrap();
  52. pub static ref KD: Float10 = Float10::try_from("-0.1").unwrap();
  53. pub static ref PID_OUT_STEP: Float10 = Float10::try_from("0.1").unwrap();
  54. pub static ref MAX_DER: Float10 = Float10::try_from("0.1").unwrap();
  55. pub static ref MIN_DER: Float10 = Float10::try_from("-0.1").unwrap();
  56. pub static ref MAX_F: Float10 = Float10::try_from("0.99").unwrap();
  57. pub static ref MIN_F: Float10 = Float10::try_from("0.05").unwrap();
  58. }
  59. /// Block version number
  60. pub const BLOCK_VERSION: u8 = 1;
  61. /// Block magic bytes
  62. pub const BLOCK_MAGIC_BYTES: [u8; 4] = [0x11, 0x6d, 0x75, 0x1f];
  63. /// Block info magic bytes
  64. pub const BLOCK_INFO_MAGIC_BYTES: [u8; 4] = [0x90, 0x44, 0xf1, 0xf6];
  65. /// Number of slots in one epoch
  66. pub const EPOCH_LENGTH: usize = 10;
  67. /// Slot time in seconds
  68. pub const SLOT_TIME: u64 = 90;
  69. /// Finalization sync period duration (should be >=2/3 of slot time)
  70. pub const FINAL_SYNC_DUR: u64 = 60;
  71. /// Max resync retries duration in epochs
  72. pub const SYNC_RETRIES_DURATION: u64 = 2;
  73. /// Max resync retries
  74. pub const SYNC_MAX_RETRIES: u64 = 10;
  75. /// Transactions included in a block cap
  76. pub const TXS_CAP: usize = 50;
  77. /// Block leader reward
  78. pub const REWARD: u64 = 1;
  79. /// Leader proofs k for zk proof rows (rows=2^k)
  80. pub const LEADER_PROOF_K: u32 = 13;
  81. // TODO: Describe these constants
  82. pub const RADIX_BITS: usize = 76;
  83. pub const P: &str = "28948022309329048855892746252171976963363056481941560715954676764349967630337";
  84. pub const LOTTERY_HEAD_START: u64 = 1;
  85. pub const PRF_NULLIFIER_PREFIX: u64 = 0;
  86. pub const PI_COMMITMENT_X_INDEX: usize = 1;
  87. pub const PI_COMMITMENT_Y_INDEX: usize = 2;
  88. pub const PI_COMMITMENT_ROOT: usize = 5;
  89. pub const PI_NULLIFIER_INDEX: usize = 7;
  90. pub const PI_MU_Y_INDEX: usize = 8;
  91. pub const PI_MU_RHO_INDEX: usize = 10;
  92. pub const PI_SIGMA1_INDEX: usize = 12;
  93. pub const PI_SIGMA2_INDEX: usize = 13;
  94. pub const GENESIS_TOTAL_STAKE: u64 = 1;
  95. pub const LEADER_HISTORY_LOG : &str = "/tmp/lead_history.log";
  96. pub const F_HISTORY_LOG : &str = "/tmp/f_history.log";
  97. pub const LOTTERY_HISTORY_LOG : &str = "/tmp/lottery_history.log";