From 2dac20919815b7a7369f71fd7eae56fabb8047f7 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 22 Jul 2019 05:25:34 -0500 Subject: [PATCH] blockchain: Use lastest major version deps. This udpates the blockchain module to use the lastest module major versions. While here, it also corrects a few typos and updates some test function names to more accurately reflect their purpose. The updated direct dependencies are as follows: - github.com/decred/dcrd/blockchain/stake/v2@v2.0.1 - github.com/decred/dcrd/chaincfg/v2@v2.2.0 - github.com/decred/dcrd/database/v2@v2.0.0 - github.com/decred/dcrd/dcrutil/v2@v2.0.0 - github.com/decred/dcrd/txscript/v2@v2.0.0 --- blockchain/accept.go | 10 +- blockchain/agendas_test.go | 16 +- blockchain/blockindex.go | 8 +- blockchain/blockindex_test.go | 13 +- blockchain/chain.go | 12 +- blockchain/chain_test.go | 33 ++-- blockchain/chaingen/README.md | 2 +- blockchain/chaingen/example_test.go | 14 +- blockchain/chaingen/generator.go | 32 ++-- blockchain/chainio.go | 11 +- blockchain/chainio_test.go | 6 +- blockchain/checkpoints.go | 8 +- blockchain/common_test.go | 14 +- blockchain/compress.go | 6 +- blockchain/difficulty.go | 4 +- blockchain/difficulty_test.go | 14 +- blockchain/error.go | 2 +- blockchain/example_test.go | 17 +- blockchain/fullblocks_test.go | 12 +- blockchain/fullblocksstakeversion_test.go | 4 +- blockchain/fullblocktests/generate.go | 70 ++++---- blockchain/fullblocktests/params.go | 25 ++- blockchain/go.mod | 10 +- blockchain/go.sum | 32 +--- blockchain/indexers/addrindex.go | 24 +-- blockchain/indexers/cfindex.go | 8 +- blockchain/indexers/common.go | 6 +- blockchain/indexers/existsaddrindex.go | 54 +++--- blockchain/indexers/manager.go | 10 +- blockchain/indexers/txindex.go | 6 +- blockchain/merkle.go | 2 +- blockchain/notifications.go | 4 +- blockchain/process.go | 4 +- blockchain/scriptval.go | 6 +- blockchain/sequencelock.go | 4 +- blockchain/sequencelock_test.go | 8 +- blockchain/stake/internal/ticketdb/chainio.go | 4 +- blockchain/stakeext.go | 12 +- blockchain/stakenode.go | 6 +- blockchain/stakeversion_test.go | 34 ++-- blockchain/subsidy.go | 157 ++++-------------- blockchain/subsidy_test.go | 6 +- blockchain/thresholdstate.go | 2 +- blockchain/thresholdstate_test.go | 6 +- blockchain/upgrade.go | 16 +- blockchain/utxoviewpoint.go | 8 +- blockchain/validate.go | 22 ++- blockchain/validate_test.go | 47 +++--- blockchain/votebits.go | 4 +- blockchain/votebits_test.go | 12 +- 50 files changed, 378 insertions(+), 469 deletions(-) diff --git a/blockchain/accept.go b/blockchain/accept.go index a6d19d2a..6062f902 100644 --- a/blockchain/accept.go +++ b/blockchain/accept.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -8,9 +8,9 @@ package blockchain import ( "fmt" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/blockchain/stake/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" ) // maybeAcceptBlock potentially accepts a block into the block chain and, if @@ -104,7 +104,7 @@ func (b *BlockChain) maybeAcceptBlock(block *dcrutil.Block, flags BehaviorFlags) // connection checks, because even though the block might still fail // to connect and becomes the new main chain tip, that is quite rare in // practice since a lot of work was expended to create a block that - // satisifies the proof of work requirement. + // satisfies the proof of work requirement. // // Notice that the chain lock is not released before sending the // notification. This is intentional and must not be changed without diff --git a/blockchain/agendas_test.go b/blockchain/agendas_test.go index c9a78ab7..761f4406 100644 --- a/blockchain/agendas_test.go +++ b/blockchain/agendas_test.go @@ -9,10 +9,10 @@ import ( "time" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/blockchain/stake/v2" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -165,8 +165,8 @@ func testLNFeaturesDeployment(t *testing.T, params *chaincfg.Params) { // TestLNFeaturesDeployment ensures the deployment of the LN features agenda // activate the expected changes. func TestLNFeaturesDeployment(t *testing.T) { - testLNFeaturesDeployment(t, &chaincfg.MainNetParams) - testLNFeaturesDeployment(t, &chaincfg.RegNetParams) + testLNFeaturesDeployment(t, chaincfg.MainNetParams()) + testLNFeaturesDeployment(t, chaincfg.RegNetParams()) } // testFixSeqLocksDeployment ensures the deployment of the fix sequence locks @@ -288,8 +288,8 @@ func testFixSeqLocksDeployment(t *testing.T, params *chaincfg.Params) { // TestFixSeqLocksDeployment ensures the deployment of the fix sequence locks // agenda activates as expected. func TestFixSeqLocksDeployment(t *testing.T) { - testFixSeqLocksDeployment(t, &chaincfg.MainNetParams) - testFixSeqLocksDeployment(t, &chaincfg.RegNetParams) + testFixSeqLocksDeployment(t, chaincfg.MainNetParams()) + testFixSeqLocksDeployment(t, chaincfg.RegNetParams()) } // TestFixedSequenceLocks ensures that sequence locks within blocks behave as diff --git a/blockchain/blockindex.go b/blockchain/blockindex.go index 716153cc..7d4e874e 100644 --- a/blockchain/blockindex.go +++ b/blockchain/blockindex.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2017 The btcsuite developers -// Copyright (c) 2018 The Decred developers +// Copyright (c) 2018-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -12,10 +12,10 @@ import ( "sync" "time" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" + "github.com/decred/dcrd/database/v2" "github.com/decred/dcrd/wire" ) @@ -222,7 +222,7 @@ func (node *blockNode) lotteryIV() chainhash.Hash { return stake.CalcHash256PRNGIV(buf.Bytes()) } -// populateTicketInfo sets prunable ticket information in the provided block +// populateTicketInfo sets pruneable ticket information in the provided block // node. // // This function is NOT safe for concurrent access. It must only be called when diff --git a/blockchain/blockindex_test.go b/blockchain/blockindex_test.go index cc077cb9..8852a448 100644 --- a/blockchain/blockindex_test.go +++ b/blockchain/blockindex_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The Decred developers +// Copyright (c) 2018-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" + "github.com/decred/dcrd/chaincfg/v2" "github.com/decred/dcrd/wire" ) @@ -32,7 +32,7 @@ func mustParseHash(s string) *chainhash.Hash { func TestBlockNodeHeader(t *testing.T) { // Create a fake chain and block header with all fields set to nondefault // values. - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() bc := newFakeChain(params) tip := bc.bestChain.Tip() testHeader := wire.BlockHeader{ @@ -154,10 +154,9 @@ func TestCalcPastMedianTime(t *testing.T) { // data. Also, clone the provided parameters first to avoid mutating them. // // The timestamp corresponds to 2018-01-01 00:00:00 +0000 UTC. - params := cloneParams(&chaincfg.RegNetParams) + params := chaincfg.RegNetParams() params.GenesisBlock.Header.Timestamp = time.Unix(1514764800, 0) - genesisHash := params.GenesisBlock.BlockHash() - params.GenesisHash = &genesisHash + params.GenesisHash = params.GenesisBlock.BlockHash() for _, test := range tests { // Create a synthetic chain with the correct number of nodes and the @@ -184,7 +183,7 @@ func TestCalcPastMedianTime(t *testing.T) { // TestChainTips ensures the chain tip tracking in the block index works // as expected. func TestChainTips(t *testing.T) { - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() bc := newFakeChain(params) genesis := bc.bestChain.NodeByHeight(0) diff --git a/blockchain/chain.go b/blockchain/chain.go index d2219c3c..c6bed200 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -11,13 +11,13 @@ import ( "sync" "time" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -2130,7 +2130,7 @@ func New(config *Config) (*BlockChain, error) { } } - b.subsidyCache = standalone.NewSubsidyCache(&subsidyParams{b.chainParams}) + b.subsidyCache = standalone.NewSubsidyCache(b.chainParams) b.pruner = newChainPruner(&b) // The version 5 database upgrade requires a full reindex. Perform, or diff --git a/blockchain/chain_test.go b/blockchain/chain_test.go index 83223915..8ab2f24c 100644 --- a/blockchain/chain_test.go +++ b/blockchain/chain_test.go @@ -17,9 +17,9 @@ import ( "time" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) @@ -42,20 +42,27 @@ func cloneParams(params *chaincfg.Params) *chaincfg.Params { // functionality. func TestBlockchainFunctions(t *testing.T) { // Update parameters to reflect what is expected by the legacy data. - params := cloneParams(&chaincfg.RegNetParams) + params := chaincfg.RegNetParams() params.GenesisBlock.Header.MerkleRoot = *mustParseHash("a216ea043f0d481a072424af646787794c32bcefd3ed181a090319bbf8a37105") params.GenesisBlock.Header.Timestamp = time.Unix(1401292357, 0) params.GenesisBlock.Transactions[0].TxIn[0].ValueIn = 0 params.PubKeyHashAddrID = [2]byte{0x0e, 0x91} params.StakeBaseSigScript = []byte{0xde, 0xad, 0xbe, 0xef} params.OrganizationPkScript = hexToBytes("a914cbb08d6ca783b533b2c7d24a51fbca92d937bf9987") - params.BlockOneLedger = []*chaincfg.TokenPayout{ - {Address: "Sshw6S86G2bV6W32cbc7EhtFy8f93rU6pae", Amount: 100000 * 1e8}, - {Address: "SsjXRK6Xz6CFuBt6PugBvrkdAa4xGbcZ18w", Amount: 100000 * 1e8}, - {Address: "SsfXiYkYkCoo31CuVQw428N6wWKus2ZEw5X", Amount: 100000 * 1e8}, - } - genesisHash := params.GenesisBlock.BlockHash() - params.GenesisHash = &genesisHash + params.BlockOneLedger = []chaincfg.TokenPayout{{ + ScriptVersion: 0, + Script: hexToBytes("76a91494ff37a0ee4d48abc45f70474f9b86f9da69a70988ac"), + Amount: 100000 * 1e8, + }, { + ScriptVersion: 0, + Script: hexToBytes("76a914a6753ebbc08e2553e7dd6d64bdead4bcbff4fcf188ac"), + Amount: 100000 * 1e8, + }, { + ScriptVersion: 0, + Script: hexToBytes("76a9147aa3211c2ead810bbf5911c275c69cc196202bd888ac"), + Amount: 100000 * 1e8, + }} + params.GenesisHash = params.GenesisBlock.BlockHash() // Create a new database and chain instance to run tests against. chain, teardownFunc, err := chainSetup("validateunittests", params) @@ -110,7 +117,7 @@ func TestBlockchainFunctions(t *testing.T) { "want %v, got %v", expectedVal, val) } - a, _ := dcrutil.DecodeAddress("SsbKpMkPnadDcZFFZqRPY8nvdFagrktKuzB") + a, _ := dcrutil.DecodeAddress("SsbKpMkPnadDcZFFZqRPY8nvdFagrktKuzB", params) hs, err := chain.TicketsWithAddress(a) if err != nil { t.Errorf("Failed to do TicketsWithAddress: %v", err) @@ -133,7 +140,7 @@ func TestBlockchainFunctions(t *testing.T) { // TestForceHeadReorg ensures forcing header reorganization works as expected. func TestForceHeadReorg(t *testing.T) { // Create a test harness initialized with the genesis block as the tip. - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() g, teardownFunc := newChaingenHarness(t, params, "forceheadreorgtest") defer teardownFunc() @@ -450,7 +457,7 @@ func TestLocateInventory(t *testing.T) { // genesis -> 1 -> 2 -> ... -> 15 -> 16 -> 17 -> 18 // \-> 16a -> 17a tip := branchTip - chain := newFakeChain(&chaincfg.MainNetParams) + chain := newFakeChain(chaincfg.MainNetParams()) branch0Nodes := chainedFakeNodes(chain.bestChain.Genesis(), 18) branch1Nodes := chainedFakeNodes(branch0Nodes[14], 2) for _, node := range branch0Nodes { diff --git a/blockchain/chaingen/README.md b/blockchain/chaingen/README.md index 66e98444..1d286c05 100644 --- a/blockchain/chaingen/README.md +++ b/blockchain/chaingen/README.md @@ -28,7 +28,7 @@ functions. * [Basic Usage Example] (https://godoc.org/github.com/decred/dcrd/blockchain/chaingen#example-package--BasicUsage) Demonstrates creating a new generator instance and using it to generate the - required premine block and enough blocks to have mature coinbase outputs to + required first block and enough blocks to have mature coinbase outputs to work with along with asserting the generator state along the way. ## Installation diff --git a/blockchain/chaingen/example_test.go b/blockchain/chaingen/example_test.go index 7fa15775..72f0251a 100644 --- a/blockchain/chaingen/example_test.go +++ b/blockchain/chaingen/example_test.go @@ -8,14 +8,14 @@ import ( "fmt" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/chaincfg/v2" ) // This example demonstrates creating a new generator instance and using it to -// generate the required premine block and enough blocks to have mature coinbase +// generate the required first block and enough blocks to have mature coinbase // outputs to work with along with asserting the generator state along the way. func Example_basicUsage() { - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() g, err := chaingen.MakeGenerator(params) if err != nil { fmt.Println(err) @@ -26,13 +26,13 @@ func Example_basicUsage() { coinbaseMaturity := params.CoinbaseMaturity // --------------------------------------------------------------------- - // Premine. + // First block. // --------------------------------------------------------------------- - // Add the required premine block. + // Add the required first block. // - // genesis -> bp - g.CreatePremineBlock("bp", 0) + // genesis -> bfb + g.CreateBlockOne("bfb", 0) g.AssertTipHeight(1) fmt.Println(g.TipName()) diff --git a/blockchain/chaingen/generator.go b/blockchain/chaingen/generator.go index 3b04b48c..2398601e 100644 --- a/blockchain/chaingen/generator.go +++ b/blockchain/chaingen/generator.go @@ -14,10 +14,10 @@ import ( "sort" "time" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -1089,7 +1089,7 @@ func (g *Generator) CalcNextRequiredStakeDifficulty() int64 { return g.CalcNextReqStakeDifficulty(g.tip) } -// hash256prng is a determinstic pseudorandom number generator that uses a +// hash256prng is a deterministic pseudorandom number generator that uses a // 256-bit secure hashing function to generate random uint32s starting from // an initial seed. type hash256prng struct { @@ -2274,7 +2274,7 @@ func (g *Generator) NextBlock(blockName string, spend *SpendableOut, ticketSpend // Update generator state and return the block. blockHash := block.BlockHash() if block.Header.PrevBlock != prevHash { - // Save the orignal block this one was built from if it was + // Save the original block this one was built from if it was // manually changed in a munger so the code which deals with // updating the live tickets when changing the tip has access to // it. @@ -2292,11 +2292,11 @@ func (g *Generator) NextBlock(blockName string, spend *SpendableOut, ticketSpend return &block } -// CreatePremineBlock generates the first block of the chain with the required -// premine payouts. The additional amount parameter can be used to create a -// block that is otherwise a completely valid premine block except it adds the -// extra amount to each payout and thus create a block that violates consensus. -func (g *Generator) CreatePremineBlock(blockName string, additionalAmount dcrutil.Amount, mungers ...func(*wire.MsgBlock)) *wire.MsgBlock { +// CreateBlockOne generates the first block of the chain with the required +// payouts. The additional amount parameter can be used to create a block that +// is otherwise a completely valid block one except it adds the extra amount to +// each payout and thus create a block that violates consensus. +func (g *Generator) CreateBlockOne(blockName string, additionalAmount dcrutil.Amount, mungers ...func(*wire.MsgBlock)) *wire.MsgBlock { coinbaseTx := wire.NewMsgTx() coinbaseTx.AddTxIn(&wire.TxIn{ PreviousOutPoint: *wire.NewOutPoint(&chainhash.Hash{}, @@ -2312,18 +2312,10 @@ func (g *Generator) CreatePremineBlock(blockName string, additionalAmount dcruti // in order to set the input value appropriately. var totalSubsidy dcrutil.Amount for _, payout := range g.params.BlockOneLedger { - payoutAddr, err := dcrutil.DecodeAddress(payout.Address) - if err != nil { - panic(err) - } - pkScript, err := txscript.PayToAddrScript(payoutAddr) - if err != nil { - panic(err) - } coinbaseTx.AddTxOut(&wire.TxOut{ Value: payout.Amount + int64(additionalAmount), - Version: 0, - PkScript: pkScript, + Version: payout.ScriptVersion, + PkScript: payout.Script, }) totalSubsidy += dcrutil.Amount(payout.Amount) diff --git a/blockchain/chainio.go b/blockchain/chainio.go index f25c925b..451962f2 100644 --- a/blockchain/chainio.go +++ b/blockchain/chainio.go @@ -14,10 +14,10 @@ import ( "time" "github.com/decred/dcrd/blockchain/internal/dbnamespace" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) @@ -1514,7 +1514,8 @@ func (b *BlockChain) createChainState() error { // Initialize the stake buckets in the database, along with // the best state for the stake database. - _, err = stake.InitDatabaseState(dbTx, b.chainParams) + _, err = stake.InitDatabaseState(dbTx, b.chainParams, + &b.chainParams.GenesisHash) if err != nil { return err } @@ -1677,7 +1678,7 @@ func (b *BlockChain) initChainState() error { var parent *blockNode if lastNode == nil { blockHash := header.BlockHash() - if blockHash != *b.chainParams.GenesisHash { + if blockHash != b.chainParams.GenesisHash { return AssertError(fmt.Sprintf("initChainState: expected "+ "first entry in block index to be genesis block, "+ "found %s", blockHash)) diff --git a/blockchain/chainio_test.go b/blockchain/chainio_test.go index aa1de01d..169fdfd5 100644 --- a/blockchain/chainio_test.go +++ b/blockchain/chainio_test.go @@ -1,5 +1,5 @@ // Copyright (c) 2015-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -14,10 +14,10 @@ import ( "testing" "time" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" + "github.com/decred/dcrd/database/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/checkpoints.go b/blockchain/checkpoints.go index 97cce475..2eadeee0 100644 --- a/blockchain/checkpoints.go +++ b/blockchain/checkpoints.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -9,10 +9,10 @@ import ( "fmt" "time" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" ) // CheckpointConfirmations is the number of blocks before the end of the current diff --git a/blockchain/common_test.go b/blockchain/common_test.go index 899030f1..9952a7c2 100644 --- a/blockchain/common_test.go +++ b/blockchain/common_test.go @@ -15,13 +15,13 @@ import ( "time" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - _ "github.com/decred/dcrd/database/ffldb" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + _ "github.com/decred/dcrd/database/v2/ffldb" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -568,7 +568,7 @@ func (g *chaingenHarness) AdvanceToStakeValidationHeight() { // Add the required first block. // // genesis -> bfb - g.CreatePremineBlock("bfb", 0) + g.CreateBlockOne("bfb", 0) g.AssertTipHeight(1) g.AcceptTipBlock() diff --git a/blockchain/compress.go b/blockchain/compress.go index fd16a474..244795a3 100644 --- a/blockchain/compress.go +++ b/blockchain/compress.go @@ -1,5 +1,5 @@ // Copyright (c) 2015-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -8,9 +8,9 @@ package blockchain import ( "fmt" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/dcrec/secp256k1" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/txscript/v2" ) // currentCompressionVersion is the current script compression version of the diff --git a/blockchain/difficulty.go b/blockchain/difficulty.go index 1a99dc29..df4dd159 100644 --- a/blockchain/difficulty.go +++ b/blockchain/difficulty.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -11,8 +11,8 @@ import ( "time" "github.com/decred/dcrd/blockchain/standalone" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" + "github.com/decred/dcrd/chaincfg/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/difficulty_test.go b/blockchain/difficulty_test.go index af0debf1..bf324fd1 100644 --- a/blockchain/difficulty_test.go +++ b/blockchain/difficulty_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/chaincfg/v2" "github.com/decred/dcrd/wire" ) @@ -78,7 +78,7 @@ func TestEstimateSupply(t *testing.T) { t.Parallel() // The parameters used for the supply estimation. - params := &chaincfg.MainNetParams + params := chaincfg.MainNetParams() baseSubsidy := params.BaseSubsidy reduxInterval := params.SubsidyReductionInterval blockOneSubsidy := params.BlockOneSubsidy() @@ -210,7 +210,7 @@ func TestCalcNextRequiredStakeDiffV2(t *testing.T) { // used by the tests are the expected ones. All of the test values will // need to be updated if these parameters change since they are manually // calculated based on them. - params := &chaincfg.MainNetParams + params := chaincfg.MainNetParams() assertStakeDiffParamsMainNet(t, params) minStakeDiff := params.MinimumStakeDiff ticketMaturity := uint32(params.TicketMaturity) @@ -516,8 +516,8 @@ func TestEstimateNextStakeDiffV2(t *testing.T) { // Assert the param values directly used by the tests are the expected // ones. All of the test values will need to be updated if these // parameters change since they are manually calculated based on them. - mainNetParams := &chaincfg.MainNetParams - testNetParams := &chaincfg.TestNet3Params + mainNetParams := chaincfg.MainNetParams() + testNetParams := chaincfg.TestNet3Params() assertStakeDiffParamsMainNet(t, mainNetParams) assertStakeDiffParamsTestNet(t, testNetParams) minStakeDiffMainNet := mainNetParams.MinimumStakeDiff @@ -1056,7 +1056,7 @@ nextTest: func TestMinDifficultyReduction(t *testing.T) { // Create chain params based on regnet params, but set the fields related to // proof-of-work difficulty to specific values expected by the tests. - params := chaincfg.RegNetParams + params := chaincfg.RegNetParams() params.ReduceMinDifficulty = true params.TargetTimePerBlock = time.Minute * 2 params.MinDiffReductionTime = time.Minute * 10 // ~99.3% chance to be mined @@ -1181,7 +1181,7 @@ func TestMinDifficultyReduction(t *testing.T) { }, } - bc := newFakeChain(¶ms) + bc := newFakeChain(params) node := bc.bestChain.Tip() blockTime := time.Unix(node.timestamp, 0) for _, test := range tests { diff --git a/blockchain/error.go b/blockchain/error.go index 55c79c2a..53c7f58b 100644 --- a/blockchain/error.go +++ b/blockchain/error.go @@ -426,7 +426,7 @@ const ( ErrBadBlockHeight // ErrBlockOneTx indicates that block height 1 failed to correct generate - // the block one premine transaction. + // the block one initial payout transaction. ErrBlockOneTx // ErrBlockOneTx indicates that block height 1 coinbase transaction in diff --git a/blockchain/example_test.go b/blockchain/example_test.go index 6dc0f5d5..76dff7c2 100644 --- a/blockchain/example_test.go +++ b/blockchain/example_test.go @@ -1,5 +1,5 @@ // Copyright (c) 2014-2016 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -12,10 +12,10 @@ import ( "path/filepath" "github.com/decred/dcrd/blockchain" - "github.com/decred/dcrd/chaincfg" - "github.com/decred/dcrd/database" - _ "github.com/decred/dcrd/database/ffldb" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + _ "github.com/decred/dcrd/database/v2/ffldb" + "github.com/decred/dcrd/dcrutil/v2" ) // This example demonstrates how to create a new chain instance and use @@ -29,9 +29,10 @@ func ExampleBlockChain_ProcessBlock() { // and creating a new database like this, but it is done here so this is // a complete working example and does not leave temporary files laying // around. + mainNetParams := chaincfg.MainNetParams() dbPath := filepath.Join(os.TempDir(), "exampleprocessblock") _ = os.RemoveAll(dbPath) - db, err := database.Create("ffldb", dbPath, chaincfg.MainNetParams.Net) + db, err := database.Create("ffldb", dbPath, mainNetParams.Net) if err != nil { fmt.Printf("Failed to create database: %v\n", err) return @@ -48,7 +49,7 @@ func ExampleBlockChain_ProcessBlock() { // adjusted to be in agreement with other peers. chain, err := blockchain.New(&blockchain.Config{ DB: db, - ChainParams: &chaincfg.MainNetParams, + ChainParams: mainNetParams, TimeSource: blockchain.NewMedianTime(), }) if err != nil { @@ -59,7 +60,7 @@ func ExampleBlockChain_ProcessBlock() { // Process a block. For this example, we are going to intentionally // cause an error by trying to process the genesis block which already // exists. - genesisBlock := dcrutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) + genesisBlock := dcrutil.NewBlock(mainNetParams.GenesisBlock) forkLen, isOrphan, err := chain.ProcessBlock(genesisBlock, blockchain.BFNone) if err != nil { diff --git a/blockchain/fullblocks_test.go b/blockchain/fullblocks_test.go index 1a1a3ed9..d2a59af6 100644 --- a/blockchain/fullblocks_test.go +++ b/blockchain/fullblocks_test.go @@ -1,5 +1,5 @@ // Copyright (c) 2016 The btcsuite developers -// Copyright (c) 2016-2018 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -14,11 +14,11 @@ import ( "github.com/decred/dcrd/blockchain" "github.com/decred/dcrd/blockchain/fullblocktests" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -123,7 +123,7 @@ func TestFullBlocks(t *testing.T) { // Create a new database and chain instance to run tests against. chain, teardownFunc, err := chainSetup("fullblocktest", - &chaincfg.RegNetParams) + chaincfg.RegNetParams()) if err != nil { t.Fatalf("Failed to setup chain instance: %v", err) } diff --git a/blockchain/fullblocksstakeversion_test.go b/blockchain/fullblocksstakeversion_test.go index 840b75bf..6f034cd2 100644 --- a/blockchain/fullblocksstakeversion_test.go +++ b/blockchain/fullblocksstakeversion_test.go @@ -9,14 +9,14 @@ import ( "testing" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/chaincfg/v2" ) // TestStakeVersion ensures that the stake version field in the block header is // enforced properly. func TestStakeVersion(t *testing.T) { // Create a test harness initialized with the genesis block as the tip. - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() g, teardownFunc := newChaingenHarness(t, params, "stakeversiontest") defer teardownFunc() diff --git a/blockchain/fullblocktests/generate.go b/blockchain/fullblocktests/generate.go index 68df3379..ef09cfb7 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockchain/fullblocktests/generate.go @@ -1,5 +1,5 @@ // Copyright (c) 2016 The btcsuite developers -// Copyright (c) 2016-2018 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -18,8 +18,8 @@ import ( "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/dcrec" "github.com/decred/dcrd/dcrec/secp256k1" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -476,74 +476,76 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { ticketsPerBlock := g.Params().TicketsPerBlock // --------------------------------------------------------------------- - // Premine tests. + // First block tests. // --------------------------------------------------------------------- - // Attempt to insert an initial premine block that does not conform to - // the required premine payouts by adding one atom too many to each - // payout. + // Attempt to insert an initial block that does not conform to the required + // payouts by adding one atom too many to each payout. // // genesis - // \-> bpbad0 - g.CreatePremineBlock("bpbad0", 1) + // \-> bfbbad0 + g.CreateBlockOne("bfbbad0", 1) rejected(blockchain.ErrBadCoinbaseValue) - // Create a premine block with one premine output removed. + // Create first block with one required output removed. // - // genesis -> bpbad1 + // genesis + // \-> bfbbad1 g.SetTip("genesis") - g.CreatePremineBlock("bpbad1", 0, func(b *wire.MsgBlock) { + g.CreateBlockOne("bfbbad1", 0, func(b *wire.MsgBlock) { b.Transactions[0].TxOut = b.Transactions[0].TxOut[:2] }) rejected(blockchain.ErrBlockOneOutputs) - // Create a premine block with a bad spend script. + // Create first block with a bad spend script. // - // genesis -> bpbad2 + // genesis + // \-> bfbbad2 g.SetTip("genesis") - g.CreatePremineBlock("bpbad2", 0, func(b *wire.MsgBlock) { + g.CreateBlockOne("bfbbad2", 0, func(b *wire.MsgBlock) { scriptSize := len(b.Transactions[0].TxOut[0].PkScript) badScript := repeatOpcode(txscript.OP_0, scriptSize) b.Transactions[0].TxOut[0].PkScript = badScript }) rejected(blockchain.ErrBlockOneOutputs) - // Create a premine block with an incorrect pay to amount. + // Create first block with an incorrect pay to amount. // - // genesis -> bpbad3 + // genesis + // \-> bfbbad3 g.SetTip("genesis") - g.CreatePremineBlock("bpbad3", 0, func(b *wire.MsgBlock) { + g.CreateBlockOne("bfbbad3", 0, func(b *wire.MsgBlock) { b.Transactions[0].TxOut[0].Value-- }) rejected(blockchain.ErrBlockOneOutputs) - // Add the required premine block. + // Add the required first block. // - // genesis -> bp + // genesis -> bfb g.SetTip("genesis") - g.CreatePremineBlock("bp", 0) + g.CreateBlockOne("bfb", 0) g.AssertTipHeight(1) accepted() - // Create block that tries to spend premine output before - // maturity in the regular tree + // Create block that tries to spend an initial payout output before maturity + // in the regular tree. // - // genesis -> bp - // \-> bpi0 - g.NextBlock("bpi0", nil, nil, func(b *wire.MsgBlock) { + // genesis -> bfb + // \-> bfbi0 + g.NextBlock("bfbi0", nil, nil, func(b *wire.MsgBlock) { spendOut := chaingen.MakeSpendableOut(g.Tip(), 0, 0) tx := g.CreateSpendTx(&spendOut, lowFee) b.AddTransaction(tx) }) rejected(blockchain.ErrImmatureSpend) - // Create block that tries to spend premine output before - // maturity in the stake tree by creating a ticket purchase + // Create block that tries to spend an initial payout output before maturity + // in the stake tree by creating a ticket purchase. // - // genesis -> bp - // \-> bpi1 - g.SetTip("bp") - g.NextBlock("bpi1", nil, nil, func(b *wire.MsgBlock) { + // genesis -> bfb + // \-> bfbi1 + g.SetTip("bfb") + g.NextBlock("bfbi1", nil, nil, func(b *wire.MsgBlock) { spendOut := chaingen.MakeSpendableOut(g.Tip(), 0, 0) ticketPrice := dcrutil.Amount(g.CalcNextRequiredStakeDifficulty()) tx := g.CreateTicketPurchaseTx(&spendOut, ticketPrice, lowFee) @@ -555,10 +557,10 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // --------------------------------------------------------------------- // Generate enough blocks to have mature coinbase outputs to work with. // - // genesis -> bp -> bm0 -> bm1 -> ... -> bm# + // genesis -> bfb -> bm0 -> bm1 -> ... -> bm# // --------------------------------------------------------------------- - g.SetTip("bp") + g.SetTip("bfb") var testInstances []TestInstance for i := uint16(0); i < coinbaseMaturity; i++ { blockName := fmt.Sprintf("bm%d", i) diff --git a/blockchain/fullblocktests/params.go b/blockchain/fullblocktests/params.go index 4889d9d0..3316642b 100644 --- a/blockchain/fullblocktests/params.go +++ b/blockchain/fullblocktests/params.go @@ -10,8 +10,8 @@ import ( "math/big" "time" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" + "github.com/decred/dcrd/chaincfg/v2" "github.com/decred/dcrd/wire" ) @@ -107,7 +107,7 @@ var regNetParams = &chaincfg.Params{ // Chain parameters GenesisBlock: ®NetGenesisBlock, - GenesisHash: newHashFromStr("2ced94b4ae95bba344cfa043268732d230649c640f92dce2d9518823d3057cb0"), + GenesisHash: *newHashFromStr("2ced94b4ae95bba344cfa043268732d230649c640f92dce2d9518823d3057cb0"), PowLimit: regNetPowLimit, PowLimitBits: 0x207fffff, ReduceMinDifficulty: false, @@ -312,9 +312,20 @@ var regNetParams = &chaincfg.Params{ // Decred organization related parameters OrganizationPkScript: fromHex("a9146913bcc838bd0087fb3f6b3c868423d5e300078d87"), OrganizationPkScriptVersion: 0, - BlockOneLedger: []*chaincfg.TokenPayout{ - {Address: "RsKrWb7Vny1jnzL1sDLgKTAteh9RZcRr5g6", Amount: 100000 * 1e8}, - {Address: "Rs8ca5cDALtsMVD4PV3xvFTC7dmuU1juvLv", Amount: 100000 * 1e8}, - {Address: "RsHzbGt6YajuHpurtpqXXHz57LmYZK8w9tX", Amount: 100000 * 1e8}, - }, + BlockOneLedger: []chaincfg.TokenPayout{{ + // RsKrWb7Vny1jnzL1sDLgKTAteh9RZcRr5g6 + ScriptVersion: 0, + Script: fromHex("76a9147e4765ae88ba9ad5c9e4715c484e90b34d358d5188ac"), + Amount: 100000 * 1e8, + }, { + // Rs8ca5cDALtsMVD4PV3xvFTC7dmuU1juvLv + ScriptVersion: 0, + Script: fromHex("76a91402fb1ac0137666d79165e13cecd403883615270788ac"), + Amount: 100000 * 1e8, + }, { + // RsHzbGt6YajuHpurtpqXXHz57LmYZK8w9tX + ScriptVersion: 0, + Script: fromHex("76a91469de627d3231b14228653dd09cba75eeb872754288ac"), + Amount: 100000 * 1e8, + }}, } diff --git a/blockchain/go.mod b/blockchain/go.mod index 6c808896..ed84306e 100644 --- a/blockchain/go.mod +++ b/blockchain/go.mod @@ -3,16 +3,16 @@ module github.com/decred/dcrd/blockchain go 1.11 require ( - github.com/decred/dcrd/blockchain/stake v1.2.1 + github.com/decred/dcrd/blockchain/stake/v2 v2.0.1 github.com/decred/dcrd/blockchain/standalone v1.0.0 - github.com/decred/dcrd/chaincfg v1.5.2 github.com/decred/dcrd/chaincfg/chainhash v1.0.2 - github.com/decred/dcrd/database v1.1.0 + github.com/decred/dcrd/chaincfg/v2 v2.2.0 + github.com/decred/dcrd/database/v2 v2.0.0 github.com/decred/dcrd/dcrec v1.0.0 github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 - github.com/decred/dcrd/dcrutil v1.4.0 + github.com/decred/dcrd/dcrutil/v2 v2.0.0 github.com/decred/dcrd/gcs v1.1.0 - github.com/decred/dcrd/txscript v1.1.0 + github.com/decred/dcrd/txscript/v2 v2.0.0 github.com/decred/dcrd/wire v1.2.0 github.com/decred/slog v1.0.0 ) diff --git a/blockchain/go.sum b/blockchain/go.sum index 39990aa4..b22e6065 100644 --- a/blockchain/go.sum +++ b/blockchain/go.sum @@ -14,16 +14,12 @@ github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4= github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= github.com/decred/base58 v1.0.0 h1:BVi1FQCThIjZ0ehG+I99NJ51o0xcc9A/fDKhmJxY6+w= github.com/decred/base58 v1.0.0/go.mod h1:LLY1p5e3g91byL/UO1eiZaYd+uRoVRarybgcoymu9Ks= -github.com/decred/dcrd/blockchain/stake v1.2.1 h1:Llj+mKNJEnMskeakMj62hllNVtiHF2vo7cDxsvoLVFg= -github.com/decred/dcrd/blockchain/stake v1.2.1/go.mod h1:3YGhsM2WCwUM6o0WLGoTCUXLOOw6H7tqXtVtWlcCE/Y= github.com/decred/dcrd/blockchain/stake/v2 v2.0.0 h1:+FMrSt5tPicBKlev0k/r/2VsaVwpIUcm1TPw69XgZw0= github.com/decred/dcrd/blockchain/stake/v2 v2.0.0/go.mod h1:jv/rKMcZ87lhvVkHot/tElxeAYEUJ3mnKPHJ7WPq86U= +github.com/decred/dcrd/blockchain/stake/v2 v2.0.1 h1:mAPZZA+Or8NPENheejmD6Fl90uykhurVuEdOBUMl35s= +github.com/decred/dcrd/blockchain/stake/v2 v2.0.1/go.mod h1:jv/rKMcZ87lhvVkHot/tElxeAYEUJ3mnKPHJ7WPq86U= github.com/decred/dcrd/blockchain/standalone v1.0.0 h1:bPkFgSV7/NeZI+ZEGhaOP+XccCUBTIJb3YTf8dMwe8g= github.com/decred/dcrd/blockchain/standalone v1.0.0/go.mod h1:U5lOleFSi1nL7heSdLgEtuvg0udS1p3cvHxvLJbihfE= -github.com/decred/dcrd/chaincfg v1.5.1 h1:u1Xbq0VTnAXIHW5ECqrWe0VYSgf5vWHqpSiwoLBzxAQ= -github.com/decred/dcrd/chaincfg v1.5.1/go.mod h1:FukMzTjkwzjPU+hK7CqDMQe3NMbSZAYU5PAcsx1wlv0= -github.com/decred/dcrd/chaincfg v1.5.2 h1:dd6l9rqcpxg2GF5neBmE2XxRc5Lqda45fWmN4XOJRW8= -github.com/decred/dcrd/chaincfg v1.5.2/go.mod h1:FukMzTjkwzjPU+hK7CqDMQe3NMbSZAYU5PAcsx1wlv0= github.com/decred/dcrd/chaincfg/chainhash v1.0.1 h1:0vG7U9+dSjSCaHQKdoSKURK2pOb47+b+8FK5q4+Je7M= github.com/decred/dcrd/chaincfg/chainhash v1.0.1/go.mod h1:OVfvaOsNLS/A1y4Eod0Ip/Lf8qga7VXCQjUQLbkY0Go= github.com/decred/dcrd/chaincfg/chainhash v1.0.2 h1:rt5Vlq/jM3ZawwiacWjPa+smINyLRN07EO0cNBV6DGU= @@ -31,10 +27,10 @@ github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D github.com/decred/dcrd/chaincfg/v2 v2.0.2/go.mod h1:hpKvhLCDAD/xDZ3V1Pqpv9fIKVYYi11DyxETguazyvg= github.com/decred/dcrd/chaincfg/v2 v2.1.0 h1:2S7TL9YWnKDDiH5bTpp3xcBo+1gl1IXFi5KU4QwSIDk= github.com/decred/dcrd/chaincfg/v2 v2.1.0/go.mod h1:hpKvhLCDAD/xDZ3V1Pqpv9fIKVYYi11DyxETguazyvg= +github.com/decred/dcrd/chaincfg/v2 v2.2.0 h1:SBkoqeM9+CkMA1V3i3Ffc4gAC4TqN2EoSRw5kjGkvx4= +github.com/decred/dcrd/chaincfg/v2 v2.2.0/go.mod h1:hpKvhLCDAD/xDZ3V1Pqpv9fIKVYYi11DyxETguazyvg= github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/database v1.1.0 h1:A9doThqEjOiE8NicDbMmRwr74itM47rcOzzWpy+keYU= -github.com/decred/dcrd/database v1.1.0/go.mod h1:/c8suHgDP20weTDFpObwvNbrMMlxn2LM4Tvm377ztwQ= github.com/decred/dcrd/database/v2 v2.0.0 h1:KWiyZHk+QyNKQvvxm/KpIejhTqYJqH9ssz1+9sT9nVA= github.com/decred/dcrd/database/v2 v2.0.0/go.mod h1:Sj2lvTRB0mfSu9uD7ObfwCY/eJ954GFU/X+AndJIyfE= github.com/decred/dcrd/dcrec v1.0.0 h1:W+z6Es+Rai3MXYVoPAxYr5U1DGis0Co33scJ6uH2J6o= @@ -45,16 +41,10 @@ github.com/decred/dcrd/dcrec/secp256k1 v1.0.1 h1:EFWVd1p0t0Y5tnsm/dJujgV0ORogRJ6 github.com/decred/dcrd/dcrec/secp256k1 v1.0.1/go.mod h1:lhu4eZFSfTJWUnR3CFRcpD+Vta0KUAqnhTsTksHXgy0= github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 h1:awk7sYJ4pGWmtkiGHFfctztJjHMKGLV8jctGQhAbKe0= github.com/decred/dcrd/dcrec/secp256k1 v1.0.2/go.mod h1:CHTUIVfmDDd0KFVFpNX1pFVCBUegxW387nN0IGwNKR0= -github.com/decred/dcrd/dcrutil v1.3.0 h1:LtKIiDnq925yJT/4OpIKKiU9/WaxfD9LfhxrpLSi0Qs= -github.com/decred/dcrd/dcrutil v1.3.0/go.mod h1:7fUT70QAarhDwQK62g92uDbbYpjXlXngpy5RBiecufo= -github.com/decred/dcrd/dcrutil v1.4.0 h1:xD5aUqysGQnsnP1c9J0kGeW8lDIwFGC3ja/gE3HnpCs= -github.com/decred/dcrd/dcrutil v1.4.0/go.mod h1:Bs74gm1jQ9ZAbmEh9FWOEZ1HQzlMg5iPATDMzMnCMlQ= github.com/decred/dcrd/dcrutil/v2 v2.0.0 h1:HTqn2tZ8eqBF4y3hJwjyKBmJt16y7/HjzpE82E/crhY= github.com/decred/dcrd/dcrutil/v2 v2.0.0/go.mod h1:gUshVAXpd51DlcEhr51QfWL2HJGkMDM1U8chY+9VvQg= github.com/decred/dcrd/gcs v1.1.0 h1:djuYzaFUzUTJR+6ulMSRZOQ+P9rxtIyuxQeViAEfB8s= github.com/decred/dcrd/gcs v1.1.0/go.mod h1:yBjhj217Vw5lw3aKnCdHip7fYb9zwMos8bCy5s79M9w= -github.com/decred/dcrd/txscript v1.1.0 h1:MwkLXdc4Yq83oeNNEQJdlBTkNlorKXn8Nd5W2JXyMZg= -github.com/decred/dcrd/txscript v1.1.0/go.mod h1:gbcq6gpGfKddPmZSKp+17ils2cLzUqHopXf8H5rCY7Y= github.com/decred/dcrd/txscript/v2 v2.0.0 h1:So+NcQY58mDHDN2N2edED5syGZp2ed8Ltxj8mDE5CAs= github.com/decred/dcrd/txscript/v2 v2.0.0/go.mod h1:WStcyYYJa+PHJB4XjrLDRzV96/Z4thtsu8mZoVrU6C0= github.com/decred/dcrd/wire v1.2.0 h1:HqJVB7vcklIguzFWgRXw/WYCQ9cD3bUC5TKj53i1Hng= @@ -63,29 +53,21 @@ github.com/decred/slog v1.0.0 h1:Dl+W8O6/JH6n2xIFN2p3DNjCmjYwvrXsjlSJTQQ4MhE= github.com/decred/slog v1.0.0/go.mod h1:zR98rEZHSnbZ4WHZtO0iqmSZjDLKhkXfrPTZQKtAonQ= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= -github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1 h1:PZSj/UFNaVp3KxrzHOcS7oyuWA7LoOY/77yCTEFu21U= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= -github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -99,5 +81,3 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/blockchain/indexers/addrindex.go b/blockchain/indexers/addrindex.go index fe86d196..cbda8190 100644 --- a/blockchain/indexers/addrindex.go +++ b/blockchain/indexers/addrindex.go @@ -1,5 +1,5 @@ // Copyright (c) 2016 The btcsuite developers -// Copyright (c) 2016-2017 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -11,13 +11,13 @@ import ( "sync" "github.com/decred/dcrd/blockchain" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" "github.com/decred/dcrd/dcrec" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -535,10 +535,10 @@ func dbRemoveAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte, // addrToKey converts known address types to an addrindex key. An error is // returned for unsupported types. -func addrToKey(addr dcrutil.Address, params *chaincfg.Params) ([addrKeySize]byte, error) { +func addrToKey(addr dcrutil.Address) ([addrKeySize]byte, error) { switch addr := addr.(type) { case *dcrutil.AddressPubKeyHash: - switch addr.DSA(params) { + switch addr.DSA() { case dcrec.STEcdsaSecp256k1: var result [addrKeySize]byte result[0] = addrKeyTypePubKeyHash @@ -704,7 +704,7 @@ func (idx *AddrIndex) indexPkScript(data writeIndexData, scriptVersion uint16, p } for _, addr := range addrs { - addrKey, err := addrToKey(addr, idx.chainParams) + addrKey, err := addrToKey(addr) if err != nil { // Ignore unsupported address types. continue @@ -893,7 +893,7 @@ func (idx *AddrIndex) DisconnectBlock(dbTx database.Tx, block, parent *dcrutil.B // // This function is safe for concurrent access. func (idx *AddrIndex) EntriesForAddress(dbTx database.Tx, addr dcrutil.Address, numToSkip, numRequested uint32, reverse bool) ([]TxIndexEntry, uint32, error) { - addrKey, err := addrToKey(addr, idx.chainParams) + addrKey, err := addrToKey(addr) if err != nil { return nil, 0, err } @@ -943,7 +943,7 @@ func (idx *AddrIndex) indexUnconfirmedAddresses(scriptVersion uint16, pkScript [ for _, addr := range addresses { // Ignore unsupported address types. - addrKey, err := addrToKey(addr, idx.chainParams) + addrKey, err := addrToKey(addr) if err != nil { continue } @@ -1042,7 +1042,7 @@ func (idx *AddrIndex) RemoveUnconfirmedTx(hash *chainhash.Hash) { // This function is safe for concurrent access. func (idx *AddrIndex) UnconfirmedTxnsForAddress(addr dcrutil.Address) []*dcrutil.Tx { // Ignore unsupported address types. - addrKey, err := addrToKey(addr, idx.chainParams) + addrKey, err := addrToKey(addr) if err != nil { return nil } diff --git a/blockchain/indexers/cfindex.go b/blockchain/indexers/cfindex.go index 677b50dc..61174162 100644 --- a/blockchain/indexers/cfindex.go +++ b/blockchain/indexers/cfindex.go @@ -1,5 +1,5 @@ // Copyright (c) 2017 The btcsuite developers -// Copyright (c) 2018 The Decred developers +// Copyright (c) 2018-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -10,10 +10,10 @@ import ( "fmt" "github.com/decred/dcrd/blockchain" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/gcs" "github.com/decred/dcrd/gcs/blockcf" "github.com/decred/dcrd/wire" diff --git a/blockchain/indexers/common.go b/blockchain/indexers/common.go index 2baa18e0..677ad0b5 100644 --- a/blockchain/indexers/common.go +++ b/blockchain/indexers/common.go @@ -1,5 +1,5 @@ // Copyright (c) 2016 The btcsuite developers -// Copyright (c) 2016-2017 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -13,8 +13,8 @@ import ( "errors" "github.com/decred/dcrd/blockchain" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" ) var ( diff --git a/blockchain/indexers/existsaddrindex.go b/blockchain/indexers/existsaddrindex.go index 4df6085c..78f5304a 100644 --- a/blockchain/indexers/existsaddrindex.go +++ b/blockchain/indexers/existsaddrindex.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2017 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -8,11 +8,11 @@ import ( "sync" "github.com/decred/dcrd/blockchain" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/blockchain/stake/v2" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -145,7 +145,7 @@ func (idx *ExistsAddrIndex) existsAddress(bucket internalBucket, k [addrKeySize] // ExistsAddress is the concurrency safe, exported function that returns // whether or not an address has been seen before. func (idx *ExistsAddrIndex) ExistsAddress(addr dcrutil.Address) (bool, error) { - k, err := addrToKey(addr, idx.chainParams) + k, err := addrToKey(addr) if err != nil { return false, err } @@ -179,7 +179,7 @@ func (idx *ExistsAddrIndex) ExistsAddresses(addrs []dcrutil.Address) ([]bool, er addrKeys := make([][addrKeySize]byte, len(addrs)) for i := range addrKeys { var err error - addrKeys[i], err = addrToKey(addrs[i], idx.chainParams) + addrKeys[i], err = addrToKey(addrs[i]) if err != nil { return nil, err } @@ -236,16 +236,15 @@ func (idx *ExistsAddrIndex) ConnectBlock(dbTx database.Tx, block, parent *dcruti msgTx := tx.MsgTx() isSStx := stake.IsSStx(msgTx) for _, txIn := range msgTx.TxIn { + // Note that the functions used here require v0 scripts. Hence it + // is used for the script version. This will ultimately need to + // updated to support new script versions. + const scriptVersion = 0 if txscript.IsMultisigSigScript(txIn.SignatureScript) { - rs, err := - txscript.MultisigRedeemScriptFromScriptSig( - txIn.SignatureScript) - if err != nil { - continue - } - + rs := txscript.MultisigRedeemScriptFromScriptSig( + txIn.SignatureScript) class, addrs, _, err := txscript.ExtractPkScriptAddrs( - txscript.DefaultScriptVersion, rs, idx.chainParams) + scriptVersion, rs, idx.chainParams) if err != nil { // Non-standard outputs are skipped. continue @@ -256,7 +255,7 @@ func (idx *ExistsAddrIndex) ConnectBlock(dbTx database.Tx, block, parent *dcruti } for _, addr := range addrs { - k, err := addrToKey(addr, idx.chainParams) + k, err := addrToKey(addr) if err != nil { continue } @@ -286,7 +285,7 @@ func (idx *ExistsAddrIndex) ConnectBlock(dbTx database.Tx, block, parent *dcruti } for _, addr := range addrs { - k, err := addrToKey(addr, idx.chainParams) + k, err := addrToKey(addr) if err != nil { // Ignore unsupported address types. continue @@ -357,15 +356,14 @@ func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx) { isSStx := stake.IsSStx(tx) for _, txIn := range tx.TxIn { if txscript.IsMultisigSigScript(txIn.SignatureScript) { - rs, err := - txscript.MultisigRedeemScriptFromScriptSig( - txIn.SignatureScript) - if err != nil { - continue - } - + // Note that the functions used here require v0 scripts. Hence it + // is used for the script version. This will ultimately need to + // updated to support new script versions. + const scriptVersion = 0 + rs := txscript.MultisigRedeemScriptFromScriptSig( + txIn.SignatureScript) class, addrs, _, err := txscript.ExtractPkScriptAddrs( - txscript.DefaultScriptVersion, rs, idx.chainParams) + scriptVersion, rs, idx.chainParams) if err != nil { // Non-standard outputs are skipped. continue @@ -376,7 +374,7 @@ func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx) { } for _, addr := range addrs { - k, err := addrToKey(addr, idx.chainParams) + k, err := addrToKey(addr) if err != nil { continue } @@ -408,7 +406,7 @@ func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx) { } for _, addr := range addrs { - k, err := addrToKey(addr, idx.chainParams) + k, err := addrToKey(addr) if err != nil { // Ignore unsupported address types. continue diff --git a/blockchain/indexers/manager.go b/blockchain/indexers/manager.go index 710cfcf4..392c814d 100644 --- a/blockchain/indexers/manager.go +++ b/blockchain/indexers/manager.go @@ -1,5 +1,5 @@ // Copyright (c) 2016 The btcsuite developers -// Copyright (c) 2016-2017 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -11,11 +11,11 @@ import ( "github.com/decred/dcrd/blockchain" "github.com/decred/dcrd/blockchain/internal/progresslog" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/indexers/txindex.go b/blockchain/indexers/txindex.go index b0298c3e..8919f64c 100644 --- a/blockchain/indexers/txindex.go +++ b/blockchain/indexers/txindex.go @@ -1,5 +1,5 @@ // Copyright (c) 2016 The btcsuite developers -// Copyright (c) 2016-2017 The Decred developers +// Copyright (c) 2016-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -11,8 +11,8 @@ import ( "github.com/decred/dcrd/blockchain" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/merkle.go b/blockchain/merkle.go index 505c4c18..7b8db51c 100644 --- a/blockchain/merkle.go +++ b/blockchain/merkle.go @@ -9,7 +9,7 @@ import ( "math" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/notifications.go b/blockchain/notifications.go index fb203b7a..0c259d56 100644 --- a/blockchain/notifications.go +++ b/blockchain/notifications.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -9,7 +9,7 @@ import ( "fmt" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/dcrutil/v2" ) // NotificationType represents the type of a notification message. diff --git a/blockchain/process.go b/blockchain/process.go index 4a8ddccd..a7dd7648 100644 --- a/blockchain/process.go +++ b/blockchain/process.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -11,7 +11,7 @@ import ( "github.com/decred/dcrd/blockchain/standalone" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/dcrutil/v2" ) // BehaviorFlags is a bitmask defining tweaks to the normal behavior when diff --git a/blockchain/scriptval.go b/blockchain/scriptval.go index 9c8b34c6..275a678a 100644 --- a/blockchain/scriptval.go +++ b/blockchain/scriptval.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -10,8 +10,8 @@ import ( "math" "runtime" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/sequencelock.go b/blockchain/sequencelock.go index 6e7ac4f9..cf0a0900 100644 --- a/blockchain/sequencelock.go +++ b/blockchain/sequencelock.go @@ -7,9 +7,9 @@ package blockchain import ( "fmt" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) diff --git a/blockchain/sequencelock_test.go b/blockchain/sequencelock_test.go index e2cecbe9..49cf72fc 100644 --- a/blockchain/sequencelock_test.go +++ b/blockchain/sequencelock_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2018 The Decred developers +// Copyright (c) 2017-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/decred/dcrd/chaincfg" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) @@ -34,7 +34,7 @@ func TestCalcSequenceLock(t *testing.T) { // Generate a synthetic simnet chain with enough nodes to properly test // the sequence lock functionality. numBlocks := uint32(20) - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() bc := newFakeChain(params) node := bc.bestChain.Tip() blockTime := time.Unix(node.timestamp, 0) diff --git a/blockchain/stake/internal/ticketdb/chainio.go b/blockchain/stake/internal/ticketdb/chainio.go index 95d5b3c4..a01502aa 100644 --- a/blockchain/stake/internal/ticketdb/chainio.go +++ b/blockchain/stake/internal/ticketdb/chainio.go @@ -250,9 +250,9 @@ type BestChainState struct { // corruption. func serializeBestChainState(state BestChainState) []byte { if int(state.PerBlock) < len(state.NextWinners) { - errStr := fmt.Sprintf("PerBlock:%d < NextWinners:%d", + str := fmt.Sprintf("PerBlock:%d < NextWinners:%d", state.PerBlock, len(state.NextWinners)) - panic(errStr) + panic(str) } serializedDataLen := minimumBestChainStateSize + diff --git a/blockchain/stakeext.go b/blockchain/stakeext.go index af04fa48..b98ecd8f 100644 --- a/blockchain/stakeext.go +++ b/blockchain/stakeext.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2014 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -9,9 +9,9 @@ import ( "fmt" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" ) // NextLotteryData returns the next tickets eligible for spending as SSGen @@ -122,12 +122,12 @@ func (b *BlockChain) TicketsWithAddress(address dcrutil.Address) ([]chainhash.Ha } _, addrs, _, err := - txscript.ExtractPkScriptAddrs(txscript.DefaultScriptVersion, + txscript.ExtractPkScriptAddrs(utxo.ScriptVersionByIndex(0), utxo.PkScriptByIndex(0), b.chainParams) if err != nil { return err } - if addrs[0].EncodeAddress() == address.EncodeAddress() { + if addrs[0].Address() == address.Address() { ticketsWithAddr = append(ticketsWithAddr, hash) } } diff --git a/blockchain/stakenode.go b/blockchain/stakenode.go index 8d67957c..764e8e79 100644 --- a/blockchain/stakenode.go +++ b/blockchain/stakenode.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -8,9 +8,9 @@ package blockchain import ( "fmt" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" + "github.com/decred/dcrd/database/v2" ) // maybeFetchNewTickets loads the list of newly maturing tickets for a given diff --git a/blockchain/stakeversion_test.go b/blockchain/stakeversion_test.go index 21a27cd5..107f6e01 100644 --- a/blockchain/stakeversion_test.go +++ b/blockchain/stakeversion_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" + "github.com/decred/dcrd/chaincfg/v2" ) // isVoterMajorityVersion determines if minVer requirement is met based on @@ -67,6 +67,10 @@ func TestCalcWantHeight(t *testing.T) { // windows start at 13 + (11 * 2) 25 and are as follows: 24-34, 35-45, 46-56 ... // If height comes in at 35 we use the 24-34 window, up to height 45. // If height comes in at 46 we use the 35-45 window, up to height 56 etc. + mainNetParams := chaincfg.MainNetParams() + testNet3Params := chaincfg.TestNet3Params() + simNetParams := chaincfg.SimNetParams() + regNetParams := chaincfg.RegNetParams() tests := []struct { name string skip int64 @@ -88,32 +92,32 @@ func TestCalcWantHeight(t *testing.T) { }, { name: "mainnet params", - skip: chaincfg.MainNetParams.StakeValidationHeight, - interval: chaincfg.MainNetParams.StakeVersionInterval, + skip: mainNetParams.StakeValidationHeight, + interval: mainNetParams.StakeVersionInterval, multiplier: 5000, }, { name: "testnet3 params", - skip: chaincfg.TestNet3Params.StakeValidationHeight, - interval: chaincfg.TestNet3Params.StakeVersionInterval, + skip: testNet3Params.StakeValidationHeight, + interval: testNet3Params.StakeVersionInterval, multiplier: 1000, }, { name: "simnet params", - skip: chaincfg.SimNetParams.StakeValidationHeight, - interval: chaincfg.SimNetParams.StakeVersionInterval, + skip: simNetParams.StakeValidationHeight, + interval: simNetParams.StakeVersionInterval, multiplier: 10000, }, { name: "regnet params", - skip: chaincfg.RegNetParams.StakeValidationHeight, - interval: chaincfg.RegNetParams.StakeVersionInterval, + skip: regNetParams.StakeValidationHeight, + interval: regNetParams.StakeVersionInterval, multiplier: 10000, }, { name: "negative mainnet params", - skip: chaincfg.MainNetParams.StakeValidationHeight, - interval: chaincfg.MainNetParams.StakeVersionInterval, + skip: mainNetParams.StakeValidationHeight, + interval: mainNetParams.StakeVersionInterval, multiplier: 1000, negative: 1, }, @@ -147,7 +151,7 @@ func TestCalcWantHeight(t *testing.T) { // TestCalcStakeVersionCorners ensures that stake version calculation works as // intended under various corner cases such as attempting to go back backwards. func TestCalcStakeVersionCorners(t *testing.T) { - params := &chaincfg.SimNetParams + params := chaincfg.SimNetParams() svh := params.StakeValidationHeight svi := params.StakeVersionInterval @@ -312,7 +316,7 @@ func TestCalcStakeVersionCorners(t *testing.T) { // TestCalcStakeVersion ensures that stake version calculation works as // intended when func TestCalcStakeVersion(t *testing.T) { - params := &chaincfg.SimNetParams + params := chaincfg.SimNetParams() svh := params.StakeValidationHeight svi := params.StakeVersionInterval tpb := params.TicketsPerBlock @@ -370,7 +374,7 @@ func TestCalcStakeVersion(t *testing.T) { // TestIsStakeMajorityVersion ensures that determining the current majority // stake version works as intended under a wide variety of scenarios. func TestIsStakeMajorityVersion(t *testing.T) { - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() svh := params.StakeValidationHeight svi := params.StakeVersionInterval tpb := params.TicketsPerBlock @@ -715,7 +719,7 @@ func TestIsStakeMajorityVersion(t *testing.T) { } func TestLarge(t *testing.T) { - params := &chaincfg.MainNetParams + params := chaincfg.MainNetParams() numRuns := 5 numBlocks := params.StakeVersionInterval * 100 diff --git a/blockchain/subsidy.go b/blockchain/subsidy.go index a6ca4d3b..c0a9be8f 100644 --- a/blockchain/subsidy.go +++ b/blockchain/subsidy.go @@ -9,11 +9,10 @@ import ( "bytes" "fmt" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" - "github.com/decred/dcrd/chaincfg" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) @@ -28,94 +27,13 @@ const subsidyCacheInitWidth = 4 // Deprecated: Use standalone.SubsidyCache instead. type SubsidyCache = standalone.SubsidyCache -// subsidyParams adapts v1 chaincfg.Params to implement the -// standalone.SubsidyParams interface. It is already implemented by the v2 -// chaincfg.Params, but updating to those requires a major version bump since -// the type is used in the public API. -type subsidyParams struct { - *chaincfg.Params -} - -// BaseSubsidyValue returns the starting base max potential subsidy amount for -// mined blocks. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) BaseSubsidyValue() int64 { - return p.BaseSubsidy -} - -// SubsidyReductionMultiplier returns the multiplier to use when performing the -// exponential subsidy reduction. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) SubsidyReductionMultiplier() int64 { - return p.MulSubsidy -} - -// SubsidyReductionDivisor returns the divisor to use when performing the -// exponential subsidy reduction. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) SubsidyReductionDivisor() int64 { - return p.DivSubsidy -} - -// SubsidyReductionIntervalBlocks returns the reduction interval in number of -// blocks. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) SubsidyReductionIntervalBlocks() int64 { - return p.SubsidyReductionInterval -} - -// WorkSubsidyProportion returns the comparative proportion of the subsidy -// generated for creating a block (PoW). -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) WorkSubsidyProportion() uint16 { - return p.WorkRewardProportion -} - -// StakeSubsidyProportion returns the comparative proportion of the subsidy -// generated for casting stake votes (collectively, per block). -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) StakeSubsidyProportion() uint16 { - return p.StakeRewardProportion -} - -// TreasurySubsidyProportion returns the comparative proportion of the subsidy -// allocated to the project treasury. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) TreasurySubsidyProportion() uint16 { - return p.BlockTaxProportion -} - -// VotesPerBlock returns the maximum number of votes a block must contain to -// receive full subsidy. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) VotesPerBlock() uint16 { - return p.TicketsPerBlock -} - -// StakeValidationBeginHeight returns the height at which votes become required -// to extend a block. This height is the first that will be voted on, but will -// not include any votes itself. -// -// This is part of the standalone.SubsidyParams interface. -func (p *subsidyParams) StakeValidationBeginHeight() int64 { - return p.StakeValidationHeight -} - // NewSubsidyCache initializes a new subsidy cache for a given height. It // precalculates the values of the subsidy that are most likely to be seen by // the client when it connects to the network. // // Deprecated: Use standalone.NewSubsidyCache instead. func NewSubsidyCache(height int64, params *chaincfg.Params) *SubsidyCache { - return standalone.NewSubsidyCache(&subsidyParams{params}) + return standalone.NewSubsidyCache(params) } // CalcBlockWorkSubsidy calculates the proof of work subsidy for a block as a @@ -149,78 +67,59 @@ func CalcBlockTaxSubsidy(subsidyCache *SubsidyCache, height int64, voters uint16 // blockOneCoinbasePaysTokens checks to see if the first block coinbase pays // out to the network initial token ledger. func blockOneCoinbasePaysTokens(tx *dcrutil.Tx, params *chaincfg.Params) error { - // If no ledger is specified, just return true. + // Nothing to do when there is no ledger specified. if len(params.BlockOneLedger) == 0 { return nil } if tx.MsgTx().LockTime != 0 { - errStr := fmt.Sprintf("block 1 coinbase has invalid locktime") - return ruleError(ErrBlockOneTx, errStr) + str := fmt.Sprintf("block 1 coinbase has invalid locktime") + return ruleError(ErrBlockOneTx, str) } if tx.MsgTx().Expiry != wire.NoExpiryValue { - errStr := fmt.Sprintf("block 1 coinbase has invalid expiry") - return ruleError(ErrBlockOneTx, errStr) + str := fmt.Sprintf("block 1 coinbase has invalid expiry") + return ruleError(ErrBlockOneTx, str) } if tx.MsgTx().TxIn[0].Sequence != wire.MaxTxInSequenceNum { - errStr := fmt.Sprintf("block 1 coinbase not finalized") - return ruleError(ErrBlockOneInputs, errStr) + str := fmt.Sprintf("block 1 coinbase not finalized") + return ruleError(ErrBlockOneInputs, str) } if len(tx.MsgTx().TxOut) == 0 { - errStr := fmt.Sprintf("coinbase outputs empty in block 1") - return ruleError(ErrBlockOneOutputs, errStr) + str := fmt.Sprintf("coinbase outputs empty in block 1") + return ruleError(ErrBlockOneOutputs, str) } ledger := params.BlockOneLedger if len(ledger) != len(tx.MsgTx().TxOut) { - errStr := fmt.Sprintf("wrong number of outputs in block 1 coinbase; "+ + str := fmt.Sprintf("wrong number of outputs in block 1 coinbase; "+ "got %v, expected %v", len(tx.MsgTx().TxOut), len(ledger)) - return ruleError(ErrBlockOneOutputs, errStr) + return ruleError(ErrBlockOneOutputs, str) } // Check the addresses and output amounts against those in the ledger. const consensusScriptVersion = 0 - for i, txout := range tx.MsgTx().TxOut { - if txout.Version != consensusScriptVersion { + for i, txOut := range tx.MsgTx().TxOut { + ledgerEntry := &ledger[i] + if txOut.Version != ledgerEntry.ScriptVersion { str := fmt.Sprintf("block one output %d script version %d is not %d", - i, txout.Version, consensusScriptVersion) + i, txOut.Version, consensusScriptVersion) return ruleError(ErrBlockOneOutputs, str) } - // There should only be one address. - _, addrs, _, err := - txscript.ExtractPkScriptAddrs(txout.Version, txout.PkScript, params) - if err != nil { - return ruleError(ErrBlockOneOutputs, err.Error()) - } - if len(addrs) != 1 { - errStr := fmt.Sprintf("too many addresses in output") - return ruleError(ErrBlockOneOutputs, errStr) + if !bytes.Equal(txOut.PkScript, ledgerEntry.Script) { + str := fmt.Sprintf("block one output %d script %x is not %x", i, + txOut.PkScript, ledgerEntry.Script) + return ruleError(ErrBlockOneOutputs, str) } - addrLedger, err := dcrutil.DecodeAddress(ledger[i].Address) - if err != nil { - return err - } - - if !bytes.Equal(addrs[0].ScriptAddress(), addrLedger.ScriptAddress()) { - errStr := fmt.Sprintf("address in output %v has non matching "+ - "address; got %v (hash160 %x), want %v (hash160 %x)", - i, - addrs[0].EncodeAddress(), - addrs[0].ScriptAddress(), - addrLedger.EncodeAddress(), - addrLedger.ScriptAddress()) - return ruleError(ErrBlockOneOutputs, errStr) - } - - if txout.Value != ledger[i].Amount { - errStr := fmt.Sprintf("address in output %v has non matching "+ - "amount; got %v, want %v", i, txout.Value, ledger[i].Amount) - return ruleError(ErrBlockOneOutputs, errStr) + if txOut.Value != ledgerEntry.Amount { + str := fmt.Sprintf("block one output %d generates %v instead of "+ + "required %v", i, dcrutil.Amount(txOut.Value), + dcrutil.Amount(ledgerEntry.Amount)) + return ruleError(ErrBlockOneOutputs, str) } } diff --git a/blockchain/subsidy_test.go b/blockchain/subsidy_test.go index 38f239cd..c8b505eb 100644 --- a/blockchain/subsidy_test.go +++ b/blockchain/subsidy_test.go @@ -8,11 +8,11 @@ package blockchain import ( "testing" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/chaincfg/v2" ) func TestBlockSubsidy(t *testing.T) { - mainnet := &chaincfg.MainNetParams + mainnet := chaincfg.MainNetParams() reductionInterval := mainnet.SubsidyReductionInterval stakeValidationHeight := mainnet.StakeValidationHeight votesPerBlock := mainnet.TicketsPerBlock @@ -67,7 +67,7 @@ func TestBlockSubsidy(t *testing.T) { } func TestCachedCalcBlockSubsidy(t *testing.T) { - mainnet := &chaincfg.MainNetParams + mainnet := chaincfg.MainNetParams() cacheA := NewSubsidyCache(0, mainnet) _ = cacheA.CalcBlockSubsidy(mainnet.SubsidyReductionInterval + 1) diff --git a/blockchain/thresholdstate.go b/blockchain/thresholdstate.go index 4eb41c58..3f965ea8 100644 --- a/blockchain/thresholdstate.go +++ b/blockchain/thresholdstate.go @@ -8,8 +8,8 @@ package blockchain import ( "fmt" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" + "github.com/decred/dcrd/chaincfg/v2" ) // ThresholdState define the various threshold states used when voting on diff --git a/blockchain/thresholdstate_test.go b/blockchain/thresholdstate_test.go index 0310305d..7993156c 100644 --- a/blockchain/thresholdstate_test.go +++ b/blockchain/thresholdstate_test.go @@ -11,7 +11,7 @@ import ( "time" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/chaincfg/v2" ) const ( @@ -117,7 +117,7 @@ func TestThresholdState(t *testing.T) { // size to a really large number so that the test chain can be generated // more quickly. posVersion := uint32(4) - params := cloneParams(&chaincfg.RegNetParams) + params := chaincfg.RegNetParams() params.WorkDiffWindowSize = 200000 params.WorkDiffWindows = 1 params.TargetTimespan = params.TargetTimePerBlock * @@ -165,7 +165,7 @@ func TestThresholdState(t *testing.T) { // Add the required initial block. // // genesis -> bfb - g.CreatePremineBlock("bfb", 0) + g.CreateBlockOne("bfb", 0) g.AssertTipHeight(1) g.AcceptTipBlock() g.TestThresholdStateChoice(testDummy1ID, ThresholdDefined, invalidChoice) diff --git a/blockchain/upgrade.go b/blockchain/upgrade.go index 2663e5c2..c8bdafdd 100644 --- a/blockchain/upgrade.go +++ b/blockchain/upgrade.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2016 The btcsuite developers -// Copyright (c) 2015-2018 The Decred developers +// Copyright (c) 2015-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -13,12 +13,12 @@ import ( "time" "github.com/decred/dcrd/blockchain/internal/progresslog" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) @@ -171,7 +171,8 @@ func upgradeToVersion2(db database.DB, chainParams *chaincfg.Params, dbInfo *dat return err } - bestStakeNode, errLocal := stake.InitDatabaseState(dbTx, chainParams) + bestStakeNode, errLocal := stake.InitDatabaseState(dbTx, chainParams, + &chainParams.GenesisHash) if errLocal != nil { return errLocal } @@ -585,7 +586,8 @@ func upgradeToVersion5(db database.DB, chainParams *chaincfg.Params, dbInfo *dat err = db.Update(func(dbTx database.Tx) error { // Reset the ticket database to the genesis block. log.Infof("Resetting the ticket database. This might take a while...") - if err := stake.ResetDatabase(dbTx, chainParams); err != nil { + err := stake.ResetDatabase(dbTx, chainParams, &chainParams.GenesisHash) + if err != nil { return err } diff --git a/blockchain/utxoviewpoint.go b/blockchain/utxoviewpoint.go index 9d05ece9..03f20697 100644 --- a/blockchain/utxoviewpoint.go +++ b/blockchain/utxoviewpoint.go @@ -8,12 +8,12 @@ package blockchain import ( "fmt" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" ) // utxoOutput houses details about an individual unspent transaction output such diff --git a/blockchain/validate.go b/blockchain/validate.go index 10c00805..bd21063e 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -13,13 +13,13 @@ import ( "math/big" "time" - "github.com/decred/dcrd/blockchain/stake" + "github.com/decred/dcrd/blockchain/stake/v2" "github.com/decred/dcrd/blockchain/standalone" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" - "github.com/decred/dcrd/txscript" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" + "github.com/decred/dcrd/txscript/v2" "github.com/decred/dcrd/wire" ) @@ -85,6 +85,13 @@ const ( // submissionOutputIdx is the index of the stake submission output of a // ticket transaction. submissionOutputIdx = 0 + + // checkForDuplicateHashes checks for duplicate hashes when validating + // blocks. Because of the rule inserting the height into the second (nonce) + // txOut, there should never be a duplicate transaction hash that overwrites + // another. However, because there is a 2^128 chance of a collision, the + // paranoid user may wish to turn this feature on. + checkForDuplicateHashes = false ) var ( @@ -1451,7 +1458,7 @@ func (b *BlockChain) checkBlockContext(block *dcrutil.Block, prevNode *blockNode // Decred: Check the stake transactions to make sure they don't have this txid // too. func (b *BlockChain) checkDupTxs(txSet []*dcrutil.Tx, view *UtxoViewpoint) error { - if !chaincfg.CheckForDuplicateHashes { + if !checkForDuplicateHashes { return nil } @@ -2462,8 +2469,7 @@ func CountP2SHSigOps(tx *dcrutil.Tx, isCoinBaseTx bool, isStakeBaseTx bool, view // Count the precise number of signature operations in the // referenced public key script. sigScript := txIn.SignatureScript - numSigOps := txscript.GetPreciseSigOpCount(sigScript, pkScript, - true) + numSigOps := txscript.GetPreciseSigOpCount(sigScript, pkScript) // We could potentially overflow the accumulator so check for // overflow. diff --git a/blockchain/validate_test.go b/blockchain/validate_test.go index d427ee2d..0ee6bade 100644 --- a/blockchain/validate_test.go +++ b/blockchain/validate_test.go @@ -17,10 +17,10 @@ import ( "time" "github.com/decred/dcrd/blockchain/chaingen" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" - "github.com/decred/dcrd/database" - "github.com/decred/dcrd/dcrutil" + "github.com/decred/dcrd/chaincfg/v2" + "github.com/decred/dcrd/database/v2" + "github.com/decred/dcrd/dcrutil/v2" "github.com/decred/dcrd/wire" ) @@ -28,20 +28,27 @@ import ( // written to disk correctly on a live blockchain. func TestBlockchainSpendJournal(t *testing.T) { // Update parameters to reflect what is expected by the legacy data. - params := cloneParams(&chaincfg.RegNetParams) + params := chaincfg.RegNetParams() params.GenesisBlock.Header.MerkleRoot = *mustParseHash("a216ea043f0d481a072424af646787794c32bcefd3ed181a090319bbf8a37105") params.GenesisBlock.Header.Timestamp = time.Unix(1401292357, 0) params.GenesisBlock.Transactions[0].TxIn[0].ValueIn = 0 params.PubKeyHashAddrID = [2]byte{0x0e, 0x91} params.StakeBaseSigScript = []byte{0xde, 0xad, 0xbe, 0xef} params.OrganizationPkScript = hexToBytes("a914cbb08d6ca783b533b2c7d24a51fbca92d937bf9987") - params.BlockOneLedger = []*chaincfg.TokenPayout{ - {Address: "Sshw6S86G2bV6W32cbc7EhtFy8f93rU6pae", Amount: 100000 * 1e8}, - {Address: "SsjXRK6Xz6CFuBt6PugBvrkdAa4xGbcZ18w", Amount: 100000 * 1e8}, - {Address: "SsfXiYkYkCoo31CuVQw428N6wWKus2ZEw5X", Amount: 100000 * 1e8}, - } - genesisHash := params.GenesisBlock.BlockHash() - params.GenesisHash = &genesisHash + params.BlockOneLedger = []chaincfg.TokenPayout{{ + ScriptVersion: 0, + Script: hexToBytes("76a91494ff37a0ee4d48abc45f70474f9b86f9da69a70988ac"), + Amount: 100000 * 1e8, + }, { + ScriptVersion: 0, + Script: hexToBytes("76a914a6753ebbc08e2553e7dd6d64bdead4bcbff4fcf188ac"), + Amount: 100000 * 1e8, + }, { + ScriptVersion: 0, + Script: hexToBytes("76a9147aa3211c2ead810bbf5911c275c69cc196202bd888ac"), + Amount: 100000 * 1e8, + }} + params.GenesisHash = params.GenesisBlock.BlockHash() // Create a new database and chain instance to run tests against. chain, teardownFunc, err := chainSetup("spendjournalunittest", params) @@ -221,7 +228,7 @@ func TestSequenceLocksActive(t *testing.T) { // validation heights, the proof-of-work block version upgrade window, the stake // version interval, and the rule change activation interval. func quickVoteActivationParams() *chaincfg.Params { - params := cloneParams(&chaincfg.RegNetParams) + params := chaincfg.RegNetParams() params.WorkDiffWindowSize = 200000 params.WorkDiffWindows = 1 params.TargetTimespan = params.TargetTimePerBlock * @@ -519,7 +526,7 @@ func TestLegacySequenceLocks(t *testing.T) { // TestCheckBlockSanity tests the context free block sanity checks with blocks // not on a chain. func TestCheckBlockSanity(t *testing.T) { - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() timeSource := NewMedianTime() block := dcrutil.NewBlock(&badBlock) err := CheckBlockSanity(block, timeSource, params) @@ -532,7 +539,7 @@ func TestCheckBlockSanity(t *testing.T) { // because its parent is nil. func TestCheckBlockHeaderContext(t *testing.T) { // Create a new database for the blocks. - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() dbPath := filepath.Join(os.TempDir(), "examplecheckheadercontext") _ = os.RemoveAll(dbPath) db, err := database.Create("ffldb", dbPath, params.Net) @@ -590,7 +597,7 @@ func TestTxValidationErrors(t *testing.T) { } // Ensure transaction is rejected due to being too large. - err := CheckTransactionSanity(tx, &chaincfg.MainNetParams) + err := CheckTransactionSanity(tx, chaincfg.MainNetParams()) rerr, ok := err.(RuleError) if !ok { t.Fatalf("CheckTransactionSanity: unexpected error type for "+ @@ -608,7 +615,7 @@ func TestTxValidationErrors(t *testing.T) { var badBlock = wire.MsgBlock{ Header: wire.BlockHeader{ Version: 1, - MerkleRoot: chaincfg.RegNetParams.GenesisBlock.Header.MerkleRoot, + MerkleRoot: *newHashFromStr("66aa7491b9adce110585ccab7e3fb5fe280de174530cca10eba2c6c3df01c10d"), VoteBits: uint16(0x0000), FinalState: [6]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, Voters: uint16(0x0000), @@ -630,7 +637,7 @@ var badBlock = wire.MsgBlock{ // checking block templates works as expected. func TestCheckConnectBlockTemplate(t *testing.T) { // Create a test harness initialized with the genesis block as the tip. - params := &chaincfg.RegNetParams + params := chaincfg.RegNetParams() g, teardownFunc := newChaingenHarness(t, params, "connectblktemplatetest") defer teardownFunc() @@ -714,7 +721,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) { // // genesis // \-> bfbbad - g.CreatePremineBlock("bfbbad", 1) + g.CreateBlockOne("bfbbad", 1) g.AssertTipHeight(1) rejectedBlockTemplate(ErrBadCoinbaseValue) @@ -724,7 +731,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) { // genesis // \-> bfbunsolved g.SetTip("genesis") - bfbunsolved := g.CreatePremineBlock("bfbunsolved", 0, changeNonce) + bfbunsolved := g.CreateBlockOne("bfbunsolved", 0, changeNonce) // Since the difficulty is so low in the tests, the block might still // end up being inadvertently solved. It can't be checked inside the // munger because the block is finalized after the function returns and @@ -747,7 +754,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) { // // genesis -> bfb g.SetTip("genesis") - g.CreatePremineBlock("bfb", 0) + g.CreateBlockOne("bfb", 0) g.AssertTipHeight(1) g.AcceptTipBlock() diff --git a/blockchain/votebits.go b/blockchain/votebits.go index b9328337..fd6dfee9 100644 --- a/blockchain/votebits.go +++ b/blockchain/votebits.go @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2018 The Decred developers // Copyright (c) 2016 The btcsuite developers +// Copyright (c) 2017-2019 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. package blockchain import ( - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/chaincfg/v2" ) // deploymentChecker provides a thresholdConditionChecker which can be used to diff --git a/blockchain/votebits_test.go b/blockchain/votebits_test.go index 135fe8b1..02de34d8 100644 --- a/blockchain/votebits_test.go +++ b/blockchain/votebits_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" + "github.com/decred/dcrd/blockchain/stake/v2" + "github.com/decred/dcrd/chaincfg/v2" ) var ( @@ -99,7 +99,7 @@ var ( // defaultParams returns net parameters modified to have a single known // deployment that is used throughout the various votebit tests. func defaultParams(vote chaincfg.Vote) chaincfg.Params { - params := chaincfg.RegNetParams + params := chaincfg.RegNetParams() params.Deployments = make(map[uint32][]chaincfg.ConsensusDeployment) params.Deployments[posVersion] = []chaincfg.ConsensusDeployment{{ Vote: vote, @@ -109,7 +109,7 @@ func defaultParams(vote chaincfg.Vote) chaincfg.Params { ExpireTime: uint64(time.Now().Add(24 * time.Hour).Unix()), }} - return params + return *params } // TestNoQuorum ensures that the quorum behavior works as expected with no @@ -1501,7 +1501,7 @@ func TestVoting(t *testing.T) { // defaultParallelParams returns net parameters modified to have two known // deployments that are used throughout the parallel votebit tests. func defaultParallelParams() chaincfg.Params { - params := chaincfg.RegNetParams + params := chaincfg.RegNetParams() params.Deployments = make(map[uint32][]chaincfg.ConsensusDeployment) params.Deployments[posVersion] = []chaincfg.ConsensusDeployment{ { @@ -1518,7 +1518,7 @@ func defaultParallelParams() chaincfg.Params { }, } - return params + return *params } // TestParallelVoting ensures that two agendas running at the same time progress