Skip to content

Commit

Permalink
chore: update berghain chainspec settings 🚀 (#4219) (#4246)
Browse files Browse the repository at this point in the history
Co-authored-by: Assem <asem.hasna@gmail.com>
Co-authored-by: tomjohnburton <39559415+tomjohnburton@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 15, 2023
1 parent 5fdba98 commit 70f1db1
Show file tree
Hide file tree
Showing 15 changed files with 625 additions and 219 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion engine/src/witness/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use eth_source::EthSource;

use anyhow::{Context, Result};

const SAFETY_MARGIN: usize = 7;
const SAFETY_MARGIN: usize = 6;

pub async fn start<
StateChainClient,
Expand Down
17 changes: 12 additions & 5 deletions state-chain/cf-integration-tests/src/mock_runtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use chainflip_node::test_account_from_seed;
use chainflip_node::{
chain_spec::testnet::{EXPIRY_SPAN_IN_SECONDS, REDEMPTION_TTL_SECS},
test_account_from_seed,
};
use pallet_cf_validator::SetSizeParameters;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_runtime::{Percent, Permill};
Expand Down Expand Up @@ -129,7 +133,7 @@ impl ExtBuilder {
genesis_accounts: self.genesis_accounts.clone(),
redemption_tax: MIN_FUNDING / 2,
minimum_funding: MIN_FUNDING,
redemption_ttl: core::time::Duration::from_secs(3 * REDEMPTION_DELAY_SECS),
redemption_ttl: core::time::Duration::from_secs(REDEMPTION_TTL_SECS),
},
reputation: ReputationConfig {
accrual_ratio: ACCRUAL_RATIO,
Expand Down Expand Up @@ -163,9 +167,12 @@ impl ExtBuilder {
),
backup_reward_node_percentage: Percent::from_percent(34),
authority_set_min_size: self.min_authorities,
min_size: self.min_authorities,
max_size: self.max_authorities,
max_expansion: self.max_authorities,
auction_parameters: SetSizeParameters {
min_size: self.min_authorities,
max_size: self.max_authorities,
max_expansion: self.max_authorities,
},
auction_bid_cutoff_percentage: Percent::from_percent(0),
max_authority_set_contraction_percentage: DEFAULT_MAX_AUTHORITY_SET_CONTRACTION,
},
ethereum_vault: EthereumVaultConfig {
Expand Down
345 changes: 345 additions & 0 deletions state-chain/node/chainspecs/berghain.chainspec.json

Large diffs are not rendered by default.

225 changes: 115 additions & 110 deletions state-chain/node/chainspecs/berghain.chainspec.raw.json

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions state-chain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use state_chain_runtime::{
EthereumChainTrackingConfig, EthereumIngressEgressConfig, EthereumThresholdSignerConfig,
EthereumVaultConfig, FlipBalance, FlipConfig, FundingConfig, GovernanceConfig, GrandpaConfig,
PolkadotChainTrackingConfig, PolkadotIngressEgressConfig, PolkadotThresholdSignerConfig,
PolkadotVaultConfig, ReputationConfig, RuntimeGenesisConfig, SessionConfig, Signature,
SwappingConfig, SystemConfig, ValidatorConfig, WASM_BINARY,
PolkadotVaultConfig, ReputationConfig, RuntimeGenesisConfig, SessionConfig, SetSizeParameters,
Signature, SwappingConfig, SystemConfig, ValidatorConfig, WASM_BINARY,
};

use std::{
Expand Down Expand Up @@ -232,8 +232,8 @@ pub fn inner_cf_development_config(
testnet::extra_accounts(),
// Governance account - Snow White
testnet::SNOW_WHITE_SR25519.into(),
1,
devnet::MAX_AUTHORITIES,
devnet::MIN_AUTHORITIES,
devnet::AUCTION_PARAMETERS,
DEFAULT_MAX_AUTHORITY_SET_CONTRACTION,
EnvironmentConfig {
flip_token_address: flip_token_address.into(),
Expand All @@ -256,7 +256,7 @@ pub fn inner_cf_development_config(
min_funding,
devnet::REDEMPTION_TAX,
8 * devnet::HOURS,
devnet::REDEMPTION_DELAY_SECS,
devnet::REDEMPTION_TTL_SECS,
devnet::CURRENT_AUTHORITY_EMISSION_INFLATION_PERBILL,
devnet::BACKUP_NODE_EMISSION_INFLATION_PERBILL,
devnet::EXPIRY_SPAN_IN_SECONDS,
Expand All @@ -272,6 +272,7 @@ pub fn inner_cf_development_config(
devnet::BITCOIN_EXPIRY_BLOCKS,
devnet::ETHEREUM_EXPIRY_BLOCKS,
devnet::POLKADOT_EXPIRY_BLOCKS,
devnet::AUCTION_BID_CUTOFF_PERCENTAGE,
)
},
// Bootnodes
Expand Down Expand Up @@ -361,7 +362,7 @@ macro_rules! network_spec {
// Governance account - Snow White
SNOW_WHITE_SR25519.into(),
MIN_AUTHORITIES,
MAX_AUTHORITIES,
AUCTION_PARAMETERS,
DEFAULT_MAX_AUTHORITY_SET_CONTRACTION,
EnvironmentConfig {
flip_token_address: flip_token_address.into(),
Expand All @@ -384,7 +385,7 @@ macro_rules! network_spec {
min_funding,
REDEMPTION_TAX,
EPOCH_DURATION_BLOCKS,
REDEMPTION_DELAY_SECS,
REDEMPTION_TTL_SECS,
CURRENT_AUTHORITY_EMISSION_INFLATION_PERBILL,
BACKUP_NODE_EMISSION_INFLATION_PERBILL,
EXPIRY_SPAN_IN_SECONDS,
Expand All @@ -399,6 +400,7 @@ macro_rules! network_spec {
BITCOIN_EXPIRY_BLOCKS,
ETHEREUM_EXPIRY_BLOCKS,
POLKADOT_EXPIRY_BLOCKS,
AUCTION_BID_CUTOFF_PERCENTAGE,
)
},
// Bootnodes
Expand Down Expand Up @@ -432,7 +434,7 @@ fn testnet_genesis(
extra_accounts: Vec<(AccountId, AccountRole, u128, Option<Vec<u8>>)>,
root_key: AccountId,
min_authorities: AuthorityCount,
max_authorities: AuthorityCount,
auction_parameters: SetSizeParameters,
max_authority_set_contraction_percentage: Percent,
config_set: EnvironmentConfig,
eth_init_agg_key: [u8; 33],
Expand All @@ -443,7 +445,7 @@ fn testnet_genesis(
minimum_funding: u128,
redemption_tax: u128,
blocks_per_epoch: BlockNumber,
redemption_delay: u64,
redemption_ttl_secs: u64,
current_authority_emission_inflation_perbill: u32,
backup_node_emission_inflation_perbill: u32,
expiry_span: u64,
Expand All @@ -458,6 +460,7 @@ fn testnet_genesis(
bitcoin_deposit_channel_lifetime: u32,
ethereum_deposit_channel_lifetime: u32,
polkadot_deposit_channel_lifetime: u32,
auction_bid_cutoff_percentage: Percent,
) -> RuntimeGenesisConfig {
// Sanity Checks
for (account_id, aura_id, grandpa_id) in initial_authorities.iter() {
Expand Down Expand Up @@ -559,9 +562,8 @@ fn testnet_genesis(
})
.expect("At least one authority is required"),
authority_set_min_size: min_authorities,
min_size: min_authorities,
max_size: max_authorities,
max_expansion: max_authorities,
auction_parameters,
auction_bid_cutoff_percentage,
max_authority_set_contraction_percentage,
},
session: SessionConfig {
Expand All @@ -575,7 +577,7 @@ fn testnet_genesis(
genesis_accounts: Vec::from_iter(all_accounts.clone()),
minimum_funding,
redemption_tax,
redemption_ttl: core::time::Duration::from_secs(3 * redemption_delay),
redemption_ttl: core::time::Duration::from_secs(redemption_ttl_secs),
},
// These are set indirectly via the session pallet.
aura: AuraConfig { authorities: vec![] },
Expand Down
100 changes: 52 additions & 48 deletions state-chain/node/src/chain_spec/berghain.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
pub use super::{
common::*,
testnet::{BITCOIN_EXPIRY_BLOCKS, ETHEREUM_EXPIRY_BLOCKS, POLKADOT_EXPIRY_BLOCKS},
};
use super::{parse_account, StateChainEnvironment};
pub use super::common::*;
use super::StateChainEnvironment;
use cf_chains::{dot::RuntimeVersion, eth::CHAIN_ID_MAINNET};
use cf_primitives::{AccountId, AccountRole, BlockNumber, FlipBalance, NetworkEnvironment};
use cf_primitives::{
AccountId, AccountRole, Asset, AssetAmount, BlockNumber, FlipBalance, NetworkEnvironment,
};
use sc_service::ChainType;
use sp_core::H256;

// *** Overrides from common
pub const ACCRUAL_RATIO: (i32, u32) = (10, 10);
// ***
use state_chain_runtime::SetSizeParameters;

pub struct Config;

Expand All @@ -19,7 +15,11 @@ pub const CHAIN_TYPE: ChainType = ChainType::Live;
pub const NETWORK_ENVIRONMENT: NetworkEnvironment = NetworkEnvironment::Mainnet;
pub const PROTOCOL_ID: &str = "flip-berghain";

// TODO: Change spec
// These represent approximately 24 hours on mainnet block times
pub const BITCOIN_EXPIRY_BLOCKS: u32 = 24 * 60 / 10;
pub const ETHEREUM_EXPIRY_BLOCKS: u32 = 24 * 3600 / 14;
pub const POLKADOT_EXPIRY_BLOCKS: u32 = 24 * 3600 / 6;

pub const ENV: StateChainEnvironment = StateChainEnvironment {
flip_token_address: hex_literal::hex!("826180541412D574cf1336d22c0C0a287822678A"),
eth_usdc_address: hex_literal::hex!("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
Expand All @@ -29,60 +29,64 @@ pub const ENV: StateChainEnvironment = StateChainEnvironment {
eth_address_checker_address: hex_literal::hex!("79001a5e762f3bEFC8e5871b42F6734e00498920"),
ethereum_chain_id: CHAIN_ID_MAINNET,
eth_init_agg_key: hex_literal::hex!(
"0250f648bae0db9366550d041e163c9b23b79b1b06be7fac83ba4f338bd02e4024" /* TODO: Albert to
* replace AGG key
* before launch */
"022a1d7efa522ce746bc40a04016178ce38154be1f0537c6957bdeed17057bb955"
),
ethereum_deployment_block: 18277081u64, // TODO: Albert to confirm block number before launch
genesis_funding_amount: 1_000 * FLIPPERINOS_PER_FLIP,
ethereum_deployment_block: 18562942,
genesis_funding_amount: GENESIS_AUTHORITY_FUNDING,
min_funding: MIN_FUNDING,
dot_genesis_hash: H256(hex_literal::hex!(
"91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3" // Polkadot mainnet
)),
dot_vault_account_id: None,
dot_runtime_version: RuntimeVersion { spec_version: 9431, transaction_version: 24 }, /* TODO:
* Dan confirm
* number */
dot_runtime_version: RuntimeVersion { spec_version: 9431, transaction_version: 24 },
};

pub const EPOCH_DURATION_BLOCKS: BlockNumber = 24 * HOURS;

// TODO: change once nodes have been spun up
pub const BASHFUL_ACCOUNT_ID: &str = "cFNBWrx4Wx68hVugPVX3KAtKwbsmHjw6ozAXE3d663bwtYF5R";
pub const BASHFUL_ACCOUNT_ID: &str = "cFNzzoURRFHx2fw2EmsCvTc7hBFP34EaP2B23oUcFdbp1FMvx";
pub const BASHFUL_SR25519: [u8; 32] =
hex_literal::hex!["beb23228343fc71c913a10299f577cbc20ee0eb44dcf8a698ab861c76223495b"];
hex_literal::hex!["e2e8c8d8a2662d11a96ab6cbf8f627e78d6c77ac011ad0ad65b704976c7c5b6c"];
pub const BASHFUL_ED25519: [u8; 32] =
hex_literal::hex!["92e620fa4cc3736bbef778b5852309936c0ce640ad50c1f4f36fc15eba7f4ed8"];
pub const DOC_ACCOUNT_ID: &str = "cFJHNnou7QwegcEEhL3xeD1aUrjeaL5Ydqtrfyd7ousKoiLPU";
hex_literal::hex!["c2729cfb8507558af71474e9610071585e4ae02c5418e053cdc25106628f9810"];
pub const DOC_ACCOUNT_ID: &str = "cFP2cGErEhxzJfVUxk1gHVuE1ALxHJQx335o19bT7QoSWwjhU";
pub const DOC_SR25519: [u8; 32] =
hex_literal::hex!["123990561086190def905deab1f5c3fe1f7dd08585e677ff4fe3196e1201a82e"];
hex_literal::hex!["e42367696495e88be9b78e7e639bc0a870139bfe43aafb46ea5f934c69903b02"];
pub const DOC_ED25519: [u8; 32] =
hex_literal::hex!["4a11427487645aade5f5134904668a9dcde93e493f668f0b347f23d3cd4d7c76"];
pub const DOPEY_ACCOUNT_ID: &str = "cFJyZdYw1p9bkYNUuwDppkfKrGinn8r4ZWaPvSaxSvrpiSTa2";
hex_literal::hex!["5e52d11949673e9ba3a6e3e11c0fc0537bc588de8ac61d41cf04e0ff43dc39a1"];
pub const DOPEY_ACCOUNT_ID: &str = "cFKzr7DwLCRtSkou5H5moKri7g9WwJ4tAbVJv6dZGhLb811Tc";
pub const DOPEY_SR25519: [u8; 32] =
hex_literal::hex!["30dfdf38642c300105e2ac604b92d08f1e26f01459539bfd7f8c51cf60e0ce68"];
hex_literal::hex!["5e16d155cf85815a0ba8957762e1e007eec4d5c6fe0b32b4719ca4435c36eb57"];
pub const DOPEY_ED25519: [u8; 32] =
hex_literal::hex!["39df8c764fb991819aeb94bfb2e7809a2728660113e6ec0758e751d3c00f4fcd"];
pub const SNOW_WHITE_ACCOUNT_ID: &str = "cFKsNoWaviRPS5s4xPxHxEXWBwAm3Q4JGXoXY3HXcsfWgun1D";
hex_literal::hex!["99cca386ea50fb33d2eee5ebd5574759facb17ddd55241e246b59567f6878242"];
pub const SNOW_WHITE_ACCOUNT_ID: &str = "cFPVXzCyCxKbxJEHhDN1yXrU3VcDPZswHSVHh8HnoGsJsAVYS";
pub const SNOW_WHITE_SR25519: [u8; 32] =
hex_literal::hex!["58642e85c7889f9cda6e5d87249c6ab4c6d9b2f6bad8c5986cab81c6317d4e61"];
hex_literal::hex!["f8aca257e6ab69e357984a885121c0ee18fcc50185c77966cdaf063df2f89126"];

pub fn extra_accounts() -> Vec<(AccountId, AccountRole, FlipBalance, Option<Vec<u8>>)> {
[vec![
(
parse_account("cFHwQ2eJQqRLJWgcHhdgAVCXx2TNRaS3R4Zc98mU2SrkW6AMH"),
AccountRole::Broker,
1_000 * FLIPPERINOS_PER_FLIP,
Some(b"Chainflip Genesis Broker".to_vec()),
),
(
parse_account("cFNaeW7FBpjVxh5haxwmnnATCXriuThVJ8vcyQWKi6SfwWHni"),
AccountRole::LiquidityProvider,
1_000 * FLIPPERINOS_PER_FLIP,
Some(b"Chainflip Genesis Liquidity Provider".to_vec()),
),
]]
.into_iter()
.flatten()
.collect()
vec![]
}

// Set to zero initially, will be updated by governance to 7% / 1% annual.
pub const CURRENT_AUTHORITY_EMISSION_INFLATION_PERBILL: u32 = 0;
pub const BACKUP_NODE_EMISSION_INFLATION_PERBILL: u32 = 0;

pub const SUPPLY_UPDATE_INTERVAL: u32 = 30 * 24 * HOURS;

pub const MINIMUM_SWAP_AMOUNTS: &[(Asset, AssetAmount)] = &[
(Asset::Eth, 0u128),
(Asset::Flip, 0u128),
(Asset::Usdc, 0u128),
(Asset::Dot, 0u128),
(Asset::Btc, 0u128),
];

pub const MIN_FUNDING: FlipBalance = 6 * FLIPPERINOS_PER_FLIP;
pub const GENESIS_AUTHORITY_FUNDING: FlipBalance = 1_000 * FLIPPERINOS_PER_FLIP;
pub const REDEMPTION_TAX: FlipBalance = 5 * FLIPPERINOS_PER_FLIP;

/// Redemption delay on mainnet is 48 HOURS.
/// We add an extra 24 hours buffer.
pub const REDEMPTION_TTL_SECS: u64 = (48 + 24) * 3600;

pub const AUCTION_PARAMETERS: SetSizeParameters =
SetSizeParameters { min_size: 3, max_size: MAX_AUTHORITIES, max_expansion: MAX_AUTHORITIES };
41 changes: 36 additions & 5 deletions state-chain/node/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
use cf_primitives::{Asset, AssetAmount, AuthorityCount};
use sp_runtime::Permill;
use sp_runtime::{Percent, Permill};
pub use state_chain_runtime::constants::common::*;
use state_chain_runtime::{chainflip::Offence, BlockNumber, FlipBalance};
use state_chain_runtime::{chainflip::Offence, BlockNumber, FlipBalance, SetSizeParameters};

pub const GENESIS_FUNDING_AMOUNT: FlipBalance = 5_000 * FLIPPERINOS_PER_FLIP;
pub const MIN_FUNDING: FlipBalance = 10 * FLIPPERINOS_PER_FLIP;
pub const REDEMPTION_TAX: FlipBalance = 5 * FLIPPERINOS_PER_FLIP;
pub const MIN_AUTHORITIES: AuthorityCount = 2;
pub const AUCTION_PARAMETERS: SetSizeParameters = SetSizeParameters {
min_size: MIN_AUTHORITIES,
max_size: MAX_AUTHORITIES,
max_expansion: MAX_AUTHORITIES,
};

/// Percent of the epoch we are allowed to redeem
pub const REDEMPTION_PERIOD_AS_PERCENTAGE: u8 = 50;

// Consider the equation (1 + x/1_000_000_000)^n = 1 + inf/100
// where inf is the target yearly inflation (percent), n is the number of compundings that
// we do in a year and x is the inflation rate (Perbill) for each compunding time period.

//
// The following values are calculated by solving the above equation for x using n =
// (365*14400)/150 (since compunding is done every heartbeat which is every 150 blocks) and inf
// is taken as 0.1 percent for authority emissions and 0.02 percent for backup node emissions.
// (365*14400)/150 (since compunding is done every heartbeat which is every 150 blocks) and
// inf is taken as 0.1 percent for authority emissions and 0.02 percent for backup node emissions.
//
// Can be generated using the following python code:
//
// ```
// import math
// def per_bill_inflation(pct):
// return (math.pow(1 + pct/100, 1/35040) - 1) * 1000000000
//
// # Testnet:
// round(per_bill_inflation(0.1)) -> 28
// round(per_bill_inflation(0.02)) -> 6
// # Mainnet:
// round(per_bill_inflation(7)) -> 1931
// round(per_bill_inflation(1)) -> 284
// ```
//
pub const CURRENT_AUTHORITY_EMISSION_INFLATION_PERBILL: u32 = 28;
pub const BACKUP_NODE_EMISSION_INFLATION_PERBILL: u32 = 6;

pub const SUPPLY_UPDATE_INTERVAL: u32 = 24 * HOURS;

// This is equivalent to one reputation point for every minute of online time.
Expand Down Expand Up @@ -51,3 +73,12 @@ pub const MINIMUM_SWAP_AMOUNTS: &[(Asset, AssetAmount)] = &[

/// Daily slashing rate 0.1% (of the bond) for offline authority
pub const DAILY_SLASHING_RATE: Permill = Permill::from_perthousand(1);

/// Redemption delay on testnets is 2 MINUTES.
/// We use a ttl of 1 hour to give enough of a buffer.
pub const REDEMPTION_TTL_SECS: u64 = 2 * 3600;

/// Determines the expiry duration for governance proposals.
pub const EXPIRY_SPAN_IN_SECONDS: u64 = 24 * 3600;

pub const AUCTION_BID_CUTOFF_PERCENTAGE: Percent = Percent::from_percent(10);
10 changes: 10 additions & 0 deletions state-chain/node/src/chain_spec/devnet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
use cf_primitives::AuthorityCount;
use state_chain_runtime::SetSizeParameters;

pub use super::common::*;

// These represent approximately 10 minutes in localnet block times
// Bitcoin blocks are 5 seconds on localnets.
pub const BITCOIN_EXPIRY_BLOCKS: u32 = 10 * 60 / 5;
pub const ETHEREUM_EXPIRY_BLOCKS: u32 = 10 * 60 / 14;
pub const POLKADOT_EXPIRY_BLOCKS: u32 = 10 * 60 / 6;

pub const MIN_AUTHORITIES: AuthorityCount = 1;
pub const AUCTION_PARAMETERS: SetSizeParameters = SetSizeParameters {
min_size: MIN_AUTHORITIES,
max_size: MAX_AUTHORITIES,
max_expansion: MAX_AUTHORITIES,
};
Loading

0 comments on commit 70f1db1

Please sign in to comment.