mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Altair consensus changes and refactors (#2279)
## Proposed Changes Implement the consensus changes necessary for the upcoming Altair hard fork. ## Additional Info This is quite a heavy refactor, with pivotal types like the `BeaconState` and `BeaconBlock` changing from structs to enums. This ripples through the whole codebase with field accesses changing to methods, e.g. `state.slot` => `state.slot()`. Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -23,11 +23,9 @@ use sensitive_url::SensitiveUrl;
|
||||
use slot_clock::SlotClock;
|
||||
use state_processing::per_slot_processing;
|
||||
use std::convert::TryInto;
|
||||
use std::iter::Iterator;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tokio::time::Duration;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
@@ -77,6 +75,7 @@ impl ApiTester {
|
||||
pub fn new() -> Self {
|
||||
let mut harness = BeaconChainHarness::new(
|
||||
MainnetEthSpec,
|
||||
None,
|
||||
generate_deterministic_keypairs(VALIDATOR_COUNT),
|
||||
);
|
||||
|
||||
@@ -189,6 +188,7 @@ impl ApiTester {
|
||||
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
|
||||
listen_port: 0,
|
||||
allow_origin: None,
|
||||
serve_legacy_spec: true,
|
||||
},
|
||||
chain: Some(chain.clone()),
|
||||
network_tx: Some(network_tx),
|
||||
@@ -235,6 +235,7 @@ impl ApiTester {
|
||||
pub fn new_from_genesis() -> Self {
|
||||
let harness = BeaconChainHarness::new(
|
||||
MainnetEthSpec,
|
||||
None,
|
||||
generate_deterministic_keypairs(VALIDATOR_COUNT),
|
||||
);
|
||||
|
||||
@@ -301,6 +302,7 @@ impl ApiTester {
|
||||
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
|
||||
listen_port: 0,
|
||||
allow_origin: None,
|
||||
serve_legacy_spec: true,
|
||||
},
|
||||
chain: Some(chain.clone()),
|
||||
network_tx: Some(network_tx),
|
||||
@@ -445,8 +447,8 @@ impl ApiTester {
|
||||
|
||||
let state = self.chain.head().unwrap().beacon_state;
|
||||
let expected = GenesisData {
|
||||
genesis_time: state.genesis_time,
|
||||
genesis_validators_root: state.genesis_validators_root,
|
||||
genesis_time: state.genesis_time(),
|
||||
genesis_validators_root: state.genesis_validators_root(),
|
||||
genesis_fork_version: self.chain.spec.genesis_fork_version,
|
||||
};
|
||||
|
||||
@@ -508,7 +510,7 @@ impl ApiTester {
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
|
||||
let expected = self.get_state(state_id).map(|state| state.fork);
|
||||
let expected = self.get_state(state_id).map(|state| state.fork());
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
@@ -528,9 +530,9 @@ impl ApiTester {
|
||||
let expected = self
|
||||
.get_state(state_id)
|
||||
.map(|state| FinalityCheckpointsData {
|
||||
previous_justified: state.previous_justified_checkpoint,
|
||||
current_justified: state.current_justified_checkpoint,
|
||||
finalized: state.finalized_checkpoint,
|
||||
previous_justified: state.previous_justified_checkpoint(),
|
||||
current_justified: state.current_justified_checkpoint(),
|
||||
finalized: state.finalized_checkpoint(),
|
||||
});
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
@@ -544,7 +546,7 @@ impl ApiTester {
|
||||
for validator_indices in self.interesting_validator_indices() {
|
||||
let state_opt = self.get_state(state_id);
|
||||
let validators: Vec<Validator> = match state_opt.as_ref() {
|
||||
Some(state) => state.validators.clone().into(),
|
||||
Some(state) => state.validators().clone().into(),
|
||||
None => vec![],
|
||||
};
|
||||
let validator_index_ids = validator_indices
|
||||
@@ -587,10 +589,10 @@ impl ApiTester {
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
|
||||
for i in validator_indices {
|
||||
if i < state.balances.len() as u64 {
|
||||
if i < state.balances().len() as u64 {
|
||||
validators.push(ValidatorBalanceData {
|
||||
index: i as u64,
|
||||
balance: state.balances[i as usize],
|
||||
balance: state.balances()[i as usize],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -612,7 +614,7 @@ impl ApiTester {
|
||||
for validator_indices in self.interesting_validator_indices() {
|
||||
let state_opt = self.get_state(state_id);
|
||||
let validators: Vec<Validator> = match state_opt.as_ref() {
|
||||
Some(state) => state.validators.clone().into(),
|
||||
Some(state) => state.validators().clone().into(),
|
||||
None => vec![],
|
||||
};
|
||||
let validator_index_ids = validator_indices
|
||||
@@ -661,10 +663,10 @@ impl ApiTester {
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
|
||||
for i in validator_indices {
|
||||
if i >= state.validators.len() as u64 {
|
||||
if i >= state.validators().len() as u64 {
|
||||
continue;
|
||||
}
|
||||
let validator = state.validators[i as usize].clone();
|
||||
let validator = state.validators()[i as usize].clone();
|
||||
let status = ValidatorStatus::from_validator(
|
||||
&validator,
|
||||
epoch,
|
||||
@@ -676,7 +678,7 @@ impl ApiTester {
|
||||
{
|
||||
validators.push(ValidatorData {
|
||||
index: i as u64,
|
||||
balance: state.balances[i as usize],
|
||||
balance: state.balances()[i as usize],
|
||||
status,
|
||||
validator,
|
||||
});
|
||||
@@ -699,7 +701,7 @@ impl ApiTester {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let state_opt = self.get_state(state_id);
|
||||
let validators = match state_opt.as_ref() {
|
||||
Some(state) => state.validators.clone().into(),
|
||||
Some(state) => state.validators().clone().into(),
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
@@ -729,7 +731,7 @@ impl ApiTester {
|
||||
|
||||
ValidatorData {
|
||||
index: i as u64,
|
||||
balance: state.balances[i],
|
||||
balance: state.balances()[i],
|
||||
status: ValidatorStatus::from_validator(
|
||||
&validator,
|
||||
epoch,
|
||||
@@ -846,8 +848,8 @@ impl ApiTester {
|
||||
root,
|
||||
canonical: true,
|
||||
header: BlockHeaderAndSignature {
|
||||
message: block.message.block_header(),
|
||||
signature: block.signature.into(),
|
||||
message: block.message().block_header(),
|
||||
signature: block.signature().clone().into(),
|
||||
},
|
||||
};
|
||||
let expected = vec![header];
|
||||
@@ -927,13 +929,13 @@ impl ApiTester {
|
||||
assert_eq!(result.root, block_root, "{:?}", block_id);
|
||||
assert_eq!(
|
||||
result.header.message,
|
||||
block.message.block_header(),
|
||||
block.message().block_header(),
|
||||
"{:?}",
|
||||
block_id
|
||||
);
|
||||
assert_eq!(
|
||||
result.header.signature,
|
||||
block.signature.into(),
|
||||
block.signature().clone().into(),
|
||||
"{:?}",
|
||||
block_id
|
||||
);
|
||||
@@ -980,7 +982,7 @@ impl ApiTester {
|
||||
|
||||
pub async fn test_post_beacon_blocks_invalid(mut self) -> Self {
|
||||
let mut next_block = self.next_block.clone();
|
||||
next_block.message.proposer_index += 1;
|
||||
*next_block.message_mut().proposer_index_mut() += 1;
|
||||
|
||||
assert!(self.client.post_beacon_blocks(&next_block).await.is_err());
|
||||
|
||||
@@ -1012,7 +1014,11 @@ impl ApiTester {
|
||||
.map(|res| res.data);
|
||||
assert_eq!(json_result, expected, "{:?}", block_id);
|
||||
|
||||
let ssz_result = self.client.get_beacon_blocks_ssz(block_id).await.unwrap();
|
||||
let ssz_result = self
|
||||
.client
|
||||
.get_beacon_blocks_ssz(block_id, &self.chain.spec)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(ssz_result, expected, "{:?}", block_id);
|
||||
}
|
||||
|
||||
@@ -1030,7 +1036,7 @@ impl ApiTester {
|
||||
|
||||
let expected = self
|
||||
.get_block(block_id)
|
||||
.map(|block| block.message.body.attestations.into());
|
||||
.map(|block| block.message().body().attestations().clone().into());
|
||||
|
||||
if let BlockId::Slot(slot) = block_id {
|
||||
if expected.is_none() {
|
||||
@@ -1264,7 +1270,8 @@ impl ApiTester {
|
||||
pub async fn test_get_config_spec(self) -> Self {
|
||||
let result = self.client.get_config_spec().await.unwrap().data;
|
||||
|
||||
let expected = YamlConfig::from_spec::<E>(&self.chain.spec);
|
||||
let mut expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec);
|
||||
expected.make_backwards_compat(&self.chain.spec);
|
||||
|
||||
assert_eq!(result, expected);
|
||||
|
||||
@@ -1432,7 +1439,7 @@ impl ApiTester {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let result_ssz = self
|
||||
.client
|
||||
.get_debug_beacon_states_ssz(state_id)
|
||||
.get_debug_beacon_states_ssz(state_id, &self.chain.spec)
|
||||
.await
|
||||
.unwrap();
|
||||
let result_json = self
|
||||
@@ -1471,7 +1478,7 @@ impl ApiTester {
|
||||
}
|
||||
|
||||
fn validator_count(&self) -> usize {
|
||||
self.chain.head().unwrap().beacon_state.validators.len()
|
||||
self.chain.head().unwrap().beacon_state.validators().len()
|
||||
}
|
||||
|
||||
fn interesting_validator_indices(&self) -> Vec<Vec<u64>> {
|
||||
@@ -1575,7 +1582,7 @@ impl ApiTester {
|
||||
|
||||
let expected_len = indices
|
||||
.iter()
|
||||
.filter(|i| **i < state.validators.len() as u64)
|
||||
.filter(|i| **i < state.validators().len() as u64)
|
||||
.count();
|
||||
|
||||
assert_eq!(result_duties.len(), expected_len);
|
||||
@@ -1586,7 +1593,7 @@ impl ApiTester {
|
||||
.unwrap()
|
||||
{
|
||||
let expected = AttesterData {
|
||||
pubkey: state.validators[i as usize].pubkey.clone().into(),
|
||||
pubkey: state.validators()[i as usize].pubkey.clone().into(),
|
||||
validator_index: i,
|
||||
committees_at_slot: duty.committees_at_slot,
|
||||
committee_index: duty.index,
|
||||
@@ -1691,7 +1698,7 @@ impl ApiTester {
|
||||
let index = state
|
||||
.get_beacon_proposer_index(slot, &self.chain.spec)
|
||||
.unwrap();
|
||||
let pubkey = state.validators[index].pubkey.clone().into();
|
||||
let pubkey = state.validators()[index].pubkey.clone().into();
|
||||
|
||||
ProposerData {
|
||||
pubkey,
|
||||
@@ -1849,7 +1856,7 @@ impl ApiTester {
|
||||
|
||||
pub async fn test_get_validator_attestation_data(self) -> Self {
|
||||
let mut state = self.chain.head_beacon_state().unwrap();
|
||||
let slot = state.slot;
|
||||
let slot = state.slot();
|
||||
state
|
||||
.build_committee_cache(RelativeEpoch::Current, &self.chain.spec)
|
||||
.unwrap();
|
||||
@@ -1879,9 +1886,9 @@ impl ApiTester {
|
||||
.chain
|
||||
.head_beacon_block()
|
||||
.unwrap()
|
||||
.message
|
||||
.body
|
||||
.attestations[0]
|
||||
.message()
|
||||
.body()
|
||||
.attestations()[0]
|
||||
.clone();
|
||||
|
||||
let result = self
|
||||
@@ -1915,7 +1922,7 @@ impl ApiTester {
|
||||
.unwrap();
|
||||
|
||||
let committee_len = head.beacon_state.get_committee_count_at_slot(slot).unwrap();
|
||||
let fork = head.beacon_state.fork;
|
||||
let fork = head.beacon_state.fork();
|
||||
let genesis_validators_root = self.chain.genesis_validators_root;
|
||||
|
||||
let duties = self
|
||||
@@ -2118,7 +2125,7 @@ impl ApiTester {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let result = self
|
||||
.client
|
||||
.get_lighthouse_beacon_states_ssz(&state_id)
|
||||
.get_lighthouse_beacon_states_ssz(&state_id, &self.chain.spec)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user