Trace comment on new block inclusion (#100)
This commit is contained in:
@@ -95,6 +95,7 @@ pub mod blocks {
|
||||
type Unverified = Unverified;
|
||||
type Verified = PreverifiedBlock;
|
||||
|
||||
// t_nb 4.0 verify_block_basic
|
||||
fn create(
|
||||
input: Self::Input,
|
||||
engine: &dyn EthEngine,
|
||||
@@ -113,6 +114,7 @@ pub mod blocks {
|
||||
}
|
||||
}
|
||||
|
||||
// t_nb 5.0 verify standalone block
|
||||
fn verify(
|
||||
un: Self::Unverified,
|
||||
engine: &dyn EthEngine,
|
||||
|
||||
@@ -364,7 +364,7 @@ impl<K: Kind> VerificationQueue<K> {
|
||||
}
|
||||
}
|
||||
|
||||
// do work.
|
||||
// do work on this item.
|
||||
let item = {
|
||||
// acquire these locks before getting the item to verify.
|
||||
let mut unverified = verification.unverified.lock();
|
||||
@@ -387,10 +387,12 @@ impl<K: Kind> VerificationQueue<K> {
|
||||
};
|
||||
|
||||
let hash = item.hash();
|
||||
// t_nb 5.0 verify standalone block (this verification is done in VerificationQueue thread pool)
|
||||
let is_ready = match K::verify(item, &*engine, verification.check_seal) {
|
||||
Ok(verified) => {
|
||||
let mut verifying = verification.verifying.lock();
|
||||
let mut idx = None;
|
||||
// find item again and remove it from verified queue
|
||||
for (i, e) in verifying.iter_mut().enumerate() {
|
||||
if e.hash == hash {
|
||||
idx = Some(i);
|
||||
@@ -515,17 +517,20 @@ impl<K: Kind> VerificationQueue<K> {
|
||||
}
|
||||
|
||||
/// Add a block to the queue.
|
||||
// t_nb 3.0 import block to verification queue
|
||||
pub fn import(&self, input: K::Input) -> Result<H256, (Option<K::Input>, Error)> {
|
||||
let hash = input.hash();
|
||||
let raw_hash = input.raw_hash();
|
||||
// t_nb 3.1 check if block is currently processing or marked as bad.
|
||||
{
|
||||
// t_nb 3.1.0 is currently processing
|
||||
if self.processing.read().contains_key(&hash) {
|
||||
bail!((
|
||||
Some(input),
|
||||
ErrorKind::Import(ImportErrorKind::AlreadyQueued).into()
|
||||
));
|
||||
}
|
||||
|
||||
// t_nb 3.1.1 is marked as bad
|
||||
let mut bad = self.verification.bad.lock();
|
||||
if bad.contains(&hash) || bad.contains(&raw_hash) {
|
||||
bail!((
|
||||
@@ -533,7 +538,7 @@ impl<K: Kind> VerificationQueue<K> {
|
||||
ErrorKind::Import(ImportErrorKind::KnownBad).into()
|
||||
));
|
||||
}
|
||||
|
||||
// t_nb 3.1.2 its parent is marked as bad
|
||||
if bad.contains(&input.parent_hash()) {
|
||||
bad.insert(hash);
|
||||
bail!((
|
||||
|
||||
@@ -63,26 +63,36 @@ impl HeapSizeOf for PreverifiedBlock {
|
||||
}
|
||||
}
|
||||
|
||||
/// Phase 1 quick block verification. Only does checks that are cheap. Operates on a single block
|
||||
// t_nb 4.0 Phase 1 quick block verification. Only does checks that are cheap. Operates on a single block
|
||||
pub fn verify_block_basic(
|
||||
block: &Unverified,
|
||||
engine: &dyn EthEngine,
|
||||
check_seal: bool,
|
||||
) -> Result<(), Error> {
|
||||
// t_nb 4.1 verify header params
|
||||
verify_header_params(&block.header, engine, true, check_seal)?;
|
||||
// t_nb 4.2 verify header time (addded in new OE version)
|
||||
// t_nb 4.3 verify block integrity
|
||||
verify_block_integrity(block)?;
|
||||
|
||||
if check_seal {
|
||||
// t_nb 4.4 Check block seal. It calls engine to verify block basic
|
||||
engine.verify_block_basic(&block.header)?;
|
||||
}
|
||||
|
||||
// t_nb 4.5 for all uncled verify header and call engine to verify block basic
|
||||
for uncle in &block.uncles {
|
||||
// t_nb 4.5.1
|
||||
verify_header_params(uncle, engine, false, check_seal)?;
|
||||
if check_seal {
|
||||
// t_nb 4.5.2
|
||||
engine.verify_block_basic(uncle)?;
|
||||
}
|
||||
}
|
||||
|
||||
// t_nb 4.6 call engine.gas_limit_override (Used only by Aura) TODO added in new version
|
||||
|
||||
// t_nb 4.7 for every transaction call engine.verify_transaction_basic
|
||||
for t in &block.transactions {
|
||||
engine.verify_transaction_basic(t, &block.header)?;
|
||||
}
|
||||
@@ -90,7 +100,7 @@ pub fn verify_block_basic(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Phase 2 verification. Perform costly checks such as transaction signatures and block nonce for ethash.
|
||||
// t_nb 5.0 Phase 2 verification. Perform costly checks such as transaction signatures and block nonce for ethash.
|
||||
/// Still operates on a individual block
|
||||
/// Returns a `PreverifiedBlock` structure populated with transactions
|
||||
pub fn verify_block_unordered(
|
||||
@@ -100,8 +110,10 @@ pub fn verify_block_unordered(
|
||||
) -> Result<PreverifiedBlock, Error> {
|
||||
let header = block.header;
|
||||
if check_seal {
|
||||
// t_nb 5.1
|
||||
engine.verify_block_unordered(&header)?;
|
||||
for uncle in &block.uncles {
|
||||
// t_nb 5.2
|
||||
engine.verify_block_unordered(uncle)?;
|
||||
}
|
||||
}
|
||||
@@ -112,11 +124,14 @@ pub fn verify_block_unordered(
|
||||
None
|
||||
};
|
||||
|
||||
// t_nb 5.3 iterate over all transactions
|
||||
let transactions = block
|
||||
.transactions
|
||||
.into_iter()
|
||||
.map(|t| {
|
||||
// t_nb 5.3.1 call verify_unordered. Check signatures and calculate address
|
||||
let t = engine.verify_transaction_unordered(t, &header)?;
|
||||
// t_nb 5.3.2 check if nonce is more then max nonce (EIP-168 and EIP169)
|
||||
if let Some(max_nonce) = nonce_cap {
|
||||
if t.nonce >= max_nonce {
|
||||
return Err(BlockError::TooManyTransactions(t.sender()).into());
|
||||
@@ -146,7 +161,7 @@ pub struct FullFamilyParams<'a, C: BlockInfo + CallContract + 'a> {
|
||||
pub client: &'a C,
|
||||
}
|
||||
|
||||
/// Phase 3 verification. Check block information against parent and uncles.
|
||||
// t_nb 6.3 Phase 3 verification. Check block information against parent and uncles.
|
||||
pub fn verify_block_family<C: BlockInfo + CallContract>(
|
||||
header: &Header,
|
||||
parent: &Header,
|
||||
@@ -154,6 +169,7 @@ pub fn verify_block_family<C: BlockInfo + CallContract>(
|
||||
do_full: Option<FullFamilyParams<C>>,
|
||||
) -> Result<(), Error> {
|
||||
// TODO: verify timestamp
|
||||
// t_nb 6.3.1 verify parent
|
||||
verify_parent(&header, &parent, engine)?;
|
||||
engine.verify_block_family(&header, &parent)?;
|
||||
|
||||
@@ -162,8 +178,10 @@ pub fn verify_block_family<C: BlockInfo + CallContract>(
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
// t_nb 6.3.2 verify uncles
|
||||
verify_uncles(params.block, params.block_provider, engine)?;
|
||||
|
||||
// t_nb 6.3.3 verify all transactions
|
||||
for tx in ¶ms.block.transactions {
|
||||
// transactions are verified against the parent header since the current
|
||||
// state wasn't available when the tx was created
|
||||
|
||||
Reference in New Issue
Block a user