Cache deposit signature verification (#1298)

* Bake in Altona testnet (without genesis state)

* Add sig verification, without optimization

* Start integration with genesis service

* Update config.yml

* Fix eth2_testnet_config test

* Stop using default spec in genesis

* Fix lcli compile error

* Update min genesis time

* Fix typo
This commit is contained in:
Paul Hauner
2020-06-26 11:43:06 +10:00
committed by GitHub
parent e3d9832fee
commit e0e41fc8e5
11 changed files with 195 additions and 71 deletions

View File

@@ -43,7 +43,7 @@ impl Eth1GenesisService {
/// Creates a new service. Does not attempt to connect to the Eth1 node.
///
/// Modifies the given `config` to make it more suitable to the task of listening to genesis.
pub fn new(config: Eth1Config, log: Logger) -> Self {
pub fn new(config: Eth1Config, log: Logger, spec: ChainSpec) -> Self {
let config = Eth1Config {
// Truncating the block cache makes searching for genesis more
// complicated.
@@ -65,7 +65,7 @@ impl Eth1GenesisService {
};
Self {
eth1_service: Eth1Service::new(config, log),
eth1_service: Eth1Service::new(config, log, spec),
stats: Arc::new(Statistics {
highest_processed_block: AtomicU64::new(0),
active_validator_count: AtomicUsize::new(0),
@@ -161,7 +161,7 @@ impl Eth1GenesisService {
log,
"Imported eth1 blocks";
"latest_block_timestamp" => eth1_service.latest_block_timestamp(),
"cache_head" => self.highest_safe_block(),
"cache_head" => eth1_service.highest_safe_block(),
"count" => outcome.blocks_imported,
);
outcome.blocks_imported
@@ -205,8 +205,9 @@ impl Eth1GenesisService {
log,
"Waiting for more validators";
"min_genesis_active_validators" => spec.min_genesis_active_validator_count,
"total_deposits" => total_deposit_count,
"active_validators" => active_validator_count,
"total_deposits" => total_deposit_count,
"valid_deposits" => eth1_service.get_valid_signature_count().unwrap_or(0),
);
}
} else {
@@ -255,7 +256,10 @@ impl Eth1GenesisService {
//
// Don't update the highest processed block since we want to come back and process this
// again later.
if self.highest_safe_block().map_or(true, |n| block.number > n) {
if eth1_service
.highest_safe_block()
.map_or(true, |n| block.number > n)
{
continue;
}
@@ -287,6 +291,21 @@ impl Eth1GenesisService {
continue;
}
let valid_signature_count = eth1_service
.get_valid_signature_count_at_block(block.number)
.unwrap_or(0);
if (valid_signature_count as u64) < spec.min_genesis_active_validator_count {
trace!(
log,
"Insufficient valid signatures";
"genesis_delay" => spec.genesis_delay,
"valid_signature_count" => valid_signature_count,
"min_validator_count" => spec.min_genesis_active_validator_count,
"eth1_block_number" => block.number,
);
continue;
}
// Generate a potential beacon state for this eth1 block.
//
// Note: this state is fully valid, some fields have been bypassed to make verification
@@ -416,14 +435,6 @@ impl Eth1GenesisService {
Ok(state)
}
/// Returns the highest block that is present in both the deposit and block caches.
fn highest_safe_block(&self) -> Option<u64> {
let block_cache = self.eth1_service.blocks().read().highest_block_number()?;
let deposit_cache = self.eth1_service.deposits().read().last_processed_block?;
Some(std::cmp::min(block_cache, deposit_cache))
}
/// Returns all deposit logs included in `block_number` and all prior blocks.
fn deposit_logs_at_block(&self, block_number: u64) -> Vec<DepositLog> {
self.eth1_service

View File

@@ -53,6 +53,7 @@ fn basic() {
..Eth1Config::default()
},
log,
spec.clone(),
);
// NOTE: this test is sensitive to the response speed of the external web3 server. If