Skip to content

Commit

Permalink
chaingen: Prevent dup block names in NextBlock.
Browse files Browse the repository at this point in the history
This modifies the chaingen test harness to error when a duplicate block
name is provided to NextBlock to help prevent misuse.

It also orrects a couple of comment typos.
  • Loading branch information
davecgh committed Feb 25, 2018
1 parent b661ebd commit 0aa73c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions blockchain/chaingen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,11 @@ func updateVoteCommitments(block *wire.MsgBlock) {
// - The size of the block will be recalculated unless it was manually changed
// - The block will be solved unless the nonce was changed
func (g *Generator) NextBlock(blockName string, spend *SpendableOut, ticketSpends []SpendableOut, mungers ...func(*wire.MsgBlock)) *wire.MsgBlock {
// Prevent block name collisions.
if g.blocksByName[blockName] != nil {
panic(fmt.Sprintf("block name %s already exists", blockName))
}

// Calculate the next required stake difficulty (aka ticket price).
ticketPrice := dcrutil.Amount(g.calcNextRequiredStakeDifficulty())

Expand Down
9 changes: 4 additions & 5 deletions blockchain/fullblocktests/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
//
// rejectNonCanonicalBlock creates a test instance that encodes the
// provided block using a non-canonical encoded as described by the
// encodeNonCanonicalBlock function and expected it to be rejected.
// encodeNonCanonicalBlock function and expects it to be rejected.
//
// orphanOrRejectBlock creates a test instance that expected the
// provided block to either by accepted as an orphan or rejected by the
// consensus rules.
// orphanOrRejectBlock creates a test instance that expects the provided
// block to either be accepted as an orphan or rejected by the consensus
// rules.
//
// expectTipBlock creates a test instance that expects the provided
// block to be the current tip of the block chain.
Expand Down Expand Up @@ -1464,7 +1464,6 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
coinbaseOuts := g.OldestCoinbaseOuts()
outs = append(outs, &coinbaseOuts[0])
ticketOuts = append(ticketOuts, coinbaseOuts[1:])

}

// ---------------------------------------------------------------------
Expand Down

0 comments on commit 0aa73c0

Please sign in to comment.