Skip to content

Commit

Permalink
feat: start of block witnesser
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Nov 28, 2024
1 parent f007d1c commit 92b9f65
Show file tree
Hide file tree
Showing 17 changed files with 1,241 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ where
Swapping(_) |
LiquidityProvider(_) |
LiquidityPools(_) |
SolanaElections(_) => {},
SolanaElections(_) |
BitcoinElections(_) => {},
};

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions state-chain/cf-integration-tests/src/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use state_chain_runtime::{
opaque::SessionKeys,
test_runner::*,
AccountId, AccountRolesConfig, ArbitrumChainTrackingConfig, BitcoinChainTrackingConfig,
EmissionsConfig, EnvironmentConfig, EthereumChainTrackingConfig, EthereumVaultConfig,
EvmThresholdSignerConfig, FlipConfig, FundingConfig, GovernanceConfig,
BitcoinElectionsConfig, EmissionsConfig, EnvironmentConfig, EthereumChainTrackingConfig,
EthereumVaultConfig, EvmThresholdSignerConfig, FlipConfig, FundingConfig, GovernanceConfig,
PolkadotChainTrackingConfig, ReputationConfig, SessionConfig, SolanaChainTrackingConfig,
SolanaElectionsConfig, ValidatorConfig,
};
Expand Down Expand Up @@ -340,6 +340,7 @@ impl ExtBuilder {
),
}),
},
bitcoin_elections: BitcoinElectionsConfig { option_initial_state: None },
ethereum_broadcaster: state_chain_runtime::EthereumBroadcasterConfig {
broadcast_timeout: 5 * BLOCKS_PER_MINUTE_ETHEREUM,
},
Expand Down
34 changes: 34 additions & 0 deletions state-chain/chains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,41 @@ pub mod mocks;
pub mod witness_period {
use core::ops::{Rem, Sub};

use sp_std::ops::RangeInclusive;

use codec::{Decode, Encode};
use frame_support::sp_runtime::traits::{One, Saturating};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};

// So we can store a range-like object in storage, since this has encode and decode.
#[derive(
Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo, Deserialize, Serialize, Default,
)]
pub struct BlockWitnessRange<I> {
start: I,
end: I,
}

impl<I: Copy> From<RangeInclusive<I>> for BlockWitnessRange<I> {
fn from(range: RangeInclusive<I>) -> Self {
Self { start: *range.start(), end: *range.end() }
}
}

impl<I> BlockWitnessRange<I> {
pub fn into_range_inclusive(range: BlockWitnessRange<I>) -> RangeInclusive<I> {
range.start..=range.end
}

pub fn start(&self) -> &I {
&self.start
}

pub fn end(&self) -> &I {
&self.end
}
}

fn block_witness_floor<
I: Copy + Saturating + Sub<I, Output = I> + Rem<I, Output = I> + Eq + One,
Expand Down
7 changes: 5 additions & 2 deletions state-chain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use state_chain_runtime::{
BLOCKS_PER_MINUTE_SOLANA,
},
opaque::SessionKeys,
AccountId, BlockNumber, FlipBalance, SetSizeParameters, Signature, SolanaElectionsConfig,
WASM_BINARY,
AccountId, BitcoinElectionsConfig, BlockNumber, FlipBalance, SetSizeParameters, Signature,
SolanaElectionsConfig, WASM_BINARY,
};

use cf_utilities::clean_hex_address;
Expand Down Expand Up @@ -849,6 +849,9 @@ fn testnet_genesis(
..Default::default()
},
solana_elections,

// TODO: Set correct initial state
bitcoin_elections: BitcoinElectionsConfig { option_initial_state: None },
// We can't use ..Default::default() here because chain tracking panics on default (by
// design). And the way ..Default::default() syntax works is that it generates the default
// value for the whole struct, not just the fields that are missing.
Expand Down
1 change: 1 addition & 0 deletions state-chain/pallets/cf-elections/src/electoral_systems.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod block_witnesser;
pub mod blockchain;
pub mod composite;
pub mod egress_success;
Expand Down
Loading

0 comments on commit 92b9f65

Please sign in to comment.