Rename BeaconStateTypes
to EthSpec
This commit is contained in:
parent
75b310a078
commit
ce8ebeccbc
@ -83,7 +83,7 @@ impl BlockProcessingOutcome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, B: BeaconStateTypes> {
|
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, B: EthSpec> {
|
||||||
pub block_store: Arc<BeaconBlockStore<T>>,
|
pub block_store: Arc<BeaconBlockStore<T>>,
|
||||||
pub state_store: Arc<BeaconStateStore<T>>,
|
pub state_store: Arc<BeaconStateStore<T>>,
|
||||||
pub slot_clock: U,
|
pub slot_clock: U,
|
||||||
@ -100,7 +100,7 @@ where
|
|||||||
T: ClientDB,
|
T: ClientDB,
|
||||||
U: SlotClock,
|
U: SlotClock,
|
||||||
F: ForkChoice,
|
F: ForkChoice,
|
||||||
B: BeaconStateTypes,
|
B: EthSpec,
|
||||||
{
|
{
|
||||||
/// Instantiate a new Beacon Chain, from genesis.
|
/// Instantiate a new Beacon Chain, from genesis.
|
||||||
pub fn from_genesis(
|
pub fn from_genesis(
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use types::{BeaconBlock, BeaconState, BeaconStateTypes, Hash256};
|
use types::{BeaconBlock, BeaconState, EthSpec, Hash256};
|
||||||
|
|
||||||
/// Represents some block and it's associated state. Generally, this will be used for tracking the
|
/// Represents some block and it's associated state. Generally, this will be used for tracking the
|
||||||
/// head, justified head and finalized head.
|
/// head, justified head and finalized head.
|
||||||
#[derive(Clone, Serialize, PartialEq, Debug)]
|
#[derive(Clone, Serialize, PartialEq, Debug)]
|
||||||
pub struct CheckPoint<B: BeaconStateTypes> {
|
pub struct CheckPoint<B: EthSpec> {
|
||||||
pub beacon_block: BeaconBlock,
|
pub beacon_block: BeaconBlock,
|
||||||
pub beacon_block_root: Hash256,
|
pub beacon_block_root: Hash256,
|
||||||
pub beacon_state: BeaconState<B>,
|
pub beacon_state: BeaconState<B>,
|
||||||
pub beacon_state_root: Hash256,
|
pub beacon_state_root: Hash256,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> CheckPoint<B> {
|
impl<B: EthSpec> CheckPoint<B> {
|
||||||
/// Create a new checkpoint.
|
/// Create a new checkpoint.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
beacon_block: BeaconBlock,
|
beacon_block: BeaconBlock,
|
||||||
|
@ -11,7 +11,7 @@ use std::path::PathBuf;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::test_utils::TestingBeaconStateBuilder;
|
use types::test_utils::TestingBeaconStateBuilder;
|
||||||
use types::{BeaconBlock, ChainSpec, FewValidatorsStateTypes, FoundationStateTypes, Hash256};
|
use types::{BeaconBlock, ChainSpec, FewValidatorsEthSpec, FoundationEthSpec, Hash256};
|
||||||
|
|
||||||
//TODO: Correct this for prod
|
//TODO: Correct this for prod
|
||||||
//TODO: Account for historical db
|
//TODO: Account for historical db
|
||||||
@ -22,8 +22,8 @@ pub fn initialise_beacon_chain(
|
|||||||
BeaconChain<
|
BeaconChain<
|
||||||
DiskDB,
|
DiskDB,
|
||||||
SystemTimeSlotClock,
|
SystemTimeSlotClock,
|
||||||
BitwiseLMDGhost<DiskDB, FoundationStateTypes>,
|
BitwiseLMDGhost<DiskDB, FoundationEthSpec>,
|
||||||
FoundationStateTypes,
|
FoundationEthSpec,
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
// set up the db
|
// set up the db
|
||||||
@ -75,8 +75,8 @@ pub fn initialise_test_beacon_chain(
|
|||||||
BeaconChain<
|
BeaconChain<
|
||||||
MemoryDB,
|
MemoryDB,
|
||||||
SystemTimeSlotClock,
|
SystemTimeSlotClock,
|
||||||
BitwiseLMDGhost<MemoryDB, FewValidatorsStateTypes>,
|
BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>,
|
||||||
FewValidatorsStateTypes,
|
FewValidatorsEthSpec,
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
let db = Arc::new(MemoryDB::open());
|
let db = Arc::new(MemoryDB::open());
|
||||||
|
@ -8,16 +8,16 @@ use slot_clock::TestingSlotClock;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::*;
|
use types::*;
|
||||||
use types::{test_utils::TestingBeaconStateBuilder, BeaconStateTypes, FewValidatorsStateTypes};
|
use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec};
|
||||||
|
|
||||||
type TestingBeaconChain<B> =
|
type TestingBeaconChain<B> =
|
||||||
BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB, FewValidatorsStateTypes>, B>;
|
BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>, B>;
|
||||||
|
|
||||||
pub struct TestingBeaconChainBuilder<B: BeaconStateTypes> {
|
pub struct TestingBeaconChainBuilder<B: EthSpec> {
|
||||||
state_builder: TestingBeaconStateBuilder<B>,
|
state_builder: TestingBeaconStateBuilder<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> TestingBeaconChainBuilder<B> {
|
impl<B: EthSpec> TestingBeaconChainBuilder<B> {
|
||||||
pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<B> {
|
pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<B> {
|
||||||
let db = Arc::new(MemoryDB::open());
|
let db = Arc::new(MemoryDB::open());
|
||||||
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
|
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
|
||||||
@ -44,7 +44,7 @@ impl<B: BeaconStateTypes> TestingBeaconChainBuilder<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> From<TestingBeaconStateBuilder<B>> for TestingBeaconChainBuilder<B> {
|
impl<B: EthSpec> From<TestingBeaconStateBuilder<B>> for TestingBeaconChainBuilder<B> {
|
||||||
fn from(state_builder: TestingBeaconStateBuilder<B>) -> TestingBeaconChainBuilder<B> {
|
fn from(state_builder: TestingBeaconStateBuilder<B>) -> TestingBeaconChainBuilder<B> {
|
||||||
TestingBeaconChainBuilder { state_builder }
|
TestingBeaconChainBuilder { state_builder }
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use std::path::PathBuf;
|
|||||||
use types::multiaddr::Protocol;
|
use types::multiaddr::Protocol;
|
||||||
use types::multiaddr::ToMultiaddr;
|
use types::multiaddr::ToMultiaddr;
|
||||||
use types::Multiaddr;
|
use types::Multiaddr;
|
||||||
use types::{BeaconStateTypes, ChainSpec, LighthouseTestnetStateTypes};
|
use types::{ChainSpec, EthSpec, LighthouseTestnetEthSpec};
|
||||||
|
|
||||||
/// Stores the client configuration for this Lighthouse instance.
|
/// Stores the client configuration for this Lighthouse instance.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -35,7 +35,7 @@ impl Default for ClientConfig {
|
|||||||
fs::create_dir_all(&data_dir)
|
fs::create_dir_all(&data_dir)
|
||||||
.unwrap_or_else(|_| panic!("Unable to create {:?}", &data_dir));
|
.unwrap_or_else(|_| panic!("Unable to create {:?}", &data_dir));
|
||||||
|
|
||||||
let default_spec = LighthouseTestnetStateTypes::spec();
|
let default_spec = LighthouseTestnetEthSpec::spec();
|
||||||
let default_net_conf = NetworkConfig::new(default_spec.boot_nodes.clone());
|
let default_net_conf = NetworkConfig::new(default_spec.boot_nodes.clone());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -6,17 +6,17 @@ use beacon_chain::{
|
|||||||
slot_clock::{SlotClock, SystemTimeSlotClock},
|
slot_clock::{SlotClock, SystemTimeSlotClock},
|
||||||
};
|
};
|
||||||
use fork_choice::ForkChoice;
|
use fork_choice::ForkChoice;
|
||||||
use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes};
|
use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec};
|
||||||
|
|
||||||
pub trait ClientTypes {
|
pub trait ClientTypes {
|
||||||
type DB: ClientDB + 'static;
|
type DB: ClientDB + 'static;
|
||||||
type SlotClock: SlotClock + 'static;
|
type SlotClock: SlotClock + 'static;
|
||||||
type ForkChoice: ForkChoice + 'static;
|
type ForkChoice: ForkChoice + 'static;
|
||||||
type BeaconStateTypes: BeaconStateTypes + 'static;
|
type EthSpec: EthSpec + 'static;
|
||||||
|
|
||||||
fn initialise_beacon_chain(
|
fn initialise_beacon_chain(
|
||||||
config: &ClientConfig,
|
config: &ClientConfig,
|
||||||
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>;
|
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StandardClientType;
|
pub struct StandardClientType;
|
||||||
@ -24,12 +24,12 @@ pub struct StandardClientType;
|
|||||||
impl ClientTypes for StandardClientType {
|
impl ClientTypes for StandardClientType {
|
||||||
type DB = DiskDB;
|
type DB = DiskDB;
|
||||||
type SlotClock = SystemTimeSlotClock;
|
type SlotClock = SystemTimeSlotClock;
|
||||||
type ForkChoice = BitwiseLMDGhost<DiskDB, Self::BeaconStateTypes>;
|
type ForkChoice = BitwiseLMDGhost<DiskDB, Self::EthSpec>;
|
||||||
type BeaconStateTypes = FoundationStateTypes;
|
type EthSpec = FoundationEthSpec;
|
||||||
|
|
||||||
fn initialise_beacon_chain(
|
fn initialise_beacon_chain(
|
||||||
config: &ClientConfig,
|
config: &ClientConfig,
|
||||||
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes> {
|
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec> {
|
||||||
initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name))
|
initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,12 +39,12 @@ pub struct TestingClientType;
|
|||||||
impl ClientTypes for TestingClientType {
|
impl ClientTypes for TestingClientType {
|
||||||
type DB = MemoryDB;
|
type DB = MemoryDB;
|
||||||
type SlotClock = SystemTimeSlotClock;
|
type SlotClock = SystemTimeSlotClock;
|
||||||
type ForkChoice = BitwiseLMDGhost<MemoryDB, Self::BeaconStateTypes>;
|
type ForkChoice = BitwiseLMDGhost<MemoryDB, Self::EthSpec>;
|
||||||
type BeaconStateTypes = FewValidatorsStateTypes;
|
type EthSpec = FewValidatorsEthSpec;
|
||||||
|
|
||||||
fn initialise_beacon_chain(
|
fn initialise_beacon_chain(
|
||||||
config: &ClientConfig,
|
config: &ClientConfig,
|
||||||
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes> {
|
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec> {
|
||||||
initialise::initialise_test_beacon_chain(&config.spec, None)
|
initialise::initialise_test_beacon_chain(&config.spec, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ use std::sync::Arc;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use tokio::runtime::TaskExecutor;
|
use tokio::runtime::TaskExecutor;
|
||||||
use tokio::timer::Interval;
|
use tokio::timer::Interval;
|
||||||
use types::BeaconStateTypes;
|
use types::EthSpec;
|
||||||
|
|
||||||
type ArcBeaconChain<D, S, F, B> = Arc<BeaconChain<D, S, F, B>>;
|
type ArcBeaconChain<D, S, F, B> = Arc<BeaconChain<D, S, F, B>>;
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ pub struct Client<T: ClientTypes> {
|
|||||||
/// Configuration for the lighthouse client.
|
/// Configuration for the lighthouse client.
|
||||||
_config: ClientConfig,
|
_config: ClientConfig,
|
||||||
/// The beacon chain for the running client.
|
/// The beacon chain for the running client.
|
||||||
_beacon_chain: ArcBeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::BeaconStateTypes>,
|
_beacon_chain: ArcBeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::EthSpec>,
|
||||||
/// Reference to the network service.
|
/// Reference to the network service.
|
||||||
pub network: Arc<NetworkService<T::BeaconStateTypes>>,
|
pub network: Arc<NetworkService<T::EthSpec>>,
|
||||||
/// Signal to terminate the RPC server.
|
/// Signal to terminate the RPC server.
|
||||||
pub rpc_exit_signal: Option<Signal>,
|
pub rpc_exit_signal: Option<Signal>,
|
||||||
/// Signal to terminate the slot timer.
|
/// Signal to terminate the slot timer.
|
||||||
@ -149,7 +149,7 @@ where
|
|||||||
T: ClientDB,
|
T: ClientDB,
|
||||||
U: SlotClock,
|
U: SlotClock,
|
||||||
F: ForkChoice,
|
F: ForkChoice,
|
||||||
B: BeaconStateTypes,
|
B: EthSpec,
|
||||||
{
|
{
|
||||||
if let Some(genesis_height) = chain.slots_since_genesis() {
|
if let Some(genesis_height) = chain.slots_since_genesis() {
|
||||||
let result = chain.catchup_state();
|
let result = chain.catchup_state();
|
||||||
|
@ -2,7 +2,7 @@ use super::STATES_DB_COLUMN as DB_COLUMN;
|
|||||||
use super::{ClientDB, DBError};
|
use super::{ClientDB, DBError};
|
||||||
use ssz::decode;
|
use ssz::decode;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconState, BeaconStateTypes, Hash256};
|
use types::{BeaconState, EthSpec, Hash256};
|
||||||
|
|
||||||
pub struct BeaconStateStore<T>
|
pub struct BeaconStateStore<T>
|
||||||
where
|
where
|
||||||
@ -19,7 +19,7 @@ impl<T: ClientDB> BeaconStateStore<T> {
|
|||||||
Self { db }
|
Self { db }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_deserialized<B: BeaconStateTypes>(
|
pub fn get_deserialized<B: EthSpec>(
|
||||||
&self,
|
&self,
|
||||||
hash: &Hash256,
|
hash: &Hash256,
|
||||||
) -> Result<Option<BeaconState<B>>, DBError> {
|
) -> Result<Option<BeaconState<B>>, DBError> {
|
||||||
|
@ -236,7 +236,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ssz_encoding() {
|
fn ssz_encoding() {
|
||||||
let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationStateTypes::spec()));
|
let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationEthSpec::spec()));
|
||||||
|
|
||||||
let encoded = ssz_encode(&original);
|
let encoded = ssz_encode(&original);
|
||||||
|
|
||||||
|
@ -9,14 +9,13 @@ use beacon_chain::{
|
|||||||
};
|
};
|
||||||
use eth2_libp2p::rpc::HelloMessage;
|
use eth2_libp2p::rpc::HelloMessage;
|
||||||
use types::{
|
use types::{
|
||||||
Attestation, BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, Epoch, Hash256,
|
Attestation, BeaconBlock, BeaconBlockBody, BeaconBlockHeader, Epoch, EthSpec, Hash256, Slot,
|
||||||
Slot,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome, InvalidBlock};
|
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome, InvalidBlock};
|
||||||
|
|
||||||
/// The network's API to the beacon chain.
|
/// The network's API to the beacon chain.
|
||||||
pub trait BeaconChain<B: BeaconStateTypes>: Send + Sync {
|
pub trait BeaconChain<B: EthSpec>: Send + Sync {
|
||||||
fn get_spec(&self) -> &ChainSpec;
|
fn get_spec(&self) -> &ChainSpec;
|
||||||
|
|
||||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
|
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
|
||||||
@ -70,7 +69,7 @@ where
|
|||||||
T: ClientDB + Sized,
|
T: ClientDB + Sized,
|
||||||
U: SlotClock,
|
U: SlotClock,
|
||||||
F: ForkChoice,
|
F: ForkChoice,
|
||||||
B: BeaconStateTypes,
|
B: EthSpec,
|
||||||
{
|
{
|
||||||
fn get_spec(&self) -> &ChainSpec {
|
fn get_spec(&self) -> &ChainSpec {
|
||||||
&self.spec
|
&self.spec
|
||||||
|
@ -13,7 +13,7 @@ use slog::{debug, warn};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use types::BeaconStateTypes;
|
use types::EthSpec;
|
||||||
|
|
||||||
/// Timeout for RPC requests.
|
/// Timeout for RPC requests.
|
||||||
// const REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
|
// const REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
@ -21,7 +21,7 @@ use types::BeaconStateTypes;
|
|||||||
// const HELLO_TIMEOUT: Duration = Duration::from_secs(30);
|
// const HELLO_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
/// Handles messages received from the network and client and organises syncing.
|
/// Handles messages received from the network and client and organises syncing.
|
||||||
pub struct MessageHandler<B: BeaconStateTypes> {
|
pub struct MessageHandler<B: EthSpec> {
|
||||||
/// Currently loaded and initialised beacon chain.
|
/// Currently loaded and initialised beacon chain.
|
||||||
_chain: Arc<BeaconChain<B>>,
|
_chain: Arc<BeaconChain<B>>,
|
||||||
/// The syncing framework.
|
/// The syncing framework.
|
||||||
@ -45,7 +45,7 @@ pub enum HandlerMessage {
|
|||||||
PubsubMessage(PeerId, Box<PubsubMessage>),
|
PubsubMessage(PeerId, Box<PubsubMessage>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> MessageHandler<B> {
|
impl<B: EthSpec> MessageHandler<B> {
|
||||||
/// Initializes and runs the MessageHandler.
|
/// Initializes and runs the MessageHandler.
|
||||||
pub fn spawn(
|
pub fn spawn(
|
||||||
beacon_chain: Arc<BeaconChain<B>>,
|
beacon_chain: Arc<BeaconChain<B>>,
|
||||||
|
@ -13,10 +13,10 @@ use slog::{debug, info, o, trace};
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::runtime::TaskExecutor;
|
use tokio::runtime::TaskExecutor;
|
||||||
use types::{BeaconStateTypes, Topic};
|
use types::{EthSpec, Topic};
|
||||||
|
|
||||||
/// Service that handles communication between internal services and the eth2_libp2p network service.
|
/// Service that handles communication between internal services and the eth2_libp2p network service.
|
||||||
pub struct Service<B: BeaconStateTypes> {
|
pub struct Service<B: EthSpec> {
|
||||||
//libp2p_service: Arc<Mutex<LibP2PService>>,
|
//libp2p_service: Arc<Mutex<LibP2PService>>,
|
||||||
_libp2p_exit: oneshot::Sender<()>,
|
_libp2p_exit: oneshot::Sender<()>,
|
||||||
network_send: crossbeam_channel::Sender<NetworkMessage>,
|
network_send: crossbeam_channel::Sender<NetworkMessage>,
|
||||||
@ -24,7 +24,7 @@ pub struct Service<B: BeaconStateTypes> {
|
|||||||
//message_handler_send: Sender<HandlerMessage>
|
//message_handler_send: Sender<HandlerMessage>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> Service<B> {
|
impl<B: EthSpec> Service<B> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
beacon_chain: Arc<BeaconChain<B>>,
|
beacon_chain: Arc<BeaconChain<B>>,
|
||||||
config: &NetworkConfig,
|
config: &NetworkConfig,
|
||||||
|
@ -5,7 +5,7 @@ use slog::{debug, error};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, Hash256, Slot};
|
use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, EthSpec, Hash256, Slot};
|
||||||
|
|
||||||
/// Provides a queue for fully and partially built `BeaconBlock`s.
|
/// Provides a queue for fully and partially built `BeaconBlock`s.
|
||||||
///
|
///
|
||||||
@ -19,7 +19,7 @@ use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, H
|
|||||||
/// `BeaconBlockBody` as the key.
|
/// `BeaconBlockBody` as the key.
|
||||||
/// - It is possible for multiple distinct blocks to have identical `BeaconBlockBodies`. Therefore
|
/// - It is possible for multiple distinct blocks to have identical `BeaconBlockBodies`. Therefore
|
||||||
/// we cannot use a `HashMap` keyed by the root of `BeaconBlockBody`.
|
/// we cannot use a `HashMap` keyed by the root of `BeaconBlockBody`.
|
||||||
pub struct ImportQueue<B: BeaconStateTypes> {
|
pub struct ImportQueue<B: EthSpec> {
|
||||||
pub chain: Arc<BeaconChain<B>>,
|
pub chain: Arc<BeaconChain<B>>,
|
||||||
/// Partially imported blocks, keyed by the root of `BeaconBlockBody`.
|
/// Partially imported blocks, keyed by the root of `BeaconBlockBody`.
|
||||||
pub partials: Vec<PartialBeaconBlock>,
|
pub partials: Vec<PartialBeaconBlock>,
|
||||||
@ -29,7 +29,7 @@ pub struct ImportQueue<B: BeaconStateTypes> {
|
|||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> ImportQueue<B> {
|
impl<B: EthSpec> ImportQueue<B> {
|
||||||
/// Return a new, empty queue.
|
/// Return a new, empty queue.
|
||||||
pub fn new(chain: Arc<BeaconChain<B>>, stale_time: Duration, log: slog::Logger) -> Self {
|
pub fn new(chain: Arc<BeaconChain<B>>, stale_time: Duration, log: slog::Logger) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::{Attestation, BeaconBlock, BeaconStateTypes, Epoch, Hash256, Slot};
|
use types::{Attestation, BeaconBlock, Epoch, EthSpec, Hash256, Slot};
|
||||||
|
|
||||||
/// The number of slots that we can import blocks ahead of us, before going into full Sync mode.
|
/// The number of slots that we can import blocks ahead of us, before going into full Sync mode.
|
||||||
const SLOT_IMPORT_TOLERANCE: u64 = 100;
|
const SLOT_IMPORT_TOLERANCE: u64 = 100;
|
||||||
@ -88,7 +88,7 @@ impl From<HelloMessage> for PeerSyncInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> From<&Arc<BeaconChain<B>>> for PeerSyncInfo {
|
impl<B: EthSpec> From<&Arc<BeaconChain<B>>> for PeerSyncInfo {
|
||||||
fn from(chain: &Arc<BeaconChain<B>>) -> PeerSyncInfo {
|
fn from(chain: &Arc<BeaconChain<B>>) -> PeerSyncInfo {
|
||||||
Self::from(chain.hello_message())
|
Self::from(chain.hello_message())
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ pub enum SyncState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Simple Syncing protocol.
|
/// Simple Syncing protocol.
|
||||||
pub struct SimpleSync<B: BeaconStateTypes> {
|
pub struct SimpleSync<B: EthSpec> {
|
||||||
/// A reference to the underlying beacon chain.
|
/// A reference to the underlying beacon chain.
|
||||||
chain: Arc<BeaconChain<B>>,
|
chain: Arc<BeaconChain<B>>,
|
||||||
/// A mapping of Peers to their respective PeerSyncInfo.
|
/// A mapping of Peers to their respective PeerSyncInfo.
|
||||||
@ -116,7 +116,7 @@ pub struct SimpleSync<B: BeaconStateTypes> {
|
|||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> SimpleSync<B> {
|
impl<B: EthSpec> SimpleSync<B> {
|
||||||
/// Instantiate a `SimpleSync` instance, with no peers and an empty queue.
|
/// Instantiate a `SimpleSync` instance, with no peers and an empty queue.
|
||||||
pub fn new(beacon_chain: Arc<BeaconChain<B>>, log: &slog::Logger) -> Self {
|
pub fn new(beacon_chain: Arc<BeaconChain<B>>, log: &slog::Logger) -> Self {
|
||||||
let sync_logger = log.new(o!("Service"=> "Sync"));
|
let sync_logger = log.new(o!("Service"=> "Sync"));
|
||||||
|
@ -9,15 +9,15 @@ use protos::services_grpc::AttestationService;
|
|||||||
use slog::{error, info, trace, warn};
|
use slog::{error, info, trace, warn};
|
||||||
use ssz::{ssz_encode, Decodable};
|
use ssz::{ssz_encode, Decodable};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{Attestation, BeaconStateTypes};
|
use types::{Attestation, EthSpec};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AttestationServiceInstance<B: BeaconStateTypes> {
|
pub struct AttestationServiceInstance<B: EthSpec> {
|
||||||
pub chain: Arc<BeaconChain<B>>,
|
pub chain: Arc<BeaconChain<B>>,
|
||||||
pub log: slog::Logger,
|
pub log: slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> AttestationService for AttestationServiceInstance<B> {
|
impl<B: EthSpec> AttestationService for AttestationServiceInstance<B> {
|
||||||
/// Produce the `AttestationData` for signing by a validator.
|
/// Produce the `AttestationData` for signing by a validator.
|
||||||
fn produce_attestation_data(
|
fn produce_attestation_data(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -13,16 +13,16 @@ use slog::Logger;
|
|||||||
use slog::{error, info, trace, warn};
|
use slog::{error, info, trace, warn};
|
||||||
use ssz::{ssz_encode, Decodable};
|
use ssz::{ssz_encode, Decodable};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, BeaconStateTypes, Signature, Slot};
|
use types::{BeaconBlock, EthSpec, Signature, Slot};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BeaconBlockServiceInstance<B: BeaconStateTypes> {
|
pub struct BeaconBlockServiceInstance<B: EthSpec> {
|
||||||
pub chain: Arc<BeaconChain<B>>,
|
pub chain: Arc<BeaconChain<B>>,
|
||||||
pub network_chan: crossbeam_channel::Sender<NetworkMessage>,
|
pub network_chan: crossbeam_channel::Sender<NetworkMessage>,
|
||||||
pub log: Logger,
|
pub log: Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> BeaconBlockService for BeaconBlockServiceInstance<B> {
|
impl<B: EthSpec> BeaconBlockService for BeaconBlockServiceInstance<B> {
|
||||||
/// Produce a `BeaconBlock` for signing by a validator.
|
/// Produce a `BeaconBlock` for signing by a validator.
|
||||||
fn produce_beacon_block(
|
fn produce_beacon_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -8,10 +8,10 @@ use beacon_chain::{
|
|||||||
AttestationValidationError, BlockProductionError,
|
AttestationValidationError, BlockProductionError,
|
||||||
};
|
};
|
||||||
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome};
|
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome};
|
||||||
use types::{Attestation, AttestationData, BeaconBlock, BeaconStateTypes};
|
use types::{Attestation, AttestationData, BeaconBlock, EthSpec};
|
||||||
|
|
||||||
/// The RPC's API to the beacon chain.
|
/// The RPC's API to the beacon chain.
|
||||||
pub trait BeaconChain<B: BeaconStateTypes>: Send + Sync {
|
pub trait BeaconChain<B: EthSpec>: Send + Sync {
|
||||||
fn get_spec(&self) -> &ChainSpec;
|
fn get_spec(&self) -> &ChainSpec;
|
||||||
|
|
||||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
|
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
|
||||||
@ -39,7 +39,7 @@ where
|
|||||||
T: ClientDB + Sized,
|
T: ClientDB + Sized,
|
||||||
U: SlotClock,
|
U: SlotClock,
|
||||||
F: ForkChoice,
|
F: ForkChoice,
|
||||||
B: BeaconStateTypes,
|
B: EthSpec,
|
||||||
{
|
{
|
||||||
fn get_spec(&self) -> &ChainSpec {
|
fn get_spec(&self) -> &ChainSpec {
|
||||||
&self.spec
|
&self.spec
|
||||||
|
@ -5,15 +5,15 @@ use protos::services::{Empty, Fork, NodeInfoResponse};
|
|||||||
use protos::services_grpc::BeaconNodeService;
|
use protos::services_grpc::BeaconNodeService;
|
||||||
use slog::{trace, warn};
|
use slog::{trace, warn};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::BeaconStateTypes;
|
use types::EthSpec;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BeaconNodeServiceInstance<B: BeaconStateTypes> {
|
pub struct BeaconNodeServiceInstance<B: EthSpec> {
|
||||||
pub chain: Arc<BeaconChain<B>>,
|
pub chain: Arc<BeaconChain<B>>,
|
||||||
pub log: slog::Logger,
|
pub log: slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> BeaconNodeService for BeaconNodeServiceInstance<B> {
|
impl<B: EthSpec> BeaconNodeService for BeaconNodeServiceInstance<B> {
|
||||||
/// Provides basic node information.
|
/// Provides basic node information.
|
||||||
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfoResponse>) {
|
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfoResponse>) {
|
||||||
trace!(self.log, "Node info requested via RPC");
|
trace!(self.log, "Node info requested via RPC");
|
||||||
|
@ -21,9 +21,9 @@ use protos::services_grpc::{
|
|||||||
use slog::{info, o, warn};
|
use slog::{info, o, warn};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::runtime::TaskExecutor;
|
use tokio::runtime::TaskExecutor;
|
||||||
use types::BeaconStateTypes;
|
use types::EthSpec;
|
||||||
|
|
||||||
pub fn start_server<B: BeaconStateTypes>(
|
pub fn start_server<B: EthSpec>(
|
||||||
config: &RPCConfig,
|
config: &RPCConfig,
|
||||||
executor: &TaskExecutor,
|
executor: &TaskExecutor,
|
||||||
network_chan: crossbeam_channel::Sender<NetworkMessage>,
|
network_chan: crossbeam_channel::Sender<NetworkMessage>,
|
||||||
|
@ -7,16 +7,16 @@ use protos::services_grpc::ValidatorService;
|
|||||||
use slog::{trace, warn};
|
use slog::{trace, warn};
|
||||||
use ssz::decode;
|
use ssz::decode;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconStateTypes, Epoch, RelativeEpoch};
|
use types::{Epoch, EthSpec, RelativeEpoch};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ValidatorServiceInstance<B: BeaconStateTypes> {
|
pub struct ValidatorServiceInstance<B: EthSpec> {
|
||||||
pub chain: Arc<BeaconChain<B>>,
|
pub chain: Arc<BeaconChain<B>>,
|
||||||
pub log: slog::Logger,
|
pub log: slog::Logger,
|
||||||
}
|
}
|
||||||
//TODO: Refactor Errors
|
//TODO: Refactor Errors
|
||||||
|
|
||||||
impl<B: BeaconStateTypes> ValidatorService for ValidatorServiceInstance<B> {
|
impl<B: EthSpec> ValidatorService for ValidatorServiceInstance<B> {
|
||||||
/// For a list of validator public keys, this function returns the slot at which each
|
/// For a list of validator public keys, this function returns the slot at which each
|
||||||
/// validator must propose a block, attest to a shard, their shard committee and the shard they
|
/// validator must propose a block, attest to a shard, their shard committee and the shard they
|
||||||
/// need to attest to.
|
/// need to attest to.
|
||||||
|
@ -11,7 +11,7 @@ use log::{debug, trace};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot, SlotHeight};
|
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
|
||||||
|
|
||||||
//TODO: Pruning - Children
|
//TODO: Pruning - Children
|
||||||
//TODO: Handle Syncing
|
//TODO: Handle Syncing
|
||||||
@ -54,7 +54,7 @@ pub struct BitwiseLMDGhost<T: ClientDB + Sized, B> {
|
|||||||
_phantom: PhantomData<B>,
|
_phantom: PhantomData<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, B: BeaconStateTypes> BitwiseLMDGhost<T, B>
|
impl<T, B: EthSpec> BitwiseLMDGhost<T, B>
|
||||||
where
|
where
|
||||||
T: ClientDB + Sized,
|
T: ClientDB + Sized,
|
||||||
{
|
{
|
||||||
@ -243,7 +243,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for BitwiseLMDGhost<T, B> {
|
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for BitwiseLMDGhost<T, B> {
|
||||||
fn add_block(
|
fn add_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
|
@ -11,7 +11,7 @@ use std::cmp::Ordering;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot, SlotHeight};
|
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
|
||||||
|
|
||||||
//TODO: Pruning - Children
|
//TODO: Pruning - Children
|
||||||
//TODO: Handle Syncing
|
//TODO: Handle Syncing
|
||||||
@ -54,7 +54,7 @@ pub struct OptimizedLMDGhost<T: ClientDB + Sized, B> {
|
|||||||
_phantom: PhantomData<B>,
|
_phantom: PhantomData<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, B: BeaconStateTypes> OptimizedLMDGhost<T, B>
|
impl<T, B: EthSpec> OptimizedLMDGhost<T, B>
|
||||||
where
|
where
|
||||||
T: ClientDB + Sized,
|
T: ClientDB + Sized,
|
||||||
{
|
{
|
||||||
@ -214,7 +214,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for OptimizedLMDGhost<T, B> {
|
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for OptimizedLMDGhost<T, B> {
|
||||||
fn add_block(
|
fn add_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
|
@ -9,7 +9,7 @@ use log::{debug, trace};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot};
|
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot};
|
||||||
|
|
||||||
//TODO: Pruning and syncing
|
//TODO: Pruning and syncing
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ pub struct SlowLMDGhost<T: ClientDB + Sized, B> {
|
|||||||
_phantom: PhantomData<B>,
|
_phantom: PhantomData<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, B: BeaconStateTypes> SlowLMDGhost<T, B>
|
impl<T, B: EthSpec> SlowLMDGhost<T, B>
|
||||||
where
|
where
|
||||||
T: ClientDB + Sized,
|
T: ClientDB + Sized,
|
||||||
{
|
{
|
||||||
@ -108,7 +108,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for SlowLMDGhost<T, B> {
|
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for SlowLMDGhost<T, B> {
|
||||||
/// Process when a block is added
|
/// Process when a block is added
|
||||||
fn add_block(
|
fn add_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -26,8 +26,7 @@ use std::sync::Arc;
|
|||||||
use std::{fs::File, io::prelude::*, path::PathBuf};
|
use std::{fs::File, io::prelude::*, path::PathBuf};
|
||||||
use types::test_utils::TestingBeaconStateBuilder;
|
use types::test_utils::TestingBeaconStateBuilder;
|
||||||
use types::{
|
use types::{
|
||||||
BeaconBlock, BeaconBlockBody, BeaconStateTypes, Eth1Data, FoundationStateTypes, Hash256,
|
BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, FoundationEthSpec, Hash256, Keypair, Slot,
|
||||||
Keypair, Slot,
|
|
||||||
};
|
};
|
||||||
use yaml_rust::yaml;
|
use yaml_rust::yaml;
|
||||||
|
|
||||||
@ -85,7 +84,7 @@ fn test_yaml_vectors(
|
|||||||
let test_cases = load_test_cases_from_yaml(yaml_file_path);
|
let test_cases = load_test_cases_from_yaml(yaml_file_path);
|
||||||
|
|
||||||
// default vars
|
// default vars
|
||||||
let spec = FoundationStateTypes::spec();
|
let spec = FoundationEthSpec::spec();
|
||||||
let zero_hash = Hash256::zero();
|
let zero_hash = Hash256::zero();
|
||||||
let eth1_data = Eth1Data {
|
let eth1_data = Eth1Data {
|
||||||
deposit_root: zero_hash.clone(),
|
deposit_root: zero_hash.clone(),
|
||||||
@ -231,26 +230,26 @@ fn setup_inital_state(
|
|||||||
// the fork choice instantiation
|
// the fork choice instantiation
|
||||||
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
|
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
|
||||||
ForkChoiceAlgorithm::OptimizedLMDGhost => {
|
ForkChoiceAlgorithm::OptimizedLMDGhost => {
|
||||||
let f: OptimizedLMDGhost<MemoryDB, FoundationStateTypes> =
|
let f: OptimizedLMDGhost<MemoryDB, FoundationEthSpec> =
|
||||||
OptimizedLMDGhost::new(block_store.clone(), state_store.clone());
|
OptimizedLMDGhost::new(block_store.clone(), state_store.clone());
|
||||||
Box::new(f)
|
Box::new(f)
|
||||||
}
|
}
|
||||||
ForkChoiceAlgorithm::BitwiseLMDGhost => {
|
ForkChoiceAlgorithm::BitwiseLMDGhost => {
|
||||||
let f: BitwiseLMDGhost<MemoryDB, FoundationStateTypes> =
|
let f: BitwiseLMDGhost<MemoryDB, FoundationEthSpec> =
|
||||||
BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
|
BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
|
||||||
Box::new(f)
|
Box::new(f)
|
||||||
}
|
}
|
||||||
ForkChoiceAlgorithm::SlowLMDGhost => {
|
ForkChoiceAlgorithm::SlowLMDGhost => {
|
||||||
let f: SlowLMDGhost<MemoryDB, FoundationStateTypes> =
|
let f: SlowLMDGhost<MemoryDB, FoundationEthSpec> =
|
||||||
SlowLMDGhost::new(block_store.clone(), state_store.clone());
|
SlowLMDGhost::new(block_store.clone(), state_store.clone());
|
||||||
Box::new(f)
|
Box::new(f)
|
||||||
}
|
}
|
||||||
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())),
|
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let spec = FoundationStateTypes::spec();
|
let spec = FoundationEthSpec::spec();
|
||||||
|
|
||||||
let mut state_builder: TestingBeaconStateBuilder<FoundationStateTypes> =
|
let mut state_builder: TestingBeaconStateBuilder<FoundationEthSpec> =
|
||||||
TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec);
|
TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec);
|
||||||
state_builder.build_caches(&spec).unwrap();
|
state_builder.build_caches(&spec).unwrap();
|
||||||
let (state, _keypairs) = state_builder.build();
|
let (state, _keypairs) = state_builder.build();
|
||||||
|
@ -16,8 +16,8 @@ use std::collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet};
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use types::chain_spec::Domain;
|
use types::chain_spec::Domain;
|
||||||
use types::{
|
use types::{
|
||||||
Attestation, AttestationData, AttesterSlashing, BeaconState, BeaconStateTypes, ChainSpec,
|
Attestation, AttestationData, AttesterSlashing, BeaconState, ChainSpec, Deposit, Epoch,
|
||||||
Deposit, Epoch, ProposerSlashing, Transfer, Validator, VoluntaryExit,
|
EthSpec, ProposerSlashing, Transfer, Validator, VoluntaryExit,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -26,7 +26,7 @@ const VERIFY_DEPOSIT_PROOFS: bool = false;
|
|||||||
const VERIFY_DEPOSIT_PROOFS: bool = false; // TODO: enable this
|
const VERIFY_DEPOSIT_PROOFS: bool = false; // TODO: enable this
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct OperationPool<T: BeaconStateTypes + Default> {
|
pub struct OperationPool<T: EthSpec + Default> {
|
||||||
/// Map from attestation ID (see below) to vectors of attestations.
|
/// Map from attestation ID (see below) to vectors of attestations.
|
||||||
attestations: RwLock<HashMap<AttestationId, Vec<Attestation>>>,
|
attestations: RwLock<HashMap<AttestationId, Vec<Attestation>>>,
|
||||||
/// Map from deposit index to deposit data.
|
/// Map from deposit index to deposit data.
|
||||||
@ -54,7 +54,7 @@ struct AttestationId(Vec<u8>);
|
|||||||
const DOMAIN_BYTES_LEN: usize = 8;
|
const DOMAIN_BYTES_LEN: usize = 8;
|
||||||
|
|
||||||
impl AttestationId {
|
impl AttestationId {
|
||||||
fn from_data<T: BeaconStateTypes>(
|
fn from_data<T: EthSpec>(
|
||||||
attestation: &AttestationData,
|
attestation: &AttestationData,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -65,7 +65,7 @@ impl AttestationId {
|
|||||||
AttestationId(bytes)
|
AttestationId(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_domain_bytes<T: BeaconStateTypes>(
|
fn compute_domain_bytes<T: EthSpec>(
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -85,7 +85,7 @@ impl AttestationId {
|
|||||||
/// receive for including it in a block.
|
/// receive for including it in a block.
|
||||||
// TODO: this could be optimised with a map from validator index to whether that validator has
|
// TODO: this could be optimised with a map from validator index to whether that validator has
|
||||||
// attested in each of the current and previous epochs. Currently quadractic in number of validators.
|
// attested in each of the current and previous epochs. Currently quadractic in number of validators.
|
||||||
fn attestation_score<T: BeaconStateTypes>(
|
fn attestation_score<T: EthSpec>(
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -127,7 +127,7 @@ pub enum DepositInsertStatus {
|
|||||||
Replaced(Box<Deposit>),
|
Replaced(Box<Deposit>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: BeaconStateTypes> OperationPool<T> {
|
impl<T: EthSpec> OperationPool<T> {
|
||||||
/// Create a new operation pool.
|
/// Create a new operation pool.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
@ -501,7 +501,7 @@ impl<T: BeaconStateTypes> OperationPool<T> {
|
|||||||
///
|
///
|
||||||
/// - Their `AttestationData` is equal.
|
/// - Their `AttestationData` is equal.
|
||||||
/// - `attestation` does not contain any signatures that `PendingAttestation` does not have.
|
/// - `attestation` does not contain any signatures that `PendingAttestation` does not have.
|
||||||
fn superior_attestation_exists_in_state<T: BeaconStateTypes>(
|
fn superior_attestation_exists_in_state<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
@ -539,7 +539,7 @@ where
|
|||||||
/// The keys in the map should be validator indices, which will be looked up
|
/// The keys in the map should be validator indices, which will be looked up
|
||||||
/// in the state's validator registry and then passed to `prune_if`.
|
/// in the state's validator registry and then passed to `prune_if`.
|
||||||
/// Entries for unknown validators will be kept.
|
/// Entries for unknown validators will be kept.
|
||||||
fn prune_validator_hash_map<T, F, B: BeaconStateTypes>(
|
fn prune_validator_hash_map<T, F, B: EthSpec>(
|
||||||
map: &mut HashMap<u64, T>,
|
map: &mut HashMap<u64, T>,
|
||||||
prune_if: F,
|
prune_if: F,
|
||||||
finalized_state: &BeaconState<B>,
|
finalized_state: &BeaconState<B>,
|
||||||
@ -666,7 +666,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a random deposit (with a valid proof of posession)
|
// Create a random deposit (with a valid proof of posession)
|
||||||
fn make_deposit<T: BeaconStateTypes>(
|
fn make_deposit<T: EthSpec>(
|
||||||
rng: &mut XorShiftRng,
|
rng: &mut XorShiftRng,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -689,7 +689,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create `count` dummy deposits with sequential deposit IDs beginning from `start`.
|
// Create `count` dummy deposits with sequential deposit IDs beginning from `start`.
|
||||||
fn dummy_deposits<T: BeaconStateTypes>(
|
fn dummy_deposits<T: EthSpec>(
|
||||||
rng: &mut XorShiftRng,
|
rng: &mut XorShiftRng,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -706,8 +706,8 @@ mod tests {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState<FoundationStateTypes>) {
|
fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState<FoundationEthSpec>) {
|
||||||
let spec = FoundationStateTypes::spec();
|
let spec = FoundationEthSpec::spec();
|
||||||
|
|
||||||
let mut state = BeaconState::random_for_test(rng);
|
let mut state = BeaconState::random_for_test(rng);
|
||||||
|
|
||||||
@ -722,10 +722,7 @@ mod tests {
|
|||||||
|
|
||||||
/// Create a signed attestation for use in tests.
|
/// Create a signed attestation for use in tests.
|
||||||
/// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`.
|
/// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`.
|
||||||
fn signed_attestation<
|
fn signed_attestation<R: std::slice::SliceIndex<[usize], Output = [usize]>, B: EthSpec>(
|
||||||
R: std::slice::SliceIndex<[usize], Output = [usize]>,
|
|
||||||
B: BeaconStateTypes,
|
|
||||||
>(
|
|
||||||
committee: &CrosslinkCommittee,
|
committee: &CrosslinkCommittee,
|
||||||
keypairs: &[Keypair],
|
keypairs: &[Keypair],
|
||||||
signing_range: R,
|
signing_range: R,
|
||||||
@ -757,7 +754,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Test state for attestation-related tests.
|
/// Test state for attestation-related tests.
|
||||||
fn attestation_test_state<B: BeaconStateTypes>(
|
fn attestation_test_state<B: EthSpec>(
|
||||||
num_committees: usize,
|
num_committees: usize,
|
||||||
) -> (BeaconState<B>, Vec<Keypair>, ChainSpec) {
|
) -> (BeaconState<B>, Vec<Keypair>, ChainSpec) {
|
||||||
let spec = B::spec();
|
let spec = B::spec();
|
||||||
@ -774,11 +771,11 @@ mod tests {
|
|||||||
state_builder.build_caches(&spec).unwrap();
|
state_builder.build_caches(&spec).unwrap();
|
||||||
let (state, keypairs) = state_builder.build();
|
let (state, keypairs) = state_builder.build();
|
||||||
|
|
||||||
(state, keypairs, FoundationStateTypes::spec())
|
(state, keypairs, FoundationEthSpec::spec())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the latest crosslink in the state to match the attestation.
|
/// Set the latest crosslink in the state to match the attestation.
|
||||||
fn fake_latest_crosslink<B: BeaconStateTypes>(
|
fn fake_latest_crosslink<B: EthSpec>(
|
||||||
att: &Attestation,
|
att: &Attestation,
|
||||||
state: &mut BeaconState<B>,
|
state: &mut BeaconState<B>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -792,7 +789,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_attestation_score() {
|
fn test_attestation_score() {
|
||||||
let (ref mut state, ref keypairs, ref spec) =
|
let (ref mut state, ref keypairs, ref spec) =
|
||||||
attestation_test_state::<FoundationStateTypes>(1);
|
attestation_test_state::<FoundationEthSpec>(1);
|
||||||
|
|
||||||
let slot = state.slot - 1;
|
let slot = state.slot - 1;
|
||||||
let committees = state
|
let committees = state
|
||||||
@ -824,7 +821,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn attestation_aggregation_insert_get_prune() {
|
fn attestation_aggregation_insert_get_prune() {
|
||||||
let (ref mut state, ref keypairs, ref spec) =
|
let (ref mut state, ref keypairs, ref spec) =
|
||||||
attestation_test_state::<FoundationStateTypes>(1);
|
attestation_test_state::<FoundationEthSpec>(1);
|
||||||
|
|
||||||
let op_pool = OperationPool::new();
|
let op_pool = OperationPool::new();
|
||||||
|
|
||||||
@ -890,7 +887,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn attestation_duplicate() {
|
fn attestation_duplicate() {
|
||||||
let (ref mut state, ref keypairs, ref spec) =
|
let (ref mut state, ref keypairs, ref spec) =
|
||||||
attestation_test_state::<FoundationStateTypes>(1);
|
attestation_test_state::<FoundationEthSpec>(1);
|
||||||
|
|
||||||
let op_pool = OperationPool::new();
|
let op_pool = OperationPool::new();
|
||||||
|
|
||||||
@ -917,7 +914,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn attestation_pairwise_overlapping() {
|
fn attestation_pairwise_overlapping() {
|
||||||
let (ref mut state, ref keypairs, ref spec) =
|
let (ref mut state, ref keypairs, ref spec) =
|
||||||
attestation_test_state::<FoundationStateTypes>(1);
|
attestation_test_state::<FoundationEthSpec>(1);
|
||||||
|
|
||||||
let op_pool = OperationPool::new();
|
let op_pool = OperationPool::new();
|
||||||
|
|
||||||
@ -963,7 +960,7 @@ mod tests {
|
|||||||
let big_step_size = 4;
|
let big_step_size = 4;
|
||||||
|
|
||||||
let (ref mut state, ref keypairs, ref spec) =
|
let (ref mut state, ref keypairs, ref spec) =
|
||||||
attestation_test_state::<FoundationStateTypes>(big_step_size);
|
attestation_test_state::<FoundationEthSpec>(big_step_size);
|
||||||
|
|
||||||
let op_pool = OperationPool::new();
|
let op_pool = OperationPool::new();
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use types::{BeaconStateError as Error, *};
|
|||||||
/// Exit the validator of the given `index`.
|
/// Exit the validator of the given `index`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn exit_validator<T: BeaconStateTypes>(
|
pub fn exit_validator<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -4,7 +4,7 @@ use types::{BeaconStateError as Error, *};
|
|||||||
/// Slash the validator with index ``index``.
|
/// Slash the validator with index ``index``.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn slash_validator<T: BeaconStateTypes>(
|
pub fn slash_validator<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -10,7 +10,7 @@ pub enum GenesisError {
|
|||||||
/// Returns the genesis `BeaconState`
|
/// Returns the genesis `BeaconState`
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn get_genesis_state<T: BeaconStateTypes>(
|
pub fn get_genesis_state<T: EthSpec>(
|
||||||
genesis_validator_deposits: &[Deposit],
|
genesis_validator_deposits: &[Deposit],
|
||||||
genesis_time: u64,
|
genesis_time: u64,
|
||||||
genesis_eth1_data: Eth1Data,
|
genesis_eth1_data: Eth1Data,
|
||||||
|
@ -40,7 +40,7 @@ const VERIFY_DEPOSIT_MERKLE_PROOFS: bool = false;
|
|||||||
/// returns an error describing why the block was invalid or how the function failed to execute.
|
/// returns an error describing why the block was invalid or how the function failed to execute.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn per_block_processing<T: BeaconStateTypes>(
|
pub fn per_block_processing<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -55,7 +55,7 @@ pub fn per_block_processing<T: BeaconStateTypes>(
|
|||||||
/// returns an error describing why the block was invalid or how the function failed to execute.
|
/// returns an error describing why the block was invalid or how the function failed to execute.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn per_block_processing_without_verifying_block_signature<T: BeaconStateTypes>(
|
pub fn per_block_processing_without_verifying_block_signature<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -70,7 +70,7 @@ pub fn per_block_processing_without_verifying_block_signature<T: BeaconStateType
|
|||||||
/// returns an error describing why the block was invalid or how the function failed to execute.
|
/// returns an error describing why the block was invalid or how the function failed to execute.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn per_block_processing_signature_optional<T: BeaconStateTypes>(
|
fn per_block_processing_signature_optional<T: EthSpec>(
|
||||||
mut state: &mut BeaconState<T>,
|
mut state: &mut BeaconState<T>,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
should_verify_block_signature: bool,
|
should_verify_block_signature: bool,
|
||||||
@ -100,7 +100,7 @@ fn per_block_processing_signature_optional<T: BeaconStateTypes>(
|
|||||||
/// Processes the block header.
|
/// Processes the block header.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_block_header<T: BeaconStateTypes>(
|
pub fn process_block_header<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -125,7 +125,7 @@ pub fn process_block_header<T: BeaconStateTypes>(
|
|||||||
/// Verifies the signature of a block.
|
/// Verifies the signature of a block.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_block_signature<T: BeaconStateTypes>(
|
pub fn verify_block_signature<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -153,7 +153,7 @@ pub fn verify_block_signature<T: BeaconStateTypes>(
|
|||||||
/// `state.latest_randao_mixes`.
|
/// `state.latest_randao_mixes`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_randao<T: BeaconStateTypes>(
|
pub fn process_randao<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
block: &BeaconBlock,
|
block: &BeaconBlock,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -184,7 +184,7 @@ pub fn process_randao<T: BeaconStateTypes>(
|
|||||||
/// Update the `state.eth1_data_votes` based upon the `eth1_data` provided.
|
/// Update the `state.eth1_data_votes` based upon the `eth1_data` provided.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_eth1_data<T: BeaconStateTypes>(
|
pub fn process_eth1_data<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
eth1_data: &Eth1Data,
|
eth1_data: &Eth1Data,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -213,7 +213,7 @@ pub fn process_eth1_data<T: BeaconStateTypes>(
|
|||||||
/// an `Err` describing the invalid object or cause of failure.
|
/// an `Err` describing the invalid object or cause of failure.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_proposer_slashings<T: BeaconStateTypes>(
|
pub fn process_proposer_slashings<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
proposer_slashings: &[ProposerSlashing],
|
proposer_slashings: &[ProposerSlashing],
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -246,7 +246,7 @@ pub fn process_proposer_slashings<T: BeaconStateTypes>(
|
|||||||
/// an `Err` describing the invalid object or cause of failure.
|
/// an `Err` describing the invalid object or cause of failure.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_attester_slashings<T: BeaconStateTypes>(
|
pub fn process_attester_slashings<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
attester_slashings: &[AttesterSlashing],
|
attester_slashings: &[AttesterSlashing],
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -304,7 +304,7 @@ pub fn process_attester_slashings<T: BeaconStateTypes>(
|
|||||||
/// an `Err` describing the invalid object or cause of failure.
|
/// an `Err` describing the invalid object or cause of failure.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_attestations<T: BeaconStateTypes>(
|
pub fn process_attestations<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
attestations: &[Attestation],
|
attestations: &[Attestation],
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -346,7 +346,7 @@ pub fn process_attestations<T: BeaconStateTypes>(
|
|||||||
/// an `Err` describing the invalid object or cause of failure.
|
/// an `Err` describing the invalid object or cause of failure.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_deposits<T: BeaconStateTypes>(
|
pub fn process_deposits<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
deposits: &[Deposit],
|
deposits: &[Deposit],
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -416,7 +416,7 @@ pub fn process_deposits<T: BeaconStateTypes>(
|
|||||||
/// an `Err` describing the invalid object or cause of failure.
|
/// an `Err` describing the invalid object or cause of failure.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_exits<T: BeaconStateTypes>(
|
pub fn process_exits<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
voluntary_exits: &[VoluntaryExit],
|
voluntary_exits: &[VoluntaryExit],
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -448,7 +448,7 @@ pub fn process_exits<T: BeaconStateTypes>(
|
|||||||
/// an `Err` describing the invalid object or cause of failure.
|
/// an `Err` describing the invalid object or cause of failure.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_transfers<T: BeaconStateTypes>(
|
pub fn process_transfers<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
transfers: &[Transfer],
|
transfers: &[Transfer],
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -9,7 +9,7 @@ use types::*;
|
|||||||
/// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity.
|
/// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn validate_attestation<T: BeaconStateTypes>(
|
pub fn validate_attestation<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -18,7 +18,7 @@ pub fn validate_attestation<T: BeaconStateTypes>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Like `validate_attestation` but doesn't run checks which may become true in future states.
|
/// Like `validate_attestation` but doesn't run checks which may become true in future states.
|
||||||
pub fn validate_attestation_time_independent_only<T: BeaconStateTypes>(
|
pub fn validate_attestation_time_independent_only<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -32,7 +32,7 @@ pub fn validate_attestation_time_independent_only<T: BeaconStateTypes>(
|
|||||||
/// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity.
|
/// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn validate_attestation_without_signature<T: BeaconStateTypes>(
|
pub fn validate_attestation_without_signature<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -45,7 +45,7 @@ pub fn validate_attestation_without_signature<T: BeaconStateTypes>(
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn validate_attestation_parametric<T: BeaconStateTypes>(
|
fn validate_attestation_parametric<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -168,7 +168,7 @@ fn validate_attestation_parametric<T: BeaconStateTypes>(
|
|||||||
/// match the current (or previous) justified epoch and root from the state.
|
/// match the current (or previous) justified epoch and root from the state.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn verify_justified_epoch_and_root<T: BeaconStateTypes>(
|
fn verify_justified_epoch_and_root<T: EthSpec>(
|
||||||
attestation: &Attestation,
|
attestation: &Attestation,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -223,7 +223,7 @@ fn verify_justified_epoch_and_root<T: BeaconStateTypes>(
|
|||||||
/// - A `validator_index` in `committee` is not in `state.validator_registry`.
|
/// - A `validator_index` in `committee` is not in `state.validator_registry`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn verify_attestation_signature<T: BeaconStateTypes>(
|
fn verify_attestation_signature<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
committee: &[usize],
|
committee: &[usize],
|
||||||
a: &Attestation,
|
a: &Attestation,
|
||||||
|
@ -8,7 +8,7 @@ use types::*;
|
|||||||
/// Returns `Ok(())` if the `AttesterSlashing` is valid, otherwise indicates the reason for invalidity.
|
/// Returns `Ok(())` if the `AttesterSlashing` is valid, otherwise indicates the reason for invalidity.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_attester_slashing<T: BeaconStateTypes>(
|
pub fn verify_attester_slashing<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attester_slashing: &AttesterSlashing,
|
attester_slashing: &AttesterSlashing,
|
||||||
should_verify_slashable_attestations: bool,
|
should_verify_slashable_attestations: bool,
|
||||||
@ -42,7 +42,7 @@ pub fn verify_attester_slashing<T: BeaconStateTypes>(
|
|||||||
/// Returns Ok(indices) if `indices.len() > 0`.
|
/// Returns Ok(indices) if `indices.len() > 0`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn gather_attester_slashing_indices<T: BeaconStateTypes>(
|
pub fn gather_attester_slashing_indices<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attester_slashing: &AttesterSlashing,
|
attester_slashing: &AttesterSlashing,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -57,7 +57,7 @@ pub fn gather_attester_slashing_indices<T: BeaconStateTypes>(
|
|||||||
|
|
||||||
/// Same as `gather_attester_slashing_indices` but allows the caller to specify the criteria
|
/// Same as `gather_attester_slashing_indices` but allows the caller to specify the criteria
|
||||||
/// for determining whether a given validator should be considered slashed.
|
/// for determining whether a given validator should be considered slashed.
|
||||||
pub fn gather_attester_slashing_indices_modular<F, T: BeaconStateTypes>(
|
pub fn gather_attester_slashing_indices_modular<F, T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attester_slashing: &AttesterSlashing,
|
attester_slashing: &AttesterSlashing,
|
||||||
is_slashed: F,
|
is_slashed: F,
|
||||||
|
@ -16,7 +16,7 @@ use types::*;
|
|||||||
/// Note: this function is incomplete.
|
/// Note: this function is incomplete.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_deposit<T: BeaconStateTypes>(
|
pub fn verify_deposit<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
deposit: &Deposit,
|
deposit: &Deposit,
|
||||||
verify_merkle_branch: bool,
|
verify_merkle_branch: bool,
|
||||||
@ -47,7 +47,7 @@ pub fn verify_deposit<T: BeaconStateTypes>(
|
|||||||
/// Verify that the `Deposit` index is correct.
|
/// Verify that the `Deposit` index is correct.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_deposit_index<T: BeaconStateTypes>(
|
pub fn verify_deposit_index<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
deposit: &Deposit,
|
deposit: &Deposit,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -68,7 +68,7 @@ pub fn verify_deposit_index<T: BeaconStateTypes>(
|
|||||||
/// ## Errors
|
/// ## Errors
|
||||||
///
|
///
|
||||||
/// Errors if the state's `pubkey_cache` is not current.
|
/// Errors if the state's `pubkey_cache` is not current.
|
||||||
pub fn get_existing_validator_index<T: BeaconStateTypes>(
|
pub fn get_existing_validator_index<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
deposit: &Deposit,
|
deposit: &Deposit,
|
||||||
) -> Result<Option<u64>, Error> {
|
) -> Result<Option<u64>, Error> {
|
||||||
@ -92,7 +92,7 @@ pub fn get_existing_validator_index<T: BeaconStateTypes>(
|
|||||||
/// Verify that a deposit is included in the state's eth1 deposit root.
|
/// Verify that a deposit is included in the state's eth1 deposit root.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn verify_deposit_merkle_proof<T: BeaconStateTypes>(
|
fn verify_deposit_merkle_proof<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
deposit: &Deposit,
|
deposit: &Deposit,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -8,7 +8,7 @@ use types::*;
|
|||||||
/// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity.
|
/// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_exit<T: BeaconStateTypes>(
|
pub fn verify_exit<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
exit: &VoluntaryExit,
|
exit: &VoluntaryExit,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -17,7 +17,7 @@ pub fn verify_exit<T: BeaconStateTypes>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Like `verify_exit` but doesn't run checks which may become true in future states.
|
/// Like `verify_exit` but doesn't run checks which may become true in future states.
|
||||||
pub fn verify_exit_time_independent_only<T: BeaconStateTypes>(
|
pub fn verify_exit_time_independent_only<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
exit: &VoluntaryExit,
|
exit: &VoluntaryExit,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -26,7 +26,7 @@ pub fn verify_exit_time_independent_only<T: BeaconStateTypes>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parametric version of `verify_exit` that skips some checks if `time_independent_only` is true.
|
/// Parametric version of `verify_exit` that skips some checks if `time_independent_only` is true.
|
||||||
fn verify_exit_parametric<T: BeaconStateTypes>(
|
fn verify_exit_parametric<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
exit: &VoluntaryExit,
|
exit: &VoluntaryExit,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -8,7 +8,7 @@ use types::*;
|
|||||||
/// Returns `Ok(())` if the `ProposerSlashing` is valid, otherwise indicates the reason for invalidity.
|
/// Returns `Ok(())` if the `ProposerSlashing` is valid, otherwise indicates the reason for invalidity.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_proposer_slashing<T: BeaconStateTypes>(
|
pub fn verify_proposer_slashing<T: EthSpec>(
|
||||||
proposer_slashing: &ProposerSlashing,
|
proposer_slashing: &ProposerSlashing,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -11,7 +11,7 @@ use types::*;
|
|||||||
/// Returns `Ok(())` if the `SlashableAttestation` is valid, otherwise indicates the reason for invalidity.
|
/// Returns `Ok(())` if the `SlashableAttestation` is valid, otherwise indicates the reason for invalidity.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_slashable_attestation<T: BeaconStateTypes>(
|
pub fn verify_slashable_attestation<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
slashable_attestation: &SlashableAttestation,
|
slashable_attestation: &SlashableAttestation,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -11,7 +11,7 @@ use types::*;
|
|||||||
/// Note: this function is incomplete.
|
/// Note: this function is incomplete.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn verify_transfer<T: BeaconStateTypes>(
|
pub fn verify_transfer<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
transfer: &Transfer,
|
transfer: &Transfer,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -20,7 +20,7 @@ pub fn verify_transfer<T: BeaconStateTypes>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Like `verify_transfer` but doesn't run checks which may become true in future states.
|
/// Like `verify_transfer` but doesn't run checks which may become true in future states.
|
||||||
pub fn verify_transfer_time_independent_only<T: BeaconStateTypes>(
|
pub fn verify_transfer_time_independent_only<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
transfer: &Transfer,
|
transfer: &Transfer,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -29,7 +29,7 @@ pub fn verify_transfer_time_independent_only<T: BeaconStateTypes>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parametric version of `verify_transfer` that allows some checks to be skipped.
|
/// Parametric version of `verify_transfer` that allows some checks to be skipped.
|
||||||
fn verify_transfer_parametric<T: BeaconStateTypes>(
|
fn verify_transfer_parametric<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
transfer: &Transfer,
|
transfer: &Transfer,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -123,7 +123,7 @@ fn verify_transfer_parametric<T: BeaconStateTypes>(
|
|||||||
/// Does not check that the transfer is valid, however checks for overflow in all actions.
|
/// Does not check that the transfer is valid, however checks for overflow in all actions.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn execute_transfer<T: BeaconStateTypes>(
|
pub fn execute_transfer<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
transfer: &Transfer,
|
transfer: &Transfer,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -33,7 +33,7 @@ pub type WinningRootHashSet = HashMap<u64, WinningRoot>;
|
|||||||
/// returned, a state might be "half-processed" and therefore in an invalid state.
|
/// returned, a state might be "half-processed" and therefore in an invalid state.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn per_epoch_processing<T: BeaconStateTypes>(
|
pub fn per_epoch_processing<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -90,7 +90,7 @@ pub fn per_epoch_processing<T: BeaconStateTypes>(
|
|||||||
/// Maybe resets the eth1 period.
|
/// Maybe resets the eth1 period.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn maybe_reset_eth1_period<T: BeaconStateTypes>(state: &mut BeaconState<T>, spec: &ChainSpec) {
|
pub fn maybe_reset_eth1_period<T: EthSpec>(state: &mut BeaconState<T>, spec: &ChainSpec) {
|
||||||
let next_epoch = state.next_epoch(spec);
|
let next_epoch = state.next_epoch(spec);
|
||||||
let voting_period = spec.epochs_per_eth1_voting_period;
|
let voting_period = spec.epochs_per_eth1_voting_period;
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ pub fn maybe_reset_eth1_period<T: BeaconStateTypes>(state: &mut BeaconState<T>,
|
|||||||
/// - `previous_justified_epoch`
|
/// - `previous_justified_epoch`
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn update_justification_and_finalization<T: BeaconStateTypes>(
|
pub fn update_justification_and_finalization<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
total_balances: &TotalBalances,
|
total_balances: &TotalBalances,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -182,7 +182,7 @@ pub fn update_justification_and_finalization<T: BeaconStateTypes>(
|
|||||||
/// Also returns a `WinningRootHashSet` for later use during epoch processing.
|
/// Also returns a `WinningRootHashSet` for later use during epoch processing.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_crosslinks<T: BeaconStateTypes>(
|
pub fn process_crosslinks<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<WinningRootHashSet, Error> {
|
) -> Result<WinningRootHashSet, Error> {
|
||||||
@ -225,7 +225,7 @@ pub fn process_crosslinks<T: BeaconStateTypes>(
|
|||||||
/// Finish up an epoch update.
|
/// Finish up an epoch update.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn finish_epoch_update<T: BeaconStateTypes>(
|
pub fn finish_epoch_update<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -33,7 +33,7 @@ impl std::ops::AddAssign for Delta {
|
|||||||
/// Apply attester and proposer rewards.
|
/// Apply attester and proposer rewards.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn apply_rewards<T: BeaconStateTypes>(
|
pub fn apply_rewards<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
validator_statuses: &mut ValidatorStatuses,
|
validator_statuses: &mut ValidatorStatuses,
|
||||||
winning_root_for_shards: &WinningRootHashSet,
|
winning_root_for_shards: &WinningRootHashSet,
|
||||||
@ -80,7 +80,7 @@ pub fn apply_rewards<T: BeaconStateTypes>(
|
|||||||
/// attestation in the previous epoch.
|
/// attestation in the previous epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn get_proposer_deltas<T: BeaconStateTypes>(
|
fn get_proposer_deltas<T: EthSpec>(
|
||||||
deltas: &mut Vec<Delta>,
|
deltas: &mut Vec<Delta>,
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
validator_statuses: &mut ValidatorStatuses,
|
validator_statuses: &mut ValidatorStatuses,
|
||||||
@ -121,7 +121,7 @@ fn get_proposer_deltas<T: BeaconStateTypes>(
|
|||||||
/// Apply rewards for participation in attestations during the previous epoch.
|
/// Apply rewards for participation in attestations during the previous epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn get_justification_and_finalization_deltas<T: BeaconStateTypes>(
|
fn get_justification_and_finalization_deltas<T: EthSpec>(
|
||||||
deltas: &mut Vec<Delta>,
|
deltas: &mut Vec<Delta>,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
validator_statuses: &ValidatorStatuses,
|
validator_statuses: &ValidatorStatuses,
|
||||||
@ -262,7 +262,7 @@ fn compute_inactivity_leak_delta(
|
|||||||
/// Calculate the deltas based upon the winning roots for attestations during the previous epoch.
|
/// Calculate the deltas based upon the winning roots for attestations during the previous epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn get_crosslink_deltas<T: BeaconStateTypes>(
|
fn get_crosslink_deltas<T: EthSpec>(
|
||||||
deltas: &mut Vec<Delta>,
|
deltas: &mut Vec<Delta>,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
validator_statuses: &ValidatorStatuses,
|
validator_statuses: &ValidatorStatuses,
|
||||||
@ -296,7 +296,7 @@ fn get_crosslink_deltas<T: BeaconStateTypes>(
|
|||||||
/// Returns the base reward for some validator.
|
/// Returns the base reward for some validator.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn get_base_reward<T: BeaconStateTypes>(
|
fn get_base_reward<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
index: usize,
|
index: usize,
|
||||||
previous_total_balance: u64,
|
previous_total_balance: u64,
|
||||||
@ -313,7 +313,7 @@ fn get_base_reward<T: BeaconStateTypes>(
|
|||||||
/// Returns the inactivity penalty for some validator.
|
/// Returns the inactivity penalty for some validator.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn get_inactivity_penalty<T: BeaconStateTypes>(
|
fn get_inactivity_penalty<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
index: usize,
|
index: usize,
|
||||||
epochs_since_finality: u64,
|
epochs_since_finality: u64,
|
||||||
@ -329,6 +329,6 @@ fn get_inactivity_penalty<T: BeaconStateTypes>(
|
|||||||
/// Returns the epochs since the last finalized epoch.
|
/// Returns the epochs since the last finalized epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn epochs_since_finality<T: BeaconStateTypes>(state: &BeaconState<T>, spec: &ChainSpec) -> Epoch {
|
fn epochs_since_finality<T: EthSpec>(state: &BeaconState<T>, spec: &ChainSpec) -> Epoch {
|
||||||
state.current_epoch(spec) + 1 - state.finalized_epoch
|
state.current_epoch(spec) + 1 - state.finalized_epoch
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use types::*;
|
|||||||
/// Returns validator indices which participated in the attestation.
|
/// Returns validator indices which participated in the attestation.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn get_attestation_participants<T: BeaconStateTypes>(
|
pub fn get_attestation_participants<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation_data: &AttestationData,
|
attestation_data: &AttestationData,
|
||||||
bitfield: &Bitfield,
|
bitfield: &Bitfield,
|
||||||
|
@ -6,7 +6,7 @@ use types::*;
|
|||||||
/// slot.
|
/// slot.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn inclusion_distance<T: BeaconStateTypes>(
|
pub fn inclusion_distance<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestations: &[&PendingAttestation],
|
attestations: &[&PendingAttestation],
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
@ -19,7 +19,7 @@ pub fn inclusion_distance<T: BeaconStateTypes>(
|
|||||||
/// Returns the slot of the earliest included attestation for some validator.
|
/// Returns the slot of the earliest included attestation for some validator.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn inclusion_slot<T: BeaconStateTypes>(
|
pub fn inclusion_slot<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestations: &[&PendingAttestation],
|
attestations: &[&PendingAttestation],
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
@ -32,7 +32,7 @@ pub fn inclusion_slot<T: BeaconStateTypes>(
|
|||||||
/// Finds the earliest included attestation for some validator.
|
/// Finds the earliest included attestation for some validator.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn earliest_included_attestation<T: BeaconStateTypes>(
|
fn earliest_included_attestation<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestations: &[&PendingAttestation],
|
attestations: &[&PendingAttestation],
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
|
@ -5,7 +5,7 @@ use types::{BeaconStateError as Error, *};
|
|||||||
/// ``EJECTION_BALANCE``.
|
/// ``EJECTION_BALANCE``.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_ejections<T: BeaconStateTypes>(
|
pub fn process_ejections<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -3,7 +3,7 @@ use types::*;
|
|||||||
/// Process the exit queue.
|
/// Process the exit queue.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_exit_queue<T: BeaconStateTypes>(state: &mut BeaconState<T>, spec: &ChainSpec) {
|
pub fn process_exit_queue<T: EthSpec>(state: &mut BeaconState<T>, spec: &ChainSpec) {
|
||||||
let current_epoch = state.current_epoch(spec);
|
let current_epoch = state.current_epoch(spec);
|
||||||
|
|
||||||
let eligible = |index: usize| {
|
let eligible = |index: usize| {
|
||||||
@ -32,7 +32,7 @@ pub fn process_exit_queue<T: BeaconStateTypes>(state: &mut BeaconState<T>, spec:
|
|||||||
/// Initiate an exit for the validator of the given `index`.
|
/// Initiate an exit for the validator of the given `index`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn prepare_validator_for_withdrawal<T: BeaconStateTypes>(
|
fn prepare_validator_for_withdrawal<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -3,7 +3,7 @@ use types::{BeaconStateError as Error, *};
|
|||||||
/// Process slashings.
|
/// Process slashings.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_slashings<T: BeaconStateTypes>(
|
pub fn process_slashings<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
current_total_balance: u64,
|
current_total_balance: u64,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
|
@ -8,9 +8,9 @@ use types::*;
|
|||||||
fn runs_without_error() {
|
fn runs_without_error() {
|
||||||
Builder::from_env(Env::default().default_filter_or("error")).init();
|
Builder::from_env(Env::default().default_filter_or("error")).init();
|
||||||
|
|
||||||
let spec = FewValidatorsStateTypes::spec();
|
let spec = FewValidatorsEthSpec::spec();
|
||||||
|
|
||||||
let mut builder: TestingBeaconStateBuilder<FewValidatorsStateTypes> =
|
let mut builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> =
|
||||||
TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec);
|
TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec);
|
||||||
|
|
||||||
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||||
|
@ -5,7 +5,7 @@ use types::*;
|
|||||||
/// Peforms a validator registry update, if required.
|
/// Peforms a validator registry update, if required.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn update_registry_and_shuffling_data<T: BeaconStateTypes>(
|
pub fn update_registry_and_shuffling_data<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
current_total_balance: u64,
|
current_total_balance: u64,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -50,7 +50,7 @@ pub fn update_registry_and_shuffling_data<T: BeaconStateTypes>(
|
|||||||
/// Returns `true` if the validator registry should be updated during an epoch processing.
|
/// Returns `true` if the validator registry should be updated during an epoch processing.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn should_update_validator_registry<T: BeaconStateTypes>(
|
pub fn should_update_validator_registry<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<bool, BeaconStateError> {
|
) -> Result<bool, BeaconStateError> {
|
||||||
@ -79,7 +79,7 @@ pub fn should_update_validator_registry<T: BeaconStateTypes>(
|
|||||||
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
|
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn update_validator_registry<T: BeaconStateTypes>(
|
pub fn update_validator_registry<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
current_total_balance: u64,
|
current_total_balance: u64,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -134,7 +134,7 @@ pub fn update_validator_registry<T: BeaconStateTypes>(
|
|||||||
/// Activate the validator of the given ``index``.
|
/// Activate the validator of the given ``index``.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn activate_validator<T: BeaconStateTypes>(
|
pub fn activate_validator<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
is_genesis: bool,
|
is_genesis: bool,
|
||||||
|
@ -161,7 +161,7 @@ impl ValidatorStatuses {
|
|||||||
/// - Total balances for the current and previous epochs.
|
/// - Total balances for the current and previous epochs.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn new<T: BeaconStateTypes>(
|
pub fn new<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<Self, BeaconStateError> {
|
) -> Result<Self, BeaconStateError> {
|
||||||
@ -199,7 +199,7 @@ impl ValidatorStatuses {
|
|||||||
/// `total_balances` fields.
|
/// `total_balances` fields.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_attestations<T: BeaconStateTypes>(
|
pub fn process_attestations<T: EthSpec>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -265,7 +265,7 @@ impl ValidatorStatuses {
|
|||||||
/// "winning" shard block root for the previous epoch.
|
/// "winning" shard block root for the previous epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn process_winning_roots<T: BeaconStateTypes>(
|
pub fn process_winning_roots<T: EthSpec>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
winning_roots: &WinningRootHashSet,
|
winning_roots: &WinningRootHashSet,
|
||||||
@ -316,7 +316,7 @@ fn is_from_epoch(a: &PendingAttestation, epoch: Epoch, spec: &ChainSpec) -> bool
|
|||||||
/// the first slot of the given epoch.
|
/// the first slot of the given epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn has_common_epoch_boundary_root<T: BeaconStateTypes>(
|
fn has_common_epoch_boundary_root<T: EthSpec>(
|
||||||
a: &PendingAttestation,
|
a: &PendingAttestation,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
@ -332,7 +332,7 @@ fn has_common_epoch_boundary_root<T: BeaconStateTypes>(
|
|||||||
/// the current slot of the `PendingAttestation`.
|
/// the current slot of the `PendingAttestation`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn has_common_beacon_block_root<T: BeaconStateTypes>(
|
fn has_common_beacon_block_root<T: EthSpec>(
|
||||||
a: &PendingAttestation,
|
a: &PendingAttestation,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
) -> Result<bool, BeaconStateError> {
|
) -> Result<bool, BeaconStateError> {
|
||||||
|
@ -35,7 +35,7 @@ impl WinningRoot {
|
|||||||
/// per-epoch processing.
|
/// per-epoch processing.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn winning_root<T: BeaconStateTypes>(
|
pub fn winning_root<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -90,7 +90,7 @@ pub fn winning_root<T: BeaconStateTypes>(
|
|||||||
/// Returns `true` if pending attestation `a` is eligible to become a winning root.
|
/// Returns `true` if pending attestation `a` is eligible to become a winning root.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn is_eligible_for_winning_root<T: BeaconStateTypes>(
|
fn is_eligible_for_winning_root<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
a: &PendingAttestation,
|
a: &PendingAttestation,
|
||||||
shard: Shard,
|
shard: Shard,
|
||||||
@ -105,7 +105,7 @@ fn is_eligible_for_winning_root<T: BeaconStateTypes>(
|
|||||||
/// Returns all indices which voted for a given crosslink. Does not contain duplicates.
|
/// Returns all indices which voted for a given crosslink. Does not contain duplicates.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
fn get_attesting_validator_indices<T: BeaconStateTypes>(
|
fn get_attesting_validator_indices<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
crosslink_data_root: &Hash256,
|
crosslink_data_root: &Hash256,
|
||||||
|
@ -11,7 +11,7 @@ pub enum Error {
|
|||||||
/// Advances a state forward by one slot, performing per-epoch processing if required.
|
/// Advances a state forward by one slot, performing per-epoch processing if required.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
pub fn per_slot_processing<T: BeaconStateTypes>(
|
pub fn per_slot_processing<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -26,10 +26,7 @@ pub fn per_slot_processing<T: BeaconStateTypes>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cache_state<T: BeaconStateTypes>(
|
fn cache_state<T: EthSpec>(state: &mut BeaconState<T>, spec: &ChainSpec) -> Result<(), Error> {
|
||||||
state: &mut BeaconState<T>,
|
|
||||||
spec: &ChainSpec,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let previous_slot_state_root = state.update_tree_hash_cache()?;
|
let previous_slot_state_root = state.update_tree_hash_cache()?;
|
||||||
|
|
||||||
// Note: increment the state slot here to allow use of our `state_root` and `block_root`
|
// Note: increment the state slot here to allow use of our `state_root` and `block_root`
|
||||||
|
@ -67,7 +67,7 @@ pub enum Error {
|
|||||||
)]
|
)]
|
||||||
pub struct BeaconState<T>
|
pub struct BeaconState<T>
|
||||||
where
|
where
|
||||||
T: BeaconStateTypes,
|
T: EthSpec,
|
||||||
{
|
{
|
||||||
// Misc
|
// Misc
|
||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
@ -140,7 +140,7 @@ where
|
|||||||
pub tree_hash_cache: TreeHashCache,
|
pub tree_hash_cache: TreeHashCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: BeaconStateTypes> BeaconState<T> {
|
impl<T: EthSpec> BeaconState<T> {
|
||||||
/// Produce the first state of the Beacon Chain.
|
/// Produce the first state of the Beacon Chain.
|
||||||
///
|
///
|
||||||
/// This does not fully build a genesis beacon state, it omits processing of initial validator
|
/// This does not fully build a genesis beacon state, it omits processing of initial validator
|
||||||
|
@ -3,7 +3,7 @@ use fixed_len_vec::typenum::{Unsigned, U1024, U8, U8192};
|
|||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
pub trait BeaconStateTypes:
|
pub trait EthSpec:
|
||||||
'static + Default + Sync + Send + Clone + Debug + PartialEq + serde::de::DeserializeOwned
|
'static + Default + Sync + Send + Clone + Debug + PartialEq + serde::de::DeserializeOwned
|
||||||
{
|
{
|
||||||
type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||||
@ -54,9 +54,9 @@ pub trait BeaconStateTypes:
|
|||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct FoundationStateTypes;
|
pub struct FoundationEthSpec;
|
||||||
|
|
||||||
impl BeaconStateTypes for FoundationStateTypes {
|
impl EthSpec for FoundationEthSpec {
|
||||||
type ShardCount = U1024;
|
type ShardCount = U1024;
|
||||||
type SlotsPerHistoricalRoot = U8192;
|
type SlotsPerHistoricalRoot = U8192;
|
||||||
type LatestRandaoMixesLength = U8192;
|
type LatestRandaoMixesLength = U8192;
|
||||||
@ -68,15 +68,15 @@ impl BeaconStateTypes for FoundationStateTypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FoundationBeaconState = BeaconState<FoundationStateTypes>;
|
pub type FoundationBeaconState = BeaconState<FoundationEthSpec>;
|
||||||
|
|
||||||
/// Ethereum Foundation specifications, modified to be suitable for < 1000 validators.
|
/// Ethereum Foundation specifications, modified to be suitable for < 1000 validators.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct FewValidatorsStateTypes;
|
pub struct FewValidatorsEthSpec;
|
||||||
|
|
||||||
impl BeaconStateTypes for FewValidatorsStateTypes {
|
impl EthSpec for FewValidatorsEthSpec {
|
||||||
type ShardCount = U8;
|
type ShardCount = U8;
|
||||||
type SlotsPerHistoricalRoot = U8192;
|
type SlotsPerHistoricalRoot = U8192;
|
||||||
type LatestRandaoMixesLength = U8192;
|
type LatestRandaoMixesLength = U8192;
|
||||||
@ -88,15 +88,15 @@ impl BeaconStateTypes for FewValidatorsStateTypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsStateTypes>;
|
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsEthSpec>;
|
||||||
|
|
||||||
/// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet.
|
/// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.5.1
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct LighthouseTestnetStateTypes;
|
pub struct LighthouseTestnetEthSpec;
|
||||||
|
|
||||||
impl BeaconStateTypes for LighthouseTestnetStateTypes {
|
impl EthSpec for LighthouseTestnetEthSpec {
|
||||||
type ShardCount = U8;
|
type ShardCount = U8;
|
||||||
type SlotsPerHistoricalRoot = U8192;
|
type SlotsPerHistoricalRoot = U8192;
|
||||||
type LatestRandaoMixesLength = U8192;
|
type LatestRandaoMixesLength = U8192;
|
||||||
@ -108,4 +108,4 @@ impl BeaconStateTypes for LighthouseTestnetStateTypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type LighthouseTestnetBeaconState = BeaconState<LighthouseTestnetStateTypes>;
|
pub type LighthouseTestnetBeaconState = BeaconState<LighthouseTestnetEthSpec>;
|
||||||
|
@ -28,7 +28,7 @@ pub struct EpochCache {
|
|||||||
|
|
||||||
impl EpochCache {
|
impl EpochCache {
|
||||||
/// Return a new, fully initialized cache.
|
/// Return a new, fully initialized cache.
|
||||||
pub fn initialized<T: BeaconStateTypes>(
|
pub fn initialized<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
relative_epoch: RelativeEpoch,
|
relative_epoch: RelativeEpoch,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -200,7 +200,7 @@ pub struct EpochCrosslinkCommitteesBuilder {
|
|||||||
|
|
||||||
impl EpochCrosslinkCommitteesBuilder {
|
impl EpochCrosslinkCommitteesBuilder {
|
||||||
/// Instantiates a builder that will build for the `state`'s previous epoch.
|
/// Instantiates a builder that will build for the `state`'s previous epoch.
|
||||||
pub fn for_previous_epoch<T: BeaconStateTypes>(
|
pub fn for_previous_epoch<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
active_validator_indices: Vec<usize>,
|
active_validator_indices: Vec<usize>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -215,7 +215,7 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a builder that will build for the `state`'s next epoch.
|
/// Instantiates a builder that will build for the `state`'s next epoch.
|
||||||
pub fn for_current_epoch<T: BeaconStateTypes>(
|
pub fn for_current_epoch<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
active_validator_indices: Vec<usize>,
|
active_validator_indices: Vec<usize>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -233,7 +233,7 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
///
|
///
|
||||||
/// Note: there are two possible epoch builds for the next epoch, one where there is a registry
|
/// Note: there are two possible epoch builds for the next epoch, one where there is a registry
|
||||||
/// change and one where there is not.
|
/// change and one where there is not.
|
||||||
pub fn for_next_epoch<T: BeaconStateTypes>(
|
pub fn for_next_epoch<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
active_validator_indices: Vec<usize>,
|
active_validator_indices: Vec<usize>,
|
||||||
registry_change: bool,
|
registry_change: bool,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::beacon_state::FewValidatorsStateTypes;
|
use crate::beacon_state::FewValidatorsEthSpec;
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
use swap_or_not_shuffle::shuffle_list;
|
use swap_or_not_shuffle::shuffle_list;
|
||||||
|
|
||||||
fn do_sane_cache_test<T: BeaconStateTypes>(
|
fn do_sane_cache_test<T: EthSpec>(
|
||||||
state: BeaconState<T>,
|
state: BeaconState<T>,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
relative_epoch: RelativeEpoch,
|
relative_epoch: RelativeEpoch,
|
||||||
@ -65,10 +65,7 @@ fn do_sane_cache_test<T: BeaconStateTypes>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_sane_cache_test<T: BeaconStateTypes>(
|
fn setup_sane_cache_test<T: EthSpec>(validator_count: usize, spec: &ChainSpec) -> BeaconState<T> {
|
||||||
validator_count: usize,
|
|
||||||
spec: &ChainSpec,
|
|
||||||
) -> BeaconState<T> {
|
|
||||||
let mut builder =
|
let mut builder =
|
||||||
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, spec);
|
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, spec);
|
||||||
|
|
||||||
@ -102,11 +99,11 @@ fn setup_sane_cache_test<T: BeaconStateTypes>(
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builds_sane_current_epoch_cache() {
|
fn builds_sane_current_epoch_cache() {
|
||||||
let mut spec = FewValidatorsStateTypes::spec();
|
let mut spec = FewValidatorsEthSpec::spec();
|
||||||
spec.shard_count = 4;
|
spec.shard_count = 4;
|
||||||
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
||||||
|
|
||||||
let state: BeaconState<FewValidatorsStateTypes> =
|
let state: BeaconState<FewValidatorsEthSpec> =
|
||||||
setup_sane_cache_test(validator_count as usize, &spec);
|
setup_sane_cache_test(validator_count as usize, &spec);
|
||||||
|
|
||||||
do_sane_cache_test(
|
do_sane_cache_test(
|
||||||
@ -122,11 +119,11 @@ fn builds_sane_current_epoch_cache() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builds_sane_previous_epoch_cache() {
|
fn builds_sane_previous_epoch_cache() {
|
||||||
let mut spec = FewValidatorsStateTypes::spec();
|
let mut spec = FewValidatorsEthSpec::spec();
|
||||||
spec.shard_count = 2;
|
spec.shard_count = 2;
|
||||||
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
||||||
|
|
||||||
let state: BeaconState<FewValidatorsStateTypes> =
|
let state: BeaconState<FewValidatorsEthSpec> =
|
||||||
setup_sane_cache_test(validator_count as usize, &spec);
|
setup_sane_cache_test(validator_count as usize, &spec);
|
||||||
|
|
||||||
do_sane_cache_test(
|
do_sane_cache_test(
|
||||||
@ -142,11 +139,11 @@ fn builds_sane_previous_epoch_cache() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builds_sane_next_without_update_epoch_cache() {
|
fn builds_sane_next_without_update_epoch_cache() {
|
||||||
let mut spec = FewValidatorsStateTypes::spec();
|
let mut spec = FewValidatorsEthSpec::spec();
|
||||||
spec.shard_count = 2;
|
spec.shard_count = 2;
|
||||||
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
||||||
|
|
||||||
let mut state: BeaconState<FewValidatorsStateTypes> =
|
let mut state: BeaconState<FewValidatorsEthSpec> =
|
||||||
setup_sane_cache_test(validator_count as usize, &spec);
|
setup_sane_cache_test(validator_count as usize, &spec);
|
||||||
|
|
||||||
state.validator_registry_update_epoch = state.slot.epoch(spec.slots_per_epoch);
|
state.validator_registry_update_epoch = state.slot.epoch(spec.slots_per_epoch);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::beacon_state::FewValidatorsStateTypes;
|
use crate::beacon_state::FewValidatorsEthSpec;
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
|
|
||||||
ssz_tests!(FoundationBeaconState);
|
ssz_tests!(FoundationBeaconState);
|
||||||
@ -11,7 +11,7 @@ cached_tree_hash_tests!(FoundationBeaconState);
|
|||||||
/// 1. Using the cache before it's built fails.
|
/// 1. Using the cache before it's built fails.
|
||||||
/// 2. Using the cache after it's build passes.
|
/// 2. Using the cache after it's build passes.
|
||||||
/// 3. Using the cache after it's dropped fails.
|
/// 3. Using the cache after it's dropped fails.
|
||||||
fn test_cache_initialization<'a, T: BeaconStateTypes>(
|
fn test_cache_initialization<'a, T: EthSpec>(
|
||||||
state: &'a mut BeaconState<T>,
|
state: &'a mut BeaconState<T>,
|
||||||
relative_epoch: RelativeEpoch,
|
relative_epoch: RelativeEpoch,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
@ -46,9 +46,9 @@ fn test_cache_initialization<'a, T: BeaconStateTypes>(
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cache_initialization() {
|
fn cache_initialization() {
|
||||||
let spec = FewValidatorsStateTypes::spec();
|
let spec = FewValidatorsEthSpec::spec();
|
||||||
|
|
||||||
let builder: TestingBeaconStateBuilder<FewValidatorsStateTypes> =
|
let builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> =
|
||||||
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec);
|
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec);
|
||||||
let (mut state, _keypairs) = builder.build();
|
let (mut state, _keypairs) = builder.build();
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
CachedTreeHash,
|
CachedTreeHash,
|
||||||
TestRandom,
|
TestRandom,
|
||||||
)]
|
)]
|
||||||
pub struct HistoricalBatch<T: BeaconStateTypes> {
|
pub struct HistoricalBatch<T: EthSpec> {
|
||||||
pub block_roots: FixedLenVec<Hash256, T::SlotsPerHistoricalRoot>,
|
pub block_roots: FixedLenVec<Hash256, T::SlotsPerHistoricalRoot>,
|
||||||
pub state_roots: FixedLenVec<Hash256, T::SlotsPerHistoricalRoot>,
|
pub state_roots: FixedLenVec<Hash256, T::SlotsPerHistoricalRoot>,
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ pub struct HistoricalBatch<T: BeaconStateTypes> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub type FoundationHistoricalBatch = HistoricalBatch<FoundationStateTypes>;
|
pub type FoundationHistoricalBatch = HistoricalBatch<FoundationEthSpec>;
|
||||||
|
|
||||||
ssz_tests!(FoundationHistoricalBatch);
|
ssz_tests!(FoundationHistoricalBatch);
|
||||||
cached_tree_hash_tests!(FoundationHistoricalBatch);
|
cached_tree_hash_tests!(FoundationHistoricalBatch);
|
||||||
|
@ -12,7 +12,7 @@ pub struct TestingAttestationBuilder {
|
|||||||
|
|
||||||
impl TestingAttestationBuilder {
|
impl TestingAttestationBuilder {
|
||||||
/// Create a new attestation builder.
|
/// Create a new attestation builder.
|
||||||
pub fn new<T: BeaconStateTypes>(
|
pub fn new<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
committee: &[usize],
|
committee: &[usize],
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
|
@ -10,7 +10,7 @@ pub struct TestingAttestationDataBuilder {
|
|||||||
impl TestingAttestationDataBuilder {
|
impl TestingAttestationDataBuilder {
|
||||||
/// Configures a new `AttestationData` which attests to all of the same parameters as the
|
/// Configures a new `AttestationData` which attests to all of the same parameters as the
|
||||||
/// state.
|
/// state.
|
||||||
pub fn new<T: BeaconStateTypes>(
|
pub fn new<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
|
@ -82,7 +82,7 @@ impl TestingBeaconBlockBuilder {
|
|||||||
///
|
///
|
||||||
/// Note: the signed messages of the split committees will be identical -- it would be possible
|
/// Note: the signed messages of the split committees will be identical -- it would be possible
|
||||||
/// to aggregate these split attestations.
|
/// to aggregate these split attestations.
|
||||||
pub fn insert_attestations<T: BeaconStateTypes>(
|
pub fn insert_attestations<T: EthSpec>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
secret_keys: &[&SecretKey],
|
secret_keys: &[&SecretKey],
|
||||||
@ -171,7 +171,7 @@ impl TestingBeaconBlockBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a `Valid` deposit into the state.
|
/// Insert a `Valid` deposit into the state.
|
||||||
pub fn insert_deposit<T: BeaconStateTypes>(
|
pub fn insert_deposit<T: EthSpec>(
|
||||||
&mut self,
|
&mut self,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
index: u64,
|
index: u64,
|
||||||
@ -193,7 +193,7 @@ impl TestingBeaconBlockBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a `Valid` exit into the state.
|
/// Insert a `Valid` exit into the state.
|
||||||
pub fn insert_exit<T: BeaconStateTypes>(
|
pub fn insert_exit<T: EthSpec>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
validator_index: u64,
|
validator_index: u64,
|
||||||
@ -214,7 +214,7 @@ impl TestingBeaconBlockBuilder {
|
|||||||
///
|
///
|
||||||
/// Note: this will set the validator to be withdrawable by directly modifying the state
|
/// Note: this will set the validator to be withdrawable by directly modifying the state
|
||||||
/// validator registry. This _may_ cause problems historic hashes, etc.
|
/// validator registry. This _may_ cause problems historic hashes, etc.
|
||||||
pub fn insert_transfer<T: BeaconStateTypes>(
|
pub fn insert_transfer<T: EthSpec>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
from: u64,
|
from: u64,
|
||||||
|
@ -25,12 +25,12 @@ pub fn keypairs_path() -> PathBuf {
|
|||||||
///
|
///
|
||||||
/// This struct should **never be used for production purposes.**
|
/// This struct should **never be used for production purposes.**
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TestingBeaconStateBuilder<T: BeaconStateTypes> {
|
pub struct TestingBeaconStateBuilder<T: EthSpec> {
|
||||||
state: BeaconState<T>,
|
state: BeaconState<T>,
|
||||||
keypairs: Vec<Keypair>,
|
keypairs: Vec<Keypair>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: BeaconStateTypes> TestingBeaconStateBuilder<T> {
|
impl<T: EthSpec> TestingBeaconStateBuilder<T> {
|
||||||
/// Attempts to load validators from a file in `$HOME/.lighthouse/keypairs.raw_keypairs`. If
|
/// Attempts to load validators from a file in `$HOME/.lighthouse/keypairs.raw_keypairs`. If
|
||||||
/// the file is unavailable, it generates the keys at runtime.
|
/// the file is unavailable, it generates the keys at runtime.
|
||||||
///
|
///
|
||||||
|
@ -16,7 +16,7 @@ impl TestingPendingAttestationBuilder {
|
|||||||
///
|
///
|
||||||
/// * The aggregation and custody bitfields will all be empty, they need to be set with
|
/// * The aggregation and custody bitfields will all be empty, they need to be set with
|
||||||
/// `Self::add_committee_participation`.
|
/// `Self::add_committee_participation`.
|
||||||
pub fn new<T: BeaconStateTypes>(
|
pub fn new<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
|
@ -7,8 +7,7 @@ use std::fs::File;
|
|||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use types::{
|
use types::{
|
||||||
BeaconStateTypes, ChainSpec, FewValidatorsStateTypes, FoundationStateTypes,
|
ChainSpec, EthSpec, FewValidatorsEthSpec, FoundationEthSpec, LighthouseTestnetEthSpec,
|
||||||
LighthouseTestnetStateTypes,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Stores the core configuration for this validator instance.
|
/// Stores the core configuration for this validator instance.
|
||||||
@ -34,7 +33,7 @@ impl Default for Config {
|
|||||||
|
|
||||||
let server = "localhost:5051".to_string();
|
let server = "localhost:5051".to_string();
|
||||||
|
|
||||||
let spec = FoundationStateTypes::spec();
|
let spec = FoundationEthSpec::spec();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
data_dir,
|
data_dir,
|
||||||
@ -68,9 +67,9 @@ impl Config {
|
|||||||
if let Some(spec_str) = args.value_of("spec") {
|
if let Some(spec_str) = args.value_of("spec") {
|
||||||
info!(log, "Using custom spec: {:?}", spec_str);
|
info!(log, "Using custom spec: {:?}", spec_str);
|
||||||
config.spec = match spec_str {
|
config.spec = match spec_str {
|
||||||
"foundation" => FoundationStateTypes::spec(),
|
"foundation" => FoundationEthSpec::spec(),
|
||||||
"few_validators" => FewValidatorsStateTypes::spec(),
|
"few_validators" => FewValidatorsEthSpec::spec(),
|
||||||
"lighthouse_testnet" => LighthouseTestnetStateTypes::spec(),
|
"lighthouse_testnet" => LighthouseTestnetEthSpec::spec(),
|
||||||
// Should be impossible due to clap's `possible_values(..)` function.
|
// Should be impossible due to clap's `possible_values(..)` function.
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user