From ce8ebeccbc2091536725030fdd4dbafc576004c9 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 10 May 2019 14:47:09 +1000 Subject: [PATCH] Rename `BeaconStateTypes` to `EthSpec` --- beacon_node/beacon_chain/src/beacon_chain.rs | 4 +- beacon_node/beacon_chain/src/checkpoint.rs | 6 +-- beacon_node/beacon_chain/src/initialise.rs | 10 ++-- .../testing_beacon_chain_builder.rs | 10 ++-- beacon_node/client/src/client_config.rs | 4 +- beacon_node/client/src/client_types.rs | 18 +++---- beacon_node/client/src/lib.rs | 8 ++-- .../db/src/stores/beacon_state_store.rs | 4 +- beacon_node/eth2-libp2p/src/behaviour.rs | 2 +- beacon_node/network/src/beacon_chain.rs | 7 ++- beacon_node/network/src/message_handler.rs | 6 +-- beacon_node/network/src/service.rs | 6 +-- beacon_node/network/src/sync/import_queue.rs | 6 +-- beacon_node/network/src/sync/simple_sync.rs | 8 ++-- beacon_node/rpc/src/attestation.rs | 6 +-- beacon_node/rpc/src/beacon_block.rs | 6 +-- beacon_node/rpc/src/beacon_chain.rs | 6 +-- beacon_node/rpc/src/beacon_node.rs | 6 +-- beacon_node/rpc/src/lib.rs | 4 +- beacon_node/rpc/src/validator.rs | 6 +-- eth2/fork_choice/src/bitwise_lmd_ghost.rs | 6 +-- eth2/fork_choice/src/optimized_lmd_ghost.rs | 6 +-- eth2/fork_choice/src/slow_lmd_ghost.rs | 6 +-- eth2/fork_choice/tests/tests.rs | 15 +++--- eth2/operation_pool/src/lib.rs | 47 +++++++++---------- .../src/common/exit_validator.rs | 2 +- .../src/common/slash_validator.rs | 2 +- .../state_processing/src/get_genesis_state.rs | 2 +- .../src/per_block_processing.rs | 26 +++++----- .../validate_attestation.rs | 12 ++--- .../verify_attester_slashing.rs | 6 +-- .../per_block_processing/verify_deposit.rs | 8 ++-- .../src/per_block_processing/verify_exit.rs | 6 +-- .../verify_proposer_slashing.rs | 2 +- .../verify_slashable_attestation.rs | 2 +- .../per_block_processing/verify_transfer.rs | 8 ++-- .../src/per_epoch_processing.rs | 10 ++-- .../src/per_epoch_processing/apply_rewards.rs | 14 +++--- .../get_attestation_participants.rs | 2 +- .../inclusion_distance.rs | 6 +-- .../per_epoch_processing/process_ejections.rs | 2 +- .../process_exit_queue.rs | 4 +- .../per_epoch_processing/process_slashings.rs | 2 +- .../src/per_epoch_processing/tests.rs | 4 +- .../update_registry_and_shuffling_data.rs | 8 ++-- .../validator_statuses.rs | 10 ++-- .../src/per_epoch_processing/winning_root.rs | 6 +-- .../src/per_slot_processing.rs | 7 +-- eth2/types/src/beacon_state.rs | 4 +- .../src/beacon_state/beacon_state_types.rs | 20 ++++---- eth2/types/src/beacon_state/epoch_cache.rs | 8 ++-- .../src/beacon_state/epoch_cache/tests.rs | 21 ++++----- eth2/types/src/beacon_state/tests.rs | 8 ++-- eth2/types/src/historical_batch.rs | 4 +- .../test_utils/testing_attestation_builder.rs | 2 +- .../testing_attestation_data_builder.rs | 2 +- .../testing_beacon_block_builder.rs | 8 ++-- .../testing_beacon_state_builder.rs | 4 +- .../testing_pending_attestation_builder.rs | 2 +- validator_client/src/config.rs | 11 ++--- 60 files changed, 223 insertions(+), 235 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2b2d5f015..b6eb1d2f7 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -83,7 +83,7 @@ impl BlockProcessingOutcome { } } -pub struct BeaconChain { +pub struct BeaconChain { pub block_store: Arc>, pub state_store: Arc>, pub slot_clock: U, @@ -100,7 +100,7 @@ where T: ClientDB, U: SlotClock, F: ForkChoice, - B: BeaconStateTypes, + B: EthSpec, { /// Instantiate a new Beacon Chain, from genesis. pub fn from_genesis( diff --git a/beacon_node/beacon_chain/src/checkpoint.rs b/beacon_node/beacon_chain/src/checkpoint.rs index c3757949f..7bed5b5ce 100644 --- a/beacon_node/beacon_chain/src/checkpoint.rs +++ b/beacon_node/beacon_chain/src/checkpoint.rs @@ -1,17 +1,17 @@ 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 /// head, justified head and finalized head. #[derive(Clone, Serialize, PartialEq, Debug)] -pub struct CheckPoint { +pub struct CheckPoint { pub beacon_block: BeaconBlock, pub beacon_block_root: Hash256, pub beacon_state: BeaconState, pub beacon_state_root: Hash256, } -impl CheckPoint { +impl CheckPoint { /// Create a new checkpoint. pub fn new( beacon_block: BeaconBlock, diff --git a/beacon_node/beacon_chain/src/initialise.rs b/beacon_node/beacon_chain/src/initialise.rs index 284393c02..83b60a4f7 100644 --- a/beacon_node/beacon_chain/src/initialise.rs +++ b/beacon_node/beacon_chain/src/initialise.rs @@ -11,7 +11,7 @@ use std::path::PathBuf; use std::sync::Arc; use tree_hash::TreeHash; 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: Account for historical db @@ -22,8 +22,8 @@ pub fn initialise_beacon_chain( BeaconChain< DiskDB, SystemTimeSlotClock, - BitwiseLMDGhost, - FoundationStateTypes, + BitwiseLMDGhost, + FoundationEthSpec, >, > { // set up the db @@ -75,8 +75,8 @@ pub fn initialise_test_beacon_chain( BeaconChain< MemoryDB, SystemTimeSlotClock, - BitwiseLMDGhost, - FewValidatorsStateTypes, + BitwiseLMDGhost, + FewValidatorsEthSpec, >, > { let db = Arc::new(MemoryDB::open()); diff --git a/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs b/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs index 9f9838ae7..b617ed0d7 100644 --- a/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs +++ b/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs @@ -8,16 +8,16 @@ use slot_clock::TestingSlotClock; use std::sync::Arc; use tree_hash::TreeHash; use types::*; -use types::{test_utils::TestingBeaconStateBuilder, BeaconStateTypes, FewValidatorsStateTypes}; +use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec}; type TestingBeaconChain = - BeaconChain, B>; + BeaconChain, B>; -pub struct TestingBeaconChainBuilder { +pub struct TestingBeaconChainBuilder { state_builder: TestingBeaconStateBuilder, } -impl TestingBeaconChainBuilder { +impl TestingBeaconChainBuilder { pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain { let db = Arc::new(MemoryDB::open()); let block_store = Arc::new(BeaconBlockStore::new(db.clone())); @@ -44,7 +44,7 @@ impl TestingBeaconChainBuilder { } } -impl From> for TestingBeaconChainBuilder { +impl From> for TestingBeaconChainBuilder { fn from(state_builder: TestingBeaconStateBuilder) -> TestingBeaconChainBuilder { TestingBeaconChainBuilder { state_builder } } diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index 74ef5f2e5..d84b63f4f 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -10,7 +10,7 @@ use std::path::PathBuf; use types::multiaddr::Protocol; use types::multiaddr::ToMultiaddr; use types::Multiaddr; -use types::{BeaconStateTypes, ChainSpec, LighthouseTestnetStateTypes}; +use types::{ChainSpec, EthSpec, LighthouseTestnetEthSpec}; /// Stores the client configuration for this Lighthouse instance. #[derive(Debug, Clone)] @@ -35,7 +35,7 @@ impl Default for ClientConfig { fs::create_dir_all(&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()); Self { diff --git a/beacon_node/client/src/client_types.rs b/beacon_node/client/src/client_types.rs index ba8fc47de..8c9352d7c 100644 --- a/beacon_node/client/src/client_types.rs +++ b/beacon_node/client/src/client_types.rs @@ -6,17 +6,17 @@ use beacon_chain::{ slot_clock::{SlotClock, SystemTimeSlotClock}, }; use fork_choice::ForkChoice; -use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes}; +use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec}; pub trait ClientTypes { type DB: ClientDB + 'static; type SlotClock: SlotClock + 'static; type ForkChoice: ForkChoice + 'static; - type BeaconStateTypes: BeaconStateTypes + 'static; + type EthSpec: EthSpec + 'static; fn initialise_beacon_chain( config: &ClientConfig, - ) -> ArcBeaconChain; + ) -> ArcBeaconChain; } pub struct StandardClientType; @@ -24,12 +24,12 @@ pub struct StandardClientType; impl ClientTypes for StandardClientType { type DB = DiskDB; type SlotClock = SystemTimeSlotClock; - type ForkChoice = BitwiseLMDGhost; - type BeaconStateTypes = FoundationStateTypes; + type ForkChoice = BitwiseLMDGhost; + type EthSpec = FoundationEthSpec; fn initialise_beacon_chain( config: &ClientConfig, - ) -> ArcBeaconChain { + ) -> ArcBeaconChain { initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name)) } } @@ -39,12 +39,12 @@ pub struct TestingClientType; impl ClientTypes for TestingClientType { type DB = MemoryDB; type SlotClock = SystemTimeSlotClock; - type ForkChoice = BitwiseLMDGhost; - type BeaconStateTypes = FewValidatorsStateTypes; + type ForkChoice = BitwiseLMDGhost; + type EthSpec = FewValidatorsEthSpec; fn initialise_beacon_chain( config: &ClientConfig, - ) -> ArcBeaconChain { + ) -> ArcBeaconChain { initialise::initialise_test_beacon_chain(&config.spec, None) } } diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index c3dd5cbd8..166f1a948 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use tokio::runtime::TaskExecutor; use tokio::timer::Interval; -use types::BeaconStateTypes; +use types::EthSpec; type ArcBeaconChain = Arc>; @@ -30,9 +30,9 @@ pub struct Client { /// Configuration for the lighthouse client. _config: ClientConfig, /// The beacon chain for the running client. - _beacon_chain: ArcBeaconChain, + _beacon_chain: ArcBeaconChain, /// Reference to the network service. - pub network: Arc>, + pub network: Arc>, /// Signal to terminate the RPC server. pub rpc_exit_signal: Option, /// Signal to terminate the slot timer. @@ -149,7 +149,7 @@ where T: ClientDB, U: SlotClock, F: ForkChoice, - B: BeaconStateTypes, + B: EthSpec, { if let Some(genesis_height) = chain.slots_since_genesis() { let result = chain.catchup_state(); diff --git a/beacon_node/db/src/stores/beacon_state_store.rs b/beacon_node/db/src/stores/beacon_state_store.rs index 4c40d2287..c0d37edd9 100644 --- a/beacon_node/db/src/stores/beacon_state_store.rs +++ b/beacon_node/db/src/stores/beacon_state_store.rs @@ -2,7 +2,7 @@ use super::STATES_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; use ssz::decode; use std::sync::Arc; -use types::{BeaconState, BeaconStateTypes, Hash256}; +use types::{BeaconState, EthSpec, Hash256}; pub struct BeaconStateStore where @@ -19,7 +19,7 @@ impl BeaconStateStore { Self { db } } - pub fn get_deserialized( + pub fn get_deserialized( &self, hash: &Hash256, ) -> Result>, DBError> { diff --git a/beacon_node/eth2-libp2p/src/behaviour.rs b/beacon_node/eth2-libp2p/src/behaviour.rs index f8a0a7249..00e6fc533 100644 --- a/beacon_node/eth2-libp2p/src/behaviour.rs +++ b/beacon_node/eth2-libp2p/src/behaviour.rs @@ -236,7 +236,7 @@ mod test { #[test] fn ssz_encoding() { - let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationStateTypes::spec())); + let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationEthSpec::spec())); let encoded = ssz_encode(&original); diff --git a/beacon_node/network/src/beacon_chain.rs b/beacon_node/network/src/beacon_chain.rs index 2ab446c52..db809086a 100644 --- a/beacon_node/network/src/beacon_chain.rs +++ b/beacon_node/network/src/beacon_chain.rs @@ -9,14 +9,13 @@ use beacon_chain::{ }; use eth2_libp2p::rpc::HelloMessage; use types::{ - Attestation, BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, Epoch, Hash256, - Slot, + Attestation, BeaconBlock, BeaconBlockBody, BeaconBlockHeader, Epoch, EthSpec, Hash256, Slot, }; pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome, InvalidBlock}; /// The network's API to the beacon chain. -pub trait BeaconChain: Send + Sync { +pub trait BeaconChain: Send + Sync { fn get_spec(&self) -> &ChainSpec; fn get_state(&self) -> RwLockReadGuard>; @@ -70,7 +69,7 @@ where T: ClientDB + Sized, U: SlotClock, F: ForkChoice, - B: BeaconStateTypes, + B: EthSpec, { fn get_spec(&self) -> &ChainSpec { &self.spec diff --git a/beacon_node/network/src/message_handler.rs b/beacon_node/network/src/message_handler.rs index 6d3348910..35743fe15 100644 --- a/beacon_node/network/src/message_handler.rs +++ b/beacon_node/network/src/message_handler.rs @@ -13,7 +13,7 @@ use slog::{debug, warn}; use std::collections::HashMap; use std::sync::Arc; use std::time::Instant; -use types::BeaconStateTypes; +use types::EthSpec; /// Timeout for RPC requests. // const REQUEST_TIMEOUT: Duration = Duration::from_secs(30); @@ -21,7 +21,7 @@ use types::BeaconStateTypes; // const HELLO_TIMEOUT: Duration = Duration::from_secs(30); /// Handles messages received from the network and client and organises syncing. -pub struct MessageHandler { +pub struct MessageHandler { /// Currently loaded and initialised beacon chain. _chain: Arc>, /// The syncing framework. @@ -45,7 +45,7 @@ pub enum HandlerMessage { PubsubMessage(PeerId, Box), } -impl MessageHandler { +impl MessageHandler { /// Initializes and runs the MessageHandler. pub fn spawn( beacon_chain: Arc>, diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index b7c6e58ec..89d1e1526 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -13,10 +13,10 @@ use slog::{debug, info, o, trace}; use std::marker::PhantomData; use std::sync::Arc; 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. -pub struct Service { +pub struct Service { //libp2p_service: Arc>, _libp2p_exit: oneshot::Sender<()>, network_send: crossbeam_channel::Sender, @@ -24,7 +24,7 @@ pub struct Service { //message_handler_send: Sender } -impl Service { +impl Service { pub fn new( beacon_chain: Arc>, config: &NetworkConfig, diff --git a/beacon_node/network/src/sync/import_queue.rs b/beacon_node/network/src/sync/import_queue.rs index 418b5c1b0..1fffd8763 100644 --- a/beacon_node/network/src/sync/import_queue.rs +++ b/beacon_node/network/src/sync/import_queue.rs @@ -5,7 +5,7 @@ use slog::{debug, error}; use std::sync::Arc; use std::time::{Duration, Instant}; 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. /// @@ -19,7 +19,7 @@ use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, H /// `BeaconBlockBody` as the key. /// - It is possible for multiple distinct blocks to have identical `BeaconBlockBodies`. Therefore /// we cannot use a `HashMap` keyed by the root of `BeaconBlockBody`. -pub struct ImportQueue { +pub struct ImportQueue { pub chain: Arc>, /// Partially imported blocks, keyed by the root of `BeaconBlockBody`. pub partials: Vec, @@ -29,7 +29,7 @@ pub struct ImportQueue { log: slog::Logger, } -impl ImportQueue { +impl ImportQueue { /// Return a new, empty queue. pub fn new(chain: Arc>, stale_time: Duration, log: slog::Logger) -> Self { Self { diff --git a/beacon_node/network/src/sync/simple_sync.rs b/beacon_node/network/src/sync/simple_sync.rs index c54a24678..3f4fb7aae 100644 --- a/beacon_node/network/src/sync/simple_sync.rs +++ b/beacon_node/network/src/sync/simple_sync.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; 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. const SLOT_IMPORT_TOLERANCE: u64 = 100; @@ -88,7 +88,7 @@ impl From for PeerSyncInfo { } } -impl From<&Arc>> for PeerSyncInfo { +impl From<&Arc>> for PeerSyncInfo { fn from(chain: &Arc>) -> PeerSyncInfo { Self::from(chain.hello_message()) } @@ -103,7 +103,7 @@ pub enum SyncState { } /// Simple Syncing protocol. -pub struct SimpleSync { +pub struct SimpleSync { /// A reference to the underlying beacon chain. chain: Arc>, /// A mapping of Peers to their respective PeerSyncInfo. @@ -116,7 +116,7 @@ pub struct SimpleSync { log: slog::Logger, } -impl SimpleSync { +impl SimpleSync { /// Instantiate a `SimpleSync` instance, with no peers and an empty queue. pub fn new(beacon_chain: Arc>, log: &slog::Logger) -> Self { let sync_logger = log.new(o!("Service"=> "Sync")); diff --git a/beacon_node/rpc/src/attestation.rs b/beacon_node/rpc/src/attestation.rs index eab6a8cd1..30f04afba 100644 --- a/beacon_node/rpc/src/attestation.rs +++ b/beacon_node/rpc/src/attestation.rs @@ -9,15 +9,15 @@ use protos::services_grpc::AttestationService; use slog::{error, info, trace, warn}; use ssz::{ssz_encode, Decodable}; use std::sync::Arc; -use types::{Attestation, BeaconStateTypes}; +use types::{Attestation, EthSpec}; #[derive(Clone)] -pub struct AttestationServiceInstance { +pub struct AttestationServiceInstance { pub chain: Arc>, pub log: slog::Logger, } -impl AttestationService for AttestationServiceInstance { +impl AttestationService for AttestationServiceInstance { /// Produce the `AttestationData` for signing by a validator. fn produce_attestation_data( &mut self, diff --git a/beacon_node/rpc/src/beacon_block.rs b/beacon_node/rpc/src/beacon_block.rs index fb6a08acc..727da9542 100644 --- a/beacon_node/rpc/src/beacon_block.rs +++ b/beacon_node/rpc/src/beacon_block.rs @@ -13,16 +13,16 @@ use slog::Logger; use slog::{error, info, trace, warn}; use ssz::{ssz_encode, Decodable}; use std::sync::Arc; -use types::{BeaconBlock, BeaconStateTypes, Signature, Slot}; +use types::{BeaconBlock, EthSpec, Signature, Slot}; #[derive(Clone)] -pub struct BeaconBlockServiceInstance { +pub struct BeaconBlockServiceInstance { pub chain: Arc>, pub network_chan: crossbeam_channel::Sender, pub log: Logger, } -impl BeaconBlockService for BeaconBlockServiceInstance { +impl BeaconBlockService for BeaconBlockServiceInstance { /// Produce a `BeaconBlock` for signing by a validator. fn produce_beacon_block( &mut self, diff --git a/beacon_node/rpc/src/beacon_chain.rs b/beacon_node/rpc/src/beacon_chain.rs index 9456c8857..e10522d04 100644 --- a/beacon_node/rpc/src/beacon_chain.rs +++ b/beacon_node/rpc/src/beacon_chain.rs @@ -8,10 +8,10 @@ use beacon_chain::{ AttestationValidationError, BlockProductionError, }; 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. -pub trait BeaconChain: Send + Sync { +pub trait BeaconChain: Send + Sync { fn get_spec(&self) -> &ChainSpec; fn get_state(&self) -> RwLockReadGuard>; @@ -39,7 +39,7 @@ where T: ClientDB + Sized, U: SlotClock, F: ForkChoice, - B: BeaconStateTypes, + B: EthSpec, { fn get_spec(&self) -> &ChainSpec { &self.spec diff --git a/beacon_node/rpc/src/beacon_node.rs b/beacon_node/rpc/src/beacon_node.rs index ed36b3deb..873d1c478 100644 --- a/beacon_node/rpc/src/beacon_node.rs +++ b/beacon_node/rpc/src/beacon_node.rs @@ -5,15 +5,15 @@ use protos::services::{Empty, Fork, NodeInfoResponse}; use protos::services_grpc::BeaconNodeService; use slog::{trace, warn}; use std::sync::Arc; -use types::BeaconStateTypes; +use types::EthSpec; #[derive(Clone)] -pub struct BeaconNodeServiceInstance { +pub struct BeaconNodeServiceInstance { pub chain: Arc>, pub log: slog::Logger, } -impl BeaconNodeService for BeaconNodeServiceInstance { +impl BeaconNodeService for BeaconNodeServiceInstance { /// Provides basic node information. fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink) { trace!(self.log, "Node info requested via RPC"); diff --git a/beacon_node/rpc/src/lib.rs b/beacon_node/rpc/src/lib.rs index ef1a6fc76..d46dee7b5 100644 --- a/beacon_node/rpc/src/lib.rs +++ b/beacon_node/rpc/src/lib.rs @@ -21,9 +21,9 @@ use protos::services_grpc::{ use slog::{info, o, warn}; use std::sync::Arc; use tokio::runtime::TaskExecutor; -use types::BeaconStateTypes; +use types::EthSpec; -pub fn start_server( +pub fn start_server( config: &RPCConfig, executor: &TaskExecutor, network_chan: crossbeam_channel::Sender, diff --git a/beacon_node/rpc/src/validator.rs b/beacon_node/rpc/src/validator.rs index 8bddcd91a..e2f8d098f 100644 --- a/beacon_node/rpc/src/validator.rs +++ b/beacon_node/rpc/src/validator.rs @@ -7,16 +7,16 @@ use protos::services_grpc::ValidatorService; use slog::{trace, warn}; use ssz::decode; use std::sync::Arc; -use types::{BeaconStateTypes, Epoch, RelativeEpoch}; +use types::{Epoch, EthSpec, RelativeEpoch}; #[derive(Clone)] -pub struct ValidatorServiceInstance { +pub struct ValidatorServiceInstance { pub chain: Arc>, pub log: slog::Logger, } //TODO: Refactor Errors -impl ValidatorService for ValidatorServiceInstance { +impl ValidatorService for ValidatorServiceInstance { /// 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 /// need to attest to. diff --git a/eth2/fork_choice/src/bitwise_lmd_ghost.rs b/eth2/fork_choice/src/bitwise_lmd_ghost.rs index 7667b28b7..3eb8bff8c 100644 --- a/eth2/fork_choice/src/bitwise_lmd_ghost.rs +++ b/eth2/fork_choice/src/bitwise_lmd_ghost.rs @@ -11,7 +11,7 @@ use log::{debug, trace}; use std::collections::HashMap; use std::marker::PhantomData; 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: Handle Syncing @@ -54,7 +54,7 @@ pub struct BitwiseLMDGhost { _phantom: PhantomData, } -impl BitwiseLMDGhost +impl BitwiseLMDGhost where T: ClientDB + Sized, { @@ -243,7 +243,7 @@ where } } -impl ForkChoice for BitwiseLMDGhost { +impl ForkChoice for BitwiseLMDGhost { fn add_block( &mut self, block: &BeaconBlock, diff --git a/eth2/fork_choice/src/optimized_lmd_ghost.rs b/eth2/fork_choice/src/optimized_lmd_ghost.rs index d2663b2b6..a471452c8 100644 --- a/eth2/fork_choice/src/optimized_lmd_ghost.rs +++ b/eth2/fork_choice/src/optimized_lmd_ghost.rs @@ -11,7 +11,7 @@ use std::cmp::Ordering; use std::collections::HashMap; use std::marker::PhantomData; 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: Handle Syncing @@ -54,7 +54,7 @@ pub struct OptimizedLMDGhost { _phantom: PhantomData, } -impl OptimizedLMDGhost +impl OptimizedLMDGhost where T: ClientDB + Sized, { @@ -214,7 +214,7 @@ where } } -impl ForkChoice for OptimizedLMDGhost { +impl ForkChoice for OptimizedLMDGhost { fn add_block( &mut self, block: &BeaconBlock, diff --git a/eth2/fork_choice/src/slow_lmd_ghost.rs b/eth2/fork_choice/src/slow_lmd_ghost.rs index 68c4ac5a6..c11ef3eec 100644 --- a/eth2/fork_choice/src/slow_lmd_ghost.rs +++ b/eth2/fork_choice/src/slow_lmd_ghost.rs @@ -9,7 +9,7 @@ use log::{debug, trace}; use std::collections::HashMap; use std::marker::PhantomData; use std::sync::Arc; -use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot}; +use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot}; //TODO: Pruning and syncing @@ -26,7 +26,7 @@ pub struct SlowLMDGhost { _phantom: PhantomData, } -impl SlowLMDGhost +impl SlowLMDGhost where T: ClientDB + Sized, { @@ -108,7 +108,7 @@ where } } -impl ForkChoice for SlowLMDGhost { +impl ForkChoice for SlowLMDGhost { /// Process when a block is added fn add_block( &mut self, diff --git a/eth2/fork_choice/tests/tests.rs b/eth2/fork_choice/tests/tests.rs index 3addb8c0a..067d39da4 100644 --- a/eth2/fork_choice/tests/tests.rs +++ b/eth2/fork_choice/tests/tests.rs @@ -26,8 +26,7 @@ use std::sync::Arc; use std::{fs::File, io::prelude::*, path::PathBuf}; use types::test_utils::TestingBeaconStateBuilder; use types::{ - BeaconBlock, BeaconBlockBody, BeaconStateTypes, Eth1Data, FoundationStateTypes, Hash256, - Keypair, Slot, + BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, FoundationEthSpec, Hash256, Keypair, Slot, }; use yaml_rust::yaml; @@ -85,7 +84,7 @@ fn test_yaml_vectors( let test_cases = load_test_cases_from_yaml(yaml_file_path); // default vars - let spec = FoundationStateTypes::spec(); + let spec = FoundationEthSpec::spec(); let zero_hash = Hash256::zero(); let eth1_data = Eth1Data { deposit_root: zero_hash.clone(), @@ -231,26 +230,26 @@ fn setup_inital_state( // the fork choice instantiation let fork_choice: Box = match fork_choice_algo { ForkChoiceAlgorithm::OptimizedLMDGhost => { - let f: OptimizedLMDGhost = + let f: OptimizedLMDGhost = OptimizedLMDGhost::new(block_store.clone(), state_store.clone()); Box::new(f) } ForkChoiceAlgorithm::BitwiseLMDGhost => { - let f: BitwiseLMDGhost = + let f: BitwiseLMDGhost = BitwiseLMDGhost::new(block_store.clone(), state_store.clone()); Box::new(f) } ForkChoiceAlgorithm::SlowLMDGhost => { - let f: SlowLMDGhost = + let f: SlowLMDGhost = SlowLMDGhost::new(block_store.clone(), state_store.clone()); Box::new(f) } ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())), }; - let spec = FoundationStateTypes::spec(); + let spec = FoundationEthSpec::spec(); - let mut state_builder: TestingBeaconStateBuilder = + let mut state_builder: TestingBeaconStateBuilder = TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec); state_builder.build_caches(&spec).unwrap(); let (state, _keypairs) = state_builder.build(); diff --git a/eth2/operation_pool/src/lib.rs b/eth2/operation_pool/src/lib.rs index 5a82fd3f1..cbaabe0cd 100644 --- a/eth2/operation_pool/src/lib.rs +++ b/eth2/operation_pool/src/lib.rs @@ -16,8 +16,8 @@ use std::collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet}; use std::marker::PhantomData; use types::chain_spec::Domain; use types::{ - Attestation, AttestationData, AttesterSlashing, BeaconState, BeaconStateTypes, ChainSpec, - Deposit, Epoch, ProposerSlashing, Transfer, Validator, VoluntaryExit, + Attestation, AttestationData, AttesterSlashing, BeaconState, ChainSpec, Deposit, Epoch, + EthSpec, ProposerSlashing, Transfer, Validator, VoluntaryExit, }; #[cfg(test)] @@ -26,7 +26,7 @@ const VERIFY_DEPOSIT_PROOFS: bool = false; const VERIFY_DEPOSIT_PROOFS: bool = false; // TODO: enable this #[derive(Default)] -pub struct OperationPool { +pub struct OperationPool { /// Map from attestation ID (see below) to vectors of attestations. attestations: RwLock>>, /// Map from deposit index to deposit data. @@ -54,7 +54,7 @@ struct AttestationId(Vec); const DOMAIN_BYTES_LEN: usize = 8; impl AttestationId { - fn from_data( + fn from_data( attestation: &AttestationData, state: &BeaconState, spec: &ChainSpec, @@ -65,7 +65,7 @@ impl AttestationId { AttestationId(bytes) } - fn compute_domain_bytes( + fn compute_domain_bytes( epoch: Epoch, state: &BeaconState, spec: &ChainSpec, @@ -85,7 +85,7 @@ impl AttestationId { /// receive for including it in a block. // 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. -fn attestation_score( +fn attestation_score( attestation: &Attestation, state: &BeaconState, spec: &ChainSpec, @@ -127,7 +127,7 @@ pub enum DepositInsertStatus { Replaced(Box), } -impl OperationPool { +impl OperationPool { /// Create a new operation pool. pub fn new() -> Self { Self::default() @@ -501,7 +501,7 @@ impl OperationPool { /// /// - Their `AttestationData` is equal. /// - `attestation` does not contain any signatures that `PendingAttestation` does not have. -fn superior_attestation_exists_in_state( +fn superior_attestation_exists_in_state( state: &BeaconState, attestation: &Attestation, ) -> bool { @@ -539,7 +539,7 @@ where /// 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`. /// Entries for unknown validators will be kept. -fn prune_validator_hash_map( +fn prune_validator_hash_map( map: &mut HashMap, prune_if: F, finalized_state: &BeaconState, @@ -666,7 +666,7 @@ mod tests { } // Create a random deposit (with a valid proof of posession) - fn make_deposit( + fn make_deposit( rng: &mut XorShiftRng, state: &BeaconState, spec: &ChainSpec, @@ -689,7 +689,7 @@ mod tests { } // Create `count` dummy deposits with sequential deposit IDs beginning from `start`. - fn dummy_deposits( + fn dummy_deposits( rng: &mut XorShiftRng, state: &BeaconState, spec: &ChainSpec, @@ -706,8 +706,8 @@ mod tests { .collect() } - fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState) { - let spec = FoundationStateTypes::spec(); + fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState) { + let spec = FoundationEthSpec::spec(); let mut state = BeaconState::random_for_test(rng); @@ -722,10 +722,7 @@ mod tests { /// Create a signed attestation for use in tests. /// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`. - fn signed_attestation< - R: std::slice::SliceIndex<[usize], Output = [usize]>, - B: BeaconStateTypes, - >( + fn signed_attestation, B: EthSpec>( committee: &CrosslinkCommittee, keypairs: &[Keypair], signing_range: R, @@ -757,7 +754,7 @@ mod tests { } /// Test state for attestation-related tests. - fn attestation_test_state( + fn attestation_test_state( num_committees: usize, ) -> (BeaconState, Vec, ChainSpec) { let spec = B::spec(); @@ -774,11 +771,11 @@ mod tests { state_builder.build_caches(&spec).unwrap(); 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. - fn fake_latest_crosslink( + fn fake_latest_crosslink( att: &Attestation, state: &mut BeaconState, spec: &ChainSpec, @@ -792,7 +789,7 @@ mod tests { #[test] fn test_attestation_score() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let slot = state.slot - 1; let committees = state @@ -824,7 +821,7 @@ mod tests { #[test] fn attestation_aggregation_insert_get_prune() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let op_pool = OperationPool::new(); @@ -890,7 +887,7 @@ mod tests { #[test] fn attestation_duplicate() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let op_pool = OperationPool::new(); @@ -917,7 +914,7 @@ mod tests { #[test] fn attestation_pairwise_overlapping() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let op_pool = OperationPool::new(); @@ -963,7 +960,7 @@ mod tests { let big_step_size = 4; let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(big_step_size); + attestation_test_state::(big_step_size); let op_pool = OperationPool::new(); diff --git a/eth2/state_processing/src/common/exit_validator.rs b/eth2/state_processing/src/common/exit_validator.rs index e71a31b65..529f5e161 100644 --- a/eth2/state_processing/src/common/exit_validator.rs +++ b/eth2/state_processing/src/common/exit_validator.rs @@ -3,7 +3,7 @@ use types::{BeaconStateError as Error, *}; /// Exit the validator of the given `index`. /// /// Spec v0.5.1 -pub fn exit_validator( +pub fn exit_validator( state: &mut BeaconState, validator_index: usize, spec: &ChainSpec, diff --git a/eth2/state_processing/src/common/slash_validator.rs b/eth2/state_processing/src/common/slash_validator.rs index bb77e914c..63c1e89ad 100644 --- a/eth2/state_processing/src/common/slash_validator.rs +++ b/eth2/state_processing/src/common/slash_validator.rs @@ -4,7 +4,7 @@ use types::{BeaconStateError as Error, *}; /// Slash the validator with index ``index``. /// /// Spec v0.5.1 -pub fn slash_validator( +pub fn slash_validator( state: &mut BeaconState, validator_index: usize, spec: &ChainSpec, diff --git a/eth2/state_processing/src/get_genesis_state.rs b/eth2/state_processing/src/get_genesis_state.rs index 0960187df..6638b5246 100644 --- a/eth2/state_processing/src/get_genesis_state.rs +++ b/eth2/state_processing/src/get_genesis_state.rs @@ -10,7 +10,7 @@ pub enum GenesisError { /// Returns the genesis `BeaconState` /// /// Spec v0.5.1 -pub fn get_genesis_state( +pub fn get_genesis_state( genesis_validator_deposits: &[Deposit], genesis_time: u64, genesis_eth1_data: Eth1Data, diff --git a/eth2/state_processing/src/per_block_processing.rs b/eth2/state_processing/src/per_block_processing.rs index e8cf7d957..5bb40e25b 100644 --- a/eth2/state_processing/src/per_block_processing.rs +++ b/eth2/state_processing/src/per_block_processing.rs @@ -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. /// /// Spec v0.5.1 -pub fn per_block_processing( +pub fn per_block_processing( state: &mut BeaconState, block: &BeaconBlock, spec: &ChainSpec, @@ -55,7 +55,7 @@ pub fn per_block_processing( /// returns an error describing why the block was invalid or how the function failed to execute. /// /// Spec v0.5.1 -pub fn per_block_processing_without_verifying_block_signature( +pub fn per_block_processing_without_verifying_block_signature( state: &mut BeaconState, block: &BeaconBlock, spec: &ChainSpec, @@ -70,7 +70,7 @@ pub fn per_block_processing_without_verifying_block_signature( +fn per_block_processing_signature_optional( mut state: &mut BeaconState, block: &BeaconBlock, should_verify_block_signature: bool, @@ -100,7 +100,7 @@ fn per_block_processing_signature_optional( /// Processes the block header. /// /// Spec v0.5.1 -pub fn process_block_header( +pub fn process_block_header( state: &mut BeaconState, block: &BeaconBlock, spec: &ChainSpec, @@ -125,7 +125,7 @@ pub fn process_block_header( /// Verifies the signature of a block. /// /// Spec v0.5.1 -pub fn verify_block_signature( +pub fn verify_block_signature( state: &BeaconState, block: &BeaconBlock, spec: &ChainSpec, @@ -153,7 +153,7 @@ pub fn verify_block_signature( /// `state.latest_randao_mixes`. /// /// Spec v0.5.1 -pub fn process_randao( +pub fn process_randao( state: &mut BeaconState, block: &BeaconBlock, spec: &ChainSpec, @@ -184,7 +184,7 @@ pub fn process_randao( /// Update the `state.eth1_data_votes` based upon the `eth1_data` provided. /// /// Spec v0.5.1 -pub fn process_eth1_data( +pub fn process_eth1_data( state: &mut BeaconState, eth1_data: &Eth1Data, ) -> Result<(), Error> { @@ -213,7 +213,7 @@ pub fn process_eth1_data( /// an `Err` describing the invalid object or cause of failure. /// /// Spec v0.5.1 -pub fn process_proposer_slashings( +pub fn process_proposer_slashings( state: &mut BeaconState, proposer_slashings: &[ProposerSlashing], spec: &ChainSpec, @@ -246,7 +246,7 @@ pub fn process_proposer_slashings( /// an `Err` describing the invalid object or cause of failure. /// /// Spec v0.5.1 -pub fn process_attester_slashings( +pub fn process_attester_slashings( state: &mut BeaconState, attester_slashings: &[AttesterSlashing], spec: &ChainSpec, @@ -304,7 +304,7 @@ pub fn process_attester_slashings( /// an `Err` describing the invalid object or cause of failure. /// /// Spec v0.5.1 -pub fn process_attestations( +pub fn process_attestations( state: &mut BeaconState, attestations: &[Attestation], spec: &ChainSpec, @@ -346,7 +346,7 @@ pub fn process_attestations( /// an `Err` describing the invalid object or cause of failure. /// /// Spec v0.5.1 -pub fn process_deposits( +pub fn process_deposits( state: &mut BeaconState, deposits: &[Deposit], spec: &ChainSpec, @@ -416,7 +416,7 @@ pub fn process_deposits( /// an `Err` describing the invalid object or cause of failure. /// /// Spec v0.5.1 -pub fn process_exits( +pub fn process_exits( state: &mut BeaconState, voluntary_exits: &[VoluntaryExit], spec: &ChainSpec, @@ -448,7 +448,7 @@ pub fn process_exits( /// an `Err` describing the invalid object or cause of failure. /// /// Spec v0.5.1 -pub fn process_transfers( +pub fn process_transfers( state: &mut BeaconState, transfers: &[Transfer], spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_block_processing/validate_attestation.rs b/eth2/state_processing/src/per_block_processing/validate_attestation.rs index f0ec1b861..cb26389df 100644 --- a/eth2/state_processing/src/per_block_processing/validate_attestation.rs +++ b/eth2/state_processing/src/per_block_processing/validate_attestation.rs @@ -9,7 +9,7 @@ use types::*; /// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity. /// /// Spec v0.5.1 -pub fn validate_attestation( +pub fn validate_attestation( state: &BeaconState, attestation: &Attestation, spec: &ChainSpec, @@ -18,7 +18,7 @@ pub fn validate_attestation( } /// Like `validate_attestation` but doesn't run checks which may become true in future states. -pub fn validate_attestation_time_independent_only( +pub fn validate_attestation_time_independent_only( state: &BeaconState, attestation: &Attestation, spec: &ChainSpec, @@ -32,7 +32,7 @@ pub fn validate_attestation_time_independent_only( /// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity. /// /// Spec v0.5.1 -pub fn validate_attestation_without_signature( +pub fn validate_attestation_without_signature( state: &BeaconState, attestation: &Attestation, spec: &ChainSpec, @@ -45,7 +45,7 @@ pub fn validate_attestation_without_signature( /// /// /// Spec v0.5.1 -fn validate_attestation_parametric( +fn validate_attestation_parametric( state: &BeaconState, attestation: &Attestation, spec: &ChainSpec, @@ -168,7 +168,7 @@ fn validate_attestation_parametric( /// match the current (or previous) justified epoch and root from the state. /// /// Spec v0.5.1 -fn verify_justified_epoch_and_root( +fn verify_justified_epoch_and_root( attestation: &Attestation, state: &BeaconState, spec: &ChainSpec, @@ -223,7 +223,7 @@ fn verify_justified_epoch_and_root( /// - A `validator_index` in `committee` is not in `state.validator_registry`. /// /// Spec v0.5.1 -fn verify_attestation_signature( +fn verify_attestation_signature( state: &BeaconState, committee: &[usize], a: &Attestation, diff --git a/eth2/state_processing/src/per_block_processing/verify_attester_slashing.rs b/eth2/state_processing/src/per_block_processing/verify_attester_slashing.rs index 804ebd517..5ac62221a 100644 --- a/eth2/state_processing/src/per_block_processing/verify_attester_slashing.rs +++ b/eth2/state_processing/src/per_block_processing/verify_attester_slashing.rs @@ -8,7 +8,7 @@ use types::*; /// Returns `Ok(())` if the `AttesterSlashing` is valid, otherwise indicates the reason for invalidity. /// /// Spec v0.5.1 -pub fn verify_attester_slashing( +pub fn verify_attester_slashing( state: &BeaconState, attester_slashing: &AttesterSlashing, should_verify_slashable_attestations: bool, @@ -42,7 +42,7 @@ pub fn verify_attester_slashing( /// Returns Ok(indices) if `indices.len() > 0`. /// /// Spec v0.5.1 -pub fn gather_attester_slashing_indices( +pub fn gather_attester_slashing_indices( state: &BeaconState, attester_slashing: &AttesterSlashing, spec: &ChainSpec, @@ -57,7 +57,7 @@ pub fn gather_attester_slashing_indices( /// Same as `gather_attester_slashing_indices` but allows the caller to specify the criteria /// for determining whether a given validator should be considered slashed. -pub fn gather_attester_slashing_indices_modular( +pub fn gather_attester_slashing_indices_modular( state: &BeaconState, attester_slashing: &AttesterSlashing, is_slashed: F, diff --git a/eth2/state_processing/src/per_block_processing/verify_deposit.rs b/eth2/state_processing/src/per_block_processing/verify_deposit.rs index b99204e77..e2868a1b6 100644 --- a/eth2/state_processing/src/per_block_processing/verify_deposit.rs +++ b/eth2/state_processing/src/per_block_processing/verify_deposit.rs @@ -16,7 +16,7 @@ use types::*; /// Note: this function is incomplete. /// /// Spec v0.5.1 -pub fn verify_deposit( +pub fn verify_deposit( state: &BeaconState, deposit: &Deposit, verify_merkle_branch: bool, @@ -47,7 +47,7 @@ pub fn verify_deposit( /// Verify that the `Deposit` index is correct. /// /// Spec v0.5.1 -pub fn verify_deposit_index( +pub fn verify_deposit_index( state: &BeaconState, deposit: &Deposit, ) -> Result<(), Error> { @@ -68,7 +68,7 @@ pub fn verify_deposit_index( /// ## Errors /// /// Errors if the state's `pubkey_cache` is not current. -pub fn get_existing_validator_index( +pub fn get_existing_validator_index( state: &BeaconState, deposit: &Deposit, ) -> Result, Error> { @@ -92,7 +92,7 @@ pub fn get_existing_validator_index( /// Verify that a deposit is included in the state's eth1 deposit root. /// /// Spec v0.5.1 -fn verify_deposit_merkle_proof( +fn verify_deposit_merkle_proof( state: &BeaconState, deposit: &Deposit, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_block_processing/verify_exit.rs b/eth2/state_processing/src/per_block_processing/verify_exit.rs index deaf9379a..333638a8d 100644 --- a/eth2/state_processing/src/per_block_processing/verify_exit.rs +++ b/eth2/state_processing/src/per_block_processing/verify_exit.rs @@ -8,7 +8,7 @@ use types::*; /// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity. /// /// Spec v0.5.1 -pub fn verify_exit( +pub fn verify_exit( state: &BeaconState, exit: &VoluntaryExit, spec: &ChainSpec, @@ -17,7 +17,7 @@ pub fn verify_exit( } /// Like `verify_exit` but doesn't run checks which may become true in future states. -pub fn verify_exit_time_independent_only( +pub fn verify_exit_time_independent_only( state: &BeaconState, exit: &VoluntaryExit, spec: &ChainSpec, @@ -26,7 +26,7 @@ pub fn verify_exit_time_independent_only( } /// Parametric version of `verify_exit` that skips some checks if `time_independent_only` is true. -fn verify_exit_parametric( +fn verify_exit_parametric( state: &BeaconState, exit: &VoluntaryExit, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_block_processing/verify_proposer_slashing.rs b/eth2/state_processing/src/per_block_processing/verify_proposer_slashing.rs index 73fffcd64..0c66a9b15 100644 --- a/eth2/state_processing/src/per_block_processing/verify_proposer_slashing.rs +++ b/eth2/state_processing/src/per_block_processing/verify_proposer_slashing.rs @@ -8,7 +8,7 @@ use types::*; /// Returns `Ok(())` if the `ProposerSlashing` is valid, otherwise indicates the reason for invalidity. /// /// Spec v0.5.1 -pub fn verify_proposer_slashing( +pub fn verify_proposer_slashing( proposer_slashing: &ProposerSlashing, state: &BeaconState, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_block_processing/verify_slashable_attestation.rs b/eth2/state_processing/src/per_block_processing/verify_slashable_attestation.rs index 1e52c6a41..4d440332a 100644 --- a/eth2/state_processing/src/per_block_processing/verify_slashable_attestation.rs +++ b/eth2/state_processing/src/per_block_processing/verify_slashable_attestation.rs @@ -11,7 +11,7 @@ use types::*; /// Returns `Ok(())` if the `SlashableAttestation` is valid, otherwise indicates the reason for invalidity. /// /// Spec v0.5.1 -pub fn verify_slashable_attestation( +pub fn verify_slashable_attestation( state: &BeaconState, slashable_attestation: &SlashableAttestation, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_block_processing/verify_transfer.rs b/eth2/state_processing/src/per_block_processing/verify_transfer.rs index 771d350a5..c6388bebe 100644 --- a/eth2/state_processing/src/per_block_processing/verify_transfer.rs +++ b/eth2/state_processing/src/per_block_processing/verify_transfer.rs @@ -11,7 +11,7 @@ use types::*; /// Note: this function is incomplete. /// /// Spec v0.5.1 -pub fn verify_transfer( +pub fn verify_transfer( state: &BeaconState, transfer: &Transfer, spec: &ChainSpec, @@ -20,7 +20,7 @@ pub fn verify_transfer( } /// Like `verify_transfer` but doesn't run checks which may become true in future states. -pub fn verify_transfer_time_independent_only( +pub fn verify_transfer_time_independent_only( state: &BeaconState, transfer: &Transfer, spec: &ChainSpec, @@ -29,7 +29,7 @@ pub fn verify_transfer_time_independent_only( } /// Parametric version of `verify_transfer` that allows some checks to be skipped. -fn verify_transfer_parametric( +fn verify_transfer_parametric( state: &BeaconState, transfer: &Transfer, spec: &ChainSpec, @@ -123,7 +123,7 @@ fn verify_transfer_parametric( /// Does not check that the transfer is valid, however checks for overflow in all actions. /// /// Spec v0.5.1 -pub fn execute_transfer( +pub fn execute_transfer( state: &mut BeaconState, transfer: &Transfer, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_epoch_processing.rs b/eth2/state_processing/src/per_epoch_processing.rs index e2ecd47d6..3f8eb5112 100644 --- a/eth2/state_processing/src/per_epoch_processing.rs +++ b/eth2/state_processing/src/per_epoch_processing.rs @@ -33,7 +33,7 @@ pub type WinningRootHashSet = HashMap; /// returned, a state might be "half-processed" and therefore in an invalid state. /// /// Spec v0.5.1 -pub fn per_epoch_processing( +pub fn per_epoch_processing( state: &mut BeaconState, spec: &ChainSpec, ) -> Result<(), Error> { @@ -90,7 +90,7 @@ pub fn per_epoch_processing( /// Maybe resets the eth1 period. /// /// Spec v0.5.1 -pub fn maybe_reset_eth1_period(state: &mut BeaconState, spec: &ChainSpec) { +pub fn maybe_reset_eth1_period(state: &mut BeaconState, spec: &ChainSpec) { let next_epoch = state.next_epoch(spec); let voting_period = spec.epochs_per_eth1_voting_period; @@ -112,7 +112,7 @@ pub fn maybe_reset_eth1_period(state: &mut BeaconState, /// - `previous_justified_epoch` /// /// Spec v0.5.1 -pub fn update_justification_and_finalization( +pub fn update_justification_and_finalization( state: &mut BeaconState, total_balances: &TotalBalances, spec: &ChainSpec, @@ -182,7 +182,7 @@ pub fn update_justification_and_finalization( /// Also returns a `WinningRootHashSet` for later use during epoch processing. /// /// Spec v0.5.1 -pub fn process_crosslinks( +pub fn process_crosslinks( state: &mut BeaconState, spec: &ChainSpec, ) -> Result { @@ -225,7 +225,7 @@ pub fn process_crosslinks( /// Finish up an epoch update. /// /// Spec v0.5.1 -pub fn finish_epoch_update( +pub fn finish_epoch_update( state: &mut BeaconState, spec: &ChainSpec, ) -> Result<(), Error> { diff --git a/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs b/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs index fe31ef244..f529523fb 100644 --- a/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs +++ b/eth2/state_processing/src/per_epoch_processing/apply_rewards.rs @@ -33,7 +33,7 @@ impl std::ops::AddAssign for Delta { /// Apply attester and proposer rewards. /// /// Spec v0.5.1 -pub fn apply_rewards( +pub fn apply_rewards( state: &mut BeaconState, validator_statuses: &mut ValidatorStatuses, winning_root_for_shards: &WinningRootHashSet, @@ -80,7 +80,7 @@ pub fn apply_rewards( /// attestation in the previous epoch. /// /// Spec v0.5.1 -fn get_proposer_deltas( +fn get_proposer_deltas( deltas: &mut Vec, state: &mut BeaconState, validator_statuses: &mut ValidatorStatuses, @@ -121,7 +121,7 @@ fn get_proposer_deltas( /// Apply rewards for participation in attestations during the previous epoch. /// /// Spec v0.5.1 -fn get_justification_and_finalization_deltas( +fn get_justification_and_finalization_deltas( deltas: &mut Vec, state: &BeaconState, 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. /// /// Spec v0.5.1 -fn get_crosslink_deltas( +fn get_crosslink_deltas( deltas: &mut Vec, state: &BeaconState, validator_statuses: &ValidatorStatuses, @@ -296,7 +296,7 @@ fn get_crosslink_deltas( /// Returns the base reward for some validator. /// /// Spec v0.5.1 -fn get_base_reward( +fn get_base_reward( state: &BeaconState, index: usize, previous_total_balance: u64, @@ -313,7 +313,7 @@ fn get_base_reward( /// Returns the inactivity penalty for some validator. /// /// Spec v0.5.1 -fn get_inactivity_penalty( +fn get_inactivity_penalty( state: &BeaconState, index: usize, epochs_since_finality: u64, @@ -329,6 +329,6 @@ fn get_inactivity_penalty( /// Returns the epochs since the last finalized epoch. /// /// Spec v0.5.1 -fn epochs_since_finality(state: &BeaconState, spec: &ChainSpec) -> Epoch { +fn epochs_since_finality(state: &BeaconState, spec: &ChainSpec) -> Epoch { state.current_epoch(spec) + 1 - state.finalized_epoch } diff --git a/eth2/state_processing/src/per_epoch_processing/get_attestation_participants.rs b/eth2/state_processing/src/per_epoch_processing/get_attestation_participants.rs index ddf0d680f..7f5504c56 100644 --- a/eth2/state_processing/src/per_epoch_processing/get_attestation_participants.rs +++ b/eth2/state_processing/src/per_epoch_processing/get_attestation_participants.rs @@ -4,7 +4,7 @@ use types::*; /// Returns validator indices which participated in the attestation. /// /// Spec v0.5.1 -pub fn get_attestation_participants( +pub fn get_attestation_participants( state: &BeaconState, attestation_data: &AttestationData, bitfield: &Bitfield, diff --git a/eth2/state_processing/src/per_epoch_processing/inclusion_distance.rs b/eth2/state_processing/src/per_epoch_processing/inclusion_distance.rs index 9d4b36876..e82d810ba 100644 --- a/eth2/state_processing/src/per_epoch_processing/inclusion_distance.rs +++ b/eth2/state_processing/src/per_epoch_processing/inclusion_distance.rs @@ -6,7 +6,7 @@ use types::*; /// slot. /// /// Spec v0.5.1 -pub fn inclusion_distance( +pub fn inclusion_distance( state: &BeaconState, attestations: &[&PendingAttestation], validator_index: usize, @@ -19,7 +19,7 @@ pub fn inclusion_distance( /// Returns the slot of the earliest included attestation for some validator. /// /// Spec v0.5.1 -pub fn inclusion_slot( +pub fn inclusion_slot( state: &BeaconState, attestations: &[&PendingAttestation], validator_index: usize, @@ -32,7 +32,7 @@ pub fn inclusion_slot( /// Finds the earliest included attestation for some validator. /// /// Spec v0.5.1 -fn earliest_included_attestation( +fn earliest_included_attestation( state: &BeaconState, attestations: &[&PendingAttestation], validator_index: usize, diff --git a/eth2/state_processing/src/per_epoch_processing/process_ejections.rs b/eth2/state_processing/src/per_epoch_processing/process_ejections.rs index 5a18d77be..e32241e24 100644 --- a/eth2/state_processing/src/per_epoch_processing/process_ejections.rs +++ b/eth2/state_processing/src/per_epoch_processing/process_ejections.rs @@ -5,7 +5,7 @@ use types::{BeaconStateError as Error, *}; /// ``EJECTION_BALANCE``. /// /// Spec v0.5.1 -pub fn process_ejections( +pub fn process_ejections( state: &mut BeaconState, spec: &ChainSpec, ) -> Result<(), Error> { diff --git a/eth2/state_processing/src/per_epoch_processing/process_exit_queue.rs b/eth2/state_processing/src/per_epoch_processing/process_exit_queue.rs index 082a64775..eafe4541e 100644 --- a/eth2/state_processing/src/per_epoch_processing/process_exit_queue.rs +++ b/eth2/state_processing/src/per_epoch_processing/process_exit_queue.rs @@ -3,7 +3,7 @@ use types::*; /// Process the exit queue. /// /// Spec v0.5.1 -pub fn process_exit_queue(state: &mut BeaconState, spec: &ChainSpec) { +pub fn process_exit_queue(state: &mut BeaconState, spec: &ChainSpec) { let current_epoch = state.current_epoch(spec); let eligible = |index: usize| { @@ -32,7 +32,7 @@ pub fn process_exit_queue(state: &mut BeaconState, spec: /// Initiate an exit for the validator of the given `index`. /// /// Spec v0.5.1 -fn prepare_validator_for_withdrawal( +fn prepare_validator_for_withdrawal( state: &mut BeaconState, validator_index: usize, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_epoch_processing/process_slashings.rs b/eth2/state_processing/src/per_epoch_processing/process_slashings.rs index e3a038bd7..a70720cce 100644 --- a/eth2/state_processing/src/per_epoch_processing/process_slashings.rs +++ b/eth2/state_processing/src/per_epoch_processing/process_slashings.rs @@ -3,7 +3,7 @@ use types::{BeaconStateError as Error, *}; /// Process slashings. /// /// Spec v0.5.1 -pub fn process_slashings( +pub fn process_slashings( state: &mut BeaconState, current_total_balance: u64, spec: &ChainSpec, diff --git a/eth2/state_processing/src/per_epoch_processing/tests.rs b/eth2/state_processing/src/per_epoch_processing/tests.rs index bbbd7d7c5..b075c5cd4 100644 --- a/eth2/state_processing/src/per_epoch_processing/tests.rs +++ b/eth2/state_processing/src/per_epoch_processing/tests.rs @@ -8,9 +8,9 @@ use types::*; fn runs_without_error() { Builder::from_env(Env::default().default_filter_or("error")).init(); - let spec = FewValidatorsStateTypes::spec(); + let spec = FewValidatorsEthSpec::spec(); - let mut builder: TestingBeaconStateBuilder = + let mut builder: TestingBeaconStateBuilder = TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec); let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch); diff --git a/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs b/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs index b1e326225..f6548fb67 100644 --- a/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs +++ b/eth2/state_processing/src/per_epoch_processing/update_registry_and_shuffling_data.rs @@ -5,7 +5,7 @@ use types::*; /// Peforms a validator registry update, if required. /// /// Spec v0.5.1 -pub fn update_registry_and_shuffling_data( +pub fn update_registry_and_shuffling_data( state: &mut BeaconState, current_total_balance: u64, spec: &ChainSpec, @@ -50,7 +50,7 @@ pub fn update_registry_and_shuffling_data( /// Returns `true` if the validator registry should be updated during an epoch processing. /// /// Spec v0.5.1 -pub fn should_update_validator_registry( +pub fn should_update_validator_registry( state: &BeaconState, spec: &ChainSpec, ) -> Result { @@ -79,7 +79,7 @@ pub fn should_update_validator_registry( /// Note: Utilizes the cache and will fail if the appropriate cache is not initialized. /// /// Spec v0.5.1 -pub fn update_validator_registry( +pub fn update_validator_registry( state: &mut BeaconState, current_total_balance: u64, spec: &ChainSpec, @@ -134,7 +134,7 @@ pub fn update_validator_registry( /// Activate the validator of the given ``index``. /// /// Spec v0.5.1 -pub fn activate_validator( +pub fn activate_validator( state: &mut BeaconState, validator_index: usize, is_genesis: bool, diff --git a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs index 038737fd9..ee0079eee 100644 --- a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs +++ b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs @@ -161,7 +161,7 @@ impl ValidatorStatuses { /// - Total balances for the current and previous epochs. /// /// Spec v0.5.1 - pub fn new( + pub fn new( state: &BeaconState, spec: &ChainSpec, ) -> Result { @@ -199,7 +199,7 @@ impl ValidatorStatuses { /// `total_balances` fields. /// /// Spec v0.5.1 - pub fn process_attestations( + pub fn process_attestations( &mut self, state: &BeaconState, spec: &ChainSpec, @@ -265,7 +265,7 @@ impl ValidatorStatuses { /// "winning" shard block root for the previous epoch. /// /// Spec v0.5.1 - pub fn process_winning_roots( + pub fn process_winning_roots( &mut self, state: &BeaconState, 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. /// /// Spec v0.5.1 -fn has_common_epoch_boundary_root( +fn has_common_epoch_boundary_root( a: &PendingAttestation, state: &BeaconState, epoch: Epoch, @@ -332,7 +332,7 @@ fn has_common_epoch_boundary_root( /// the current slot of the `PendingAttestation`. /// /// Spec v0.5.1 -fn has_common_beacon_block_root( +fn has_common_beacon_block_root( a: &PendingAttestation, state: &BeaconState, ) -> Result { diff --git a/eth2/state_processing/src/per_epoch_processing/winning_root.rs b/eth2/state_processing/src/per_epoch_processing/winning_root.rs index 246043b05..8ffa717e8 100644 --- a/eth2/state_processing/src/per_epoch_processing/winning_root.rs +++ b/eth2/state_processing/src/per_epoch_processing/winning_root.rs @@ -35,7 +35,7 @@ impl WinningRoot { /// per-epoch processing. /// /// Spec v0.5.1 -pub fn winning_root( +pub fn winning_root( state: &BeaconState, shard: u64, spec: &ChainSpec, @@ -90,7 +90,7 @@ pub fn winning_root( /// Returns `true` if pending attestation `a` is eligible to become a winning root. /// /// Spec v0.5.1 -fn is_eligible_for_winning_root( +fn is_eligible_for_winning_root( state: &BeaconState, a: &PendingAttestation, shard: Shard, @@ -105,7 +105,7 @@ fn is_eligible_for_winning_root( /// Returns all indices which voted for a given crosslink. Does not contain duplicates. /// /// Spec v0.5.1 -fn get_attesting_validator_indices( +fn get_attesting_validator_indices( state: &BeaconState, shard: u64, crosslink_data_root: &Hash256, diff --git a/eth2/state_processing/src/per_slot_processing.rs b/eth2/state_processing/src/per_slot_processing.rs index 08875cf4d..ebab36ff7 100644 --- a/eth2/state_processing/src/per_slot_processing.rs +++ b/eth2/state_processing/src/per_slot_processing.rs @@ -11,7 +11,7 @@ pub enum Error { /// Advances a state forward by one slot, performing per-epoch processing if required. /// /// Spec v0.5.1 -pub fn per_slot_processing( +pub fn per_slot_processing( state: &mut BeaconState, spec: &ChainSpec, ) -> Result<(), Error> { @@ -26,10 +26,7 @@ pub fn per_slot_processing( Ok(()) } -fn cache_state( - state: &mut BeaconState, - spec: &ChainSpec, -) -> Result<(), Error> { +fn cache_state(state: &mut BeaconState, spec: &ChainSpec) -> Result<(), Error> { 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` diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 03c39db61..cb68c4c40 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -67,7 +67,7 @@ pub enum Error { )] pub struct BeaconState where - T: BeaconStateTypes, + T: EthSpec, { // Misc pub slot: Slot, @@ -140,7 +140,7 @@ where pub tree_hash_cache: TreeHashCache, } -impl BeaconState { +impl BeaconState { /// Produce the first state of the Beacon Chain. /// /// This does not fully build a genesis beacon state, it omits processing of initial validator diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index 8f0f6d524..b6c943a36 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -3,7 +3,7 @@ use fixed_len_vec::typenum::{Unsigned, U1024, U8, U8192}; use serde_derive::{Deserialize, Serialize}; use std::fmt::Debug; -pub trait BeaconStateTypes: +pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq + serde::de::DeserializeOwned { type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq; @@ -54,9 +54,9 @@ pub trait BeaconStateTypes: /// /// Spec v0.5.1 #[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 SlotsPerHistoricalRoot = U8192; type LatestRandaoMixesLength = U8192; @@ -68,15 +68,15 @@ impl BeaconStateTypes for FoundationStateTypes { } } -pub type FoundationBeaconState = BeaconState; +pub type FoundationBeaconState = BeaconState; /// Ethereum Foundation specifications, modified to be suitable for < 1000 validators. /// /// Spec v0.5.1 #[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 SlotsPerHistoricalRoot = U8192; type LatestRandaoMixesLength = U8192; @@ -88,15 +88,15 @@ impl BeaconStateTypes for FewValidatorsStateTypes { } } -pub type FewValidatorsBeaconState = BeaconState; +pub type FewValidatorsBeaconState = BeaconState; /// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet. /// /// Spec v0.5.1 #[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 SlotsPerHistoricalRoot = U8192; type LatestRandaoMixesLength = U8192; @@ -108,4 +108,4 @@ impl BeaconStateTypes for LighthouseTestnetStateTypes { } } -pub type LighthouseTestnetBeaconState = BeaconState; +pub type LighthouseTestnetBeaconState = BeaconState; diff --git a/eth2/types/src/beacon_state/epoch_cache.rs b/eth2/types/src/beacon_state/epoch_cache.rs index 31becc5d3..c76c71684 100644 --- a/eth2/types/src/beacon_state/epoch_cache.rs +++ b/eth2/types/src/beacon_state/epoch_cache.rs @@ -28,7 +28,7 @@ pub struct EpochCache { impl EpochCache { /// Return a new, fully initialized cache. - pub fn initialized( + pub fn initialized( state: &BeaconState, relative_epoch: RelativeEpoch, spec: &ChainSpec, @@ -200,7 +200,7 @@ pub struct EpochCrosslinkCommitteesBuilder { impl EpochCrosslinkCommitteesBuilder { /// Instantiates a builder that will build for the `state`'s previous epoch. - pub fn for_previous_epoch( + pub fn for_previous_epoch( state: &BeaconState, active_validator_indices: Vec, spec: &ChainSpec, @@ -215,7 +215,7 @@ impl EpochCrosslinkCommitteesBuilder { } /// Instantiates a builder that will build for the `state`'s next epoch. - pub fn for_current_epoch( + pub fn for_current_epoch( state: &BeaconState, active_validator_indices: Vec, 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 /// change and one where there is not. - pub fn for_next_epoch( + pub fn for_next_epoch( state: &BeaconState, active_validator_indices: Vec, registry_change: bool, diff --git a/eth2/types/src/beacon_state/epoch_cache/tests.rs b/eth2/types/src/beacon_state/epoch_cache/tests.rs index 6ba7c9086..2a3034192 100644 --- a/eth2/types/src/beacon_state/epoch_cache/tests.rs +++ b/eth2/types/src/beacon_state/epoch_cache/tests.rs @@ -1,11 +1,11 @@ #![cfg(test)] use super::*; -use crate::beacon_state::FewValidatorsStateTypes; +use crate::beacon_state::FewValidatorsEthSpec; use crate::test_utils::*; use swap_or_not_shuffle::shuffle_list; -fn do_sane_cache_test( +fn do_sane_cache_test( state: BeaconState, epoch: Epoch, relative_epoch: RelativeEpoch, @@ -65,10 +65,7 @@ fn do_sane_cache_test( } } -fn setup_sane_cache_test( - validator_count: usize, - spec: &ChainSpec, -) -> BeaconState { +fn setup_sane_cache_test(validator_count: usize, spec: &ChainSpec) -> BeaconState { let mut builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, spec); @@ -102,11 +99,11 @@ fn setup_sane_cache_test( #[test] fn builds_sane_current_epoch_cache() { - let mut spec = FewValidatorsStateTypes::spec(); + let mut spec = FewValidatorsEthSpec::spec(); spec.shard_count = 4; let validator_count = (spec.shard_count * spec.target_committee_size) + 1; - let state: BeaconState = + let state: BeaconState = setup_sane_cache_test(validator_count as usize, &spec); do_sane_cache_test( @@ -122,11 +119,11 @@ fn builds_sane_current_epoch_cache() { #[test] fn builds_sane_previous_epoch_cache() { - let mut spec = FewValidatorsStateTypes::spec(); + let mut spec = FewValidatorsEthSpec::spec(); spec.shard_count = 2; let validator_count = (spec.shard_count * spec.target_committee_size) + 1; - let state: BeaconState = + let state: BeaconState = setup_sane_cache_test(validator_count as usize, &spec); do_sane_cache_test( @@ -142,11 +139,11 @@ fn builds_sane_previous_epoch_cache() { #[test] fn builds_sane_next_without_update_epoch_cache() { - let mut spec = FewValidatorsStateTypes::spec(); + let mut spec = FewValidatorsEthSpec::spec(); spec.shard_count = 2; let validator_count = (spec.shard_count * spec.target_committee_size) + 1; - let mut state: BeaconState = + let mut state: BeaconState = setup_sane_cache_test(validator_count as usize, &spec); state.validator_registry_update_epoch = state.slot.epoch(spec.slots_per_epoch); diff --git a/eth2/types/src/beacon_state/tests.rs b/eth2/types/src/beacon_state/tests.rs index 8948a94f6..aa3c0b98a 100644 --- a/eth2/types/src/beacon_state/tests.rs +++ b/eth2/types/src/beacon_state/tests.rs @@ -1,6 +1,6 @@ #![cfg(test)] use super::*; -use crate::beacon_state::FewValidatorsStateTypes; +use crate::beacon_state::FewValidatorsEthSpec; use crate::test_utils::*; ssz_tests!(FoundationBeaconState); @@ -11,7 +11,7 @@ cached_tree_hash_tests!(FoundationBeaconState); /// 1. Using the cache before it's built fails. /// 2. Using the cache after it's build passes. /// 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, relative_epoch: RelativeEpoch, spec: &ChainSpec, @@ -46,9 +46,9 @@ fn test_cache_initialization<'a, T: BeaconStateTypes>( #[test] fn cache_initialization() { - let spec = FewValidatorsStateTypes::spec(); + let spec = FewValidatorsEthSpec::spec(); - let builder: TestingBeaconStateBuilder = + let builder: TestingBeaconStateBuilder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec); let (mut state, _keypairs) = builder.build(); diff --git a/eth2/types/src/historical_batch.rs b/eth2/types/src/historical_batch.rs index ecd7aad89..d80838221 100644 --- a/eth2/types/src/historical_batch.rs +++ b/eth2/types/src/historical_batch.rs @@ -22,7 +22,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; CachedTreeHash, TestRandom, )] -pub struct HistoricalBatch { +pub struct HistoricalBatch { pub block_roots: FixedLenVec, pub state_roots: FixedLenVec, } @@ -31,7 +31,7 @@ pub struct HistoricalBatch { mod tests { use super::*; - pub type FoundationHistoricalBatch = HistoricalBatch; + pub type FoundationHistoricalBatch = HistoricalBatch; ssz_tests!(FoundationHistoricalBatch); cached_tree_hash_tests!(FoundationHistoricalBatch); diff --git a/eth2/types/src/test_utils/testing_attestation_builder.rs b/eth2/types/src/test_utils/testing_attestation_builder.rs index 2d9b5ac6f..0df1c01b8 100644 --- a/eth2/types/src/test_utils/testing_attestation_builder.rs +++ b/eth2/types/src/test_utils/testing_attestation_builder.rs @@ -12,7 +12,7 @@ pub struct TestingAttestationBuilder { impl TestingAttestationBuilder { /// Create a new attestation builder. - pub fn new( + pub fn new( state: &BeaconState, committee: &[usize], slot: Slot, diff --git a/eth2/types/src/test_utils/testing_attestation_data_builder.rs b/eth2/types/src/test_utils/testing_attestation_data_builder.rs index 9d6bc5ec6..fbe79df1e 100644 --- a/eth2/types/src/test_utils/testing_attestation_data_builder.rs +++ b/eth2/types/src/test_utils/testing_attestation_data_builder.rs @@ -10,7 +10,7 @@ pub struct TestingAttestationDataBuilder { impl TestingAttestationDataBuilder { /// Configures a new `AttestationData` which attests to all of the same parameters as the /// state. - pub fn new( + pub fn new( state: &BeaconState, shard: u64, slot: Slot, diff --git a/eth2/types/src/test_utils/testing_beacon_block_builder.rs b/eth2/types/src/test_utils/testing_beacon_block_builder.rs index a2ea65949..18f57c589 100644 --- a/eth2/types/src/test_utils/testing_beacon_block_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_block_builder.rs @@ -82,7 +82,7 @@ impl TestingBeaconBlockBuilder { /// /// Note: the signed messages of the split committees will be identical -- it would be possible /// to aggregate these split attestations. - pub fn insert_attestations( + pub fn insert_attestations( &mut self, state: &BeaconState, secret_keys: &[&SecretKey], @@ -171,7 +171,7 @@ impl TestingBeaconBlockBuilder { } /// Insert a `Valid` deposit into the state. - pub fn insert_deposit( + pub fn insert_deposit( &mut self, amount: u64, index: u64, @@ -193,7 +193,7 @@ impl TestingBeaconBlockBuilder { } /// Insert a `Valid` exit into the state. - pub fn insert_exit( + pub fn insert_exit( &mut self, state: &BeaconState, validator_index: u64, @@ -214,7 +214,7 @@ impl TestingBeaconBlockBuilder { /// /// Note: this will set the validator to be withdrawable by directly modifying the state /// validator registry. This _may_ cause problems historic hashes, etc. - pub fn insert_transfer( + pub fn insert_transfer( &mut self, state: &BeaconState, from: u64, diff --git a/eth2/types/src/test_utils/testing_beacon_state_builder.rs b/eth2/types/src/test_utils/testing_beacon_state_builder.rs index 67f23a44c..727b70d93 100644 --- a/eth2/types/src/test_utils/testing_beacon_state_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_state_builder.rs @@ -25,12 +25,12 @@ pub fn keypairs_path() -> PathBuf { /// /// This struct should **never be used for production purposes.** #[derive(Clone)] -pub struct TestingBeaconStateBuilder { +pub struct TestingBeaconStateBuilder { state: BeaconState, keypairs: Vec, } -impl TestingBeaconStateBuilder { +impl TestingBeaconStateBuilder { /// Attempts to load validators from a file in `$HOME/.lighthouse/keypairs.raw_keypairs`. If /// the file is unavailable, it generates the keys at runtime. /// diff --git a/eth2/types/src/test_utils/testing_pending_attestation_builder.rs b/eth2/types/src/test_utils/testing_pending_attestation_builder.rs index 330203448..023b039b0 100644 --- a/eth2/types/src/test_utils/testing_pending_attestation_builder.rs +++ b/eth2/types/src/test_utils/testing_pending_attestation_builder.rs @@ -16,7 +16,7 @@ impl TestingPendingAttestationBuilder { /// /// * The aggregation and custody bitfields will all be empty, they need to be set with /// `Self::add_committee_participation`. - pub fn new( + pub fn new( state: &BeaconState, shard: u64, slot: Slot, diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index 66e9f2391..1e9450d59 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -7,8 +7,7 @@ use std::fs::File; use std::io::{Error, ErrorKind}; use std::path::PathBuf; use types::{ - BeaconStateTypes, ChainSpec, FewValidatorsStateTypes, FoundationStateTypes, - LighthouseTestnetStateTypes, + ChainSpec, EthSpec, FewValidatorsEthSpec, FoundationEthSpec, LighthouseTestnetEthSpec, }; /// Stores the core configuration for this validator instance. @@ -34,7 +33,7 @@ impl Default for Config { let server = "localhost:5051".to_string(); - let spec = FoundationStateTypes::spec(); + let spec = FoundationEthSpec::spec(); Self { data_dir, @@ -68,9 +67,9 @@ impl Config { if let Some(spec_str) = args.value_of("spec") { info!(log, "Using custom spec: {:?}", spec_str); config.spec = match spec_str { - "foundation" => FoundationStateTypes::spec(), - "few_validators" => FewValidatorsStateTypes::spec(), - "lighthouse_testnet" => LighthouseTestnetStateTypes::spec(), + "foundation" => FoundationEthSpec::spec(), + "few_validators" => FewValidatorsEthSpec::spec(), + "lighthouse_testnet" => LighthouseTestnetEthSpec::spec(), // Should be impossible due to clap's `possible_values(..)` function. _ => unreachable!(), };