mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 06:18:31 +00:00
Make eth1 caching work with fast synced node (#709)
* Add functions to get deposit_count and deposit_root from deposit cache
* Fetch deposit root and deposit count from cache
* Fix bugs
* Add test
* Compare deposit_count between the caching and http eth1 blocks
* Revert "Compare deposit_count between the caching and http eth1 blocks"
This reverts commit e3d0325ae6.
* Fetch deposit cache using binary search instead of linear search
* BlockCache waits till DepositCache is in sync
* Truncate required_blocks in block_cache upto latest_processed_block in deposit cache
* Clean up
* Handled getting deposit count before deploying deposit contract
* More cleanup
* Remove calls to http get deposit/count
* Fix block cache tests
* Minor changes
* Fix bootnode ports
* Address some of Paul's comments
* Optimize `get_deposit_root` by caching `DepositDataTree`
* Fix comments and minor changes
* Change eth1 default config parameters
* Use `Vec` instead of `HashMap` to store `deposit_roots`
* Minor renaming
This commit is contained in:
committed by
Paul Hauner
parent
251aea645c
commit
74b327b50d
@@ -133,7 +133,7 @@ mod auto_update {
|
||||
|
||||
// NOTE: this test is sensitive to the response speed of the external web3 server. If
|
||||
// you're experiencing failures, try increasing the update_interval.
|
||||
let update_interval = Duration::from_millis(2_000);
|
||||
let update_interval = Duration::from_millis(3000);
|
||||
|
||||
assert_eq!(
|
||||
service.block_cache_len(),
|
||||
@@ -235,9 +235,12 @@ mod eth1_cache {
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
runtime
|
||||
.block_on(service.update_deposit_cache())
|
||||
.expect("should update deposit cache");
|
||||
runtime
|
||||
.block_on(service.update_block_cache())
|
||||
.expect("should update cache");
|
||||
.expect("should update block cache");
|
||||
|
||||
runtime
|
||||
.block_on(service.update_block_cache())
|
||||
@@ -294,9 +297,12 @@ mod eth1_cache {
|
||||
.expect("should mine block")
|
||||
}
|
||||
|
||||
runtime
|
||||
.block_on(service.update_deposit_cache())
|
||||
.expect("should update deposit cache");
|
||||
runtime
|
||||
.block_on(service.update_block_cache())
|
||||
.expect("should update cache");
|
||||
.expect("should update block cache");
|
||||
|
||||
assert_eq!(
|
||||
service.block_cache_len(),
|
||||
@@ -339,9 +345,12 @@ mod eth1_cache {
|
||||
.block_on(eth1.ganache.evm_mine())
|
||||
.expect("should mine block")
|
||||
}
|
||||
runtime
|
||||
.block_on(service.update_deposit_cache())
|
||||
.expect("should update deposit cache");
|
||||
runtime
|
||||
.block_on(service.update_block_cache())
|
||||
.expect("should update cache");
|
||||
.expect("should update block cache");
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
@@ -381,14 +390,20 @@ mod eth1_cache {
|
||||
.block_on(eth1.ganache.evm_mine())
|
||||
.expect("should mine block")
|
||||
}
|
||||
|
||||
runtime
|
||||
.block_on(
|
||||
service
|
||||
.update_deposit_cache()
|
||||
.join(service.update_deposit_cache()),
|
||||
)
|
||||
.expect("should perform two simultaneous updates of deposit cache");
|
||||
runtime
|
||||
.block_on(
|
||||
service
|
||||
.update_block_cache()
|
||||
.join(service.update_block_cache()),
|
||||
)
|
||||
.expect("should perform two simultaneous updates");
|
||||
.expect("should perform two simultaneous updates of block cache");
|
||||
|
||||
assert!(service.block_cache_len() >= n, "should grow the cache");
|
||||
}
|
||||
@@ -711,3 +726,80 @@ mod http {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod fast {
|
||||
use super::*;
|
||||
|
||||
// Adds deposits into deposit cache and matches deposit_count and deposit_root
|
||||
// with the deposit count and root computed from the deposit cache.
|
||||
#[test]
|
||||
fn deposit_cache_query() {
|
||||
let mut env = new_env();
|
||||
let log = env.core_context().log;
|
||||
let runtime = env.runtime();
|
||||
|
||||
let eth1 = runtime
|
||||
.block_on(GanacheEth1Instance::new())
|
||||
.expect("should start eth1 environment");
|
||||
let deposit_contract = ð1.deposit_contract;
|
||||
let web3 = eth1.web3();
|
||||
|
||||
let now = get_block_number(runtime, &web3);
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoint: eth1.endpoint(),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
deposit_contract_deploy_block: now,
|
||||
lowest_cached_block_number: now,
|
||||
follow_distance: 0,
|
||||
block_cache_truncation: None,
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
);
|
||||
let n = 10;
|
||||
let deposits: Vec<_> = (0..n).into_iter().map(|_| random_deposit_data()).collect();
|
||||
for deposit in &deposits {
|
||||
deposit_contract
|
||||
.deposit(runtime, deposit.clone())
|
||||
.expect("should perform a deposit");
|
||||
// Mine an extra block between deposits to test for corner cases
|
||||
runtime
|
||||
.block_on(eth1.ganache.evm_mine())
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
runtime
|
||||
.block_on(service.update_deposit_cache())
|
||||
.expect("should perform update");
|
||||
|
||||
assert!(
|
||||
service.deposit_cache_len() >= n,
|
||||
"should have imported n deposits"
|
||||
);
|
||||
|
||||
for block_num in 0..=get_block_number(runtime, &web3) {
|
||||
let expected_deposit_count = blocking_deposit_count(runtime, ð1, block_num);
|
||||
let expected_deposit_root = blocking_deposit_root(runtime, ð1, block_num);
|
||||
|
||||
let deposit_count = service
|
||||
.deposits()
|
||||
.read()
|
||||
.cache
|
||||
.get_deposit_count_from_cache(block_num);
|
||||
let deposit_root = service
|
||||
.deposits()
|
||||
.read()
|
||||
.cache
|
||||
.get_deposit_root_from_cache(block_num);
|
||||
assert_eq!(
|
||||
expected_deposit_count, deposit_count,
|
||||
"deposit count from cache should match queried"
|
||||
);
|
||||
assert_eq!(
|
||||
expected_deposit_root, deposit_root,
|
||||
"deposit root from cache should match queried"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user