Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockchain: Add ReconsiderBlock() #2181

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fullblocktests, testhelper: move standardCoinbaseScript to testhelper
standardCoinbaseScript is moved to testhelper and is exported.  This
allows test code in package blockchain to reuse the code without
introducing an import cycle.  This code is used in the testing code
for invalidateblock and reconsiderblock that's added in the later
commits.
  • Loading branch information
kcalvinalvin committed Apr 22, 2024
commit 59c7d105073717a9f1b7363c673a49496d76cfdd
10 changes: 1 addition & 9 deletions blockchain/fullblocktests/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,12 @@ func pushDataScript(items ...[]byte) []byte {
return script
}

// standardCoinbaseScript returns a standard script suitable for use as the
// signature script of the coinbase transaction of a new block. In particular,
// it starts with the block height that is required by version 2 blocks.
func standardCoinbaseScript(blockHeight int32, extraNonce uint64) ([]byte, error) {
return txscript.NewScriptBuilder().AddInt64(int64(blockHeight)).
AddInt64(int64(extraNonce)).Script()
}

// createCoinbaseTx returns a coinbase transaction paying an appropriate
// subsidy based on the passed block height. The coinbase signature script
// conforms to the requirements of version 2 blocks.
func (g *testGenerator) createCoinbaseTx(blockHeight int32) *wire.MsgTx {
extraNonce := uint64(0)
coinbaseScript, err := standardCoinbaseScript(blockHeight, extraNonce)
coinbaseScript, err := testhelper.StandardCoinbaseScript(blockHeight, extraNonce)
if err != nil {
panic(err)
}
Expand Down
8 changes: 8 additions & 0 deletions blockchain/internal/testhelper/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ var (
LowFee = btcutil.Amount(1)
)

// StandardCoinbaseScript returns a standard script suitable for use as the
// signature script of the coinbase transaction of a new block. In particular,
// it starts with the block height that is required by version 2 blocks.
func StandardCoinbaseScript(blockHeight int32, extraNonce uint64) ([]byte, error) {
return txscript.NewScriptBuilder().AddInt64(int64(blockHeight)).
AddInt64(int64(extraNonce)).Script()
}

// OpReturnScript returns a provably-pruneable OP_RETURN script with the
// provided data.
func OpReturnScript(data []byte) ([]byte, error) {
Expand Down