[NOD-251] Use bluest parent anywhere validating difficulty, instead of selectedTip (#348)

This commit is contained in:
Svarog 2019-07-17 14:46:58 +03:00 committed by stasatdaglabs
parent 96842353de
commit 7a4deb6f18
3 changed files with 6 additions and 4 deletions

1
.gitignore vendored
View File

@ -38,6 +38,7 @@ _testmain.go
.vscode .vscode
debug debug
debug.test debug.test
__debug_bin
# CI # CI
version.txt version.txt

View File

@ -30,8 +30,7 @@ func (dag *BlockDAG) maybeAcceptBlock(block *util.Block, flags BehaviorFlags) er
// The block must pass all of the validation rules which depend on the // The block must pass all of the validation rules which depend on the
// position of the block within the block DAG. // position of the block within the block DAG.
bluestParent := parents.bluest() err = dag.checkBlockContext(block, parents, flags)
err = dag.checkBlockContext(block, parents, bluestParent, flags)
if err != nil { if err != nil {
return err return err
} }
@ -59,6 +58,7 @@ func (dag *BlockDAG) maybeAcceptBlock(block *util.Block, flags BehaviorFlags) er
// Make sure that all the block's transactions are finalized // Make sure that all the block's transactions are finalized
fastAdd := flags&BFFastAdd == BFFastAdd fastAdd := flags&BFFastAdd == BFFastAdd
bluestParent := parents.bluest()
if !fastAdd { if !fastAdd {
if err := dag.validateAllTxsFinalized(block, newNode, bluestParent); err != nil { if err := dag.validateAllTxsFinalized(block, newNode, bluestParent); err != nil {
return err return err

View File

@ -657,7 +657,8 @@ func validateParents(blockHeader *wire.BlockHeader, parents blockSet) error {
// for how the flags modify its behavior. // for how the flags modify its behavior.
// //
// This function MUST be called with the dag state lock held (for writes). // This function MUST be called with the dag state lock held (for writes).
func (dag *BlockDAG) checkBlockContext(block *util.Block, parents blockSet, bluestParent *blockNode, flags BehaviorFlags) error { func (dag *BlockDAG) checkBlockContext(block *util.Block, parents blockSet, flags BehaviorFlags) error {
bluestParent := parents.bluest()
fastAdd := flags&BFFastAdd == BFFastAdd fastAdd := flags&BFFastAdd == BFFastAdd
err := validateParents(&block.MsgBlock().Header, parents) err := validateParents(&block.MsgBlock().Header, parents)
@ -1030,7 +1031,7 @@ func (dag *BlockDAG) CheckConnectBlockTemplateNoLock(block *util.Block) error {
return err return err
} }
err = dag.checkBlockContext(block, parents, dag.selectedTip(), flags) err = dag.checkBlockContext(block, parents, flags)
if err != nil { if err != nil {
return err return err
} }