Skip to content

Commit

Permalink
Merge pull request #612 from lochjin/dev1.2
Browse files Browse the repository at this point in the history
Optimize BehaviorFlags
  • Loading branch information
dindinw authored Feb 25, 2024
2 parents 6f27822 + 8f44ba8 commit d263936
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 3 additions & 6 deletions core/blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ func (b *BlockChain) preProcessBlock(block *types.SerializedBlock, flags Behavio
b.ChainRLock()
defer b.ChainRUnlock()

fastAdd := flags&BFFastAdd == BFFastAdd

blockHash := block.Hash()
log.Trace("Processing block ", "hash", blockHash)

Expand Down Expand Up @@ -148,7 +146,7 @@ func (b *BlockChain) preProcessBlock(block *types.SerializedBlock, flags Behavio
return false, ruleError(ErrCheckpointTimeTooOld, str)
}

if !fastAdd {
if !flags.Has(BFFastAdd) {
// Even though the checks prior to now have already ensured the
// proof of work exceeds the claimed amount, the claimed amount
// is a field in the block header which could be forged. This
Expand Down Expand Up @@ -207,8 +205,7 @@ func (b *BlockChain) maybeAcceptBlock(block *types.SerializedBlock, flags Behavi

newNode := NewBlockNode(block)

fastAdd := flags&BFFastAdd == BFFastAdd
if !fastAdd {
if !flags.Has(BFFastAdd) {
mainParent := b.bd.GetBlock(newNode.GetMainParent())
if mainParent == nil {
b.ChainUnlock()
Expand Down Expand Up @@ -282,7 +279,7 @@ func (b *BlockChain) maybeAcceptBlock(block *types.SerializedBlock, flags Behavi
}
}

if flags&BFP2PAdd == BFP2PAdd {
if flags.Has(BFP2PAdd) {
b.progressLogger.LogBlockOrder(ib.GetOrder(), block)
}

Expand Down
8 changes: 3 additions & 5 deletions core/blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func checkProofOfWork(header *types.BlockHeader, powConfig *pow.PowConfig, flags

// The block hash must be less than the claimed target unless the flag
// to avoid proof of work checks is set.
if flags&BFNoPoWCheck != BFNoPoWCheck {
if !flags.Has(BFNoPoWCheck) {
header.Pow.SetParams(powConfig)
header.Pow.SetMainHeight(pow.MainHeight(mHeight))
// The block hash must be less than the claimed target.
Expand Down Expand Up @@ -590,8 +590,7 @@ func (b *BlockChain) checkBlockContext(block *types.SerializedBlock, mainParent
return err
}
header := &block.Block().Header
fastAdd := flags&BFFastAdd == BFFastAdd
if !fastAdd {
if !flags.Has(BFFastAdd) {
// A block must not exceed the maximum allowed size as defined
// by the network parameters and the current status of any hard
// fork votes to change it when serialized.
Expand Down Expand Up @@ -751,8 +750,7 @@ func (b *BlockChain) checkBlockHeaderContext(block *types.SerializedBlock, prevN
}

header := &block.Block().Header
fastAdd := flags&BFFastAdd == BFFastAdd
if !fastAdd {
if !flags.Has(BFFastAdd) {
instance := pow.GetInstance(header.Pow.GetPowType(), 0, []byte{})
instance.SetMainHeight(pow.MainHeight(prevNode.GetHeight() + 1))
instance.SetParams(b.params.PowConfig)
Expand Down

0 comments on commit d263936

Please sign in to comment.