mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
This commit syncs Prater
This commit is contained in:
@@ -92,3 +92,6 @@ eth2_ssz = { path = "consensus/ssz" }
|
|||||||
eth2_ssz_types = { path = "consensus/ssz_types" }
|
eth2_ssz_types = { path = "consensus/ssz_types" }
|
||||||
tree_hash = { path = "consensus/tree_hash" }
|
tree_hash = { path = "consensus/tree_hash" }
|
||||||
eth2_serde_utils = { path = "consensus/serde_utils" }
|
eth2_serde_utils = { path = "consensus/serde_utils" }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = 1
|
||||||
|
|||||||
@@ -417,6 +417,12 @@ where
|
|||||||
let (_, updated_builder) = self.set_genesis_state(genesis_state)?;
|
let (_, updated_builder) = self.set_genesis_state(genesis_state)?;
|
||||||
self = updated_builder;
|
self = updated_builder;
|
||||||
|
|
||||||
|
// Build the committee caches before storing. The database assumes that states have
|
||||||
|
// committee caches built before storing.
|
||||||
|
weak_subj_state
|
||||||
|
.build_all_committee_caches(&self.spec)
|
||||||
|
.map_err(|e| format!("Error building caches on checkpoint state: {:?}", e))?;
|
||||||
|
|
||||||
// Write the state and block non-atomically, it doesn't matter if they're forgotten
|
// Write the state and block non-atomically, it doesn't matter if they're forgotten
|
||||||
// about on a crash restart.
|
// about on a crash restart.
|
||||||
store
|
store
|
||||||
|
|||||||
@@ -111,12 +111,11 @@ impl<T: BeaconChainTypes> ValidatorPubkeyCache<T> {
|
|||||||
state: &BeaconState<T::EthSpec>,
|
state: &BeaconState<T::EthSpec>,
|
||||||
) -> Result<(), BeaconChainError> {
|
) -> Result<(), BeaconChainError> {
|
||||||
if state.validators().len() > self.pubkeys.len() {
|
if state.validators().len() > self.pubkeys.len() {
|
||||||
// FIXME(sproul): iter_from would be more efficient than `skip` here
|
|
||||||
self.import(
|
self.import(
|
||||||
state
|
state
|
||||||
.validators()
|
.validators()
|
||||||
.iter()
|
.iter_from(self.pubkeys.len())
|
||||||
.skip(self.pubkeys.len())
|
.unwrap() // FIXME(sproul)
|
||||||
.map(|v| v.pubkey),
|
.map(|v| v.pubkey),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -827,11 +827,13 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
sync_committee: &SyncCommittee<T>,
|
sync_committee: &SyncCommittee<T>,
|
||||||
) -> Result<Vec<usize>, Error> {
|
) -> Result<Vec<usize>, Error> {
|
||||||
|
self.update_pubkey_cache()?;
|
||||||
sync_committee
|
sync_committee
|
||||||
.pubkeys
|
.pubkeys
|
||||||
.iter()
|
.iter()
|
||||||
.map(|pubkey| {
|
.map(|pubkey| {
|
||||||
self.get_validator_index(pubkey)?
|
self.pubkey_cache()
|
||||||
|
.get(pubkey)
|
||||||
.ok_or(Error::PubkeyCacheInconsistent)
|
.ok_or(Error::PubkeyCacheInconsistent)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@@ -1650,13 +1652,11 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
/// never re-add a pubkey.
|
/// never re-add a pubkey.
|
||||||
pub fn update_pubkey_cache(&mut self) -> Result<(), Error> {
|
pub fn update_pubkey_cache(&mut self) -> Result<(), Error> {
|
||||||
let mut pubkey_cache = mem::take(self.pubkey_cache_mut());
|
let mut pubkey_cache = mem::take(self.pubkey_cache_mut());
|
||||||
for (i, validator) in self
|
let start_index = pubkey_cache.len();
|
||||||
.validators()
|
|
||||||
.iter()
|
for (i, validator) in self.validators().iter_from(start_index)?.enumerate() {
|
||||||
.enumerate()
|
let index = start_index.safe_add(i)?;
|
||||||
.skip(pubkey_cache.len())
|
let success = pubkey_cache.insert(validator.pubkey, index);
|
||||||
{
|
|
||||||
let success = pubkey_cache.insert(validator.pubkey, i);
|
|
||||||
if !success {
|
if !success {
|
||||||
return Err(Error::PubkeyCacheInconsistent);
|
return Err(Error::PubkeyCacheInconsistent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
[features]
|
[features]
|
||||||
portable = ["bls/supranational-portable"]
|
portable = ["bls/supranational-portable"]
|
||||||
fake_crypto = ['bls/fake_crypto']
|
fake_crypto = ['bls/fake_crypto']
|
||||||
|
tree-states = ["store/milhouse"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bls = { path = "../crypto/bls" }
|
bls = { path = "../crypto/bls" }
|
||||||
@@ -37,3 +38,4 @@ web3 = { version = "0.17.0", default-features = false, features = ["http-tls", "
|
|||||||
eth1_test_rig = { path = "../testing/eth1_test_rig" }
|
eth1_test_rig = { path = "../testing/eth1_test_rig" }
|
||||||
sensitive_url = { path = "../common/sensitive_url" }
|
sensitive_url = { path = "../common/sensitive_url" }
|
||||||
eth2 = { path = "../common/eth2" }
|
eth2 = { path = "../common/eth2" }
|
||||||
|
store = { path = "../beacon_node/store" }
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
|
|||||||
|
|
||||||
let mut deposit_tree = DepositDataTree::create(&[], 0, DEPOSIT_TREE_DEPTH);
|
let mut deposit_tree = DepositDataTree::create(&[], 0, DEPOSIT_TREE_DEPTH);
|
||||||
let mut deposit_root = Hash256::zero();
|
let mut deposit_root = Hash256::zero();
|
||||||
for (index, validator) in state.validators_mut().iter_mut().enumerate() {
|
let mut validators = state.validators_mut();
|
||||||
|
for index in 0..validators.len() {
|
||||||
let (secret, _) =
|
let (secret, _) =
|
||||||
recover_validator_secret_from_mnemonic(seed.as_bytes(), index as u32, KeyType::Voting)
|
recover_validator_secret_from_mnemonic(seed.as_bytes(), index as u32, KeyType::Voting)
|
||||||
.map_err(|e| format!("Unable to generate validator key: {:?}", e))?;
|
.map_err(|e| format!("Unable to generate validator key: {:?}", e))?;
|
||||||
@@ -52,11 +53,11 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
|
|||||||
|
|
||||||
eprintln!("{}: {}", index, keypair.pk);
|
eprintln!("{}: {}", index, keypair.pk);
|
||||||
|
|
||||||
validator.pubkey = keypair.pk.into();
|
validators.get_mut(index).unwrap().pubkey = keypair.pk.into();
|
||||||
|
|
||||||
// Update the deposit tree.
|
// Update the deposit tree.
|
||||||
let mut deposit_data = DepositData {
|
let mut deposit_data = DepositData {
|
||||||
pubkey: validator.pubkey,
|
pubkey: validators.get(index).unwrap().pubkey,
|
||||||
// Set this to a junk value since it's very time consuming to generate the withdrawal
|
// Set this to a junk value since it's very time consuming to generate the withdrawal
|
||||||
// keys and it's not useful for the time being.
|
// keys and it's not useful for the time being.
|
||||||
withdrawal_credentials: Hash256::zero(),
|
withdrawal_credentials: Hash256::zero(),
|
||||||
@@ -69,6 +70,7 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
|
|||||||
.map_err(|e| format!("failed to create deposit tree: {:?}", e))?;
|
.map_err(|e| format!("failed to create deposit tree: {:?}", e))?;
|
||||||
deposit_root = deposit_tree.root();
|
deposit_root = deposit_tree.root();
|
||||||
}
|
}
|
||||||
|
drop(validators);
|
||||||
|
|
||||||
// Update the genesis validators root since we changed the validators.
|
// Update the genesis validators root since we changed the validators.
|
||||||
*state.genesis_validators_root_mut() = state.validators().tree_hash_root();
|
*state.genesis_validators_root_mut() = state.validators().tree_hash_root();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub fn run_transition_blocks<T: EthSpec>(
|
|||||||
let block: SignedBeaconBlock<T> =
|
let block: SignedBeaconBlock<T> =
|
||||||
load_from_ssz_with(&block_path, spec, SignedBeaconBlock::from_ssz_bytes)?;
|
load_from_ssz_with(&block_path, spec, SignedBeaconBlock::from_ssz_bytes)?;
|
||||||
|
|
||||||
let post_state = do_transition(pre_state, block, spec)?;
|
let post_state = do_transition(pre_state.clone(), block, spec)?;
|
||||||
|
|
||||||
let mut output_file =
|
let mut output_file =
|
||||||
File::create(output_path).map_err(|e| format!("Unable to create output file: {:?}", e))?;
|
File::create(output_path).map_err(|e| format!("Unable to create output file: {:?}", e))?;
|
||||||
@@ -52,6 +52,9 @@ pub fn run_transition_blocks<T: EthSpec>(
|
|||||||
.write_all(&post_state.as_ssz_bytes())
|
.write_all(&post_state.as_ssz_bytes())
|
||||||
.map_err(|e| format!("Unable to write to output file: {:?}", e))?;
|
.map_err(|e| format!("Unable to write to output file: {:?}", e))?;
|
||||||
|
|
||||||
|
drop(pre_state);
|
||||||
|
drop(post_state);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user