From 1626994433f20b65d6f8da7603a0f70ffb15c2aa Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 19 Jan 2014 12:38:31 -0600 Subject: [PATCH] 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. --- accept.go | 3 +-- process.go | 4 ++-- validate.go | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/accept.go b/accept.go index 2e51279c..a0609ae4 100644 --- a/accept.go +++ b/accept.go @@ -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 diff --git a/process.go b/process.go index ced8042d..42d08181 100644 --- a/process.go +++ b/process.go @@ -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 "+ diff --git a/validate.go b/validate.go index 8ea9f519..ecee9208 100644 --- a/validate.go +++ b/validate.go @@ -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)