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

Commit

Permalink
blockchain: drop height param from newBlockNode()
Browse files Browse the repository at this point in the history
newBlockNode can grab it from the passed blockheader.
  • Loading branch information
dajohi authored and davecgh committed May 24, 2017
1 parent 480f2a1 commit e1f9455
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 37 deletions.
5 changes: 2 additions & 3 deletions blockchain/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,8 @@ 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, blockHeight,
ticketsSpentInBlock(block), ticketsRevokedInBlock(block),
voteBitsInBlock(block))
newNode := newBlockNode(blockHeader, ticketsSpentInBlock(block),
ticketsRevokedInBlock(block), voteBitsInBlock(block))
if prevNode != nil {
newNode.parent = prevNode
newNode.height = blockHeight
Expand Down
9 changes: 4 additions & 5 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ 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, height int64, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, votes []VoteVersionTuple) *blockNode {
func newBlockNode(blockHeader *wire.BlockHeader, 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: blockHeader.BlockHash(),
workSum: CalcWork(blockHeader.Bits),
height: height,
height: int64(blockHeader.Height),
header: *blockHeader,
ticketsSpent: ticketsSpent,
ticketsRevoked: ticketsRevoked,
Expand Down Expand Up @@ -618,9 +618,8 @@ func (b *BlockChain) loadBlockNode(dbTx database.Tx, hash *chainhash.Hash) (*blo
}

blockHeader := block.MsgBlock().Header
node := newBlockNode(&blockHeader, int64(blockHeader.Height),
ticketsSpentInBlock(block), ticketsRevokedInBlock(block),
voteBitsInBlock(block))
node := newBlockNode(&blockHeader, ticketsSpentInBlock(block),
ticketsRevokedInBlock(block), voteBitsInBlock(block))
node.inMainChain = true
prevHash := &blockHeader.PrevBlock

Expand Down
7 changes: 3 additions & 4 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, 0, nil, nil, nil)
node := newBlockNode(header, nil, nil, nil)
node.inMainChain = true
b.bestNode = node

Expand Down Expand Up @@ -1483,9 +1483,8 @@ func (b *BlockChain) initChainState() error {
// nodes will be loaded on demand as needed.
blk := dcrutil.NewBlock(&block)
header := &block.Header
node := newBlockNode(header, int64(state.height),
ticketsSpentInBlock(blk), ticketsRevokedInBlock(blk),
voteBitsInBlock(blk))
node := newBlockNode(header, ticketsSpentInBlock(blk),
ticketsRevokedInBlock(blk), voteBitsInBlock(blk))
node.inMainChain = true
node.workSum = state.workSum

Expand Down
4 changes: 2 additions & 2 deletions blockchain/difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ nextTest:
PoolSize: poolSize,
}
node := newBlockNode(header,
int64(nextHeight), nil, nil, nil)
nil, nil, nil)
node.parent = bc.bestNode

// Update the pool size for the next header.
Expand Down Expand Up @@ -733,7 +733,7 @@ nextTest:
PoolSize: poolSize,
}
node := newBlockNode(header,
int64(nextHeight), nil, nil, nil)
nil, nil, nil)
node.parent = bc.bestNode

// Update the pool size for the next header.
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, height int64, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, voteBits []VoteVersionTuple) *blockNode {
return newBlockNode(blockHeader, height, ticketsSpent, ticketsRevoked, voteBits)
func TstNewBlockNode(blockHeader *wire.BlockHeader, ticketsSpent []chainhash.Hash, ticketsRevoked []chainhash.Hash, voteBits []VoteVersionTuple) *blockNode {
return newBlockNode(blockHeader, ticketsSpent, ticketsRevoked, voteBits)
}
12 changes: 5 additions & 7 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, 0, nil, nil, nil)
node := newBlockNode(header, nil, nil, nil)
node.inMainChain = true

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

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

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

Expand Down Expand Up @@ -909,9 +909,7 @@ func TestLarge(t *testing.T) {
Nonce: uint32(0),
StakeVersion: test.startStakeVersion,
}
node := newBlockNode(header, 0,
[]chainhash.Hash{}, []chainhash.Hash{},
[]VoteVersionTuple{})
node := newBlockNode(header, nil, nil, nil)
node.height = i
node.parent = currentNode

Expand Down
2 changes: 1 addition & 1 deletion blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ func (b *BlockChain) CheckConnectBlock(block *dcrutil.Block) error {
}

newNode := newBlockNode(&block.MsgBlock().Header,
block.Height(), ticketsSpentInBlock(block),
ticketsSpentInBlock(block),
ticketsRevokedInBlock(block),
voteBitsInBlock(block))
newNode.parent = prevNode
Expand Down
2 changes: 1 addition & 1 deletion blockchain/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ func TestCheckBlockHeaderContext(t *testing.T) {
// fails.
block := dcrutil.NewBlock(&badBlock)
newNode := blockchain.TstNewBlockNode(&block.MsgBlock().Header,
block.Height(), nil, nil, nil)
nil, nil, nil)
err = chain.TstCheckBlockHeaderContext(&block.MsgBlock().Header, newNode, blockchain.BFNone)
if err == nil {
t.Fatalf("Should fail due to bad diff in newNode\n")
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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil, nil)
node := newBlockNode(header, 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, 0, nil, nil,
node := newBlockNode(header, 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, 0, nil, nil,
node := newBlockNode(header, nil, nil,
nil)
node.height = int64(currentHeight)
node.parent = currentNode
Expand Down

0 comments on commit e1f9455

Please sign in to comment.