mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
take write lock on txhashet earlier when processing blocks (#1456)
* take write lock on txhashet earlier when processing blocks * no txhashset lock in process_block_header
This commit is contained in:
parent
9f7625e8aa
commit
eae0ab6b2a
1 changed files with 8 additions and 6 deletions
|
@ -75,6 +75,14 @@ pub fn process_block(
|
||||||
b.outputs().len(),
|
b.outputs().len(),
|
||||||
b.kernels().len(),
|
b.kernels().len(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// First thing we do is take a write lock on the txhashset.
|
||||||
|
// We may receive the same block from multiple peers simultaneously.
|
||||||
|
// We want to process the first one fully to avoid redundant work
|
||||||
|
// processing the duplicates.
|
||||||
|
let txhashset = ctx.txhashset.clone();
|
||||||
|
let mut txhashset = txhashset.write().unwrap();
|
||||||
|
|
||||||
check_known(b.hash(), ctx)?;
|
check_known(b.hash(), ctx)?;
|
||||||
|
|
||||||
validate_header(&b.header, ctx)?;
|
validate_header(&b.header, ctx)?;
|
||||||
|
@ -99,14 +107,8 @@ pub fn process_block(
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate the block itself
|
// validate the block itself
|
||||||
// we can do this now before interacting with the txhashset
|
|
||||||
let _sums = validate_block(b, ctx, verifier_cache)?;
|
let _sums = validate_block(b, ctx, verifier_cache)?;
|
||||||
|
|
||||||
// header and block both valid, and we have a previous block
|
|
||||||
// so take the lock on the txhashset
|
|
||||||
let local_txhashset = ctx.txhashset.clone();
|
|
||||||
let mut txhashset = local_txhashset.write().unwrap();
|
|
||||||
|
|
||||||
// update head now that we're in the lock
|
// update head now that we're in the lock
|
||||||
ctx.head = ctx.store.head()?;
|
ctx.head = ctx.store.head()?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue