constants.rs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2022 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. /// Genesis timestamp for the mainnet chain
  24. pub static ref MAINNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1650887115);
  25. /// Genesis hash for the testnet chain
  26. pub static ref TESTNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_testnet");
  27. /// Genesis timestamp for the testnet chain
  28. pub static ref TESTNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1670506503);
  29. // Commonly used Float10
  30. pub static ref FLOAT10_ZERO: Float10 = Float10::from_str_native("0").unwrap().with_precision(RADIX_BITS).value();
  31. pub static ref FLOAT10_ONE: Float10 = Float10::from_str_native("1").unwrap().with_precision(RADIX_BITS).value();
  32. pub static ref FLOAT10_TWO: Float10 = Float10::from_str_native("2").unwrap().with_precision(RADIX_BITS).value();
  33. pub static ref FLOAT10_THREE: Float10 = Float10::from_str_native("3").unwrap().with_precision(RADIX_BITS).value();
  34. pub static ref FLOAT10_FIVE: Float10 = Float10::from_str_native("5").unwrap().with_precision(RADIX_BITS).value();
  35. pub static ref FLOAT10_NINE: Float10 = Float10::from_str_native("9").unwrap().with_precision(RADIX_BITS).value();
  36. pub static ref FLOAT10_TEN: Float10 = Float10::from_str_native("10").unwrap().with_precision(RADIX_BITS).value();
  37. // Consensus parameters
  38. pub static ref DT: Float10 = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
  39. pub static ref TI: Float10 = FLOAT10_ONE.clone();
  40. pub static ref TD: Float10 = FLOAT10_ONE.clone();
  41. pub static ref KP: Float10 = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
  42. pub static ref KI: Float10 = Float10::from_str_native("0.03").unwrap().with_precision(RADIX_BITS).value();
  43. pub static ref KD: Float10 = FLOAT10_ONE.clone();
  44. pub static ref PID_OUT_STEP: Float10 = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
  45. pub static ref MAX_DER: Float10 = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
  46. pub static ref MIN_DER: Float10 = Float10::from_str_native("-0.1").unwrap().with_precision(RADIX_BITS).value();
  47. pub static ref MAX_F: Float10 = Float10::from_str_native("0.99").unwrap().with_precision(RADIX_BITS).value();
  48. pub static ref MIN_F: Float10 = Float10::from_str_native("0.05").unwrap().with_precision(RADIX_BITS).value();
  49. pub static ref DEG_RATE: Float10 = Float10::from_str_native("0.9").unwrap().with_precision(RADIX_BITS).value();
  50. }
  51. /// Block version number
  52. pub const BLOCK_VERSION: u8 = 1;
  53. /// Block magic bytes
  54. pub const BLOCK_MAGIC_BYTES: [u8; 4] = [0x11, 0x6d, 0x75, 0x1f];
  55. /// Block info magic bytes
  56. pub const BLOCK_INFO_MAGIC_BYTES: [u8; 4] = [0x90, 0x44, 0xf1, 0xf6];
  57. /// Number of slots in one epoch
  58. pub const EPOCH_LENGTH: usize = 10;
  59. /// Slot time in seconds
  60. pub const SLOT_TIME: u64 = 90;
  61. /// Finalization sync period duration (should be >=2/3 of slot time)
  62. pub const FINAL_SYNC_DUR: u64 = 60;
  63. /// Max resync retries
  64. pub const SYNC_MAX_RETRIES: u64 = 10;
  65. /// Transactions included in a block cap
  66. pub const TXS_CAP: usize = 50;
  67. /// Block leader reward
  68. pub const REWARD: u64 = 1;
  69. /// Leader proofs k for zk proof rows (rows=2^k)
  70. pub const LEADER_PROOF_K: u32 = 13;
  71. // TODO: Describe these constants
  72. pub const RADIX_BITS: usize = 76;
  73. pub const P: &str = "28948022309329048855892746252171976963363056481941560715954676764349967630337";
  74. pub const LOTTERY_HEAD_START: u64 = 1;
  75. pub const PRF_NULLIFIER_PREFIX: u64 = 0;
  76. pub const PI_COMMITMENT_X_INDEX: usize = 1;
  77. pub const PI_COMMITMENT_Y_INDEX: usize = 2;
  78. pub const PI_COMMITMENT_ROOT: usize = 5;
  79. pub const PI_NULLIFIER_INDEX: usize = 7;
  80. pub const PI_MU_Y_INDEX: usize = 8;
  81. pub const PI_MU_RHO_INDEX: usize = 10;
  82. pub const PI_SIGMA1_INDEX: usize = 12;
  83. pub const PI_SIGMA2_INDEX: usize = 13;
  84. pub const GENESIS_TOTAL_STAKE: i64 = 1;