From 6d64421965dfed51a2cb54485bef4d56b4d46fa4 Mon Sep 17 00:00:00 2001 From: Stas Boutenko Date: Sun, 17 Jun 2018 18:46:47 +0300 Subject: [PATCH] [DEV-26] Renamed package blockchain to blockdag. --- {blockchain => blockdag}/README.md | 0 {blockchain => blockdag}/accept.go | 2 +- {blockchain => blockdag}/bench_test.go | 2 +- {blockchain => blockdag}/blockindex.go | 2 +- {blockchain => blockdag}/chain.go | 2 +- {blockchain => blockdag}/chain_test.go | 2 +- {blockchain => blockdag}/chainio.go | 2 +- {blockchain => blockdag}/chainio_test.go | 2 +- {blockchain => blockdag}/chainview.go | 2 +- {blockchain => blockdag}/chainview_test.go | 2 +- {blockchain => blockdag}/checkpoints.go | 2 +- {blockchain => blockdag}/common_test.go | 2 +- {blockchain => blockdag}/compress.go | 2 +- {blockchain => blockdag}/compress_test.go | 2 +- {blockchain => blockdag}/difficulty.go | 2 +- {blockchain => blockdag}/difficulty_test.go | 2 +- {blockchain => blockdag}/doc.go | 2 +- {blockchain => blockdag}/error.go | 2 +- {blockchain => blockdag}/error_test.go | 2 +- {blockchain => blockdag}/example_test.go | 14 +- {blockchain => blockdag}/fullblocks_test.go | 22 +-- .../fullblocktests/README.md | 0 .../fullblocktests/doc.go | 0 .../fullblocktests/generate.go | 102 ++++++------- .../fullblocktests/params.go | 0 {blockchain => blockdag}/indexers/README.md | 0 .../indexers/addrindex.go | 10 +- .../indexers/addrindex_test.go | 0 .../indexers/blocklogger.go | 0 {blockchain => blockdag}/indexers/cfindex.go | 6 +- {blockchain => blockdag}/indexers/common.go | 6 +- {blockchain => blockdag}/indexers/log.go | 0 {blockchain => blockdag}/indexers/manager.go | 22 +-- {blockchain => blockdag}/indexers/txindex.go | 6 +- {blockchain => blockdag}/log.go | 2 +- {blockchain => blockdag}/mediantime.go | 2 +- {blockchain => blockdag}/mediantime_test.go | 2 +- {blockchain => blockdag}/merkle.go | 2 +- {blockchain => blockdag}/merkle_test.go | 2 +- {blockchain => blockdag}/notifications.go | 2 +- .../notifications_test.go | 2 +- {blockchain => blockdag}/process.go | 2 +- {blockchain => blockdag}/scriptval.go | 2 +- {blockchain => blockdag}/scriptval_test.go | 2 +- .../testdata/277647.dat.bz2 | Bin .../testdata/277647.utxostore.bz2 | Bin .../testdata/blk_0_to_4.dat.bz2 | Bin .../testdata/blk_3A.dat.bz2 | Bin .../testdata/blk_4A.dat.bz2 | Bin .../testdata/blk_5A.dat.bz2 | Bin .../testdata/reorgtest.hex | 0 {blockchain => blockdag}/thresholdstate.go | 2 +- .../thresholdstate_test.go | 2 +- {blockchain => blockdag}/timesorter.go | 2 +- {blockchain => blockdag}/timesorter_test.go | 2 +- {blockchain => blockdag}/upgrade.go | 2 +- {blockchain => blockdag}/upgrade_test.go | 2 +- {blockchain => blockdag}/utxoviewpoint.go | 2 +- {blockchain => blockdag}/validate.go | 2 +- {blockchain => blockdag}/validate_test.go | 2 +- {blockchain => blockdag}/versionbits.go | 2 +- btcd.go | 2 +- cmd/addblock/addblock.go | 6 +- cmd/addblock/import.go | 14 +- cmd/findcheckpoint/findcheckpoint.go | 10 +- integration/bip0009_test.go | 30 ++-- integration/csv_fork_test.go | 28 ++-- integration/rpctest/blockgen.go | 8 +- integration/rpctest/memwallet.go | 4 +- log.go | 6 +- mempool/error.go | 18 +-- mempool/mempool.go | 36 ++--- mempool/mempool_test.go | 18 +-- mempool/policy.go | 6 +- mining/cpuminer/cpuminer.go | 12 +- mining/mining.go | 54 +++---- mining/policy.go | 6 +- mining/policy_test.go | 16 +- netsync/interface.go | 4 +- netsync/manager.go | 32 ++-- peer/peer.go | 6 +- rpcadapters.go | 4 +- rpcserver.go | 144 +++++++++--------- rpcwebsocket.go | 6 +- server.go | 18 +-- 85 files changed, 376 insertions(+), 376 deletions(-) rename {blockchain => blockdag}/README.md (100%) rename {blockchain => blockdag}/accept.go (99%) rename {blockchain => blockdag}/bench_test.go (97%) rename {blockchain => blockdag}/blockindex.go (99%) rename {blockchain => blockdag}/chain.go (99%) rename {blockchain => blockdag}/chain_test.go (99%) rename {blockchain => blockdag}/chainio.go (99%) rename {blockchain => blockdag}/chainio_test.go (99%) rename {blockchain => blockdag}/chainview.go (99%) rename {blockchain => blockdag}/chainview_test.go (99%) rename {blockchain => blockdag}/checkpoints.go (99%) rename {blockchain => blockdag}/common_test.go (99%) rename {blockchain => blockdag}/compress.go (99%) rename {blockchain => blockdag}/compress_test.go (99%) rename {blockchain => blockdag}/difficulty.go (99%) rename {blockchain => blockdag}/difficulty_test.go (98%) rename {blockchain => blockdag}/doc.go (99%) rename {blockchain => blockdag}/error.go (99%) rename {blockchain => blockdag}/error_test.go (99%) rename {blockchain => blockdag}/example_test.go (92%) rename {blockchain => blockdag}/fullblocks_test.go (94%) rename {blockchain => blockdag}/fullblocktests/README.md (100%) rename {blockchain => blockdag}/fullblocktests/doc.go (100%) rename {blockchain => blockdag}/fullblocktests/generate.go (97%) rename {blockchain => blockdag}/fullblocktests/params.go (100%) rename {blockchain => blockdag}/indexers/README.md (100%) rename {blockchain => blockdag}/indexers/addrindex.go (99%) rename {blockchain => blockdag}/indexers/addrindex_test.go (100%) rename {blockchain => blockdag}/indexers/blocklogger.go (100%) rename {blockchain => blockdag}/indexers/cfindex.go (98%) rename {blockchain => blockdag}/indexers/common.go (97%) rename {blockchain => blockdag}/indexers/log.go (100%) rename {blockchain => blockdag}/indexers/manager.go (97%) rename {blockchain => blockdag}/indexers/txindex.go (99%) rename {blockchain => blockdag}/log.go (97%) rename {blockchain => blockdag}/mediantime.go (99%) rename {blockchain => blockdag}/mediantime_test.go (99%) rename {blockchain => blockdag}/merkle.go (99%) rename {blockchain => blockdag}/merkle_test.go (97%) rename {blockchain => blockdag}/notifications.go (99%) rename {blockchain => blockdag}/notifications_test.go (98%) rename {blockchain => blockdag}/process.go (99%) rename {blockchain => blockdag}/scriptval.go (99%) rename {blockchain => blockdag}/scriptval_test.go (98%) rename {blockchain => blockdag}/testdata/277647.dat.bz2 (100%) rename {blockchain => blockdag}/testdata/277647.utxostore.bz2 (100%) rename {blockchain => blockdag}/testdata/blk_0_to_4.dat.bz2 (100%) rename {blockchain => blockdag}/testdata/blk_3A.dat.bz2 (100%) rename {blockchain => blockdag}/testdata/blk_4A.dat.bz2 (100%) rename {blockchain => blockdag}/testdata/blk_5A.dat.bz2 (100%) rename {blockchain => blockdag}/testdata/reorgtest.hex (100%) rename {blockchain => blockdag}/thresholdstate.go (99%) rename {blockchain => blockdag}/thresholdstate_test.go (99%) rename {blockchain => blockdag}/timesorter.go (97%) rename {blockchain => blockdag}/timesorter_test.go (98%) rename {blockchain => blockdag}/upgrade.go (99%) rename {blockchain => blockdag}/upgrade_test.go (99%) rename {blockchain => blockdag}/utxoviewpoint.go (99%) rename {blockchain => blockdag}/validate.go (99%) rename {blockchain => blockdag}/validate_test.go (99%) rename {blockchain => blockdag}/versionbits.go (99%) diff --git a/blockchain/README.md b/blockdag/README.md similarity index 100% rename from blockchain/README.md rename to blockdag/README.md diff --git a/blockchain/accept.go b/blockdag/accept.go similarity index 99% rename from blockchain/accept.go rename to blockdag/accept.go index c162b0454..37b05773e 100644 --- a/blockchain/accept.go +++ b/blockdag/accept.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/bench_test.go b/blockdag/bench_test.go similarity index 97% rename from blockchain/bench_test.go rename to blockdag/bench_test.go index 7f20ad487..0856d1496 100644 --- a/blockchain/bench_test.go +++ b/blockdag/bench_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "testing" diff --git a/blockchain/blockindex.go b/blockdag/blockindex.go similarity index 99% rename from blockchain/blockindex.go rename to blockdag/blockindex.go index 65e589851..5b504fa60 100644 --- a/blockchain/blockindex.go +++ b/blockdag/blockindex.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math/big" diff --git a/blockchain/chain.go b/blockdag/chain.go similarity index 99% rename from blockchain/chain.go rename to blockdag/chain.go index 9cab74fdb..09617f40f 100644 --- a/blockchain/chain.go +++ b/blockdag/chain.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "container/list" diff --git a/blockchain/chain_test.go b/blockdag/chain_test.go similarity index 99% rename from blockchain/chain_test.go rename to blockdag/chain_test.go index 4d6fefc8d..071762830 100644 --- a/blockchain/chain_test.go +++ b/blockdag/chain_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "reflect" diff --git a/blockchain/chainio.go b/blockdag/chainio.go similarity index 99% rename from blockchain/chainio.go rename to blockdag/chainio.go index 06954128e..4f25c66ea 100644 --- a/blockchain/chainio.go +++ b/blockdag/chainio.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "bytes" diff --git a/blockchain/chainio_test.go b/blockdag/chainio_test.go similarity index 99% rename from blockchain/chainio_test.go rename to blockdag/chainio_test.go index 98bd91ed9..963ff9e3d 100644 --- a/blockchain/chainio_test.go +++ b/blockdag/chainio_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "bytes" diff --git a/blockchain/chainview.go b/blockdag/chainview.go similarity index 99% rename from blockchain/chainview.go rename to blockdag/chainview.go index a4c3692cd..5ba1e557e 100644 --- a/blockchain/chainview.go +++ b/blockdag/chainview.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "sync" diff --git a/blockchain/chainview_test.go b/blockdag/chainview_test.go similarity index 99% rename from blockchain/chainview_test.go rename to blockdag/chainview_test.go index 7e0bacd02..4f5ca23aa 100644 --- a/blockchain/chainview_test.go +++ b/blockdag/chainview_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/checkpoints.go b/blockdag/checkpoints.go similarity index 99% rename from blockchain/checkpoints.go rename to blockdag/checkpoints.go index 4447dd3fd..134b2deb5 100644 --- a/blockchain/checkpoints.go +++ b/blockdag/checkpoints.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/common_test.go b/blockdag/common_test.go similarity index 99% rename from blockchain/common_test.go rename to blockdag/common_test.go index e947129cb..017795a71 100644 --- a/blockchain/common_test.go +++ b/blockdag/common_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "compress/bzip2" diff --git a/blockchain/compress.go b/blockdag/compress.go similarity index 99% rename from blockchain/compress.go rename to blockdag/compress.go index c7f48a5ad..68ebea64b 100644 --- a/blockchain/compress.go +++ b/blockdag/compress.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "github.com/daglabs/btcd/btcec" diff --git a/blockchain/compress_test.go b/blockdag/compress_test.go similarity index 99% rename from blockchain/compress_test.go rename to blockdag/compress_test.go index b1a6ff274..bfa261036 100644 --- a/blockchain/compress_test.go +++ b/blockdag/compress_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "bytes" diff --git a/blockchain/difficulty.go b/blockdag/difficulty.go similarity index 99% rename from blockchain/difficulty.go rename to blockdag/difficulty.go index 819067a03..08c900a05 100644 --- a/blockchain/difficulty.go +++ b/blockdag/difficulty.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math/big" diff --git a/blockchain/difficulty_test.go b/blockdag/difficulty_test.go similarity index 98% rename from blockchain/difficulty_test.go rename to blockdag/difficulty_test.go index b42b7c730..3b6350b5c 100644 --- a/blockchain/difficulty_test.go +++ b/blockdag/difficulty_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math/big" diff --git a/blockchain/doc.go b/blockdag/doc.go similarity index 99% rename from blockchain/doc.go rename to blockdag/doc.go index df99c5f5f..e85188933 100644 --- a/blockchain/doc.go +++ b/blockdag/doc.go @@ -78,4 +78,4 @@ This package includes spec changes outlined by the following BIPs: BIP0030 (https://en.bitcoin.it/wiki/BIP_0030) BIP0034 (https://en.bitcoin.it/wiki/BIP_0034) */ -package blockchain \ No newline at end of file +package blockdag \ No newline at end of file diff --git a/blockchain/error.go b/blockdag/error.go similarity index 99% rename from blockchain/error.go rename to blockdag/error.go index 77d1bb39d..c7b902dfd 100644 --- a/blockchain/error.go +++ b/blockdag/error.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/error_test.go b/blockdag/error_test.go similarity index 99% rename from blockchain/error_test.go rename to blockdag/error_test.go index 90fe83f8a..079e2fc46 100644 --- a/blockchain/error_test.go +++ b/blockdag/error_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "testing" diff --git a/blockchain/example_test.go b/blockdag/example_test.go similarity index 92% rename from blockchain/example_test.go rename to blockdag/example_test.go index b9a6fe666..ebb623988 100644 --- a/blockchain/example_test.go +++ b/blockdag/example_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain_test +package blockdag_test import ( "fmt" @@ -10,7 +10,7 @@ import ( "os" "path/filepath" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/database" _ "github.com/daglabs/btcd/database/ffldb" @@ -45,10 +45,10 @@ func ExampleBlockChain_ProcessBlock() { // ordinarily keep a reference to the median time source and add time // values obtained from other peers on the network so the local time is // adjusted to be in agreement with other peers. - chain, err := blockchain.New(&blockchain.Config{ + chain, err := blockdag.New(&blockdag.Config{ DB: db, ChainParams: &chaincfg.MainNetParams, - TimeSource: blockchain.NewMedianTime(), + TimeSource: blockdag.NewMedianTime(), }) if err != nil { fmt.Printf("Failed to create chain instance: %v\n", err) @@ -60,7 +60,7 @@ func ExampleBlockChain_ProcessBlock() { // exists. genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) isMainChain, isOrphan, err := chain.ProcessBlock(genesisBlock, - blockchain.BFNone) + blockdag.BFNone) if err != nil { fmt.Printf("Failed to process block: %v\n", err) return @@ -78,7 +78,7 @@ func ExampleBlockChain_ProcessBlock() { func ExampleCompactToBig() { // Convert the bits from block 300000 in the main block chain. bits := uint32(419465580) - targetDifficulty := blockchain.CompactToBig(bits) + targetDifficulty := blockdag.CompactToBig(bits) // Display it in hex. fmt.Printf("%064x\n", targetDifficulty.Bytes()) @@ -98,7 +98,7 @@ func ExampleBigToCompact() { fmt.Println("invalid target difficulty") return } - bits := blockchain.BigToCompact(targetDifficulty) + bits := blockdag.BigToCompact(targetDifficulty) fmt.Println(bits) diff --git a/blockchain/fullblocks_test.go b/blockdag/fullblocks_test.go similarity index 94% rename from blockchain/fullblocks_test.go rename to blockdag/fullblocks_test.go index 244046d79..bd11fc29e 100644 --- a/blockchain/fullblocks_test.go +++ b/blockdag/fullblocks_test.go @@ -3,7 +3,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain_test +package blockdag_test import ( "bytes" @@ -12,8 +12,8 @@ import ( "path/filepath" "testing" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/fullblocktests" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/fullblocktests" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" @@ -60,7 +60,7 @@ func isSupportedDbType(dbType string) bool { // chainSetup is used to create a new db and chain instance with the genesis // block already inserted. In addition to the new chain instance, it returns // a teardown function the caller should invoke when done testing to clean up. -func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain, func(), error) { +func chainSetup(dbName string, params *chaincfg.Params) (*blockdag.BlockChain, func(), error) { if !isSupportedDbType(testDbType) { return nil, nil, fmt.Errorf("unsupported db type %v", testDbType) } @@ -114,11 +114,11 @@ func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain, paramsCopy := *params // Create the main chain instance. - chain, err := blockchain.New(&blockchain.Config{ + chain, err := blockdag.New(&blockdag.Config{ DB: db, ChainParams: ¶msCopy, Checkpoints: nil, - TimeSource: blockchain.NewMedianTime(), + TimeSource: blockdag.NewMedianTime(), SigCache: txscript.NewSigCache(1000), }) if err != nil { @@ -157,7 +157,7 @@ func TestFullBlocks(t *testing.T) { item.Name, block.Hash(), blockHeight) isMainChain, isOrphan, err := chain.ProcessBlock(block, - blockchain.BFNone) + blockdag.BFNone) if err != nil { t.Fatalf("block %q (hash %s, height %d) should "+ "have been accepted: %v", item.Name, @@ -190,7 +190,7 @@ func TestFullBlocks(t *testing.T) { t.Logf("Testing block %s (hash %s, height %d)", item.Name, block.Hash(), blockHeight) - _, _, err := chain.ProcessBlock(block, blockchain.BFNone) + _, _, err := chain.ProcessBlock(block, blockdag.BFNone) if err == nil { t.Fatalf("block %q (hash %s, height %d) should not "+ "have been accepted", item.Name, block.Hash(), @@ -199,7 +199,7 @@ func TestFullBlocks(t *testing.T) { // Ensure the error code is of the expected type and the reject // code matches the value specified in the test instance. - rerr, ok := err.(blockchain.RuleError) + rerr, ok := err.(blockdag.RuleError) if !ok { t.Fatalf("block %q (hash %s, height %d) returned "+ "unexpected error type -- got %T, want "+ @@ -247,10 +247,10 @@ func TestFullBlocks(t *testing.T) { t.Logf("Testing block %s (hash %s, height %d)", item.Name, block.Hash(), blockHeight) - _, isOrphan, err := chain.ProcessBlock(block, blockchain.BFNone) + _, isOrphan, err := chain.ProcessBlock(block, blockdag.BFNone) if err != nil { // Ensure the error code is of the expected type. - if _, ok := err.(blockchain.RuleError); !ok { + if _, ok := err.(blockdag.RuleError); !ok { t.Fatalf("block %q (hash %s, height %d) "+ "returned unexpected error type -- "+ "got %T, want blockchain.RuleError", diff --git a/blockchain/fullblocktests/README.md b/blockdag/fullblocktests/README.md similarity index 100% rename from blockchain/fullblocktests/README.md rename to blockdag/fullblocktests/README.md diff --git a/blockchain/fullblocktests/doc.go b/blockdag/fullblocktests/doc.go similarity index 100% rename from blockchain/fullblocktests/doc.go rename to blockdag/fullblocktests/doc.go diff --git a/blockchain/fullblocktests/generate.go b/blockdag/fullblocktests/generate.go similarity index 97% rename from blockchain/fullblocktests/generate.go rename to blockdag/fullblocktests/generate.go index ae44edd6f..2ddbc4ddb 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockdag/fullblocktests/generate.go @@ -18,7 +18,7 @@ import ( "runtime" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -86,7 +86,7 @@ type RejectedBlock struct { Name string Block *wire.MsgBlock Height int32 - RejectCode blockchain.ErrorCode + RejectCode blockdag.ErrorCode } // Ensure RejectedBlock implements the TestInstance interface. @@ -292,7 +292,7 @@ func (g *testGenerator) createCoinbaseTx(blockHeight int32) *wire.MsgTx { SignatureScript: coinbaseScript, }) tx.AddTxOut(&wire.TxOut{ - Value: blockchain.CalcBlockSubsidy(blockHeight, g.params), + Value: blockdag.CalcBlockSubsidy(blockHeight, g.params), PkScript: opTrueScript, }) return tx @@ -309,7 +309,7 @@ func calcMerkleRoot(txns []*wire.MsgTx) chainhash.Hash { for _, tx := range txns { utilTxns = append(utilTxns, btcutil.NewTx(tx)) } - merkles := blockchain.BuildMerkleTreeStore(utilTxns) + merkles := blockdag.BuildMerkleTreeStore(utilTxns) return *merkles[len(merkles)-1] } @@ -330,7 +330,7 @@ func solveBlock(header *wire.BlockHeader) bool { // solver accepts a block header and a nonce range to test. It is // intended to be run as a goroutine. - targetDifficulty := blockchain.CompactToBig(header.Bits) + targetDifficulty := blockdag.CompactToBig(header.Bits) quit := make(chan bool) results := make(chan sbResult) solver := func(hdr wire.BlockHeader, startNonce, stopNonce uint32) { @@ -343,7 +343,7 @@ func solveBlock(header *wire.BlockHeader) bool { default: hdr.Nonce = i hash := hdr.BlockHash() - if blockchain.HashToBig(&hash).Cmp( + if blockdag.HashToBig(&hash).Cmp( targetDifficulty) <= 0 { results <- sbResult{true, i} @@ -840,7 +840,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { return AcceptedBlock{blockName, block, blockHeight, isMainChain, isOrphan} } - rejectBlock := func(blockName string, block *wire.MsgBlock, code blockchain.ErrorCode) TestInstance { + rejectBlock := func(blockName string, block *wire.MsgBlock, code blockdag.ErrorCode) TestInstance { blockHeight := g.blockHeights[blockName] return RejectedBlock{blockName, block, blockHeight, code} } @@ -890,7 +890,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { expectTipBlock(tipName, g.blocksByName[tipName]), }) } - rejected := func(code blockchain.ErrorCode) { + rejected := func(code blockdag.ErrorCode) { tests = append(tests, []TestInstance{ rejectBlock(g.tipName, g.tip, code), }) @@ -997,7 +997,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { acceptedToSideChainWithExpectedTip("b6") g.nextBlock("b8", outs[4]) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // --------------------------------------------------------------------- // Too much proof-of-work coinbase tests. @@ -1010,7 +1010,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // \-> b3(1) -> b4(2) g.setTip("b6") g.nextBlock("b9", outs[4], additionalCoinbase(1)) - rejected(blockchain.ErrBadCoinbaseValue) + rejected(blockdag.ErrBadCoinbaseValue) // Create a fork that ends with block that generates too much coinbase. // @@ -1022,7 +1022,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { acceptedToSideChainWithExpectedTip("b6") g.nextBlock("b11", outs[4], additionalCoinbase(1)) - rejected(blockchain.ErrBadCoinbaseValue) + rejected(blockdag.ErrBadCoinbaseValue) // Create a fork that ends with block that generates too much coinbase // as before, but with a valid fork first. @@ -1038,7 +1038,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { tests = append(tests, []TestInstance{ acceptBlock("b13", b13, false, true), acceptBlock("b14", b14, false, true), - rejectBlock("b12", b12, blockchain.ErrBadCoinbaseValue), + rejectBlock("b12", b12, blockdag.ErrBadCoinbaseValue), expectTipBlock("b13", b13), }) @@ -1065,7 +1065,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { tooManySigOps := repeatOpcode(txscript.OP_CHECKSIG, maxBlockSigOps+1) g.nextBlock("b16", outs[6], replaceSpendScript(tooManySigOps)) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // --------------------------------------------------------------------- // Cross-fork spend tests. @@ -1078,7 +1078,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // \-> b3(1) -> b4(2) g.setTip("b15") g.nextBlock("b17", &b3Tx1Out) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // Create block that forks and spends a tx created on a third fork. // @@ -1090,7 +1090,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { acceptedToSideChainWithExpectedTip("b15") g.nextBlock("b19", outs[6]) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // --------------------------------------------------------------------- // Immature coinbase tests. @@ -1102,7 +1102,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // \-> b20(7) g.setTip("b15") g.nextBlock("b20", outs[7]) - rejected(blockchain.ErrImmatureSpend) + rejected(blockdag.ErrImmatureSpend) // Create block that spends immature coinbase on a fork. // @@ -1113,7 +1113,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { acceptedToSideChainWithExpectedTip("b15") g.nextBlock("b22", outs[7]) - rejected(blockchain.ErrImmatureSpend) + rejected(blockdag.ErrImmatureSpend) // --------------------------------------------------------------------- // Max block size tests. @@ -1143,7 +1143,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { replaceSpendScript(sizePadScript)(b) }) g.assertTipBlockSize(maxBlockSize + 1) - rejected(blockchain.ErrBlockTooBig) + rejected(blockdag.ErrBlockTooBig) // Parent was rejected, so this block must either be an orphan or // outright rejected due to an invalid parent. @@ -1163,7 +1163,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.setTip("b15") tooSmallCbScript := repeatOpcode(0x00, minCoinbaseScriptLen-1) g.nextBlock("b26", outs[6], replaceCoinbaseSigScript(tooSmallCbScript)) - rejected(blockchain.ErrBadCoinbaseScriptLen) + rejected(blockdag.ErrBadCoinbaseScriptLen) // Parent was rejected, so this block must either be an orphan or // outright rejected due to an invalid parent. @@ -1179,7 +1179,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.setTip("b15") tooLargeCbScript := repeatOpcode(0x00, maxCoinbaseScriptLen+1) g.nextBlock("b28", outs[6], replaceCoinbaseSigScript(tooLargeCbScript)) - rejected(blockchain.ErrBadCoinbaseScriptLen) + rejected(blockdag.ErrBadCoinbaseScriptLen) // Parent was rejected, so this block must either be an orphan or // outright rejected due to an invalid parent. @@ -1219,7 +1219,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG) g.nextBlock("b32", outs[9], replaceSpendScript(tooManySigOps)) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // Create block with max signature operations as OP_CHECKMULTISIGVERIFY. // @@ -1240,7 +1240,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG) g.nextBlock("b34", outs[10], replaceSpendScript(tooManySigOps)) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // Create block with max signature operations as OP_CHECKSIGVERIFY. // @@ -1261,7 +1261,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { tooManySigOps = repeatOpcode(txscript.OP_CHECKSIGVERIFY, maxBlockSigOps+1) g.nextBlock("b36", outs[11], replaceSpendScript(tooManySigOps)) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // --------------------------------------------------------------------- // Spending of tx outputs in block that failed to connect tests. @@ -1278,11 +1278,11 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { doubleSpendTx := createSpendTx(outs[11], lowFee) g.nextBlock("b37", outs[11], additionalTx(doubleSpendTx)) b37Tx1Out := makeSpendableOut(g.tip, 1, 0) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) g.setTip("b35") g.nextBlock("b38", &b37Tx1Out) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // --------------------------------------------------------------------- // Pay-to-script-hash signature operation count tests. @@ -1354,7 +1354,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { tx.TxOut[0].PkScript = repeatOpcode(txscript.OP_CHECKSIG, fill) b.AddTransaction(tx) }) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // Create a block with the max allowed signature operations where the // majority of them are in pay-to-script-hash scripts. @@ -1417,7 +1417,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { nonCoinbaseTx := createSpendTx(outs[14], lowFee) b.Transactions[0] = nonCoinbaseTx }) - rejected(blockchain.ErrFirstTxNotCoinbase) + rejected(blockdag.ErrFirstTxNotCoinbase) // Create block with no transactions. // @@ -1427,7 +1427,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.nextBlock("b45", nil, func(b *wire.MsgBlock) { b.Transactions = nil }) - rejected(blockchain.ErrNoTransactions) + rejected(blockdag.ErrNoTransactions) // Create block with invalid proof of work. // @@ -1445,14 +1445,14 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // a uint256 is higher than the limit. b46.Header.Nonce++ blockHash := b46.BlockHash() - hashNum := blockchain.HashToBig(&blockHash) + hashNum := blockdag.HashToBig(&blockHash) if hashNum.Cmp(g.params.PowLimit) >= 0 { break } } g.updateBlockState("b46", origHash, "b46", b46) } - rejected(blockchain.ErrHighHash) + rejected(blockdag.ErrHighHash) // Create block with a timestamp too far in the future. // @@ -1464,7 +1464,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { nowPlus3Hours := time.Now().Add(time.Hour * 3) b.Header.Timestamp = time.Unix(nowPlus3Hours.Unix(), 0) }) - rejected(blockchain.ErrTimeTooNew) + rejected(blockdag.ErrTimeTooNew) // Create block with an invalid merkle root. // @@ -1474,7 +1474,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.nextBlock("b48", outs[14], func(b *wire.MsgBlock) { b.Header.MerkleRoot = chainhash.Hash{} }) - rejected(blockchain.ErrBadMerkleRoot) + rejected(blockdag.ErrBadMerkleRoot) // Create block with an invalid proof-of-work limit. // @@ -1484,7 +1484,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.nextBlock("b49", outs[14], func(b *wire.MsgBlock) { b.Header.Bits-- }) - rejected(blockchain.ErrUnexpectedDifficulty) + rejected(blockdag.ErrUnexpectedDifficulty) // Create block with an invalid negative proof-of-work limit. // @@ -1500,7 +1500,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b49a.Header.Bits = 0x01810000 // -1 in compact form. g.updateBlockState("b49a", origHash, "b49a", b49a) } - rejected(blockchain.ErrUnexpectedDifficulty) + rejected(blockdag.ErrUnexpectedDifficulty) // Create block with two coinbase transactions. // @@ -1509,7 +1509,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.setTip("b43") coinbaseTx := g.createCoinbaseTx(g.tipHeight + 1) g.nextBlock("b50", outs[14], additionalTx(coinbaseTx)) - rejected(blockchain.ErrMultipleCoinbases) + rejected(blockdag.ErrMultipleCoinbases) // Create block with duplicate transactions. // @@ -1523,7 +1523,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.AddTransaction(b.Transactions[1]) }) g.assertTipBlockNumTxns(3) - rejected(blockchain.ErrDuplicateTx) + rejected(blockdag.ErrDuplicateTx) // Create a block that spends a transaction that does not exist. // @@ -1536,7 +1536,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.Transactions[1].TxIn[0].PreviousOutPoint.Hash = *hash b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 0 }) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // --------------------------------------------------------------------- // Block header median time tests. @@ -1561,7 +1561,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { } b.Header.Timestamp = medianBlock.Header.Timestamp }) - rejected(blockchain.ErrTimeTooOld) + rejected(blockdag.ErrTimeTooOld) // Create a block with a timestamp that is one second after the median // time. The block must be accepted. @@ -1632,7 +1632,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.assertTipBlockNumTxns(4) g.assertTipBlockHash(b57.BlockHash()) g.assertTipBlockMerkleRoot(b57.Header.MerkleRoot) - rejected(blockchain.ErrDuplicateTx) + rejected(blockdag.ErrDuplicateTx) // Since the two blocks have the same hash and the generator state now // has b56 associated with the hash, manually remove b56, replace it @@ -1673,7 +1673,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.AddTransaction(b.Transactions[3]) }) g.assertTipBlockNumTxns(8) - rejected(blockchain.ErrDuplicateTx) + rejected(blockdag.ErrDuplicateTx) // --------------------------------------------------------------------- // Invalid transaction type tests. @@ -1688,7 +1688,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.nextBlock("b58", outs[17], func(b *wire.MsgBlock) { b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 42 }) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // Create block with transaction that pays more than its inputs. // @@ -1698,7 +1698,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.nextBlock("b59", outs[17], func(b *wire.MsgBlock) { b.Transactions[1].TxOut[0].Value = int64(outs[17].amount) + 1 }) - rejected(blockchain.ErrSpendTooHigh) + rejected(blockdag.ErrSpendTooHigh) // --------------------------------------------------------------------- // BIP0030 tests. @@ -1722,7 +1722,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { parent := g.blocks[b.Header.PrevBlock] b.Transactions[0] = parent.Transactions[0] }) - rejected(blockchain.ErrOverwriteTx) + rejected(blockdag.ErrOverwriteTx) // --------------------------------------------------------------------- // Blocks with non-final transaction tests. @@ -1740,7 +1740,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.Transactions[1].LockTime = 0xffffffff b.Transactions[1].TxIn[0].Sequence = 0 }) - rejected(blockchain.ErrUnfinalizedTx) + rejected(blockdag.ErrUnfinalizedTx) // Create block that contains a non-final coinbase transaction. // @@ -1754,7 +1754,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.Transactions[0].LockTime = 0xffffffff b.Transactions[0].TxIn[0].Sequence = 0 }) - rejected(blockchain.ErrUnfinalizedTx) + rejected(blockdag.ErrUnfinalizedTx) // --------------------------------------------------------------------- // Non-canonical variable-length integer tests. @@ -1816,7 +1816,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.AddTransaction(tx3) b.AddTransaction(tx2) }) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // Create block that double spends a transaction created in the same // block. @@ -1831,7 +1831,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { b.AddTransaction(tx3) b.AddTransaction(tx4) }) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // --------------------------------------------------------------------- // Extra subsidy tests. @@ -1844,7 +1844,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // \-> b68(20) g.setTip("b65") g.nextBlock("b68", outs[20], additionalCoinbase(10), additionalSpendFee(9)) - rejected(blockchain.ErrBadCoinbaseValue) + rejected(blockdag.ErrBadCoinbaseValue) // Create block that pays 10 extra to the coinbase and a tx that pays // the extra 10 fee. @@ -1892,7 +1892,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { maxScriptElementSize+1) g.nextBlock("b70", outs[21], replaceSpendScript(tooManySigOps)) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // Create block with more than max allowed signature operations such // that the signature operation that pushes it over the limit is before @@ -1908,7 +1908,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { binary.LittleEndian.PutUint32(tooManySigOps[maxBlockSigOps+2:], 0xffffffff) g.nextBlock("b71", outs[21], replaceSpendScript(tooManySigOps)) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) - rejected(blockchain.ErrTooManySigOps) + rejected(blockdag.ErrTooManySigOps) // Create block with the max allowed signature operations such that all // counted signature operations are before an invalid push data that @@ -2022,7 +2022,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // to effective negate that behavior. b75OpReturnOut.amount++ g.nextBlock("b80", &b75OpReturnOut) - rejected(blockchain.ErrMissingTxOut) + rejected(blockdag.ErrMissingTxOut) // Create a block that has a transaction with multiple OP_RETURNs. Even // though it's not considered a standard transaction, it is still valid diff --git a/blockchain/fullblocktests/params.go b/blockdag/fullblocktests/params.go similarity index 100% rename from blockchain/fullblocktests/params.go rename to blockdag/fullblocktests/params.go diff --git a/blockchain/indexers/README.md b/blockdag/indexers/README.md similarity index 100% rename from blockchain/indexers/README.md rename to blockdag/indexers/README.md diff --git a/blockchain/indexers/addrindex.go b/blockdag/indexers/addrindex.go similarity index 99% rename from blockchain/indexers/addrindex.go rename to blockdag/indexers/addrindex.go index 9358e357e..cfbbfcaad 100644 --- a/blockchain/indexers/addrindex.go +++ b/blockdag/indexers/addrindex.go @@ -9,7 +9,7 @@ import ( "fmt" "sync" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" @@ -662,7 +662,7 @@ func (idx *AddrIndex) indexPkScript(data writeIndexData, pkScript []byte, txIdx // indexBlock extract all of the standard addresses from all of the transactions // in the passed block and maps each of them to the associated transaction using // the passed map. -func (idx *AddrIndex) indexBlock(data writeIndexData, block *btcutil.Block, view *blockchain.UtxoViewpoint) { +func (idx *AddrIndex) indexBlock(data writeIndexData, block *btcutil.Block, view *blockdag.UtxoViewpoint) { for txIdx, tx := range block.Transactions() { // Coinbases do not reference any inputs. Since the block is // required to have already gone through full validation, it has @@ -693,7 +693,7 @@ func (idx *AddrIndex) indexBlock(data writeIndexData, block *btcutil.Block, view // the transactions in the block involve. // // This is part of the Indexer interface. -func (idx *AddrIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func (idx *AddrIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // The offset and length of the transactions within the serialized // block. txLocs, err := block.TxLoc() @@ -731,7 +731,7 @@ func (idx *AddrIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view // each transaction in the block involve. // // This is part of the Indexer interface. -func (idx *AddrIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func (idx *AddrIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Build all of the address to transaction mappings in a local map. addrsToTxns := make(writeIndexData) idx.indexBlock(addrsToTxns, block, view) @@ -833,7 +833,7 @@ func (idx *AddrIndex) indexUnconfirmedAddresses(pkScript []byte, tx *btcutil.Tx) // addresses not being indexed. // // This function is safe for concurrent access. -func (idx *AddrIndex) AddUnconfirmedTx(tx *btcutil.Tx, utxoView *blockchain.UtxoViewpoint) { +func (idx *AddrIndex) AddUnconfirmedTx(tx *btcutil.Tx, utxoView *blockdag.UtxoViewpoint) { // Index addresses of all referenced previous transaction outputs. // // The existence checks are elided since this is only called after the diff --git a/blockchain/indexers/addrindex_test.go b/blockdag/indexers/addrindex_test.go similarity index 100% rename from blockchain/indexers/addrindex_test.go rename to blockdag/indexers/addrindex_test.go diff --git a/blockchain/indexers/blocklogger.go b/blockdag/indexers/blocklogger.go similarity index 100% rename from blockchain/indexers/blocklogger.go rename to blockdag/indexers/blocklogger.go diff --git a/blockchain/indexers/cfindex.go b/blockdag/indexers/cfindex.go similarity index 98% rename from blockchain/indexers/cfindex.go rename to blockdag/indexers/cfindex.go index 12138f511..5ea2f491c 100644 --- a/blockchain/indexers/cfindex.go +++ b/blockdag/indexers/cfindex.go @@ -7,7 +7,7 @@ package indexers import ( "errors" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" @@ -202,7 +202,7 @@ func storeFilter(dbTx database.Tx, block *btcutil.Block, f *gcs.Filter, // connected to the main chain. This indexer adds a hash-to-cf mapping for // every passed block. This is part of the Indexer interface. func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, - view *blockchain.UtxoViewpoint) error { + view *blockdag.UtxoViewpoint) error { f, err := builder.BuildBasicFilter(block.MsgBlock()) if err != nil { @@ -226,7 +226,7 @@ func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, // disconnected from the main chain. This indexer removes the hash-to-cf // mapping for every passed block. This is part of the Indexer interface. func (idx *CfIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, - view *blockchain.UtxoViewpoint) error { + view *blockdag.UtxoViewpoint) error { for _, key := range cfIndexKeys { err := dbDeleteFilterIdxEntry(dbTx, key, block.Hash()) diff --git a/blockchain/indexers/common.go b/blockdag/indexers/common.go similarity index 97% rename from blockchain/indexers/common.go rename to blockdag/indexers/common.go index a4783d0f3..d1dd8d2c7 100644 --- a/blockchain/indexers/common.go +++ b/blockdag/indexers/common.go @@ -11,7 +11,7 @@ import ( "encoding/binary" "errors" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/database" "github.com/daglabs/btcutil" ) @@ -52,11 +52,11 @@ type Indexer interface { // ConnectBlock is invoked when the index manager is notified that a new // block has been connected to the main chain. - ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error + ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error // DisconnectBlock is invoked when the index manager is notified that a // block has been disconnected from the main chain. - DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error + DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error } // AssertError identifies an error that indicates an internal code consistency diff --git a/blockchain/indexers/log.go b/blockdag/indexers/log.go similarity index 100% rename from blockchain/indexers/log.go rename to blockdag/indexers/log.go diff --git a/blockchain/indexers/manager.go b/blockdag/indexers/manager.go similarity index 97% rename from blockchain/indexers/manager.go rename to blockdag/indexers/manager.go index fa351280e..f37ec9b2f 100644 --- a/blockchain/indexers/manager.go +++ b/blockdag/indexers/manager.go @@ -8,7 +8,7 @@ import ( "bytes" "fmt" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" "github.com/daglabs/btcd/wire" @@ -68,7 +68,7 @@ func dbFetchIndexerTip(dbTx database.Tx, idxKey []byte) (*chainhash.Hash, int32, // given block using the provided indexer and updates the tip of the indexer // accordingly. An error will be returned if the current tip for the indexer is // not the previous block for the passed block. -func dbIndexConnectBlock(dbTx database.Tx, indexer Indexer, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func dbIndexConnectBlock(dbTx database.Tx, indexer Indexer, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Assert that the block being connected properly connects to the // current tip of the index. idxKey := indexer.Key() @@ -96,7 +96,7 @@ func dbIndexConnectBlock(dbTx database.Tx, indexer Indexer, block *btcutil.Block // given block using the provided indexer and updates the tip of the indexer // accordingly. An error will be returned if the current tip for the indexer is // not the passed block. -func dbIndexDisconnectBlock(dbTx database.Tx, indexer Indexer, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func dbIndexDisconnectBlock(dbTx database.Tx, indexer Indexer, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Assert that the block being disconnected is the current tip of the // index. idxKey := indexer.Key() @@ -131,7 +131,7 @@ type Manager struct { } // Ensure the Manager type implements the blockchain.IndexManager interface. -var _ blockchain.IndexManager = (*Manager)(nil) +var _ blockdag.IndexManager = (*Manager)(nil) // indexDropKey returns the key for an index which indicates it is in the // process of being dropped. @@ -229,7 +229,7 @@ func (m *Manager) maybeCreateIndexes(dbTx database.Tx) error { // catch up due to the I/O contention. // // This is part of the blockchain.IndexManager interface. -func (m *Manager) Init(chain *blockchain.BlockChain, interrupt <-chan struct{}) error { +func (m *Manager) Init(chain *blockdag.BlockChain, interrupt <-chan struct{}) error { // Nothing to do when no indexes are enabled. if len(m.enabledIndexes) == 0 { return nil @@ -313,7 +313,7 @@ func (m *Manager) Init(chain *blockchain.BlockChain, interrupt <-chan struct{}) // When the index requires all of the referenced // txouts they need to be retrieved from the // transaction index. - var view *blockchain.UtxoViewpoint + var view *blockdag.UtxoViewpoint if indexNeedsInputs(indexer) { var err error view, err = makeUtxoView(dbTx, block, @@ -407,7 +407,7 @@ func (m *Manager) Init(chain *blockchain.BlockChain, interrupt <-chan struct{}) } // Connect the block for all indexes that need it. - var view *blockchain.UtxoViewpoint + var view *blockdag.UtxoViewpoint for i, indexer := range m.enabledIndexes { // Skip indexes that don't need to be updated with this // block. @@ -492,8 +492,8 @@ func dbFetchTx(dbTx database.Tx, hash *chainhash.Hash) (*wire.MsgTx, error) { // transactions in the block. This is sometimes needed when catching indexes up // because many of the txouts could actually already be spent however the // associated scripts are still required to index them. -func makeUtxoView(dbTx database.Tx, block *btcutil.Block, interrupt <-chan struct{}) (*blockchain.UtxoViewpoint, error) { - view := blockchain.NewUtxoViewpoint() +func makeUtxoView(dbTx database.Tx, block *btcutil.Block, interrupt <-chan struct{}) (*blockdag.UtxoViewpoint, error) { + view := blockdag.NewUtxoViewpoint() for txIdx, tx := range block.Transactions() { // Coinbases do not reference any inputs. Since the block is // required to have already gone through full validation, it has @@ -528,7 +528,7 @@ func makeUtxoView(dbTx database.Tx, block *btcutil.Block, interrupt <-chan struc // checks, and invokes each indexer. // // This is part of the blockchain.IndexManager interface. -func (m *Manager) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func (m *Manager) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Call each of the currently active optional indexes with the block // being connected so they can update accordingly. for _, index := range m.enabledIndexes { @@ -546,7 +546,7 @@ func (m *Manager) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blo // the index entries associated with the block. // // This is part of the blockchain.IndexManager interface. -func (m *Manager) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func (m *Manager) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Call each of the currently active optional indexes with the block // being disconnected so they can update accordingly. for _, index := range m.enabledIndexes { diff --git a/blockchain/indexers/txindex.go b/blockdag/indexers/txindex.go similarity index 99% rename from blockchain/indexers/txindex.go rename to blockdag/indexers/txindex.go index b43a41904..72850e450 100644 --- a/blockchain/indexers/txindex.go +++ b/blockdag/indexers/txindex.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" "github.com/daglabs/btcd/wire" @@ -388,7 +388,7 @@ func (idx *TxIndex) Create(dbTx database.Tx) error { // for every transaction in the passed block. // // This is part of the Indexer interface. -func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Increment the internal block ID to use for the block being connected // and add all of the transactions in the block to the index. newBlockID := idx.curBlockID + 1 @@ -411,7 +411,7 @@ func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, view *b // hash-to-transaction mapping for every transaction in the block. // // This is part of the Indexer interface. -func (idx *TxIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { +func (idx *TxIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockdag.UtxoViewpoint) error { // Remove all of the transactions in the block from the index. if err := dbRemoveTxIndexEntries(dbTx, block); err != nil { return err diff --git a/blockchain/log.go b/blockdag/log.go similarity index 97% rename from blockchain/log.go rename to blockdag/log.go index d5fb2625c..56725b296 100644 --- a/blockchain/log.go +++ b/blockdag/log.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "github.com/btcsuite/btclog" diff --git a/blockchain/mediantime.go b/blockdag/mediantime.go similarity index 99% rename from blockchain/mediantime.go rename to blockdag/mediantime.go index ac0689e28..1b19ed80e 100644 --- a/blockchain/mediantime.go +++ b/blockdag/mediantime.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math" diff --git a/blockchain/mediantime_test.go b/blockdag/mediantime_test.go similarity index 99% rename from blockchain/mediantime_test.go rename to blockdag/mediantime_test.go index 948d03105..4c5432dab 100644 --- a/blockchain/mediantime_test.go +++ b/blockdag/mediantime_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "strconv" diff --git a/blockchain/merkle.go b/blockdag/merkle.go similarity index 99% rename from blockchain/merkle.go rename to blockdag/merkle.go index ba670813f..c8d94162e 100644 --- a/blockchain/merkle.go +++ b/blockdag/merkle.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math" diff --git a/blockchain/merkle_test.go b/blockdag/merkle_test.go similarity index 97% rename from blockchain/merkle_test.go rename to blockdag/merkle_test.go index 1c00ba659..a93fc815d 100644 --- a/blockchain/merkle_test.go +++ b/blockdag/merkle_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "testing" diff --git a/blockchain/notifications.go b/blockdag/notifications.go similarity index 99% rename from blockchain/notifications.go rename to blockdag/notifications.go index 25cc4f1f0..a94b0ca43 100644 --- a/blockchain/notifications.go +++ b/blockdag/notifications.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/notifications_test.go b/blockdag/notifications_test.go similarity index 98% rename from blockchain/notifications_test.go rename to blockdag/notifications_test.go index 56648da28..31ced1392 100644 --- a/blockchain/notifications_test.go +++ b/blockdag/notifications_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "testing" diff --git a/blockchain/process.go b/blockdag/process.go similarity index 99% rename from blockchain/process.go rename to blockdag/process.go index fd7d8b378..44dff9920 100644 --- a/blockchain/process.go +++ b/blockdag/process.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/scriptval.go b/blockdag/scriptval.go similarity index 99% rename from blockchain/scriptval.go rename to blockdag/scriptval.go index 855ee50c8..b88bc4199 100644 --- a/blockchain/scriptval.go +++ b/blockdag/scriptval.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/scriptval_test.go b/blockdag/scriptval_test.go similarity index 98% rename from blockchain/scriptval_test.go rename to blockdag/scriptval_test.go index 6f739fe5f..035c71e8b 100644 --- a/blockchain/scriptval_test.go +++ b/blockdag/scriptval_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/testdata/277647.dat.bz2 b/blockdag/testdata/277647.dat.bz2 similarity index 100% rename from blockchain/testdata/277647.dat.bz2 rename to blockdag/testdata/277647.dat.bz2 diff --git a/blockchain/testdata/277647.utxostore.bz2 b/blockdag/testdata/277647.utxostore.bz2 similarity index 100% rename from blockchain/testdata/277647.utxostore.bz2 rename to blockdag/testdata/277647.utxostore.bz2 diff --git a/blockchain/testdata/blk_0_to_4.dat.bz2 b/blockdag/testdata/blk_0_to_4.dat.bz2 similarity index 100% rename from blockchain/testdata/blk_0_to_4.dat.bz2 rename to blockdag/testdata/blk_0_to_4.dat.bz2 diff --git a/blockchain/testdata/blk_3A.dat.bz2 b/blockdag/testdata/blk_3A.dat.bz2 similarity index 100% rename from blockchain/testdata/blk_3A.dat.bz2 rename to blockdag/testdata/blk_3A.dat.bz2 diff --git a/blockchain/testdata/blk_4A.dat.bz2 b/blockdag/testdata/blk_4A.dat.bz2 similarity index 100% rename from blockchain/testdata/blk_4A.dat.bz2 rename to blockdag/testdata/blk_4A.dat.bz2 diff --git a/blockchain/testdata/blk_5A.dat.bz2 b/blockdag/testdata/blk_5A.dat.bz2 similarity index 100% rename from blockchain/testdata/blk_5A.dat.bz2 rename to blockdag/testdata/blk_5A.dat.bz2 diff --git a/blockchain/testdata/reorgtest.hex b/blockdag/testdata/reorgtest.hex similarity index 100% rename from blockchain/testdata/reorgtest.hex rename to blockdag/testdata/reorgtest.hex diff --git a/blockchain/thresholdstate.go b/blockdag/thresholdstate.go similarity index 99% rename from blockchain/thresholdstate.go rename to blockdag/thresholdstate.go index 32fb45608..92135883b 100644 --- a/blockchain/thresholdstate.go +++ b/blockdag/thresholdstate.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/thresholdstate_test.go b/blockdag/thresholdstate_test.go similarity index 99% rename from blockchain/thresholdstate_test.go rename to blockdag/thresholdstate_test.go index 089d24c5b..5f08f2cab 100644 --- a/blockchain/thresholdstate_test.go +++ b/blockdag/thresholdstate_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "testing" diff --git a/blockchain/timesorter.go b/blockdag/timesorter.go similarity index 97% rename from blockchain/timesorter.go rename to blockdag/timesorter.go index d0288e1d3..5e6921b0d 100644 --- a/blockchain/timesorter.go +++ b/blockdag/timesorter.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag // timeSorter implements sort.Interface to allow a slice of timestamps to // be sorted. diff --git a/blockchain/timesorter_test.go b/blockdag/timesorter_test.go similarity index 98% rename from blockchain/timesorter_test.go rename to blockdag/timesorter_test.go index 68eb69326..1bd3e492e 100644 --- a/blockchain/timesorter_test.go +++ b/blockdag/timesorter_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "reflect" diff --git a/blockchain/upgrade.go b/blockdag/upgrade.go similarity index 99% rename from blockchain/upgrade.go rename to blockdag/upgrade.go index 06694cd83..4f6698a06 100644 --- a/blockchain/upgrade.go +++ b/blockdag/upgrade.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "bytes" diff --git a/blockchain/upgrade_test.go b/blockdag/upgrade_test.go similarity index 99% rename from blockchain/upgrade_test.go rename to blockdag/upgrade_test.go index 97e7f55c3..792965e5c 100644 --- a/blockchain/upgrade_test.go +++ b/blockdag/upgrade_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "reflect" diff --git a/blockchain/utxoviewpoint.go b/blockdag/utxoviewpoint.go similarity index 99% rename from blockchain/utxoviewpoint.go rename to blockdag/utxoviewpoint.go index 256103a1b..6ee0a6fa4 100644 --- a/blockchain/utxoviewpoint.go +++ b/blockdag/utxoviewpoint.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "fmt" diff --git a/blockchain/validate.go b/blockdag/validate.go similarity index 99% rename from blockchain/validate.go rename to blockdag/validate.go index 98e3e0a8e..e3329805e 100644 --- a/blockchain/validate.go +++ b/blockdag/validate.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "encoding/binary" diff --git a/blockchain/validate_test.go b/blockdag/validate_test.go similarity index 99% rename from blockchain/validate_test.go rename to blockdag/validate_test.go index 6a2dc0219..25640eecf 100644 --- a/blockchain/validate_test.go +++ b/blockdag/validate_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math" diff --git a/blockchain/versionbits.go b/blockdag/versionbits.go similarity index 99% rename from blockchain/versionbits.go rename to blockdag/versionbits.go index 61423d098..01bbeda86 100644 --- a/blockchain/versionbits.go +++ b/blockdag/versionbits.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package blockchain +package blockdag import ( "math" diff --git a/btcd.go b/btcd.go index 7b73b8242..718bd5ec8 100644 --- a/btcd.go +++ b/btcd.go @@ -15,7 +15,7 @@ import ( "runtime/debug" "runtime/pprof" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/database" "github.com/daglabs/btcd/limits" ) diff --git a/cmd/addblock/addblock.go b/cmd/addblock/addblock.go index d8b558032..cba2e3288 100644 --- a/cmd/addblock/addblock.go +++ b/cmd/addblock/addblock.go @@ -9,8 +9,8 @@ import ( "path/filepath" "runtime" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/database" "github.com/daglabs/btcd/limits" "github.com/btcsuite/btclog" @@ -73,7 +73,7 @@ func realMain() error { defer os.Stdout.Sync() log = backendLogger.Logger("MAIN") database.UseLogger(backendLogger.Logger("BCDB")) - blockchain.UseLogger(backendLogger.Logger("CHAN")) + blockdag.UseLogger(backendLogger.Logger("CHAN")) indexers.UseLogger(backendLogger.Logger("INDX")) // Load the block database. diff --git a/cmd/addblock/import.go b/cmd/addblock/import.go index 0e4ad07b7..250fb453a 100644 --- a/cmd/addblock/import.go +++ b/cmd/addblock/import.go @@ -11,8 +11,8 @@ import ( "sync" "time" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" "github.com/daglabs/btcd/wire" @@ -32,7 +32,7 @@ type importResults struct { // file to the block database. type blockImporter struct { db database.DB - chain *blockchain.BlockChain + chain *blockdag.BlockChain r io.ReadSeeker processQueue chan []byte doneChan chan bool @@ -130,7 +130,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) { // Ensure the blocks follows all of the chain rules and match up to the // known checkpoints. isMainChain, isOrphan, err := bi.chain.ProcessBlock(block, - blockchain.BFFastAdd) + blockdag.BFFastAdd) if err != nil { return false, err } @@ -325,15 +325,15 @@ func newBlockImporter(db database.DB, r io.ReadSeeker) (*blockImporter, error) { } // Create an index manager if any of the optional indexes are enabled. - var indexManager blockchain.IndexManager + var indexManager blockdag.IndexManager if len(indexes) > 0 { indexManager = indexers.NewManager(db, indexes) } - chain, err := blockchain.New(&blockchain.Config{ + chain, err := blockdag.New(&blockdag.Config{ DB: db, ChainParams: activeNetParams, - TimeSource: blockchain.NewMedianTime(), + TimeSource: blockdag.NewMedianTime(), IndexManager: indexManager, }) if err != nil { diff --git a/cmd/findcheckpoint/findcheckpoint.go b/cmd/findcheckpoint/findcheckpoint.go index 89edbce31..e64793b61 100644 --- a/cmd/findcheckpoint/findcheckpoint.go +++ b/cmd/findcheckpoint/findcheckpoint.go @@ -9,7 +9,7 @@ import ( "os" "path/filepath" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" @@ -39,7 +39,7 @@ func loadBlockDB() (database.DB, error) { // candidates at the last checkpoint that is already hard coded into btcchain // since there is no point in finding candidates before already existing // checkpoints. -func findCandidates(chain *blockchain.BlockChain, latestHash *chainhash.Hash) ([]*chaincfg.Checkpoint, error) { +func findCandidates(chain *blockdag.BlockChain, latestHash *chainhash.Hash) ([]*chaincfg.Checkpoint, error) { // Start with the latest block of the main chain. block, err := chain.BlockByHash(latestHash) if err != nil { @@ -59,7 +59,7 @@ func findCandidates(chain *blockchain.BlockChain, latestHash *chainhash.Hash) ([ // The latest known block must be at least the last known checkpoint // plus required checkpoint confirmations. - checkpointConfirmations := int32(blockchain.CheckpointConfirmations) + checkpointConfirmations := int32(blockdag.CheckpointConfirmations) requiredHeight := latestCheckpoint.Height + checkpointConfirmations if block.Height() < requiredHeight { return nil, fmt.Errorf("the block database is only at height "+ @@ -150,10 +150,10 @@ func main() { // Setup chain. Ignore notifications since they aren't needed for this // util. - chain, err := blockchain.New(&blockchain.Config{ + chain, err := blockdag.New(&blockdag.Config{ DB: db, ChainParams: activeNetParams, - TimeSource: blockchain.NewMedianTime(), + TimeSource: blockdag.NewMedianTime(), }) if err != nil { fmt.Fprintf(os.Stderr, "failed to initialize chain: %v\n", err) diff --git a/integration/bip0009_test.go b/integration/bip0009_test.go index e572dd869..13461c20b 100644 --- a/integration/bip0009_test.go +++ b/integration/bip0009_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/integration/rpctest" @@ -66,17 +66,17 @@ func assertChainHeight(r *rpctest.Harness, t *testing.T, expectedHeight uint32) // thresholdStateToStatus converts the passed threshold state to the equivalent // status string returned in the getblockchaininfo RPC. -func thresholdStateToStatus(state blockchain.ThresholdState) (string, error) { +func thresholdStateToStatus(state blockdag.ThresholdState) (string, error) { switch state { - case blockchain.ThresholdDefined: + case blockdag.ThresholdDefined: return "defined", nil - case blockchain.ThresholdStarted: + case blockdag.ThresholdStarted: return "started", nil - case blockchain.ThresholdLockedIn: + case blockdag.ThresholdLockedIn: return "lockedin", nil - case blockchain.ThresholdActive: + case blockdag.ThresholdActive: return "active", nil - case blockchain.ThresholdFailed: + case blockdag.ThresholdFailed: return "failed", nil } @@ -86,7 +86,7 @@ func thresholdStateToStatus(state blockchain.ThresholdState) (string, error) { // assertSoftForkStatus retrieves the current blockchain info from the given // test harness and ensures the provided soft fork key is both available and its // status is the equivalent of the passed state. -func assertSoftForkStatus(r *rpctest.Harness, t *testing.T, forkKey string, state blockchain.ThresholdState) { +func assertSoftForkStatus(r *rpctest.Harness, t *testing.T, forkKey string, state blockdag.ThresholdState) { // Convert the expected threshold state into the equivalent // getblockchaininfo RPC status string. status, err := thresholdStateToStatus(state) @@ -143,7 +143,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { // Assert the chain height is the expected value and the soft fork // status starts out as defined. assertChainHeight(r, t, 0) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdDefined) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdDefined) // *** ThresholdDefined part 2 - 1 block prior to ThresholdStarted *** // @@ -168,7 +168,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { } } assertChainHeight(r, t, confirmationWindow-2) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdDefined) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdDefined) // *** ThresholdStarted *** // @@ -181,7 +181,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { t.Fatalf("failed to generated block: %v", err) } assertChainHeight(r, t, confirmationWindow-1) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdStarted) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdStarted) // *** ThresholdStarted part 2 - Fail to achieve ThresholdLockedIn *** // @@ -212,7 +212,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { } } assertChainHeight(r, t, (confirmationWindow*2)-1) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdStarted) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdStarted) // *** ThresholdLockedIn *** // @@ -237,7 +237,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { } } assertChainHeight(r, t, (confirmationWindow*3)-1) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdLockedIn) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdLockedIn) // *** ThresholdLockedIn part 2 -- 1 block prior to ThresholdActive *** // @@ -255,7 +255,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { } } assertChainHeight(r, t, (confirmationWindow*4)-2) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdLockedIn) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdLockedIn) // *** ThresholdActive *** // @@ -269,7 +269,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { t.Fatalf("failed to generated block: %v", err) } assertChainHeight(r, t, (confirmationWindow*4)-1) - assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdActive) + assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdActive) } // TestBIP0009 ensures the BIP0009 soft fork mechanism follows the state diff --git a/integration/csv_fork_test.go b/integration/csv_fork_test.go index 5bbf1dd44..5a342ee9c 100644 --- a/integration/csv_fork_test.go +++ b/integration/csv_fork_test.go @@ -14,7 +14,7 @@ import ( "testing" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -206,7 +206,7 @@ func TestBIP0113Activation(t *testing.T) { } assertChainHeight(r, t, 299) - assertSoftForkStatus(r, t, csvKey, blockchain.ThresholdActive) + assertSoftForkStatus(r, t, csvKey, blockdag.ThresholdActive) // The timeLockDeltas slice represents a series of deviations from the // current MTP which will be used to test border conditions w.r.t @@ -286,7 +286,7 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T, // Convert the time-lock to the proper sequence lock based according to // if the lock is seconds or time based. - sequenceLock := blockchain.LockTimeToSequence(isSeconds, + sequenceLock := blockdag.LockTimeToSequence(isSeconds, uint32(timeLock)) // Our CSV script is simply: OP_CSV OP_DROP @@ -414,7 +414,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { } defer r.TearDown() - assertSoftForkStatus(r, t, csvKey, blockchain.ThresholdStarted) + assertSoftForkStatus(r, t, csvKey, blockdag.ThresholdStarted) harnessAddr, err := r.NewAddress() if err != nil { @@ -460,7 +460,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { assertTxInBlock(r, t, blocks[0], &txid) // Generate a custom transaction which spends the CSV output. - sequenceNum := blockchain.LockTimeToSequence(false, 10) + sequenceNum := blockdag.LockTimeToSequence(false, 10) spendingTx, err := spendCSVOutput(redeemScript, testUTXO, sequenceNum, sweepOutput, txVersion) if err != nil { @@ -501,7 +501,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { } assertChainHeight(r, t, 299) - assertSoftForkStatus(r, t, csvKey, blockchain.ThresholdActive) + assertSoftForkStatus(r, t, csvKey, blockdag.ThresholdActive) // Knowing the number of outputs needed for the tests below, create a // fresh output for use within each of the test-cases below. @@ -591,7 +591,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { // should be rejected as its version number is 1, and only tx // of version > 2 will trigger the CSV behavior. { - tx: makeTxCase(blockchain.LockTimeToSequence(false, 100), 1), + tx: makeTxCase(blockdag.LockTimeToSequence(false, 100), 1), accept: false, }, // A transaction of version 2 spending a single input. The @@ -599,7 +599,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { // bit it set. The transaction should be rejected as a result. { tx: makeTxCase( - blockchain.LockTimeToSequence(false, 1)|wire.SequenceLockTimeDisabled, + blockdag.LockTimeToSequence(false, 1)|wire.SequenceLockTimeDisabled, 2, ), accept: false, @@ -609,14 +609,14 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { // but the CSV output requires a 10 block relative lock-time. // Therefore, the transaction should be rejected. { - tx: makeTxCase(blockchain.LockTimeToSequence(false, 9), 2), + tx: makeTxCase(blockdag.LockTimeToSequence(false, 9), 2), accept: false, }, // A v2 transaction with a single input having a 10 block // relative time lock. The referenced input is 11 blocks old so // the transaction should be accepted. { - tx: makeTxCase(blockchain.LockTimeToSequence(false, 10), 2), + tx: makeTxCase(blockdag.LockTimeToSequence(false, 10), 2), accept: true, }, // A v2 transaction with a single input having a 11 block @@ -624,14 +624,14 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { // 11 and the CSV op-code requires 10 blocks to have passed, so // this transaction should be accepted. { - tx: makeTxCase(blockchain.LockTimeToSequence(false, 11), 2), + tx: makeTxCase(blockdag.LockTimeToSequence(false, 11), 2), accept: true, }, // A v2 transaction whose input has a 1000 blck relative time // lock. This should be rejected as the input's age is only 11 // blocks. { - tx: makeTxCase(blockchain.LockTimeToSequence(false, 1000), 2), + tx: makeTxCase(blockdag.LockTimeToSequence(false, 1000), 2), accept: false, }, // A v2 transaction with a single input having a 512,000 second @@ -639,14 +639,14 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) { // days worth of blocks haven't yet been mined. The referenced // input doesn't have sufficient age. { - tx: makeTxCase(blockchain.LockTimeToSequence(true, 512000), 2), + tx: makeTxCase(blockdag.LockTimeToSequence(true, 512000), 2), accept: false, }, // A v2 transaction whose single input has a 512 second // relative time-lock. This transaction should be accepted as // finalized. { - tx: makeTxCase(blockchain.LockTimeToSequence(true, 512), 2), + tx: makeTxCase(blockdag.LockTimeToSequence(true, 512), 2), accept: true, }, } diff --git a/integration/rpctest/blockgen.go b/integration/rpctest/blockgen.go index 19d1c9e90..9a785e118 100644 --- a/integration/rpctest/blockgen.go +++ b/integration/rpctest/blockgen.go @@ -11,7 +11,7 @@ import ( "runtime" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/txscript" @@ -44,7 +44,7 @@ func solveBlock(header *wire.BlockHeader, targetDifficulty *big.Int) bool { default: hdr.Nonce = i hash := hdr.BlockHash() - if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 { + if blockdag.HashToBig(&hash).Cmp(targetDifficulty) <= 0 { select { case results <- sbResult{true, i}: return @@ -116,7 +116,7 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32, }) if len(mineTo) == 0 { tx.AddTxOut(&wire.TxOut{ - Value: blockchain.CalcBlockSubsidy(nextBlockHeight, net), + Value: blockdag.CalcBlockSubsidy(nextBlockHeight, net), PkScript: pkScript, }) } else { @@ -181,7 +181,7 @@ func CreateBlock(prevBlock *btcutil.Block, inclusionTxs []*btcutil.Tx, if inclusionTxs != nil { blockTxns = append(blockTxns, inclusionTxs...) } - merkles := blockchain.BuildMerkleTreeStore(blockTxns) + merkles := blockdag.BuildMerkleTreeStore(blockTxns) var block wire.MsgBlock block.Header = wire.BlockHeader{ Version: blockVersion, diff --git a/integration/rpctest/memwallet.go b/integration/rpctest/memwallet.go index bb39ed100..f618a9774 100644 --- a/integration/rpctest/memwallet.go +++ b/integration/rpctest/memwallet.go @@ -10,7 +10,7 @@ import ( "fmt" "sync" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -207,7 +207,7 @@ func (m *memWallet) ingestBlock(update *chainUpdate) { } for _, tx := range update.filteredTxns { mtx := tx.MsgTx() - isCoinbase := blockchain.IsCoinBaseTx(mtx) + isCoinbase := blockdag.IsCoinBaseTx(mtx) txHash := mtx.TxHash() m.evalOutputs(mtx.TxOut, &txHash, isCoinbase, undo) m.evalInputs(mtx.TxIn, undo) diff --git a/log.go b/log.go index 2192c61c9..4199fd565 100644 --- a/log.go +++ b/log.go @@ -11,8 +11,8 @@ import ( "path/filepath" "github.com/daglabs/btcd/addrmgr" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/connmgr" "github.com/daglabs/btcd/database" "github.com/daglabs/btcd/mempool" @@ -76,7 +76,7 @@ func init() { addrmgr.UseLogger(amgrLog) connmgr.UseLogger(cmgrLog) database.UseLogger(bcdbLog) - blockchain.UseLogger(chanLog) + blockdag.UseLogger(chanLog) indexers.UseLogger(indxLog) mining.UseLogger(minrLog) cpuminer.UseLogger(minrLog) diff --git a/mempool/error.go b/mempool/error.go index 03e3f7ca4..1c89f8b8c 100644 --- a/mempool/error.go +++ b/mempool/error.go @@ -5,7 +5,7 @@ package mempool import ( - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/wire" ) @@ -52,7 +52,7 @@ func txRuleError(c wire.RejectCode, desc string) RuleError { // chainRuleError returns a RuleError that encapsulates the given // blockchain.RuleError. -func chainRuleError(chainErr blockchain.RuleError) RuleError { +func chainRuleError(chainErr blockdag.RuleError) RuleError { return RuleError{ Err: chainErr, } @@ -68,26 +68,26 @@ func extractRejectCode(err error) (wire.RejectCode, bool) { } switch err := err.(type) { - case blockchain.RuleError: + case blockdag.RuleError: // Convert the chain error to a reject code. var code wire.RejectCode switch err.ErrorCode { // Rejected due to duplicate. - case blockchain.ErrDuplicateBlock: + case blockdag.ErrDuplicateBlock: code = wire.RejectDuplicate // Rejected due to obsolete version. - case blockchain.ErrBlockVersionTooOld: + case blockdag.ErrBlockVersionTooOld: code = wire.RejectObsolete // Rejected due to checkpoint. - case blockchain.ErrCheckpointTimeTooOld: + case blockdag.ErrCheckpointTimeTooOld: fallthrough - case blockchain.ErrDifficultyTooLow: + case blockdag.ErrDifficultyTooLow: fallthrough - case blockchain.ErrBadCheckpoint: + case blockdag.ErrBadCheckpoint: fallthrough - case blockchain.ErrForkTooOld: + case blockdag.ErrForkTooOld: code = wire.RejectCheckpoint // Everything else is due to the block or transaction being invalid. diff --git a/mempool/mempool.go b/mempool/mempool.go index 1934bbb12..b6b419146 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -12,8 +12,8 @@ import ( "sync/atomic" "time" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -57,7 +57,7 @@ type Config struct { // FetchUtxoView defines the function to use to fetch unspent // transaction output information. - FetchUtxoView func(*btcutil.Tx) (*blockchain.UtxoViewpoint, error) + FetchUtxoView func(*btcutil.Tx) (*blockdag.UtxoViewpoint, error) // BestHeight defines the function to use to access the block height of // the current best chain. @@ -71,7 +71,7 @@ type Config struct { // CalcSequenceLock defines the function to use in order to generate // the current sequence lock for the given transaction using the passed // utxo view. - CalcSequenceLock func(*btcutil.Tx, *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) + CalcSequenceLock func(*btcutil.Tx, *blockdag.UtxoViewpoint) (*blockdag.SequenceLock, error) // IsDeploymentActive returns true if the target deploymentID is // active, and false otherwise. The mempool uses this function to gauge @@ -515,7 +515,7 @@ func (mp *TxPool) RemoveDoubleSpends(tx *btcutil.Tx) { // helper for maybeAcceptTransaction. // // This function MUST be called with the mempool lock held (for writes). -func (mp *TxPool) addTransaction(utxoView *blockchain.UtxoViewpoint, tx *btcutil.Tx, height int32, fee int64) *TxDesc { +func (mp *TxPool) addTransaction(utxoView *blockdag.UtxoViewpoint, tx *btcutil.Tx, height int32, fee int64) *TxDesc { // Add the transaction to the pool and mark the referenced outpoints // as spent by the pool. txD := &TxDesc{ @@ -585,7 +585,7 @@ func (mp *TxPool) CheckSpend(op wire.OutPoint) *btcutil.Tx { // transaction pool. // // This function MUST be called with the mempool lock held (for reads). -func (mp *TxPool) fetchInputUtxos(tx *btcutil.Tx) (*blockchain.UtxoViewpoint, error) { +func (mp *TxPool) fetchInputUtxos(tx *btcutil.Tx) (*blockdag.UtxoViewpoint, error) { utxoView, err := mp.cfg.FetchUtxoView(tx) if err != nil { return nil, err @@ -650,16 +650,16 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // Perform preliminary sanity checks on the transaction. This makes // use of blockchain which contains the invariant rules for what // transactions are allowed into blocks. - err := blockchain.CheckTransactionSanity(tx) + err := blockdag.CheckTransactionSanity(tx) if err != nil { - if cerr, ok := err.(blockchain.RuleError); ok { + if cerr, ok := err.(blockdag.RuleError); ok { return nil, nil, chainRuleError(cerr) } return nil, nil, err } // A standalone transaction must not be a coinbase transaction. - if blockchain.IsCoinBase(tx) { + if blockdag.IsCoinBase(tx) { str := fmt.Sprintf("transaction %v is an individual coinbase", txHash) return nil, nil, txRuleError(wire.RejectInvalid, str) @@ -712,7 +712,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // without needing to do a separate lookup. utxoView, err := mp.fetchInputUtxos(tx) if err != nil { - if cerr, ok := err.(blockchain.RuleError); ok { + if cerr, ok := err.(blockdag.RuleError); ok { return nil, nil, chainRuleError(cerr) } return nil, nil, err @@ -755,12 +755,12 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // with respect to its defined relative lock times. sequenceLock, err := mp.cfg.CalcSequenceLock(tx, utxoView) if err != nil { - if cerr, ok := err.(blockchain.RuleError); ok { + if cerr, ok := err.(blockdag.RuleError); ok { return nil, nil, chainRuleError(cerr) } return nil, nil, err } - if !blockchain.SequenceLockActive(sequenceLock, nextBlockHeight, + if !blockdag.SequenceLockActive(sequenceLock, nextBlockHeight, medianTimePast) { return nil, nil, txRuleError(wire.RejectNonstandard, "transaction's sequence locks on inputs not met") @@ -770,10 +770,10 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // rules in blockchain for what transactions are allowed into blocks. // Also returns the fees associated with the transaction which will be // used later. - txFee, err := blockchain.CheckTransactionInputs(tx, nextBlockHeight, + txFee, err := blockdag.CheckTransactionInputs(tx, nextBlockHeight, utxoView, mp.cfg.ChainParams) if err != nil { - if cerr, ok := err.(blockchain.RuleError); ok { + if cerr, ok := err.(blockdag.RuleError); ok { return nil, nil, chainRuleError(cerr) } return nil, nil, err @@ -806,9 +806,9 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // the coinbase address itself can contain signature operations, the // maximum allowed signature operations per transaction is less than // the maximum allowed signature operations per block. - sigOpCount, err := blockchain.CountP2SHSigOps(tx, false, utxoView) + sigOpCount, err := blockdag.CountP2SHSigOps(tx, false, utxoView) if err != nil { - if cerr, ok := err.(blockchain.RuleError); ok { + if cerr, ok := err.(blockdag.RuleError); ok { return nil, nil, chainRuleError(cerr) } return nil, nil, err @@ -881,10 +881,10 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // Verify crypto signatures for each input and reject the transaction if // any don't verify. - err = blockchain.ValidateTransactionScripts(tx, utxoView, + err = blockdag.ValidateTransactionScripts(tx, utxoView, txscript.StandardVerifyFlags, mp.cfg.SigCache) if err != nil { - if cerr, ok := err.(blockchain.RuleError); ok { + if cerr, ok := err.(blockdag.RuleError); ok { return nil, nil, chainRuleError(cerr) } return nil, nil, err diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index f18719fc2..c7476d7e7 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -26,7 +26,7 @@ import ( // transactions to appear as though they are spending completely valid utxos. type fakeChain struct { sync.RWMutex - utxos *blockchain.UtxoViewpoint + utxos *blockdag.UtxoViewpoint currentHeight int32 medianTimePast time.Time } @@ -37,7 +37,7 @@ type fakeChain struct { // view can be examined for duplicate transactions. // // This function is safe for concurrent access however the returned view is NOT. -func (s *fakeChain) FetchUtxoView(tx *btcutil.Tx) (*blockchain.UtxoViewpoint, error) { +func (s *fakeChain) FetchUtxoView(tx *btcutil.Tx) (*blockdag.UtxoViewpoint, error) { s.RLock() defer s.RUnlock() @@ -45,7 +45,7 @@ func (s *fakeChain) FetchUtxoView(tx *btcutil.Tx) (*blockchain.UtxoViewpoint, er // do not affect the fake chain's view. // Add an entry for the tx itself to the new view. - viewpoint := blockchain.NewUtxoViewpoint() + viewpoint := blockdag.NewUtxoViewpoint() prevOut := wire.OutPoint{Hash: *tx.Hash()} for txOutIdx := range tx.MsgTx().TxOut { prevOut.Index = uint32(txOutIdx) @@ -98,9 +98,9 @@ func (s *fakeChain) SetMedianTimePast(mtp time.Time) { // CalcSequenceLock returns the current sequence lock for the passed // transaction associated with the fake chain instance. func (s *fakeChain) CalcSequenceLock(tx *btcutil.Tx, - view *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) { + view *blockdag.UtxoViewpoint) (*blockdag.SequenceLock, error) { - return &blockchain.SequenceLock{ + return &blockdag.SequenceLock{ Seconds: -1, BlockHeight: -1, }, nil @@ -164,7 +164,7 @@ func (p *poolHarness) CreateCoinbaseTx(blockHeight int32, numOutputs uint32) (*b SignatureScript: coinbaseScript, Sequence: wire.MaxTxInSequenceNum, }) - totalInput := blockchain.CalcBlockSubsidy(blockHeight, p.chainParams) + totalInput := blockdag.CalcBlockSubsidy(blockHeight, p.chainParams) amountPerOutput := totalInput / int64(numOutputs) remainder := totalInput - amountPerOutput*int64(numOutputs) for i := uint32(0); i < numOutputs; i++ { @@ -299,7 +299,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp } // Create a new fake chain and harness bound to it. - chain := &fakeChain{utxos: blockchain.NewUtxoViewpoint()} + chain := &fakeChain{utxos: blockdag.NewUtxoViewpoint()} harness := poolHarness{ signKey: signKey, payAddr: payAddr, @@ -313,7 +313,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp FreeTxRelayLimit: 15.0, MaxOrphanTxs: 5, MaxOrphanTxSize: 1000, - MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, + MaxSigOpsPerTx: blockdag.MaxSigOpsPerBlock / 5, MinRelayTxFee: 1000, // 1 Satoshi per byte MaxTxVersion: 1, }, diff --git a/mempool/policy.go b/mempool/policy.go index 891d8a878..1f6c45f7f 100644 --- a/mempool/policy.go +++ b/mempool/policy.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/txscript" "github.com/daglabs/btcd/wire" "github.com/daglabs/btcutil" @@ -90,7 +90,7 @@ func calcMinRequiredTxRelayFee(serializedSize int64, minRelayTxFee btcutil.Amoun // not perform those checks because the script engine already does this more // accurately and concisely via the txscript.ScriptVerifyCleanStack and // txscript.ScriptVerifySigPushOnly flags. -func checkInputsStandard(tx *btcutil.Tx, utxoView *blockchain.UtxoViewpoint) error { +func checkInputsStandard(tx *btcutil.Tx, utxoView *blockdag.UtxoViewpoint) error { // NOTE: The reference implementation also does a coinbase check here, // but coinbases have already been rejected prior to calling this // function so no need to recheck. @@ -265,7 +265,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32, // The transaction must be finalized to be standard and therefore // considered for inclusion in a block. - if !blockchain.IsFinalizedTransaction(tx, height, medianTimePast) { + if !blockdag.IsFinalizedTransaction(tx, height, medianTimePast) { return txRuleError(wire.RejectNonstandard, "transaction is not finalized") } diff --git a/mining/cpuminer/cpuminer.go b/mining/cpuminer/cpuminer.go index da2fcf21d..f6d4883a0 100644 --- a/mining/cpuminer/cpuminer.go +++ b/mining/cpuminer/cpuminer.go @@ -12,7 +12,7 @@ import ( "sync" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/mining" @@ -64,7 +64,7 @@ type Config struct { // ProcessBlock defines the function to call with any solved blocks. // It typically must run the provided block through the same set of // rules and handling as any other block coming from the network. - ProcessBlock func(*btcutil.Block, blockchain.BehaviorFlags) (bool, error) + ProcessBlock func(*btcutil.Block, blockdag.BehaviorFlags) (bool, error) // ConnectedCount defines the function to use to obtain how many other // peers the server is connected to. This is used by the automatic @@ -170,11 +170,11 @@ func (m *CPUMiner) submitBlock(block *btcutil.Block) bool { // Process this block using the same rules as blocks coming from other // nodes. This will in turn relay it to the network like normal. - isOrphan, err := m.cfg.ProcessBlock(block, blockchain.BFNone) + isOrphan, err := m.cfg.ProcessBlock(block, blockdag.BFNone) if err != nil { // Anything other than a rule violation is an unexpected error, // so log that error as an internal error. - if _, ok := err.(blockchain.RuleError); !ok { + if _, ok := err.(blockdag.RuleError); !ok { log.Errorf("Unexpected error while processing "+ "block submitted via CPU miner: %v", err) return false @@ -218,7 +218,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32, // Create some convenience variables. header := &msgBlock.Header - targetDifficulty := blockchain.CompactToBig(header.Bits) + targetDifficulty := blockdag.CompactToBig(header.Bits) // Initial state. lastGenerated := time.Now() @@ -279,7 +279,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32, // The block is solved when the new block hash is less // than the target difficulty. Yay! - if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 { + if blockdag.HashToBig(&hash).Cmp(targetDifficulty) <= 0 { m.updateHashes <- hashesCompleted return true } diff --git a/mining/mining.go b/mining/mining.go index b84ec3836..caa5c8650 100644 --- a/mining/mining.go +++ b/mining/mining.go @@ -9,7 +9,7 @@ import ( "fmt" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/txscript" @@ -216,7 +216,7 @@ type BlockTemplate struct { // viewA will contain all of its original entries plus all of the entries // in viewB. It will replace any entries in viewB which also exist in viewA // if the entry in viewA is spent. -func mergeUtxoView(viewA *blockchain.UtxoViewpoint, viewB *blockchain.UtxoViewpoint) { +func mergeUtxoView(viewA *blockdag.UtxoViewpoint, viewB *blockdag.UtxoViewpoint) { viewAEntries := viewA.Entries() for outpoint, entryB := range viewB.Entries() { if entryA, exists := viewAEntries[outpoint]; !exists || @@ -273,7 +273,7 @@ func createCoinbaseTx(params *chaincfg.Params, coinbaseScript []byte, nextBlockH Sequence: wire.MaxTxInSequenceNum, }) tx.AddTxOut(&wire.TxOut{ - Value: blockchain.CalcBlockSubsidy(nextBlockHeight, params), + Value: blockdag.CalcBlockSubsidy(nextBlockHeight, params), PkScript: pkScript, }) return btcutil.NewTx(tx), nil @@ -282,7 +282,7 @@ func createCoinbaseTx(params *chaincfg.Params, coinbaseScript []byte, nextBlockH // spendTransaction updates the passed view by marking the inputs to the passed // transaction as spent. It also adds all outputs in the passed transaction // which are not provably unspendable as available unspent transaction outputs. -func spendTransaction(utxoView *blockchain.UtxoViewpoint, tx *btcutil.Tx, height int32) error { +func spendTransaction(utxoView *blockdag.UtxoViewpoint, tx *btcutil.Tx, height int32) error { for _, txIn := range tx.MsgTx().TxIn { entry := utxoView.LookupEntry(txIn.PreviousOutPoint) if entry != nil { @@ -311,14 +311,14 @@ func logSkippedDeps(tx *btcutil.Tx, deps map[chainhash.Hash]*txPrioItem) { // on the end of the provided best chain. In particular, it is one second after // the median timestamp of the last several blocks per the chain consensus // rules. -func MinimumMedianTime(chainState *blockchain.BestState) time.Time { +func MinimumMedianTime(chainState *blockdag.BestState) time.Time { return chainState.MedianTime.Add(time.Second) } // medianAdjustedTime returns the current time adjusted to ensure it is at least // one second after the median timestamp of the last several blocks per the // chain consensus rules. -func medianAdjustedTime(chainState *blockchain.BestState, timeSource blockchain.MedianTimeSource) time.Time { +func medianAdjustedTime(chainState *blockdag.BestState, timeSource blockdag.MedianTimeSource) time.Time { // The timestamp for the block must not be before the median timestamp // of the last several blocks. Thus, choose the maximum between the // current time and one second after the past median time. The current @@ -342,8 +342,8 @@ type BlkTmplGenerator struct { policy *Policy chainParams *chaincfg.Params txSource TxSource - chain *blockchain.BlockChain - timeSource blockchain.MedianTimeSource + chain *blockdag.BlockChain + timeSource blockdag.MedianTimeSource sigCache *txscript.SigCache } @@ -354,8 +354,8 @@ type BlkTmplGenerator struct { // templates are built on top of the current best chain and adhere to the // consensus rules. func NewBlkTmplGenerator(policy *Policy, params *chaincfg.Params, - txSource TxSource, chain *blockchain.BlockChain, - timeSource blockchain.MedianTimeSource, + txSource TxSource, chain *blockdag.BlockChain, + timeSource blockdag.MedianTimeSource, sigCache *txscript.SigCache) *BlkTmplGenerator { return &BlkTmplGenerator{ @@ -453,7 +453,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*Bloc if err != nil { return nil, err } - numCoinbaseSigOps := int64(blockchain.CountSigOps(coinbaseTx)) + numCoinbaseSigOps := int64(blockdag.CountSigOps(coinbaseTx)) // Get the current source transactions and create a priority queue to // hold the transactions which are ready for inclusion into a block @@ -471,7 +471,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*Bloc // avoided. blockTxns := make([]*btcutil.Tx, 0, len(sourceTxns)) blockTxns = append(blockTxns, coinbaseTx) - blockUtxos := blockchain.NewUtxoViewpoint() + blockUtxos := blockdag.NewUtxoViewpoint() // dependers is used to track transactions which depend on another // transaction in the source pool. This, in conjunction with the @@ -499,11 +499,11 @@ mempoolLoop: // A block can't have more than one coinbase or contain // non-finalized transactions. tx := txDesc.Tx - if blockchain.IsCoinBase(tx) { + if blockdag.IsCoinBase(tx) { log.Tracef("Skipping coinbase tx %s", tx.Hash()) continue } - if !blockchain.IsFinalizedTransaction(tx, nextBlockHeight, + if !blockdag.IsFinalizedTransaction(tx, nextBlockHeight, g.timeSource.AdjustedTime()) { log.Tracef("Skipping non-finalized tx %s", tx.Hash()) @@ -615,15 +615,15 @@ mempoolLoop: // Enforce maximum signature operations per block. Also check // for overflow. - numSigOps := int64(blockchain.CountSigOps(tx)) + numSigOps := int64(blockdag.CountSigOps(tx)) if blockSigOps+numSigOps < blockSigOps || - blockSigOps+numSigOps > blockchain.MaxSigOpsPerBlock { + blockSigOps+numSigOps > blockdag.MaxSigOpsPerBlock { log.Tracef("Skipping tx %s because it would exceed "+ "the maximum sigops per block", tx.Hash()) logSkippedDeps(tx, deps) continue } - numP2SHSigOps, err := blockchain.CountP2SHSigOps(tx, false, + numP2SHSigOps, err := blockdag.CountP2SHSigOps(tx, false, blockUtxos) if err != nil { log.Tracef("Skipping tx %s due to error in "+ @@ -633,7 +633,7 @@ mempoolLoop: } numSigOps += int64(numP2SHSigOps) if blockSigOps+numSigOps < blockSigOps || - blockSigOps+numSigOps > blockchain.MaxSigOpsPerBlock { + blockSigOps+numSigOps > blockdag.MaxSigOpsPerBlock { log.Tracef("Skipping tx %s because it would "+ "exceed the maximum sigops per block", tx.Hash()) logSkippedDeps(tx, deps) @@ -686,7 +686,7 @@ mempoolLoop: // Ensure the transaction inputs pass all of the necessary // preconditions before allowing it to be added to the block. - _, err = blockchain.CheckTransactionInputs(tx, nextBlockHeight, + _, err = blockdag.CheckTransactionInputs(tx, nextBlockHeight, blockUtxos, g.chainParams) if err != nil { log.Tracef("Skipping tx %s due to error in "+ @@ -694,7 +694,7 @@ mempoolLoop: logSkippedDeps(tx, deps) continue } - err = blockchain.ValidateTransactionScripts(tx, blockUtxos, + err = blockdag.ValidateTransactionScripts(tx, blockUtxos, txscript.StandardVerifyFlags, g.sigCache) if err != nil { log.Tracef("Skipping tx %s due to error in "+ @@ -760,7 +760,7 @@ mempoolLoop: } // Create a new block ready to be solved. - merkles := blockchain.BuildMerkleTreeStore(blockTxns) + merkles := blockdag.BuildMerkleTreeStore(blockTxns) var msgBlock wire.MsgBlock msgBlock.Header = wire.BlockHeader{ Version: nextBlockVersion, @@ -787,7 +787,7 @@ mempoolLoop: log.Debugf("Created new block template (%d transactions, %d in fees, "+ "%d signature operations, %d bytes, target difficulty %064x)", len(msgBlock.Transactions), totalFees, blockSigOps, blockSize, - blockchain.CompactToBig(msgBlock.Header.Bits)) + blockdag.CompactToBig(msgBlock.Header.Bits)) return &BlockTemplate{ Block: &msgBlock, @@ -832,11 +832,11 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight if err != nil { return err } - if len(coinbaseScript) > blockchain.MaxCoinbaseScriptLen { + if len(coinbaseScript) > blockdag.MaxCoinbaseScriptLen { return fmt.Errorf("coinbase transaction script length "+ "of %d is out of range (min: %d, max: %d)", - len(coinbaseScript), blockchain.MinCoinbaseScriptLen, - blockchain.MaxCoinbaseScriptLen) + len(coinbaseScript), blockdag.MinCoinbaseScriptLen, + blockdag.MaxCoinbaseScriptLen) } msgBlock.Transactions[0].TxIn[0].SignatureScript = coinbaseScript @@ -846,7 +846,7 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight // Recalculate the merkle root with the updated extra nonce. block := btcutil.NewBlock(msgBlock) - merkles := blockchain.BuildMerkleTreeStore(block.Transactions()) + merkles := blockdag.BuildMerkleTreeStore(block.Transactions()) msgBlock.Header.MerkleRoot = *merkles[len(merkles)-1] return nil } @@ -857,7 +857,7 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight // treated as immutable since it is shared by all callers. // // This function is safe for concurrent access. -func (g *BlkTmplGenerator) BestSnapshot() *blockchain.BestState { +func (g *BlkTmplGenerator) BestSnapshot() *blockdag.BestState { return g.chain.BestSnapshot() } diff --git a/mining/policy.go b/mining/policy.go index fddb7381d..43759d54f 100644 --- a/mining/policy.go +++ b/mining/policy.go @@ -5,7 +5,7 @@ package mining import ( - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/wire" "github.com/daglabs/btcutil" ) @@ -54,7 +54,7 @@ func minInt(a, b int) int { // age is the sum of this value for each txin. Any inputs to the transaction // which are currently in the mempool and hence not mined into a block yet, // contribute no additional input age to the transaction. -func calcInputValueAge(tx *wire.MsgTx, utxoView *blockchain.UtxoViewpoint, nextBlockHeight int32) float64 { +func calcInputValueAge(tx *wire.MsgTx, utxoView *blockdag.UtxoViewpoint, nextBlockHeight int32) float64 { var totalInputAge float64 for _, txIn := range tx.TxIn { // Don't attempt to accumulate the total input age if the @@ -86,7 +86,7 @@ func calcInputValueAge(tx *wire.MsgTx, utxoView *blockchain.UtxoViewpoint, nextB // of each of its input values multiplied by their age (# of confirmations). // Thus, the final formula for the priority is: // sum(inputValue * inputAge) / adjustedTxSize -func CalcPriority(tx *wire.MsgTx, utxoView *blockchain.UtxoViewpoint, nextBlockHeight int32) float64 { +func CalcPriority(tx *wire.MsgTx, utxoView *blockdag.UtxoViewpoint, nextBlockHeight int32) float64 { // In order to encourage spending multiple old unspent transaction // outputs thereby reducing the total set, don't count the constant // overhead for each input as well as enough bytes of the signature diff --git a/mining/policy_test.go b/mining/policy_test.go index 09da443a4..a725b5fdc 100644 --- a/mining/policy_test.go +++ b/mining/policy_test.go @@ -8,7 +8,7 @@ import ( "encoding/hex" "testing" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/wire" "github.com/daglabs/btcutil" @@ -42,12 +42,12 @@ func hexToBytes(s string) []byte { // provided source transactions as if there were available at the respective // block height specified in the heights slice. The length of the source txns // and source tx heights must match or it will panic. -func newUtxoViewpoint(sourceTxns []*wire.MsgTx, sourceTxHeights []int32) *blockchain.UtxoViewpoint { +func newUtxoViewpoint(sourceTxns []*wire.MsgTx, sourceTxHeights []int32) *blockdag.UtxoViewpoint { if len(sourceTxns) != len(sourceTxHeights) { panic("each transaction must have its block height specified") } - view := blockchain.NewUtxoViewpoint() + view := blockdag.NewUtxoViewpoint() for i, tx := range sourceTxns { view.AddTxOuts(btcutil.NewTx(tx), sourceTxHeights[i]) } @@ -117,11 +117,11 @@ func TestCalcPriority(t *testing.T) { } tests := []struct { - name string // test description - tx *wire.MsgTx // tx to calc priority for - utxoView *blockchain.UtxoViewpoint // inputs to tx - nextHeight int32 // height for priority calc - want float64 // expected priority + name string // test description + tx *wire.MsgTx // tx to calc priority for + utxoView *blockdag.UtxoViewpoint // inputs to tx + nextHeight int32 // height for priority calc + want float64 // expected priority }{ { name: "one height 7 input, prio tx height 169", diff --git a/netsync/interface.go b/netsync/interface.go index 0a8cc075d..8374c156a 100644 --- a/netsync/interface.go +++ b/netsync/interface.go @@ -5,7 +5,7 @@ package netsync import ( - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/mempool" @@ -30,7 +30,7 @@ type PeerNotifier interface { // Config is a configuration struct used to initialize a new SyncManager. type Config struct { PeerNotifier PeerNotifier - Chain *blockchain.BlockChain + Chain *blockdag.BlockChain TxMemPool *mempool.TxPool ChainParams *chaincfg.Params diff --git a/netsync/manager.go b/netsync/manager.go index c2f8b0d24..793106935 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -11,7 +11,7 @@ import ( "sync/atomic" "time" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/database" @@ -103,7 +103,7 @@ type processBlockResponse struct { // way to call ProcessBlock on the internal block chain instance. type processBlockMsg struct { block *btcutil.Block - flags blockchain.BehaviorFlags + flags blockdag.BehaviorFlags reply chan processBlockResponse } @@ -147,7 +147,7 @@ type SyncManager struct { peerNotifier PeerNotifier started int32 shutdown int32 - chain *blockchain.BlockChain + chain *blockdag.BlockChain txMemPool *mempool.TxPool chainParams *chaincfg.Params progressLogger *blockProgressLogger @@ -521,13 +521,13 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { // since it is needed to verify the next round of headers links // properly. isCheckpointBlock := false - behaviorFlags := blockchain.BFNone + behaviorFlags := blockdag.BFNone if sm.headersFirstMode { firstNodeEl := sm.headerList.Front() if firstNodeEl != nil { firstNode := firstNodeEl.Value.(*headerNode) if blockHash.IsEqual(firstNode.hash) { - behaviorFlags |= blockchain.BFFastAdd + behaviorFlags |= blockdag.BFFastAdd if firstNode.hash.IsEqual(sm.nextCheckpoint.Hash) { isCheckpointBlock = true } else { @@ -551,7 +551,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { // rejected as opposed to something actually going wrong, so log // it as such. Otherwise, something really did go wrong, so log // it as an actual error. - if _, ok := err.(blockchain.RuleError); ok { + if _, ok := err.(blockdag.RuleError); ok { log.Infof("Rejected block %v from %s: %v", blockHash, peer, err) } else { @@ -590,9 +590,9 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { // Extraction is only attempted if the block's version is // high enough (ver 2+). header := &bmsg.block.MsgBlock().Header - if blockchain.ShouldHaveSerializedBlockHeight(header) { + if blockdag.ShouldHaveSerializedBlockHeight(header) { coinbaseTx := bmsg.block.Transactions()[0] - cbHeight, err := blockchain.ExtractCoinbaseHeight(coinbaseTx) + cbHeight, err := blockdag.ExtractCoinbaseHeight(coinbaseTx) if err != nil { log.Warnf("Unable to extract height from "+ "coinbase tx: %v", err) @@ -663,7 +663,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { prevHash := sm.nextCheckpoint.Hash sm.nextCheckpoint = sm.findNextHeaderCheckpoint(prevHeight) if sm.nextCheckpoint != nil { - locator := blockchain.BlockLocator([]*chainhash.Hash{prevHash}) + locator := blockdag.BlockLocator([]*chainhash.Hash{prevHash}) err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash) if err != nil { log.Warnf("Failed to send getheaders message to "+ @@ -682,7 +682,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { sm.headersFirstMode = false sm.headerList.Init() log.Infof("Reached the final checkpoint -- switching to normal mode") - locator := blockchain.BlockLocator([]*chainhash.Hash{blockHash}) + locator := blockdag.BlockLocator([]*chainhash.Hash{blockHash}) err = peer.PushGetBlocksMsg(locator, &zeroHash) if err != nil { log.Warnf("Failed to send getblocks message to peer %s: %v", @@ -837,7 +837,7 @@ func (sm *SyncManager) handleHeadersMsg(hmsg *headersMsg) { // This header is not a checkpoint, so request the next batch of // headers starting from the latest known header and ending with the // next checkpoint. - locator := blockchain.BlockLocator([]*chainhash.Hash{finalHash}) + locator := blockdag.BlockLocator([]*chainhash.Hash{finalHash}) err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash) if err != nil { log.Warnf("Failed to send getheaders message to "+ @@ -1165,11 +1165,11 @@ out: // handleBlockchainNotification handles notifications from blockchain. It does // things such as request orphan block parents and relay accepted blocks to // connected peers. -func (sm *SyncManager) handleBlockchainNotification(notification *blockchain.Notification) { +func (sm *SyncManager) handleBlockchainNotification(notification *blockdag.Notification) { switch notification.Type { // A block has been accepted into the block chain. Relay it to other // peers. - case blockchain.NTBlockAccepted: + case blockdag.NTBlockAccepted: // Don't relay if we are not current. Other peers that are // current should already know about it. if !sm.current() { @@ -1187,7 +1187,7 @@ func (sm *SyncManager) handleBlockchainNotification(notification *blockchain.Not sm.peerNotifier.RelayInventory(iv, block.MsgBlock().Header) // A block has been connected to the main block chain. - case blockchain.NTBlockConnected: + case blockdag.NTBlockConnected: block, ok := notification.Data.(*btcutil.Block) if !ok { log.Warnf("Chain connected notification is not a block.") @@ -1225,7 +1225,7 @@ func (sm *SyncManager) handleBlockchainNotification(notification *blockchain.Not } // A block has been disconnected from the main block chain. - case blockchain.NTBlockDisconnected: + case blockdag.NTBlockDisconnected: block, ok := notification.Data.(*btcutil.Block) if !ok { log.Warnf("Chain disconnected notification is not a block.") @@ -1356,7 +1356,7 @@ func (sm *SyncManager) SyncPeerID() int32 { // ProcessBlock makes use of ProcessBlock on an internal instance of a block // chain. -func (sm *SyncManager) ProcessBlock(block *btcutil.Block, flags blockchain.BehaviorFlags) (bool, error) { +func (sm *SyncManager) ProcessBlock(block *btcutil.Block, flags blockdag.BehaviorFlags) (bool, error) { reply := make(chan processBlockResponse, 1) sm.msgChan <- processBlockMsg{block: block, flags: flags, reply: reply} response := <-reply diff --git a/peer/peer.go b/peer/peer.go index a9e059330..524bd7b7e 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -18,7 +18,7 @@ import ( "time" "github.com/btcsuite/go-socks/socks" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/wire" @@ -904,7 +904,7 @@ func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, er // and stop hash. It will ignore back-to-back duplicate requests. // // This function is safe for concurrent access. -func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error { +func (p *Peer) PushGetBlocksMsg(locator blockdag.BlockLocator, stopHash *chainhash.Hash) error { // Extract the begin hash from the block locator, if one was specified, // to use for filtering duplicate getblocks requests. var beginHash *chainhash.Hash @@ -948,7 +948,7 @@ func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chain // and stop hash. It will ignore back-to-back duplicate requests. // // This function is safe for concurrent access. -func (p *Peer) PushGetHeadersMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error { +func (p *Peer) PushGetHeadersMsg(locator blockdag.BlockLocator, stopHash *chainhash.Hash) error { // Extract the begin hash from the block locator, if one was specified, // to use for filtering duplicate getheaders requests. var beginHash *chainhash.Hash diff --git a/rpcadapters.go b/rpcadapters.go index b7ae5e2ea..d613c8d2d 100644 --- a/rpcadapters.go +++ b/rpcadapters.go @@ -7,7 +7,7 @@ package main import ( "sync/atomic" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/mempool" "github.com/daglabs/btcd/netsync" @@ -247,7 +247,7 @@ func (b *rpcSyncMgr) IsCurrent() bool { // // This function is safe for concurrent access and is part of the // rpcserverSyncManager interface implementation. -func (b *rpcSyncMgr) SubmitBlock(block *btcutil.Block, flags blockchain.BehaviorFlags) (bool, error) { +func (b *rpcSyncMgr) SubmitBlock(block *btcutil.Block, flags blockdag.BehaviorFlags) (bool, error) { return b.syncMgr.ProcessBlock(block, flags) } diff --git a/rpcserver.go b/rpcserver.go index 79762684c..1195cb3ae 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -28,8 +28,8 @@ import ( "time" "github.com/btcsuite/websocket" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/chaincfg" @@ -334,12 +334,12 @@ type gbtWorkState struct { minTimestamp time.Time template *mining.BlockTemplate notifyMap map[chainhash.Hash]map[int64]chan struct{} - timeSource blockchain.MedianTimeSource + timeSource blockdag.MedianTimeSource } // newGbtWorkState returns a new instance of a gbtWorkState with all internal // fields initialized and ready to use. -func newGbtWorkState(timeSource blockchain.MedianTimeSource) *gbtWorkState { +func newGbtWorkState(timeSource blockdag.MedianTimeSource) *gbtWorkState { return &gbtWorkState{ notifyMap: make(map[chainhash.Hash]map[int64]chan struct{}), timeSource: timeSource, @@ -639,7 +639,7 @@ func handleDebugLevel(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) func createVinList(mtx *wire.MsgTx) []btcjson.Vin { // Coinbase transactions only have a single txin by definition. vinList := make([]btcjson.Vin, len(mtx.TxIn)) - if blockchain.IsCoinBaseTx(mtx) { + if blockdag.IsCoinBaseTx(mtx) { txIn := mtx.TxIn[0] vinList[0].Coinbase = hex.EncodeToString(txIn.SignatureScript) vinList[0].Sequence = txIn.Sequence @@ -1023,8 +1023,8 @@ func getDifficultyRatio(bits uint32, params *chaincfg.Params) float64 { // converted back to a number. Note this is not the same as the proof of // work limit directly because the block difficulty is encoded in a block // with the compact form which loses precision. - max := blockchain.CompactToBig(params.PowLimitBits) - target := blockchain.CompactToBig(bits) + max := blockdag.CompactToBig(params.PowLimitBits) + target := blockdag.CompactToBig(bits) difficulty := new(big.Rat).SetFrac(max, target) outString := difficulty.FloatString(8) @@ -1139,17 +1139,17 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i // softForkStatus converts a ThresholdState state into a human readable string // corresponding to the particular state. -func softForkStatus(state blockchain.ThresholdState) (string, error) { +func softForkStatus(state blockdag.ThresholdState) (string, error) { switch state { - case blockchain.ThresholdDefined: + case blockdag.ThresholdDefined: return "defined", nil - case blockchain.ThresholdStarted: + case blockdag.ThresholdStarted: return "started", nil - case blockchain.ThresholdLockedIn: + case blockdag.ThresholdLockedIn: return "lockedin", nil - case blockchain.ThresholdActive: + case blockdag.ThresholdActive: return "active", nil - case blockchain.ThresholdFailed: + case blockdag.ThresholdFailed: return "failed", nil default: return "", fmt.Errorf("unknown deployment state: %v", state) @@ -1550,7 +1550,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo template = blkTemplate msgBlock = template.Block targetDifficulty = fmt.Sprintf("%064x", - blockchain.CompactToBig(msgBlock.Header.Bits)) + blockdag.CompactToBig(msgBlock.Header.Bits)) // Get the minimum allowed timestamp for the block based on the // median timestamp of the last several blocks per the chain @@ -1603,14 +1603,14 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo // Update the merkle root. block := btcutil.NewBlock(template.Block) - merkles := blockchain.BuildMerkleTreeStore(block.Transactions()) + merkles := blockdag.BuildMerkleTreeStore(block.Transactions()) template.Block.Header.MerkleRoot = *merkles[len(merkles)-1] } // Set locals for convenience. msgBlock = template.Block targetDifficulty = fmt.Sprintf("%064x", - blockchain.CompactToBig(msgBlock.Header.Bits)) + blockdag.CompactToBig(msgBlock.Header.Bits)) // Update the time of the block template to the current time // while accounting for the median time of the past several @@ -1640,7 +1640,7 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld msgBlock := template.Block header := &msgBlock.Header adjustedTime := state.timeSource.AdjustedTime() - maxTime := adjustedTime.Add(time.Second * blockchain.MaxTimeOffsetSeconds) + maxTime := adjustedTime.Add(time.Second * blockdag.MaxTimeOffsetSeconds) if header.Timestamp.After(maxTime) { return nil, &btcjson.RPCError{ Code: btcjson.ErrRPCOutOfRange, @@ -1704,14 +1704,14 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld // implied by the included or omission of fields: // Including MinTime -> time/decrement // Omitting CoinbaseTxn -> coinbase, generation - targetDifficulty := fmt.Sprintf("%064x", blockchain.CompactToBig(header.Bits)) + targetDifficulty := fmt.Sprintf("%064x", blockdag.CompactToBig(header.Bits)) templateID := encodeTemplateID(state.prevHash, state.lastGenerated) reply := btcjson.GetBlockTemplateResult{ Bits: strconv.FormatInt(int64(header.Bits), 16), CurTime: header.Timestamp.Unix(), Height: int64(template.Height), PreviousHash: header.PrevBlock.String(), - SigOpLimit: blockchain.MaxSigOpsPerBlock, + SigOpLimit: blockdag.MaxSigOpsPerBlock, SizeLimit: wire.MaxBlockPayload, Transactions: transactions, Version: header.Version, @@ -1951,89 +1951,89 @@ func handleGetBlockTemplateRequest(s *rpcServer, request *btcjson.TemplateReques func chainErrToGBTErrString(err error) string { // When the passed error is not a RuleError, just return a generic // rejected string with the error text. - ruleErr, ok := err.(blockchain.RuleError) + ruleErr, ok := err.(blockdag.RuleError) if !ok { return "rejected: " + err.Error() } switch ruleErr.ErrorCode { - case blockchain.ErrDuplicateBlock: + case blockdag.ErrDuplicateBlock: return "duplicate" - case blockchain.ErrBlockTooBig: + case blockdag.ErrBlockTooBig: return "bad-blk-length" - case blockchain.ErrBlockVersionTooOld: + case blockdag.ErrBlockVersionTooOld: return "bad-version" - case blockchain.ErrInvalidTime: + case blockdag.ErrInvalidTime: return "bad-time" - case blockchain.ErrTimeTooOld: + case blockdag.ErrTimeTooOld: return "time-too-old" - case blockchain.ErrTimeTooNew: + case blockdag.ErrTimeTooNew: return "time-too-new" - case blockchain.ErrDifficultyTooLow: + case blockdag.ErrDifficultyTooLow: return "bad-diffbits" - case blockchain.ErrUnexpectedDifficulty: + case blockdag.ErrUnexpectedDifficulty: return "bad-diffbits" - case blockchain.ErrHighHash: + case blockdag.ErrHighHash: return "high-hash" - case blockchain.ErrBadMerkleRoot: + case blockdag.ErrBadMerkleRoot: return "bad-txnmrklroot" - case blockchain.ErrBadCheckpoint: + case blockdag.ErrBadCheckpoint: return "bad-checkpoint" - case blockchain.ErrForkTooOld: + case blockdag.ErrForkTooOld: return "fork-too-old" - case blockchain.ErrCheckpointTimeTooOld: + case blockdag.ErrCheckpointTimeTooOld: return "checkpoint-time-too-old" - case blockchain.ErrNoTransactions: + case blockdag.ErrNoTransactions: return "bad-txns-none" - case blockchain.ErrNoTxInputs: + case blockdag.ErrNoTxInputs: return "bad-txns-noinputs" - case blockchain.ErrNoTxOutputs: + case blockdag.ErrNoTxOutputs: return "bad-txns-nooutputs" - case blockchain.ErrTxTooBig: + case blockdag.ErrTxTooBig: return "bad-txns-size" - case blockchain.ErrBadTxOutValue: + case blockdag.ErrBadTxOutValue: return "bad-txns-outputvalue" - case blockchain.ErrDuplicateTxInputs: + case blockdag.ErrDuplicateTxInputs: return "bad-txns-dupinputs" - case blockchain.ErrBadTxInput: + case blockdag.ErrBadTxInput: return "bad-txns-badinput" - case blockchain.ErrMissingTxOut: + case blockdag.ErrMissingTxOut: return "bad-txns-missinginput" - case blockchain.ErrUnfinalizedTx: + case blockdag.ErrUnfinalizedTx: return "bad-txns-unfinalizedtx" - case blockchain.ErrDuplicateTx: + case blockdag.ErrDuplicateTx: return "bad-txns-duplicate" - case blockchain.ErrOverwriteTx: + case blockdag.ErrOverwriteTx: return "bad-txns-overwrite" - case blockchain.ErrImmatureSpend: + case blockdag.ErrImmatureSpend: return "bad-txns-maturity" - case blockchain.ErrSpendTooHigh: + case blockdag.ErrSpendTooHigh: return "bad-txns-highspend" - case blockchain.ErrBadFees: + case blockdag.ErrBadFees: return "bad-txns-fees" - case blockchain.ErrTooManySigOps: + case blockdag.ErrTooManySigOps: return "high-sigops" - case blockchain.ErrFirstTxNotCoinbase: + case blockdag.ErrFirstTxNotCoinbase: return "bad-txns-nocoinbase" - case blockchain.ErrMultipleCoinbases: + case blockdag.ErrMultipleCoinbases: return "bad-txns-multicoinbase" - case blockchain.ErrBadCoinbaseScriptLen: + case blockdag.ErrBadCoinbaseScriptLen: return "bad-cb-length" - case blockchain.ErrBadCoinbaseValue: + case blockdag.ErrBadCoinbaseValue: return "bad-cb-value" - case blockchain.ErrMissingCoinbaseHeight: + case blockdag.ErrMissingCoinbaseHeight: return "bad-cb-height" - case blockchain.ErrBadCoinbaseHeight: + case blockdag.ErrBadCoinbaseHeight: return "bad-cb-height" - case blockchain.ErrScriptMalformed: + case blockdag.ErrScriptMalformed: return "bad-script-malformed" - case blockchain.ErrScriptValidation: + case blockdag.ErrScriptValidation: return "bad-script-validate" - case blockchain.ErrPreviousBlockUnknown: + case blockdag.ErrPreviousBlockUnknown: return "prev-blk-not-found" - case blockchain.ErrInvalidAncestorBlock: + case blockdag.ErrInvalidAncestorBlock: return "bad-prevblk" - case blockchain.ErrPrevBlockNotBest: + case blockdag.ErrPrevBlockNotBest: return "inconclusive-not-best-prvblk" } @@ -2084,7 +2084,7 @@ func handleGetBlockTemplateProposal(s *rpcServer, request *btcjson.TemplateReque } if err := s.cfg.Chain.CheckConnectBlockTemplate(block); err != nil { - if _, ok := err.(blockchain.RuleError); !ok { + if _, ok := err.(blockdag.RuleError); !ok { errStr := fmt.Sprintf("Failed to process block proposal: %v", err) rpcsLog.Error(errStr) return nil, &btcjson.RPCError{ @@ -2407,7 +2407,7 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru minTimestamp = header.Timestamp maxTimestamp = minTimestamp } else { - totalWork.Add(totalWork, blockchain.CalcWork(header.Bits)) + totalWork.Add(totalWork, blockdag.CalcWork(header.Bits)) if minTimestamp.After(header.Timestamp) { minTimestamp = header.Timestamp @@ -2658,7 +2658,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i confirmations = 0 value = txOut.Value pkScript = txOut.PkScript - isCoinbase = blockchain.IsCoinBaseTx(mtx) + isCoinbase = blockdag.IsCoinBaseTx(mtx) } else { out := wire.OutPoint{Hash: *txHash, Index: c.Vout} entry, err := s.cfg.Chain.FetchUtxoEntry(out) @@ -2849,7 +2849,7 @@ func fetchInputTxos(s *rpcServer, tx *wire.MsgTx) (map[wire.OutPoint]wire.TxOut, // passed transaction. func createVinListPrevOut(s *rpcServer, mtx *wire.MsgTx, chainParams *chaincfg.Params, vinExtra bool, filterAddrMap map[string]struct{}) ([]btcjson.VinPrevOut, error) { // Coinbase transactions only have a single txin by definition. - if blockchain.IsCoinBaseTx(mtx) { + if blockdag.IsCoinBaseTx(mtx) { // Only include the transaction if the filter map is empty // because a coinbase input has no addresses and so would never // match a non-empty filter. @@ -3393,7 +3393,7 @@ func handleSubmitBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) // Process this block using the same rules as blocks coming from other // nodes. This will in turn relay it to the network like normal. - _, err = s.cfg.SyncMgr.SubmitBlock(block, blockchain.BFNone) + _, err = s.cfg.SyncMgr.SubmitBlock(block, blockdag.BFNone) if err != nil { return fmt.Sprintf("rejected: %s", err.Error()), nil } @@ -3444,7 +3444,7 @@ func verifyChain(s *rpcServer, level, depth int32) error { // Level 1 does basic chain sanity checks. if level > 0 { - err := blockchain.CheckBlockSanity(block, + err := blockdag.CheckBlockSanity(block, s.cfg.ChainParams.PowLimit, s.cfg.TimeSource) if err != nil { rpcsLog.Errorf("Verify is unable to validate "+ @@ -4158,7 +4158,7 @@ type rpcserverSyncManager interface { // SubmitBlock submits the provided block to the network after // processing it locally. - SubmitBlock(block *btcutil.Block, flags blockchain.BehaviorFlags) (bool, error) + SubmitBlock(block *btcutil.Block, flags blockdag.BehaviorFlags) (bool, error) // Pause pauses the sync manager until the returned channel is closed. Pause() chan<- struct{} @@ -4197,8 +4197,8 @@ type rpcserverConfig struct { // These fields allow the RPC server to interface with the local block // chain data and state. - TimeSource blockchain.MedianTimeSource - Chain *blockchain.BlockChain + TimeSource blockdag.MedianTimeSource + Chain *blockdag.BlockChain ChainParams *chaincfg.Params DB database.DB @@ -4252,9 +4252,9 @@ func newRPCServer(config *rpcserverConfig) (*rpcServer, error) { // Callback for notifications from blockchain. It notifies clients that are // long polling for changes or subscribed to websockets notifications. -func (s *rpcServer) handleBlockchainNotification(notification *blockchain.Notification) { +func (s *rpcServer) handleBlockchainNotification(notification *blockdag.Notification) { switch notification.Type { - case blockchain.NTBlockAccepted: + case blockdag.NTBlockAccepted: block, ok := notification.Data.(*btcutil.Block) if !ok { rpcsLog.Warnf("Chain accepted notification is not a block.") @@ -4266,7 +4266,7 @@ func (s *rpcServer) handleBlockchainNotification(notification *blockchain.Notifi // their old block template to become stale. s.gbtWorkState.NotifyBlockConnected(block.Hash()) - case blockchain.NTBlockConnected: + case blockdag.NTBlockConnected: block, ok := notification.Data.(*btcutil.Block) if !ok { rpcsLog.Warnf("Chain connected notification is not a block.") @@ -4276,7 +4276,7 @@ func (s *rpcServer) handleBlockchainNotification(notification *blockchain.Notifi // Notify registered websocket clients of incoming block. s.ntfnMgr.NotifyBlockConnected(block) - case blockchain.NTBlockDisconnected: + case blockdag.NTBlockDisconnected: block, ok := notification.Data.(*btcutil.Block) if !ok { rpcsLog.Warnf("Chain disconnected notification is not a block.") diff --git a/rpcwebsocket.go b/rpcwebsocket.go index 9eba21665..3aa2164dd 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -22,7 +22,7 @@ import ( "golang.org/x/crypto/ripemd160" - "github.com/daglabs/btcd/blockchain" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -2156,7 +2156,7 @@ func rescanBlockFilter(filter *wsClientFilter, block *btcutil.Block, params *cha added := false // Scan inputs if not a coinbase transaction. - if !blockchain.IsCoinBaseTx(msgTx) { + if !blockdag.IsCoinBaseTx(msgTx) { for _, input := range msgTx.TxIn { if !filter.existsUnspentOutPoint(&input.PreviousOutPoint) { continue @@ -2274,7 +2274,7 @@ func handleRescanBlocks(wsc *wsClient, icmd interface{}) (interface{}, error) { // verifies that the new range of blocks is on the same fork as a previous // range of blocks. If this condition does not hold true, the JSON-RPC error // for an unrecoverable reorganize is returned. -func recoverFromReorg(chain *blockchain.BlockChain, minBlock, maxBlock int32, +func recoverFromReorg(chain *blockdag.BlockChain, minBlock, maxBlock int32, lastBlock *chainhash.Hash) ([]chainhash.Hash, error) { hashList, err := chain.HeightRange(minBlock, maxBlock) diff --git a/server.go b/server.go index 9af8518bc..1648f12c3 100644 --- a/server.go +++ b/server.go @@ -23,8 +23,8 @@ import ( "time" "github.com/daglabs/btcd/addrmgr" - "github.com/daglabs/btcd/blockchain" - "github.com/daglabs/btcd/blockchain/indexers" + "github.com/daglabs/btcd/blockdag" + "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/connmgr" @@ -210,7 +210,7 @@ type server struct { sigCache *txscript.SigCache rpcServer *rpcServer syncManager *netsync.SyncManager - chain *blockchain.BlockChain + chain *blockdag.BlockChain txMemPool *mempool.TxPool cpuMiner *cpuminer.CPUMiner modifyRebroadcastInv chan interface{} @@ -225,7 +225,7 @@ type server struct { quit chan struct{} nat NAT db database.DB - timeSource blockchain.MedianTimeSource + timeSource blockdag.MedianTimeSource services wire.ServiceFlag // The following fields are used for optional indexes. They will be nil @@ -2431,7 +2431,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param peerHeightsUpdate: make(chan updatePeerHeightsMsg), nat: nat, db: db, - timeSource: blockchain.NewMedianTime(), + timeSource: blockdag.NewMedianTime(), services: services, sigCache: txscript.NewSigCache(cfg.SigCacheMaxSize), cfCheckptCaches: make(map[wire.FilterType][]cfHeaderKV), @@ -2470,7 +2470,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param } // Create an index manager if any of the optional indexes are enabled. - var indexManager blockchain.IndexManager + var indexManager blockdag.IndexManager if len(indexes) > 0 { indexManager = indexers.NewManager(db, indexes) } @@ -2483,7 +2483,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param // Create a new block chain instance with the appropriate configuration. var err error - s.chain, err = blockchain.New(&blockchain.Config{ + s.chain, err = blockdag.New(&blockdag.Config{ DB: s.db, Interrupt: interrupt, ChainParams: s.chainParams, @@ -2533,7 +2533,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param FreeTxRelayLimit: cfg.FreeTxRelayLimit, MaxOrphanTxs: cfg.MaxOrphanTxs, MaxOrphanTxSize: defaultMaxOrphanTxSize, - MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, + MaxSigOpsPerTx: blockdag.MaxSigOpsPerBlock / 5, MinRelayTxFee: cfg.minRelayTxFee, MaxTxVersion: 2, }, @@ -2541,7 +2541,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param FetchUtxoView: s.chain.FetchUtxoView, BestHeight: func() int32 { return s.chain.BestSnapshot().Height }, MedianTimePast: func() time.Time { return s.chain.BestSnapshot().MedianTime }, - CalcSequenceLock: func(tx *btcutil.Tx, view *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) { + CalcSequenceLock: func(tx *btcutil.Tx, view *blockdag.UtxoViewpoint) (*blockdag.SequenceLock, error) { return s.chain.CalcSequenceLock(tx, view, true) }, IsDeploymentActive: s.chain.IsDeploymentActive,