From 0aa73c02b4b2db36be9cf73bcbaf4312e8de525a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 24 Feb 2018 11:54:02 -0600 Subject: [PATCH] chaingen: Prevent dup block names in NextBlock. 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. --- blockchain/chaingen/generator.go | 5 +++++ blockchain/fullblocktests/generate.go | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/blockchain/chaingen/generator.go b/blockchain/chaingen/generator.go index 6988c87d..48c25407 100644 --- a/blockchain/chaingen/generator.go +++ b/blockchain/chaingen/generator.go @@ -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()) diff --git a/blockchain/fullblocktests/generate.go b/blockchain/fullblocktests/generate.go index 3913733f..4907a4b6 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockchain/fullblocktests/generate.go @@ -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. @@ -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:]) - } // ---------------------------------------------------------------------