Avoid copying block headers in convenience locals.

This commit modifies local variables that are used for more convenient
access to a block's header to use pointers.  This avoids copying the
header multiple times.
This commit is contained in:
Dave Collins 2014-01-19 12:38:31 -06:00
parent be277b7230
commit 1626994433
3 changed files with 4 additions and 6 deletions

View file

@ -34,8 +34,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, fastAdd bool) error
}
block.SetHeight(blockHeight)
blockHeader := block.MsgBlock().Header
blockHeader := &block.MsgBlock().Header
if !fastAdd {
// Ensure the difficulty specified in the block header matches
// the calculated difficulty based on the previous block and

View file

@ -123,14 +123,14 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, fastAdd bool) error {
// easy to mine, but otherwise bogus, blocks that could be used to eat
// memory, and ensuring expected (versus claimed) proof of work
// requirements since the last checkpoint are met.
blockHeader := block.MsgBlock().Header
blockHeader := &block.MsgBlock().Header
checkpointBlock, err := b.findLatestKnownCheckpoint()
if err != nil {
return err
}
if checkpointBlock != nil {
// Ensure the block timestamp is after the checkpoint timestamp.
checkpointHeader := checkpointBlock.MsgBlock().Header
checkpointHeader := &checkpointBlock.MsgBlock().Header
checkpointTime := checkpointHeader.Timestamp
if blockHeader.Timestamp.Before(checkpointTime) {
str := fmt.Sprintf("block %v has timestamp %v before "+

View file

@ -268,8 +268,7 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
// target difficulty as claimed.
func checkProofOfWork(block *btcutil.Block, powLimit *big.Int) error {
// The target difficulty must be larger than zero.
header := block.MsgBlock().Header
target := CompactToBig(header.Bits)
target := CompactToBig(block.MsgBlock().Header.Bits)
if target.Sign() <= 0 {
str := fmt.Sprintf("block target difficulty of %064x is too low",
target)