Kintsugi on_merge_block tests (#2811)

* Start v1.1.5 updates

* Implement new payload creation logic

* Tidy, add comments

* Remove unused error enums

* Add validate payload for gossip

* Refactor validate_merge_block

* Split payload verification in per block processing

* Add execute_payload

* Tidy

* Tidy

* Start working on new fork choice tests

* Fix failing merge block test

* Skip block_lookup_failed test

* Fix failing terminal block test

* Fixes from self-review

* Address review comments
This commit is contained in:
Paul Hauner
2021-11-17 11:45:30 +11:00
parent 44a7b37ce3
commit 5f0fef2d1e
14 changed files with 585 additions and 271 deletions

View File

@@ -170,6 +170,11 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
self.insert_pow_blocks(next_block..=target_block)
}
pub fn drop_all_blocks(&mut self) {
self.blocks = <_>::default();
self.block_hashes = <_>::default();
}
pub fn insert_pow_blocks(
&mut self,
block_numbers: impl Iterator<Item = u64>,
@@ -211,12 +216,14 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
"block {} is already known, forking is not supported",
block.block_number()
));
} else if block.parent_hash() != Hash256::zero()
&& !self.blocks.contains_key(&block.parent_hash())
{
} else if block.block_number() != 0 && !self.blocks.contains_key(&block.parent_hash()) {
return Err(format!("parent block {:?} is unknown", block.parent_hash()));
}
self.insert_block_without_checks(block)
}
pub fn insert_block_without_checks(&mut self, block: Block<T>) -> Result<(), String> {
self.block_hashes
.insert(block.block_number(), block.block_hash());
self.blocks.insert(block.block_hash(), block);

View File

@@ -4,6 +4,7 @@ use crate::engine_api::http::JSONRPC_VERSION;
use crate::engine_api::ExecutePayloadResponseStatus;
use bytes::Bytes;
use environment::null_logger;
use execution_block_generator::{Block, PoWBlock};
use handle_rpc::handle_rpc;
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
use serde::{Deserialize, Serialize};
@@ -118,6 +119,40 @@ impl<T: EthSpec> MockServer<T> {
pub fn all_payloads_valid(&self) {
*self.ctx.static_execute_payload_response.lock() = Some(ExecutePayloadResponseStatus::Valid)
}
pub fn insert_pow_block(
&self,
block_number: u64,
block_hash: Hash256,
parent_hash: Hash256,
total_difficulty: Uint256,
) {
let block = Block::PoW(PoWBlock {
block_number,
block_hash,
parent_hash,
total_difficulty,
});
self.ctx
.execution_block_generator
.write()
// The EF tests supply blocks out of order, so we must import them "without checks" and
// trust they form valid chains.
.insert_block_without_checks(block)
.unwrap()
}
pub fn get_block(&self, block_hash: Hash256) -> Option<Block<T>> {
self.ctx
.execution_block_generator
.read()
.block_by_hash(block_hash)
}
pub fn drop_all_blocks(&self) {
self.ctx.execution_block_generator.write().drop_all_blocks()
}
}
#[derive(Debug)]