Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
blockchain: drop hash param from newBlockNode()
Browse files Browse the repository at this point in the history
newBlockNode can produce it itself from the passed blockheader.
  • Loading branch information
dajohi authored and davecgh committed May 24, 2017
1 parent 2a2ab09 commit 480f2a1
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion blockchain/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (b *BlockChain) maybeAcceptBlock(block *dcrutil.Block,
// Create a new block node for the block and add it to the in-memory
// block chain (could be either a side chain or the main chain).
blockHeader := &block.MsgBlock().Header
newNode := newBlockNode(blockHeader, block.Hash(), blockHeight,
newNode := newBlockNode(blockHeader, blockHeight,
ticketsSpentInBlock(block), ticketsRevokedInBlock(block),
voteBitsInBlock(block))
if prevNode != nil {
Expand Down
6 changes: 3 additions & 3 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ type blockNode struct {
// completely disconnected from the chain and the workSum value is just the work
// for the passed block. The work sum is updated accordingly when the node is
// inserted into a chain.
func newBlockNode(blockHeader *wire.BlockHeader, blockHash *chainhash.Hash, height int64, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, votes []VoteVersionTuple) *blockNode {
func newBlockNode(blockHeader *wire.BlockHeader, height int64, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, votes []VoteVersionTuple) *blockNode {
// Make a copy of the hash so the node doesn't keep a reference to part
// of the full block/block header preventing it from being garbage
// collected.
node := blockNode{
hash: *blockHash,
hash: blockHeader.BlockHash(),
workSum: CalcWork(blockHeader.Bits),
height: height,
header: *blockHeader,
Expand Down Expand Up @@ -618,7 +618,7 @@ func (b *BlockChain) loadBlockNode(dbTx database.Tx, hash *chainhash.Hash) (*blo
}

blockHeader := block.MsgBlock().Header
node := newBlockNode(&blockHeader, hash, int64(blockHeader.Height),
node := newBlockNode(&blockHeader, int64(blockHeader.Height),
ticketsSpentInBlock(block), ticketsRevokedInBlock(block),
voteBitsInBlock(block))
node.inMainChain = true
Expand Down
4 changes: 2 additions & 2 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func (b *BlockChain) createChainState() error {
// Create a new node from the genesis block and set it as the best node.
genesisBlock := dcrutil.NewBlock(b.chainParams.GenesisBlock)
header := &genesisBlock.MsgBlock().Header
node := newBlockNode(header, genesisBlock.Hash(), 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.inMainChain = true
b.bestNode = node

Expand Down Expand Up @@ -1483,7 +1483,7 @@ func (b *BlockChain) initChainState() error {
// nodes will be loaded on demand as needed.
blk := dcrutil.NewBlock(&block)
header := &block.Header
node := newBlockNode(header, &state.hash, int64(state.height),
node := newBlockNode(header, int64(state.height),
ticketsSpentInBlock(blk), ticketsRevokedInBlock(blk),
voteBitsInBlock(blk))
node.inMainChain = true
Expand Down
6 changes: 2 additions & 4 deletions blockchain/difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ nextTest:
FreshStake: ticketInfo.newTickets,
PoolSize: poolSize,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash,
node := newBlockNode(header,
int64(nextHeight), nil, nil, nil)
node.parent = bc.bestNode

Expand Down Expand Up @@ -733,8 +732,7 @@ nextTest:
FreshStake: ticketInfo.newTickets,
PoolSize: poolSize,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash,
node := newBlockNode(header,
int64(nextHeight), nil, nil, nil)
node.parent = bc.bestNode

Expand Down
4 changes: 2 additions & 2 deletions blockchain/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ func (b *BlockChain) TstCheckBlockHeaderContext(header *wire.BlockHeader, prevNo

// TstNewBlockNode makes the internal newBlockNode function available to the
// test package.
func TstNewBlockNode(blockHeader *wire.BlockHeader, blockHash *chainhash.Hash, height int64, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, voteBits []VoteVersionTuple) *blockNode {
return newBlockNode(blockHeader, blockHash, height, ticketsSpent, ticketsRevoked, voteBits)
func TstNewBlockNode(blockHeader *wire.BlockHeader, height int64, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, voteBits []VoteVersionTuple) *blockNode {
return newBlockNode(blockHeader, height, ticketsSpent, ticketsRevoked, voteBits)
}
14 changes: 5 additions & 9 deletions blockchain/stakeversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func genesisBlockNode(params *chaincfg.Params) *blockNode {
// Create a new node from the genesis block.
genesisBlock := dcrutil.NewBlock(params.GenesisBlock)
header := &genesisBlock.MsgBlock().Header
node := newBlockNode(header, genesisBlock.Hash(), 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.inMainChain = true

return node
Expand Down Expand Up @@ -125,8 +125,7 @@ func newFakeNode(blockVersion int32, height int64, currentNode *blockNode) *bloc
Height: uint32(height),
Nonce: 0,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = height
node.parent = currentNode

Expand Down Expand Up @@ -440,8 +439,7 @@ func TestCalcStakeVersionByNode(t *testing.T) {
Height: uint32(i),
Nonce: uint32(0),
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = i
node.parent = currentNode

Expand Down Expand Up @@ -824,8 +822,7 @@ func TestIsStakeMajorityVersion(t *testing.T) {
Nonce: uint32(0),
StakeVersion: test.startStakeVersion,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = i
node.parent = currentNode

Expand Down Expand Up @@ -912,8 +909,7 @@ func TestLarge(t *testing.T) {
Nonce: uint32(0),
StakeVersion: test.startStakeVersion,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0,
node := newBlockNode(header, 0,
[]chainhash.Hash{}, []chainhash.Hash{},
[]VoteVersionTuple{})
node.height = i
Expand Down
2 changes: 1 addition & 1 deletion blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ func (b *BlockChain) CheckConnectBlock(block *dcrutil.Block) error {
return ruleError(ErrMissingParent, err.Error())
}

newNode := newBlockNode(&block.MsgBlock().Header, block.Hash(),
newNode := newBlockNode(&block.MsgBlock().Header,
block.Height(), ticketsSpentInBlock(block),
ticketsRevokedInBlock(block),
voteBitsInBlock(block))
Expand Down
2 changes: 1 addition & 1 deletion blockchain/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ func TestCheckBlockHeaderContext(t *testing.T) {
// Test failing checkBlockHeaderContext when calcNextRequiredDifficulty
// fails.
block := dcrutil.NewBlock(&badBlock)
newNode := blockchain.TstNewBlockNode(&block.MsgBlock().Header, block.Hash(),
newNode := blockchain.TstNewBlockNode(&block.MsgBlock().Header,
block.Height(), nil, nil, nil)
err = chain.TstCheckBlockHeaderContext(&block.MsgBlock().Header, newNode, blockchain.BFNone)
if err == nil {
Expand Down
24 changes: 12 additions & 12 deletions blockchain/votebits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestNoQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -214,7 +214,7 @@ func TestNoQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -260,7 +260,7 @@ func TestNoQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -312,7 +312,7 @@ func TestNoQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -374,7 +374,7 @@ func TestNoQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -447,7 +447,7 @@ func TestYesQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -484,7 +484,7 @@ func TestYesQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -530,7 +530,7 @@ func TestYesQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -582,7 +582,7 @@ func TestYesQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -644,7 +644,7 @@ func TestYesQuorum(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil, nil)
node := newBlockNode(header, 0, nil, nil, nil)
node.height = int64(currentHeight)
node.parent = currentNode

Expand Down Expand Up @@ -1849,7 +1849,7 @@ func TestVoting(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil,
node := newBlockNode(header, 0, nil, nil,
nil)
node.height = int64(currentHeight)
node.parent = currentNode
Expand Down Expand Up @@ -2115,7 +2115,7 @@ func TestParallelVoting(t *testing.T) {
Timestamp: currentTimestamp,
}
hash := header.BlockHash()
node := newBlockNode(header, &hash, 0, nil, nil,
node := newBlockNode(header, 0, nil, nil,
nil)
node.height = int64(currentHeight)
node.parent = currentNode
Expand Down

0 comments on commit 480f2a1

Please sign in to comment.