mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
explicitly handle the header when processing blocks (#1600)
This commit is contained in:
parent
4b0fdc2499
commit
5a83989cf6
1 changed files with 17 additions and 12 deletions
|
@ -93,10 +93,6 @@ pub fn process_block(
|
||||||
let txhashset = ctx.txhashset.clone();
|
let txhashset = ctx.txhashset.clone();
|
||||||
let mut txhashset = txhashset.write().unwrap();
|
let mut txhashset = txhashset.write().unwrap();
|
||||||
|
|
||||||
// TODO - Do we actually need this? We don't this for block_headers
|
|
||||||
// Update head now that we are in the lock.
|
|
||||||
// ctx.head = ctx.store.head()?;
|
|
||||||
|
|
||||||
// Fast in-memory checks to avoid re-processing a block we recently processed.
|
// Fast in-memory checks to avoid re-processing a block we recently processed.
|
||||||
{
|
{
|
||||||
// Check if we have recently processed this block (via ctx chain head).
|
// Check if we have recently processed this block (via ctx chain head).
|
||||||
|
@ -109,8 +105,8 @@ pub fn process_block(
|
||||||
check_known_orphans(&b.header, ctx)?;
|
check_known_orphans(&b.header, ctx)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check our header itself is actually valid before proceeding any further.
|
// Header specific processing.
|
||||||
validate_header(&b.header, ctx, batch)?;
|
handle_block_header(&b.header, ctx, batch)?;
|
||||||
|
|
||||||
// Check if are processing the "next" block relative to the current chain head.
|
// Check if are processing the "next" block relative to the current chain head.
|
||||||
if is_next_block(&b.header, ctx) {
|
if is_next_block(&b.header, ctx) {
|
||||||
|
@ -223,12 +219,7 @@ pub fn sync_block_headers(
|
||||||
let mut tip = batch.get_header_head()?;
|
let mut tip = batch.get_header_head()?;
|
||||||
|
|
||||||
for header in headers {
|
for header in headers {
|
||||||
validate_header(header, ctx, batch)?;
|
handle_block_header(header, ctx, batch)?;
|
||||||
add_block_header(header, batch)?;
|
|
||||||
|
|
||||||
// Update header_head (but only if this header increases our total known work).
|
|
||||||
// i.e. Only if this header is now the head of the current "most work" chain.
|
|
||||||
update_header_head(header, ctx, batch)?;
|
|
||||||
|
|
||||||
// Update sync_head regardless of total work.
|
// Update sync_head regardless of total work.
|
||||||
// We may be syncing a long fork that will *eventually* increase the work
|
// We may be syncing a long fork that will *eventually* increase the work
|
||||||
|
@ -240,6 +231,20 @@ pub fn sync_block_headers(
|
||||||
Ok(tip)
|
Ok(tip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_block_header(
|
||||||
|
header: &BlockHeader,
|
||||||
|
ctx: &mut BlockContext,
|
||||||
|
batch: &mut store::Batch,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
validate_header(header, ctx, batch)?;
|
||||||
|
add_block_header(header, batch)?;
|
||||||
|
|
||||||
|
// Update header_head (but only if this header increases our total known work).
|
||||||
|
// i.e. Only if this header is now the head of the current "most work" chain.
|
||||||
|
update_header_head(header, ctx, batch)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Process block header as part of "header first" block propagation.
|
/// Process block header as part of "header first" block propagation.
|
||||||
/// We validate the header but we do not store it or update header head based
|
/// We validate the header but we do not store it or update header head based
|
||||||
/// on this. We will update these once we get the block back after requesting
|
/// on this. We will update these once we get the block back after requesting
|
||||||
|
|
Loading…
Reference in a new issue