Merge remote-tracking branch 'origin/dev-20-primitive-blockdag' into dev-24-primitive-blockdag-wire

This commit is contained in:
Mike Zak 2018-06-19 17:06:12 +03:00
commit f7a80acdd3
87 changed files with 538 additions and 550 deletions

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"testing" "testing"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math/big" "math/big"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"container/list" "container/list"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"reflect" "reflect"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"bytes" "bytes"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"bytes" "bytes"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"sync" "sync"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"compress/bzip2" "compress/bzip2"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcec"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"bytes" "bytes"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math/big" "math/big"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math/big" "math/big"

View File

@ -78,4 +78,4 @@ This package includes spec changes outlined by the following BIPs:
BIP0030 (https://en.bitcoin.it/wiki/BIP_0030) BIP0030 (https://en.bitcoin.it/wiki/BIP_0030)
BIP0034 (https://en.bitcoin.it/wiki/BIP_0034) BIP0034 (https://en.bitcoin.it/wiki/BIP_0034)
*/ */
package blockchain package blockdag

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"testing" "testing"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain_test package blockdag_test
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
_ "github.com/daglabs/btcd/database/ffldb" _ "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 // 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 // values obtained from other peers on the network so the local time is
// adjusted to be in agreement with other peers. // adjusted to be in agreement with other peers.
chain, err := blockchain.New(&blockchain.Config{ chain, err := blockdag.New(&blockdag.Config{
DB: db, DB: db,
ChainParams: &chaincfg.MainNetParams, ChainParams: &chaincfg.MainNetParams,
TimeSource: blockchain.NewMedianTime(), TimeSource: blockdag.NewMedianTime(),
}) })
if err != nil { if err != nil {
fmt.Printf("Failed to create chain instance: %v\n", err) fmt.Printf("Failed to create chain instance: %v\n", err)
@ -60,7 +60,7 @@ func ExampleBlockChain_ProcessBlock() {
// exists. // exists.
genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
isMainChain, isOrphan, err := chain.ProcessBlock(genesisBlock, isMainChain, isOrphan, err := chain.ProcessBlock(genesisBlock,
blockchain.BFNone) blockdag.BFNone)
if err != nil { if err != nil {
fmt.Printf("Failed to process block: %v\n", err) fmt.Printf("Failed to process block: %v\n", err)
return return
@ -78,7 +78,7 @@ func ExampleBlockChain_ProcessBlock() {
func ExampleCompactToBig() { func ExampleCompactToBig() {
// Convert the bits from block 300000 in the main block chain. // Convert the bits from block 300000 in the main block chain.
bits := uint32(419465580) bits := uint32(419465580)
targetDifficulty := blockchain.CompactToBig(bits) targetDifficulty := blockdag.CompactToBig(bits)
// Display it in hex. // Display it in hex.
fmt.Printf("%064x\n", targetDifficulty.Bytes()) fmt.Printf("%064x\n", targetDifficulty.Bytes())
@ -98,7 +98,7 @@ func ExampleBigToCompact() {
fmt.Println("invalid target difficulty") fmt.Println("invalid target difficulty")
return return
} }
bits := blockchain.BigToCompact(targetDifficulty) bits := blockdag.BigToCompact(targetDifficulty)
fmt.Println(bits) fmt.Println(bits)

View File

@ -3,7 +3,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain_test package blockdag_test
import ( import (
"bytes" "bytes"
@ -12,8 +12,8 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/fullblocktests" "github.com/daglabs/btcd/blockdag/fullblocktests"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "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 // 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 // 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. // 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) { if !isSupportedDbType(testDbType) {
return nil, nil, fmt.Errorf("unsupported db type %v", 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 paramsCopy := *params
// Create the main chain instance. // Create the main chain instance.
chain, err := blockchain.New(&blockchain.Config{ chain, err := blockdag.New(&blockdag.Config{
DB: db, DB: db,
ChainParams: &paramsCopy, ChainParams: &paramsCopy,
Checkpoints: nil, Checkpoints: nil,
TimeSource: blockchain.NewMedianTime(), TimeSource: blockdag.NewMedianTime(),
SigCache: txscript.NewSigCache(1000), SigCache: txscript.NewSigCache(1000),
}) })
if err != nil { if err != nil {
@ -157,7 +157,7 @@ func TestFullBlocks(t *testing.T) {
item.Name, block.Hash(), blockHeight) item.Name, block.Hash(), blockHeight)
isMainChain, isOrphan, err := chain.ProcessBlock(block, isMainChain, isOrphan, err := chain.ProcessBlock(block,
blockchain.BFNone) blockdag.BFNone)
if err != nil { if err != nil {
t.Fatalf("block %q (hash %s, height %d) should "+ t.Fatalf("block %q (hash %s, height %d) should "+
"have been accepted: %v", item.Name, "have been accepted: %v", item.Name,
@ -190,7 +190,7 @@ func TestFullBlocks(t *testing.T) {
t.Logf("Testing block %s (hash %s, height %d)", t.Logf("Testing block %s (hash %s, height %d)",
item.Name, block.Hash(), blockHeight) item.Name, block.Hash(), blockHeight)
_, _, err := chain.ProcessBlock(block, blockchain.BFNone) _, _, err := chain.ProcessBlock(block, blockdag.BFNone)
if err == nil { if err == nil {
t.Fatalf("block %q (hash %s, height %d) should not "+ t.Fatalf("block %q (hash %s, height %d) should not "+
"have been accepted", item.Name, block.Hash(), "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 // Ensure the error code is of the expected type and the reject
// code matches the value specified in the test instance. // code matches the value specified in the test instance.
rerr, ok := err.(blockchain.RuleError) rerr, ok := err.(blockdag.RuleError)
if !ok { if !ok {
t.Fatalf("block %q (hash %s, height %d) returned "+ t.Fatalf("block %q (hash %s, height %d) returned "+
"unexpected error type -- got %T, want "+ "unexpected error type -- got %T, want "+
@ -247,10 +247,10 @@ func TestFullBlocks(t *testing.T) {
t.Logf("Testing block %s (hash %s, height %d)", t.Logf("Testing block %s (hash %s, height %d)",
item.Name, block.Hash(), blockHeight) item.Name, block.Hash(), blockHeight)
_, isOrphan, err := chain.ProcessBlock(block, blockchain.BFNone) _, isOrphan, err := chain.ProcessBlock(block, blockdag.BFNone)
if err != nil { if err != nil {
// Ensure the error code is of the expected type. // 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) "+ t.Fatalf("block %q (hash %s, height %d) "+
"returned unexpected error type -- "+ "returned unexpected error type -- "+
"got %T, want blockchain.RuleError", "got %T, want blockchain.RuleError",

View File

@ -18,7 +18,7 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcec"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
@ -86,7 +86,7 @@ type RejectedBlock struct {
Name string Name string
Block *wire.MsgBlock Block *wire.MsgBlock
Height int32 Height int32
RejectCode blockchain.ErrorCode RejectCode blockdag.ErrorCode
} }
// Ensure RejectedBlock implements the TestInstance interface. // Ensure RejectedBlock implements the TestInstance interface.
@ -292,7 +292,7 @@ func (g *testGenerator) createCoinbaseTx(blockHeight int32) *wire.MsgTx {
SignatureScript: coinbaseScript, SignatureScript: coinbaseScript,
}) })
tx.AddTxOut(&wire.TxOut{ tx.AddTxOut(&wire.TxOut{
Value: blockchain.CalcBlockSubsidy(blockHeight, g.params), Value: blockdag.CalcBlockSubsidy(blockHeight, g.params),
PkScript: opTrueScript, PkScript: opTrueScript,
}) })
return tx return tx
@ -309,7 +309,7 @@ func calcMerkleRoot(txns []*wire.MsgTx) chainhash.Hash {
for _, tx := range txns { for _, tx := range txns {
utilTxns = append(utilTxns, btcutil.NewTx(tx)) utilTxns = append(utilTxns, btcutil.NewTx(tx))
} }
merkles := blockchain.BuildMerkleTreeStore(utilTxns) merkles := blockdag.BuildMerkleTreeStore(utilTxns)
return *merkles[len(merkles)-1] 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 // solver accepts a block header and a nonce range to test. It is
// intended to be run as a goroutine. // intended to be run as a goroutine.
targetDifficulty := blockchain.CompactToBig(header.Bits) targetDifficulty := blockdag.CompactToBig(header.Bits)
quit := make(chan bool) quit := make(chan bool)
results := make(chan sbResult) results := make(chan sbResult)
solver := func(hdr wire.BlockHeader, startNonce, stopNonce uint32) { solver := func(hdr wire.BlockHeader, startNonce, stopNonce uint32) {
@ -343,7 +343,7 @@ func solveBlock(header *wire.BlockHeader) bool {
default: default:
hdr.Nonce = i hdr.Nonce = i
hash := hdr.BlockHash() hash := hdr.BlockHash()
if blockchain.HashToBig(&hash).Cmp( if blockdag.HashToBig(&hash).Cmp(
targetDifficulty) <= 0 { targetDifficulty) <= 0 {
results <- sbResult{true, i} results <- sbResult{true, i}
@ -840,7 +840,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
return AcceptedBlock{blockName, block, blockHeight, isMainChain, return AcceptedBlock{blockName, block, blockHeight, isMainChain,
isOrphan} 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] blockHeight := g.blockHeights[blockName]
return RejectedBlock{blockName, block, blockHeight, code} return RejectedBlock{blockName, block, blockHeight, code}
} }
@ -890,7 +890,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
expectTipBlock(tipName, g.blocksByName[tipName]), expectTipBlock(tipName, g.blocksByName[tipName]),
}) })
} }
rejected := func(code blockchain.ErrorCode) { rejected := func(code blockdag.ErrorCode) {
tests = append(tests, []TestInstance{ tests = append(tests, []TestInstance{
rejectBlock(g.tipName, g.tip, code), rejectBlock(g.tipName, g.tip, code),
}) })
@ -997,7 +997,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
acceptedToSideChainWithExpectedTip("b6") acceptedToSideChainWithExpectedTip("b6")
g.nextBlock("b8", outs[4]) g.nextBlock("b8", outs[4])
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Too much proof-of-work coinbase tests. // Too much proof-of-work coinbase tests.
@ -1010,7 +1010,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
// \-> b3(1) -> b4(2) // \-> b3(1) -> b4(2)
g.setTip("b6") g.setTip("b6")
g.nextBlock("b9", outs[4], additionalCoinbase(1)) 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. // 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") acceptedToSideChainWithExpectedTip("b6")
g.nextBlock("b11", outs[4], additionalCoinbase(1)) 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 // Create a fork that ends with block that generates too much coinbase
// as before, but with a valid fork first. // as before, but with a valid fork first.
@ -1038,7 +1038,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
tests = append(tests, []TestInstance{ tests = append(tests, []TestInstance{
acceptBlock("b13", b13, false, true), acceptBlock("b13", b13, false, true),
acceptBlock("b14", b14, false, true), acceptBlock("b14", b14, false, true),
rejectBlock("b12", b12, blockchain.ErrBadCoinbaseValue), rejectBlock("b12", b12, blockdag.ErrBadCoinbaseValue),
expectTipBlock("b13", b13), expectTipBlock("b13", b13),
}) })
@ -1065,7 +1065,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
tooManySigOps := repeatOpcode(txscript.OP_CHECKSIG, maxBlockSigOps+1) tooManySigOps := repeatOpcode(txscript.OP_CHECKSIG, maxBlockSigOps+1)
g.nextBlock("b16", outs[6], replaceSpendScript(tooManySigOps)) g.nextBlock("b16", outs[6], replaceSpendScript(tooManySigOps))
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Cross-fork spend tests. // Cross-fork spend tests.
@ -1078,7 +1078,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
// \-> b3(1) -> b4(2) // \-> b3(1) -> b4(2)
g.setTip("b15") g.setTip("b15")
g.nextBlock("b17", &b3Tx1Out) g.nextBlock("b17", &b3Tx1Out)
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// Create block that forks and spends a tx created on a third fork. // 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") acceptedToSideChainWithExpectedTip("b15")
g.nextBlock("b19", outs[6]) g.nextBlock("b19", outs[6])
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Immature coinbase tests. // Immature coinbase tests.
@ -1102,7 +1102,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
// \-> b20(7) // \-> b20(7)
g.setTip("b15") g.setTip("b15")
g.nextBlock("b20", outs[7]) g.nextBlock("b20", outs[7])
rejected(blockchain.ErrImmatureSpend) rejected(blockdag.ErrImmatureSpend)
// Create block that spends immature coinbase on a fork. // Create block that spends immature coinbase on a fork.
// //
@ -1113,7 +1113,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
acceptedToSideChainWithExpectedTip("b15") acceptedToSideChainWithExpectedTip("b15")
g.nextBlock("b22", outs[7]) g.nextBlock("b22", outs[7])
rejected(blockchain.ErrImmatureSpend) rejected(blockdag.ErrImmatureSpend)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Max block size tests. // Max block size tests.
@ -1143,7 +1143,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
replaceSpendScript(sizePadScript)(b) replaceSpendScript(sizePadScript)(b)
}) })
g.assertTipBlockSize(maxBlockSize + 1) g.assertTipBlockSize(maxBlockSize + 1)
rejected(blockchain.ErrBlockTooBig) rejected(blockdag.ErrBlockTooBig)
// Parent was rejected, so this block must either be an orphan or // Parent was rejected, so this block must either be an orphan or
// outright rejected due to an invalid parent. // outright rejected due to an invalid parent.
@ -1163,7 +1163,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
g.setTip("b15") g.setTip("b15")
tooSmallCbScript := repeatOpcode(0x00, minCoinbaseScriptLen-1) tooSmallCbScript := repeatOpcode(0x00, minCoinbaseScriptLen-1)
g.nextBlock("b26", outs[6], replaceCoinbaseSigScript(tooSmallCbScript)) 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 // Parent was rejected, so this block must either be an orphan or
// outright rejected due to an invalid parent. // outright rejected due to an invalid parent.
@ -1179,7 +1179,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
g.setTip("b15") g.setTip("b15")
tooLargeCbScript := repeatOpcode(0x00, maxCoinbaseScriptLen+1) tooLargeCbScript := repeatOpcode(0x00, maxCoinbaseScriptLen+1)
g.nextBlock("b28", outs[6], replaceCoinbaseSigScript(tooLargeCbScript)) 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 // Parent was rejected, so this block must either be an orphan or
// outright rejected due to an invalid parent. // 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) tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG)
g.nextBlock("b32", outs[9], replaceSpendScript(tooManySigOps)) g.nextBlock("b32", outs[9], replaceSpendScript(tooManySigOps))
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// Create block with max signature operations as OP_CHECKMULTISIGVERIFY. // 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) tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG)
g.nextBlock("b34", outs[10], replaceSpendScript(tooManySigOps)) g.nextBlock("b34", outs[10], replaceSpendScript(tooManySigOps))
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// Create block with max signature operations as OP_CHECKSIGVERIFY. // 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) tooManySigOps = repeatOpcode(txscript.OP_CHECKSIGVERIFY, maxBlockSigOps+1)
g.nextBlock("b36", outs[11], replaceSpendScript(tooManySigOps)) g.nextBlock("b36", outs[11], replaceSpendScript(tooManySigOps))
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Spending of tx outputs in block that failed to connect tests. // 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) doubleSpendTx := createSpendTx(outs[11], lowFee)
g.nextBlock("b37", outs[11], additionalTx(doubleSpendTx)) g.nextBlock("b37", outs[11], additionalTx(doubleSpendTx))
b37Tx1Out := makeSpendableOut(g.tip, 1, 0) b37Tx1Out := makeSpendableOut(g.tip, 1, 0)
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
g.setTip("b35") g.setTip("b35")
g.nextBlock("b38", &b37Tx1Out) g.nextBlock("b38", &b37Tx1Out)
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Pay-to-script-hash signature operation count tests. // 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) tx.TxOut[0].PkScript = repeatOpcode(txscript.OP_CHECKSIG, fill)
b.AddTransaction(tx) b.AddTransaction(tx)
}) })
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// Create a block with the max allowed signature operations where the // Create a block with the max allowed signature operations where the
// majority of them are in pay-to-script-hash scripts. // 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) nonCoinbaseTx := createSpendTx(outs[14], lowFee)
b.Transactions[0] = nonCoinbaseTx b.Transactions[0] = nonCoinbaseTx
}) })
rejected(blockchain.ErrFirstTxNotCoinbase) rejected(blockdag.ErrFirstTxNotCoinbase)
// Create block with no transactions. // 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) { g.nextBlock("b45", nil, func(b *wire.MsgBlock) {
b.Transactions = nil b.Transactions = nil
}) })
rejected(blockchain.ErrNoTransactions) rejected(blockdag.ErrNoTransactions)
// Create block with invalid proof of work. // 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. // a uint256 is higher than the limit.
b46.Header.Nonce++ b46.Header.Nonce++
blockHash := b46.BlockHash() blockHash := b46.BlockHash()
hashNum := blockchain.HashToBig(&blockHash) hashNum := blockdag.HashToBig(&blockHash)
if hashNum.Cmp(g.params.PowLimit) >= 0 { if hashNum.Cmp(g.params.PowLimit) >= 0 {
break break
} }
} }
g.updateBlockState("b46", origHash, "b46", b46) g.updateBlockState("b46", origHash, "b46", b46)
} }
rejected(blockchain.ErrHighHash) rejected(blockdag.ErrHighHash)
// Create block with a timestamp too far in the future. // 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) nowPlus3Hours := time.Now().Add(time.Hour * 3)
b.Header.Timestamp = time.Unix(nowPlus3Hours.Unix(), 0) b.Header.Timestamp = time.Unix(nowPlus3Hours.Unix(), 0)
}) })
rejected(blockchain.ErrTimeTooNew) rejected(blockdag.ErrTimeTooNew)
// Create block with an invalid merkle root. // 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) { g.nextBlock("b48", outs[14], func(b *wire.MsgBlock) {
b.Header.MerkleRoot = chainhash.Hash{} b.Header.MerkleRoot = chainhash.Hash{}
}) })
rejected(blockchain.ErrBadMerkleRoot) rejected(blockdag.ErrBadMerkleRoot)
// Create block with an invalid proof-of-work limit. // 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) { g.nextBlock("b49", outs[14], func(b *wire.MsgBlock) {
b.Header.Bits-- b.Header.Bits--
}) })
rejected(blockchain.ErrUnexpectedDifficulty) rejected(blockdag.ErrUnexpectedDifficulty)
// Create block with an invalid negative proof-of-work limit. // 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. b49a.Header.Bits = 0x01810000 // -1 in compact form.
g.updateBlockState("b49a", origHash, "b49a", b49a) g.updateBlockState("b49a", origHash, "b49a", b49a)
} }
rejected(blockchain.ErrUnexpectedDifficulty) rejected(blockdag.ErrUnexpectedDifficulty)
// Create block with two coinbase transactions. // Create block with two coinbase transactions.
// //
@ -1509,7 +1509,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
g.setTip("b43") g.setTip("b43")
coinbaseTx := g.createCoinbaseTx(g.tipHeight + 1) coinbaseTx := g.createCoinbaseTx(g.tipHeight + 1)
g.nextBlock("b50", outs[14], additionalTx(coinbaseTx)) g.nextBlock("b50", outs[14], additionalTx(coinbaseTx))
rejected(blockchain.ErrMultipleCoinbases) rejected(blockdag.ErrMultipleCoinbases)
// Create block with duplicate transactions. // Create block with duplicate transactions.
// //
@ -1523,7 +1523,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
b.AddTransaction(b.Transactions[1]) b.AddTransaction(b.Transactions[1])
}) })
g.assertTipBlockNumTxns(3) g.assertTipBlockNumTxns(3)
rejected(blockchain.ErrDuplicateTx) rejected(blockdag.ErrDuplicateTx)
// Create a block that spends a transaction that does not exist. // 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.Hash = *hash
b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 0 b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 0
}) })
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Block header median time tests. // Block header median time tests.
@ -1561,7 +1561,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
} }
b.Header.Timestamp = medianBlock.Header.Timestamp 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 // Create a block with a timestamp that is one second after the median
// time. The block must be accepted. // time. The block must be accepted.
@ -1632,7 +1632,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
g.assertTipBlockNumTxns(4) g.assertTipBlockNumTxns(4)
g.assertTipBlockHash(b57.BlockHash()) g.assertTipBlockHash(b57.BlockHash())
g.assertTipBlockMerkleRoot(b57.Header.MerkleRoot) g.assertTipBlockMerkleRoot(b57.Header.MerkleRoot)
rejected(blockchain.ErrDuplicateTx) rejected(blockdag.ErrDuplicateTx)
// Since the two blocks have the same hash and the generator state now // Since the two blocks have the same hash and the generator state now
// has b56 associated with the hash, manually remove b56, replace it // 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]) b.AddTransaction(b.Transactions[3])
}) })
g.assertTipBlockNumTxns(8) g.assertTipBlockNumTxns(8)
rejected(blockchain.ErrDuplicateTx) rejected(blockdag.ErrDuplicateTx)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Invalid transaction type tests. // 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) { g.nextBlock("b58", outs[17], func(b *wire.MsgBlock) {
b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 42 b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 42
}) })
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// Create block with transaction that pays more than its inputs. // 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) { g.nextBlock("b59", outs[17], func(b *wire.MsgBlock) {
b.Transactions[1].TxOut[0].Value = int64(outs[17].amount) + 1 b.Transactions[1].TxOut[0].Value = int64(outs[17].amount) + 1
}) })
rejected(blockchain.ErrSpendTooHigh) rejected(blockdag.ErrSpendTooHigh)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// BIP0030 tests. // BIP0030 tests.
@ -1722,7 +1722,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
parent := g.blocks[b.Header.PrevBlock] parent := g.blocks[b.Header.PrevBlock]
b.Transactions[0] = parent.Transactions[0] b.Transactions[0] = parent.Transactions[0]
}) })
rejected(blockchain.ErrOverwriteTx) rejected(blockdag.ErrOverwriteTx)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Blocks with non-final transaction tests. // 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].LockTime = 0xffffffff
b.Transactions[1].TxIn[0].Sequence = 0 b.Transactions[1].TxIn[0].Sequence = 0
}) })
rejected(blockchain.ErrUnfinalizedTx) rejected(blockdag.ErrUnfinalizedTx)
// Create block that contains a non-final coinbase transaction. // 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].LockTime = 0xffffffff
b.Transactions[0].TxIn[0].Sequence = 0 b.Transactions[0].TxIn[0].Sequence = 0
}) })
rejected(blockchain.ErrUnfinalizedTx) rejected(blockdag.ErrUnfinalizedTx)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Non-canonical variable-length integer tests. // Non-canonical variable-length integer tests.
@ -1816,7 +1816,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
b.AddTransaction(tx3) b.AddTransaction(tx3)
b.AddTransaction(tx2) b.AddTransaction(tx2)
}) })
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// Create block that double spends a transaction created in the same // Create block that double spends a transaction created in the same
// block. // block.
@ -1831,7 +1831,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
b.AddTransaction(tx3) b.AddTransaction(tx3)
b.AddTransaction(tx4) b.AddTransaction(tx4)
}) })
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Extra subsidy tests. // Extra subsidy tests.
@ -1844,7 +1844,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
// \-> b68(20) // \-> b68(20)
g.setTip("b65") g.setTip("b65")
g.nextBlock("b68", outs[20], additionalCoinbase(10), additionalSpendFee(9)) 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 // Create block that pays 10 extra to the coinbase and a tx that pays
// the extra 10 fee. // the extra 10 fee.
@ -1892,7 +1892,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
maxScriptElementSize+1) maxScriptElementSize+1)
g.nextBlock("b70", outs[21], replaceSpendScript(tooManySigOps)) g.nextBlock("b70", outs[21], replaceSpendScript(tooManySigOps))
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// Create block with more than max allowed signature operations such // Create block with more than max allowed signature operations such
// that the signature operation that pushes it over the limit is before // 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) binary.LittleEndian.PutUint32(tooManySigOps[maxBlockSigOps+2:], 0xffffffff)
g.nextBlock("b71", outs[21], replaceSpendScript(tooManySigOps)) g.nextBlock("b71", outs[21], replaceSpendScript(tooManySigOps))
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1) g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps) rejected(blockdag.ErrTooManySigOps)
// Create block with the max allowed signature operations such that all // Create block with the max allowed signature operations such that all
// counted signature operations are before an invalid push data that // 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. // to effective negate that behavior.
b75OpReturnOut.amount++ b75OpReturnOut.amount++
g.nextBlock("b80", &b75OpReturnOut) g.nextBlock("b80", &b75OpReturnOut)
rejected(blockchain.ErrMissingTxOut) rejected(blockdag.ErrMissingTxOut)
// Create a block that has a transaction with multiple OP_RETURNs. Even // Create a block that has a transaction with multiple OP_RETURNs. Even
// though it's not considered a standard transaction, it is still valid // though it's not considered a standard transaction, it is still valid

View File

@ -9,7 +9,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "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 // 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 // in the passed block and maps each of them to the associated transaction using
// the passed map. // 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() { for txIdx, tx := range block.Transactions() {
// Coinbases do not reference any inputs. Since the block is // Coinbases do not reference any inputs. Since the block is
// required to have already gone through full validation, it has // 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. // the transactions in the block involve.
// //
// This is part of the Indexer interface. // 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 // The offset and length of the transactions within the serialized
// block. // block.
txLocs, err := block.TxLoc() 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. // each transaction in the block involve.
// //
// This is part of the Indexer interface. // 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. // Build all of the address to transaction mappings in a local map.
addrsToTxns := make(writeIndexData) addrsToTxns := make(writeIndexData)
idx.indexBlock(addrsToTxns, block, view) idx.indexBlock(addrsToTxns, block, view)
@ -833,7 +833,7 @@ func (idx *AddrIndex) indexUnconfirmedAddresses(pkScript []byte, tx *btcutil.Tx)
// addresses not being indexed. // addresses not being indexed.
// //
// This function is safe for concurrent access. // 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. // Index addresses of all referenced previous transaction outputs.
// //
// The existence checks are elided since this is only called after the // The existence checks are elided since this is only called after the

View File

@ -7,7 +7,7 @@ package indexers
import ( import (
"errors" "errors"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "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 // connected to the main chain. This indexer adds a hash-to-cf mapping for
// every passed block. This is part of the Indexer interface. // every passed block. This is part of the Indexer interface.
func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block,
view *blockchain.UtxoViewpoint) error { view *blockdag.UtxoViewpoint) error {
f, err := builder.BuildBasicFilter(block.MsgBlock()) f, err := builder.BuildBasicFilter(block.MsgBlock())
if err != nil { 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 // disconnected from the main chain. This indexer removes the hash-to-cf
// mapping for every passed block. This is part of the Indexer interface. // mapping for every passed block. This is part of the Indexer interface.
func (idx *CfIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, func (idx *CfIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block,
view *blockchain.UtxoViewpoint) error { view *blockdag.UtxoViewpoint) error {
for _, key := range cfIndexKeys { for _, key := range cfIndexKeys {
err := dbDeleteFilterIdxEntry(dbTx, key, block.Hash()) err := dbDeleteFilterIdxEntry(dbTx, key, block.Hash())

View File

@ -11,7 +11,7 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcutil" "github.com/daglabs/btcutil"
) )
@ -52,11 +52,11 @@ type Indexer interface {
// ConnectBlock is invoked when the index manager is notified that a new // ConnectBlock is invoked when the index manager is notified that a new
// block has been connected to the main chain. // 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 // DisconnectBlock is invoked when the index manager is notified that a
// block has been disconnected from the main chain. // 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 // AssertError identifies an error that indicates an internal code consistency

View File

@ -8,7 +8,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/wire" "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 // 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 // accordingly. An error will be returned if the current tip for the indexer is
// not the previous block for the passed block. // 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 // Assert that the block being connected properly connects to the
// current tip of the index. // current tip of the index.
idxKey := indexer.Key() 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 // 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 // accordingly. An error will be returned if the current tip for the indexer is
// not the passed block. // 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 // Assert that the block being disconnected is the current tip of the
// index. // index.
idxKey := indexer.Key() idxKey := indexer.Key()
@ -131,7 +131,7 @@ type Manager struct {
} }
// Ensure the Manager type implements the blockchain.IndexManager interface. // 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 // indexDropKey returns the key for an index which indicates it is in the
// process of being dropped. // process of being dropped.
@ -229,7 +229,7 @@ func (m *Manager) maybeCreateIndexes(dbTx database.Tx) error {
// catch up due to the I/O contention. // catch up due to the I/O contention.
// //
// This is part of the blockchain.IndexManager interface. // 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. // Nothing to do when no indexes are enabled.
if len(m.enabledIndexes) == 0 { if len(m.enabledIndexes) == 0 {
return nil return nil
@ -313,7 +313,7 @@ func (m *Manager) Init(chain *blockchain.BlockChain, interrupt <-chan struct{})
// When the index requires all of the referenced // When the index requires all of the referenced
// txouts they need to be retrieved from the // txouts they need to be retrieved from the
// transaction index. // transaction index.
var view *blockchain.UtxoViewpoint var view *blockdag.UtxoViewpoint
if indexNeedsInputs(indexer) { if indexNeedsInputs(indexer) {
var err error var err error
view, err = makeUtxoView(dbTx, block, 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. // Connect the block for all indexes that need it.
var view *blockchain.UtxoViewpoint var view *blockdag.UtxoViewpoint
for i, indexer := range m.enabledIndexes { for i, indexer := range m.enabledIndexes {
// Skip indexes that don't need to be updated with this // Skip indexes that don't need to be updated with this
// block. // 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 // transactions in the block. This is sometimes needed when catching indexes up
// because many of the txouts could actually already be spent however the // because many of the txouts could actually already be spent however the
// associated scripts are still required to index them. // associated scripts are still required to index them.
func makeUtxoView(dbTx database.Tx, block *btcutil.Block, interrupt <-chan struct{}) (*blockchain.UtxoViewpoint, error) { func makeUtxoView(dbTx database.Tx, block *btcutil.Block, interrupt <-chan struct{}) (*blockdag.UtxoViewpoint, error) {
view := blockchain.NewUtxoViewpoint() view := blockdag.NewUtxoViewpoint()
for txIdx, tx := range block.Transactions() { for txIdx, tx := range block.Transactions() {
// Coinbases do not reference any inputs. Since the block is // Coinbases do not reference any inputs. Since the block is
// required to have already gone through full validation, it has // 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. // checks, and invokes each indexer.
// //
// This is part of the blockchain.IndexManager interface. // 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 // Call each of the currently active optional indexes with the block
// being connected so they can update accordingly. // being connected so they can update accordingly.
for _, index := range m.enabledIndexes { 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. // the index entries associated with the block.
// //
// This is part of the blockchain.IndexManager interface. // 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 // Call each of the currently active optional indexes with the block
// being disconnected so they can update accordingly. // being disconnected so they can update accordingly.
for _, index := range m.enabledIndexes { for _, index := range m.enabledIndexes {

View File

@ -8,7 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/wire"
@ -388,7 +388,7 @@ func (idx *TxIndex) Create(dbTx database.Tx) error {
// for every transaction in the passed block. // for every transaction in the passed block.
// //
// This is part of the Indexer interface. // 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 // Increment the internal block ID to use for the block being connected
// and add all of the transactions in the block to the index. // and add all of the transactions in the block to the index.
newBlockID := idx.curBlockID + 1 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. // hash-to-transaction mapping for every transaction in the block.
// //
// This is part of the Indexer interface. // 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. // Remove all of the transactions in the block from the index.
if err := dbRemoveTxIndexEntries(dbTx, block); err != nil { if err := dbRemoveTxIndexEntries(dbTx, block); err != nil {
return err return err

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"github.com/btcsuite/btclog" "github.com/btcsuite/btclog"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math" "math"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"strconv" "strconv"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math" "math"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"testing" "testing"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"testing" "testing"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"testing" "testing"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
// timeSorter implements sort.Interface to allow a slice of timestamps to // timeSorter implements sort.Interface to allow a slice of timestamps to
// be sorted. // be sorted.

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"reflect" "reflect"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"bytes" "bytes"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"reflect" "reflect"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"encoding/binary" "encoding/binary"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math" "math"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package blockchain package blockdag
import ( import (
"math" "math"

View File

@ -15,7 +15,7 @@ import (
"runtime/debug" "runtime/debug"
"runtime/pprof" "runtime/pprof"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/limits" "github.com/daglabs/btcd/limits"
) )

View File

@ -58,10 +58,10 @@ var genesisCoinbaseTx = wire.MsgTx{
// genesisHash is the hash of the first block in the block chain for the main // genesisHash is the hash of the first block in the block chain for the main
// network (genesis block). // network (genesis block).
var genesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy. var genesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, 0x82, 0xdc, 0xbd, 0xe6, 0x88, 0x37, 0x74, 0x5b,
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, 0x78, 0x6b, 0x03, 0x1d, 0xa3, 0x48, 0x3c, 0x45,
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, 0x3f, 0xc3, 0x2e, 0xd4, 0x53, 0x5b, 0x6f, 0x26,
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0xb0, 0x48, 0x4f, 0x09, 0x00, 0x00, 0x00,
}) })
// genesisMerkleRoot is the hash of the first transaction in the genesis block // genesisMerkleRoot is the hash of the first transaction in the genesis block
@ -78,11 +78,12 @@ var genesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet
var genesisBlock = wire.MsgBlock{ var genesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000 NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: genesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b MerkleRoot: genesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 18:15:05 +0000 UTC Timestamp: time.Unix(0x5b28c4c8, 0), // 2018-06-19 08:54:32 +0000 UTC
Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000] Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Nonce: 0x7c2bac1d, // 2083236893 Nonce: 0xc0192550, // 2148484547
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }
@ -90,10 +91,10 @@ var genesisBlock = wire.MsgBlock{
// regTestGenesisHash is the hash of the first block in the block chain for the // regTestGenesisHash is the hash of the first block in the block chain for the
// regression test network (genesis block). // regression test network (genesis block).
var regTestGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy. var regTestGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59, 0x7c, 0x03, 0x27, 0x80, 0x78, 0xfc, 0xe8, 0xed,
0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf, 0xcd, 0xfc, 0x3d, 0xe1, 0x63, 0x45, 0x4c, 0x03,
0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f, 0x0f, 0xef, 0x38, 0x16, 0xec, 0x54, 0x61, 0x6f,
0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f, 0xca, 0xc9, 0x58, 0x12, 0xb4, 0x6a, 0x15, 0x08,
}) })
// regTestGenesisMerkleRoot is the hash of the first transaction in the genesis // regTestGenesisMerkleRoot is the hash of the first transaction in the genesis
@ -106,11 +107,12 @@ var regTestGenesisMerkleRoot = genesisMerkleRoot
var regTestGenesisBlock = wire.MsgBlock{ var regTestGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000 NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC Timestamp: time.Unix(0x5b28c636, 0), // 2018-06-19 09:00:38 +0000 UTC
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000] Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Nonce: 2, Nonce: 1,
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }
@ -118,10 +120,10 @@ var regTestGenesisBlock = wire.MsgBlock{
// testNet3GenesisHash is the hash of the first block in the block chain for the // testNet3GenesisHash is the hash of the first block in the block chain for the
// test network (version 3). // test network (version 3).
var testNet3GenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy. var testNet3GenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71, 0x91, 0x1c, 0xe0, 0x47, 0x77, 0xad, 0x5e, 0xc5,
0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae, 0x60, 0x10, 0x21, 0x32, 0x51, 0x1b, 0x39, 0x06,
0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad, 0x24, 0xb3, 0xbf, 0x08, 0x8e, 0x04, 0x8c, 0xd3,
0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00, 0x80, 0xb4, 0x83, 0x83, 0xed, 0x00, 0x00, 0x00,
}) })
// testNet3GenesisMerkleRoot is the hash of the first transaction in the genesis // testNet3GenesisMerkleRoot is the hash of the first transaction in the genesis
@ -134,11 +136,12 @@ var testNet3GenesisMerkleRoot = genesisMerkleRoot
var testNet3GenesisBlock = wire.MsgBlock{ var testNet3GenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000 NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC Timestamp: time.Unix(0x5b28c706, 0), // 2018-06-19 09:04:06 +0000 UTC
Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000] Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Nonce: 0x18aea41a, // 414098458 Nonce: 0x802f1b3b, // 2150570811
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }
@ -146,10 +149,10 @@ var testNet3GenesisBlock = wire.MsgBlock{
// simNetGenesisHash is the hash of the first block in the block chain for the // simNetGenesisHash is the hash of the first block in the block chain for the
// simulation test network. // simulation test network.
var simNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy. var simNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a, 0xc1, 0x5b, 0x71, 0xfe, 0x20, 0x70, 0x0f, 0xd0,
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0, 0x08, 0x49, 0x88, 0x1b, 0x32, 0xb5, 0xbd, 0x13,
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91, 0x17, 0xbe, 0x75, 0xe7, 0x29, 0x46, 0xdd, 0x03,
0x0d, 0x11, 0x6d, 0x5c, 0xbd, 0x86, 0x3e, 0x68, 0x01, 0x92, 0x90, 0xf1, 0xca, 0x8a, 0x88, 0x11,
}) })
// simNetGenesisMerkleRoot is the hash of the first transaction in the genesis // simNetGenesisMerkleRoot is the hash of the first transaction in the genesis
@ -162,11 +165,12 @@ var simNetGenesisMerkleRoot = genesisMerkleRoot
var simNetGenesisBlock = wire.MsgBlock{ var simNetGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000 NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: simNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b MerkleRoot: simNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1401292357, 0), // 2014-05-28 15:52:37 +0000 UTC Timestamp: time.Unix(0x5b28c7ec, 0), // 2018-06-19 09:07:56 +0000 UTC
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000] Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Nonce: 2, Nonce: 0x9ffffffb, // 2684354555
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }

View File

@ -121,163 +121,147 @@ func TestSimNetGenesisBlock(t *testing.T) {
// genesisBlockBytes are the wire encoded bytes for the genesis block of the // genesisBlockBytes are the wire encoded bytes for the genesis block of the
// main network as of protocol version 60002. // main network as of protocol version 60002.
var genesisBlockBytes = []byte{ var genesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, /* |.....;..| */
0xfd, 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, /* |.z{..z.,| */
0x3e, 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, /* |>gv.a...| */
0xc3, 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, /* |...Q2:..| */
0xaa, 0x4b, 0x1e, 0x5e, 0x4a, 0xc8, 0xc4, 0x28, /* |.K.^J..(| */
0x5b, 0xff, 0xff, 0x00, 0x1e, 0x50, 0x25, 0x19, /* |[....P%.| */
0xc0, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ 0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ 0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ 0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x4b, 0x1e, 0x5e, 0x4a, 0x29, 0xab, 0x5f, 0x49, /* |K.^J)._I| */ 0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0xff, 0xff, 0x00, 0x1d, 0x1d, 0xac, 0x2b, 0x7c, /* |......+|| */ 0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* |........| */ 0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* |........| */ 0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */ 0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */
0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */
0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */
0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */
0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */
0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */
0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */
0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */
0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/
0xac, 0x00, 0x00, 0x00, 0x00, /* |.....| */
} }
// regTestGenesisBlockBytes are the wire encoded bytes for the genesis block of // regTestGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the regression test network as of protocol version 60002. // the regression test network as of protocol version 60002.
var regTestGenesisBlockBytes = []byte{ var regTestGenesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, /* |.....;..| */
0xfd, 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, /* |.z{..z.,| */
0x3e, 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, /* |>gv.a...| */
0xc3, 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, /* |...Q2:..| */
0xaa, 0x4b, 0x1e, 0x5e, 0x4a, 0x36, 0xc6, 0x28, /* |.K.^J6.(| */
0x5b, 0xff, 0xff, 0x7f, 0x20, 0x01, 0x00, 0x00, /* |[... ...| */
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ 0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ 0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ 0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x4b, 0x1e, 0x5e, 0x4a, 0xda, 0xe5, 0x49, 0x4d, /* |K.^J)._I| */ 0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0xff, 0xff, 0x7f, 0x20, 0x02, 0x00, 0x00, 0x00, /* |......+|| */ 0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* |........| */ 0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* |........| */ 0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */ 0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */
0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */
0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */
0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */
0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */
0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */
0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */
0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */
0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/
0xac, 0x00, 0x00, 0x00, 0x00, /* |.....| */
} }
// testNet3GenesisBlockBytes are the wire encoded bytes for the genesis block of // testNet3GenesisBlockBytes are the wire encoded bytes for the genesis block of
// the test network (version 3) as of protocol version 60002. // the test network (version 3) as of protocol version 60002.
var testNet3GenesisBlockBytes = []byte{ var testNet3GenesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, /* |.....;..| */
0xfd, 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, /* |.z{..z.,| */
0x3e, 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, /* |>gv.a...| */
0xc3, 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, /* |...Q2:..| */
0xaa, 0x4b, 0x1e, 0x5e, 0x4a, 0x06, 0xc7, 0x28, /* |.K.^J..(| */
0x5b, 0xff, 0xff, 0x00, 0x1e, 0x3b, 0x1b, 0x2f, /* |[....;./| */
0x80, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ 0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ 0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ 0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x4b, 0x1e, 0x5e, 0x4a, 0xda, 0xe5, 0x49, 0x4d, /* |K.^J)._I| */ 0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0xff, 0xff, 0x00, 0x1d, 0x1a, 0xa4, 0xae, 0x18, /* |......+|| */ 0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* |........| */ 0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* |........| */ 0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */ 0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */
0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */
0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */
0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */
0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */
0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */
0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */
0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */
0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/
0xac, 0x00, 0x00, 0x00, 0x00, /* |.....| */
} }
// simNetGenesisBlockBytes are the wire encoded bytes for the genesis block of // simNetGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the simulation test network as of protocol version 70002. // the simulation test network as of protocol version 70002.
var simNetGenesisBlockBytes = []byte{ var simNetGenesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x01, 0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, /* |.....;..| */
0xfd, 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, /* |.z{..z.,| */
0x3e, 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, /* |>gv.a...| */
0xc3, 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, /* |...Q2:..| */
0xaa, 0x4b, 0x1e, 0x5e, 0x4a, 0xec, 0xc7, 0x28, /* |.K.^J..(| */
0x5b, 0xff, 0xff, 0x7f, 0x20, 0xfb, 0xff, 0xff, /* |[... ...| */
0x9f, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ 0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ 0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ 0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x4b, 0x1e, 0x5e, 0x4a, 0x45, 0x06, 0x86, 0x53, /* |K.^J)._I| */ 0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0xff, 0xff, 0x7f, 0x20, 0x02, 0x00, 0x00, 0x00, /* |......+|| */ 0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* |........| */ 0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */ 0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* |........| */ 0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */ 0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ 0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */
0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */
0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */
0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */
0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */
0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */
0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */
0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */
0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/
0xac, 0x00, 0x00, 0x00, 0x00, /* |.....| */
} }

View File

@ -9,8 +9,8 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/limits" "github.com/daglabs/btcd/limits"
"github.com/btcsuite/btclog" "github.com/btcsuite/btclog"
@ -73,7 +73,7 @@ func realMain() error {
defer os.Stdout.Sync() defer os.Stdout.Sync()
log = backendLogger.Logger("MAIN") log = backendLogger.Logger("MAIN")
database.UseLogger(backendLogger.Logger("BCDB")) database.UseLogger(backendLogger.Logger("BCDB"))
blockchain.UseLogger(backendLogger.Logger("CHAN")) blockdag.UseLogger(backendLogger.Logger("CHAN"))
indexers.UseLogger(backendLogger.Logger("INDX")) indexers.UseLogger(backendLogger.Logger("INDX"))
// Load the block database. // Load the block database.

View File

@ -11,8 +11,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/wire"
@ -32,7 +32,7 @@ type importResults struct {
// file to the block database. // file to the block database.
type blockImporter struct { type blockImporter struct {
db database.DB db database.DB
chain *blockchain.BlockChain chain *blockdag.BlockChain
r io.ReadSeeker r io.ReadSeeker
processQueue chan []byte processQueue chan []byte
doneChan chan bool 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 // Ensure the blocks follows all of the chain rules and match up to the
// known checkpoints. // known checkpoints.
isMainChain, isOrphan, err := bi.chain.ProcessBlock(block, isMainChain, isOrphan, err := bi.chain.ProcessBlock(block,
blockchain.BFFastAdd) blockdag.BFFastAdd)
if err != nil { if err != nil {
return false, err 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. // Create an index manager if any of the optional indexes are enabled.
var indexManager blockchain.IndexManager var indexManager blockdag.IndexManager
if len(indexes) > 0 { if len(indexes) > 0 {
indexManager = indexers.NewManager(db, indexes) indexManager = indexers.NewManager(db, indexes)
} }
chain, err := blockchain.New(&blockchain.Config{ chain, err := blockdag.New(&blockdag.Config{
DB: db, DB: db,
ChainParams: activeNetParams, ChainParams: activeNetParams,
TimeSource: blockchain.NewMedianTime(), TimeSource: blockdag.NewMedianTime(),
IndexManager: indexManager, IndexManager: indexManager,
}) })
if err != nil { if err != nil {

View File

@ -9,7 +9,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "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 // candidates at the last checkpoint that is already hard coded into btcchain
// since there is no point in finding candidates before already existing // since there is no point in finding candidates before already existing
// checkpoints. // 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. // Start with the latest block of the main chain.
block, err := chain.BlockByHash(latestHash) block, err := chain.BlockByHash(latestHash)
if err != nil { 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 // The latest known block must be at least the last known checkpoint
// plus required checkpoint confirmations. // plus required checkpoint confirmations.
checkpointConfirmations := int32(blockchain.CheckpointConfirmations) checkpointConfirmations := int32(blockdag.CheckpointConfirmations)
requiredHeight := latestCheckpoint.Height + checkpointConfirmations requiredHeight := latestCheckpoint.Height + checkpointConfirmations
if block.Height() < requiredHeight { if block.Height() < requiredHeight {
return nil, fmt.Errorf("the block database is only at height "+ 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 // Setup chain. Ignore notifications since they aren't needed for this
// util. // util.
chain, err := blockchain.New(&blockchain.Config{ chain, err := blockdag.New(&blockdag.Config{
DB: db, DB: db,
ChainParams: activeNetParams, ChainParams: activeNetParams,
TimeSource: blockchain.NewMedianTime(), TimeSource: blockdag.NewMedianTime(),
}) })
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "failed to initialize chain: %v\n", err) fmt.Fprintf(os.Stderr, "failed to initialize chain: %v\n", err)

View File

@ -13,7 +13,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/integration/rpctest" "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 // thresholdStateToStatus converts the passed threshold state to the equivalent
// status string returned in the getblockchaininfo RPC. // status string returned in the getblockchaininfo RPC.
func thresholdStateToStatus(state blockchain.ThresholdState) (string, error) { func thresholdStateToStatus(state blockdag.ThresholdState) (string, error) {
switch state { switch state {
case blockchain.ThresholdDefined: case blockdag.ThresholdDefined:
return "defined", nil return "defined", nil
case blockchain.ThresholdStarted: case blockdag.ThresholdStarted:
return "started", nil return "started", nil
case blockchain.ThresholdLockedIn: case blockdag.ThresholdLockedIn:
return "lockedin", nil return "lockedin", nil
case blockchain.ThresholdActive: case blockdag.ThresholdActive:
return "active", nil return "active", nil
case blockchain.ThresholdFailed: case blockdag.ThresholdFailed:
return "failed", nil return "failed", nil
} }
@ -86,7 +86,7 @@ func thresholdStateToStatus(state blockchain.ThresholdState) (string, error) {
// assertSoftForkStatus retrieves the current blockchain info from the given // assertSoftForkStatus retrieves the current blockchain info from the given
// test harness and ensures the provided soft fork key is both available and its // test harness and ensures the provided soft fork key is both available and its
// status is the equivalent of the passed state. // 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 // Convert the expected threshold state into the equivalent
// getblockchaininfo RPC status string. // getblockchaininfo RPC status string.
status, err := thresholdStateToStatus(state) 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 // Assert the chain height is the expected value and the soft fork
// status starts out as defined. // status starts out as defined.
assertChainHeight(r, t, 0) assertChainHeight(r, t, 0)
assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdDefined) assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdDefined)
// *** ThresholdDefined part 2 - 1 block prior to ThresholdStarted *** // *** 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) assertChainHeight(r, t, confirmationWindow-2)
assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdDefined) assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdDefined)
// *** ThresholdStarted *** // *** ThresholdStarted ***
// //
@ -181,7 +181,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
t.Fatalf("failed to generated block: %v", err) t.Fatalf("failed to generated block: %v", err)
} }
assertChainHeight(r, t, confirmationWindow-1) assertChainHeight(r, t, confirmationWindow-1)
assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdStarted) assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdStarted)
// *** ThresholdStarted part 2 - Fail to achieve ThresholdLockedIn *** // *** 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) assertChainHeight(r, t, (confirmationWindow*2)-1)
assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdStarted) assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdStarted)
// *** ThresholdLockedIn *** // *** ThresholdLockedIn ***
// //
@ -237,7 +237,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
} }
} }
assertChainHeight(r, t, (confirmationWindow*3)-1) 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 *** // *** 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) assertChainHeight(r, t, (confirmationWindow*4)-2)
assertSoftForkStatus(r, t, forkKey, blockchain.ThresholdLockedIn) assertSoftForkStatus(r, t, forkKey, blockdag.ThresholdLockedIn)
// *** ThresholdActive *** // *** ThresholdActive ***
// //
@ -269,7 +269,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
t.Fatalf("failed to generated block: %v", err) t.Fatalf("failed to generated block: %v", err)
} }
assertChainHeight(r, t, (confirmationWindow*4)-1) 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 // TestBIP0009 ensures the BIP0009 soft fork mechanism follows the state

View File

@ -14,7 +14,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcec"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
@ -206,7 +206,7 @@ func TestBIP0113Activation(t *testing.T) {
} }
assertChainHeight(r, t, 299) 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 // The timeLockDeltas slice represents a series of deviations from the
// current MTP which will be used to test border conditions w.r.t // 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 // Convert the time-lock to the proper sequence lock based according to
// if the lock is seconds or time based. // if the lock is seconds or time based.
sequenceLock := blockchain.LockTimeToSequence(isSeconds, sequenceLock := blockdag.LockTimeToSequence(isSeconds,
uint32(timeLock)) uint32(timeLock))
// Our CSV script is simply: <sequenceLock> OP_CSV OP_DROP // Our CSV script is simply: <sequenceLock> OP_CSV OP_DROP
@ -414,7 +414,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
} }
defer r.TearDown() defer r.TearDown()
assertSoftForkStatus(r, t, csvKey, blockchain.ThresholdStarted) assertSoftForkStatus(r, t, csvKey, blockdag.ThresholdStarted)
harnessAddr, err := r.NewAddress() harnessAddr, err := r.NewAddress()
if err != nil { if err != nil {
@ -460,7 +460,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
assertTxInBlock(r, t, blocks[0], &txid) assertTxInBlock(r, t, blocks[0], &txid)
// Generate a custom transaction which spends the CSV output. // Generate a custom transaction which spends the CSV output.
sequenceNum := blockchain.LockTimeToSequence(false, 10) sequenceNum := blockdag.LockTimeToSequence(false, 10)
spendingTx, err := spendCSVOutput(redeemScript, testUTXO, spendingTx, err := spendCSVOutput(redeemScript, testUTXO,
sequenceNum, sweepOutput, txVersion) sequenceNum, sweepOutput, txVersion)
if err != nil { if err != nil {
@ -501,7 +501,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
} }
assertChainHeight(r, t, 299) 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 // Knowing the number of outputs needed for the tests below, create a
// fresh output for use within each of the test-cases below. // 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 // should be rejected as its version number is 1, and only tx
// of version > 2 will trigger the CSV behavior. // of version > 2 will trigger the CSV behavior.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(false, 100), 1), tx: makeTxCase(blockdag.LockTimeToSequence(false, 100), 1),
accept: false, accept: false,
}, },
// A transaction of version 2 spending a single input. The // 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. // bit it set. The transaction should be rejected as a result.
{ {
tx: makeTxCase( tx: makeTxCase(
blockchain.LockTimeToSequence(false, 1)|wire.SequenceLockTimeDisabled, blockdag.LockTimeToSequence(false, 1)|wire.SequenceLockTimeDisabled,
2, 2,
), ),
accept: false, accept: false,
@ -609,14 +609,14 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
// but the CSV output requires a 10 block relative lock-time. // but the CSV output requires a 10 block relative lock-time.
// Therefore, the transaction should be rejected. // Therefore, the transaction should be rejected.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(false, 9), 2), tx: makeTxCase(blockdag.LockTimeToSequence(false, 9), 2),
accept: false, accept: false,
}, },
// A v2 transaction with a single input having a 10 block // A v2 transaction with a single input having a 10 block
// relative time lock. The referenced input is 11 blocks old so // relative time lock. The referenced input is 11 blocks old so
// the transaction should be accepted. // the transaction should be accepted.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(false, 10), 2), tx: makeTxCase(blockdag.LockTimeToSequence(false, 10), 2),
accept: true, accept: true,
}, },
// A v2 transaction with a single input having a 11 block // 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 // 11 and the CSV op-code requires 10 blocks to have passed, so
// this transaction should be accepted. // this transaction should be accepted.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(false, 11), 2), tx: makeTxCase(blockdag.LockTimeToSequence(false, 11), 2),
accept: true, accept: true,
}, },
// A v2 transaction whose input has a 1000 blck relative time // A v2 transaction whose input has a 1000 blck relative time
// lock. This should be rejected as the input's age is only 11 // lock. This should be rejected as the input's age is only 11
// blocks. // blocks.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(false, 1000), 2), tx: makeTxCase(blockdag.LockTimeToSequence(false, 1000), 2),
accept: false, accept: false,
}, },
// A v2 transaction with a single input having a 512,000 second // 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 // days worth of blocks haven't yet been mined. The referenced
// input doesn't have sufficient age. // input doesn't have sufficient age.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(true, 512000), 2), tx: makeTxCase(blockdag.LockTimeToSequence(true, 512000), 2),
accept: false, accept: false,
}, },
// A v2 transaction whose single input has a 512 second // A v2 transaction whose single input has a 512 second
// relative time-lock. This transaction should be accepted as // relative time-lock. This transaction should be accepted as
// finalized. // finalized.
{ {
tx: makeTxCase(blockchain.LockTimeToSequence(true, 512), 2), tx: makeTxCase(blockdag.LockTimeToSequence(true, 512), 2),
accept: true, accept: true,
}, },
} }

View File

@ -11,7 +11,7 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/txscript" "github.com/daglabs/btcd/txscript"
@ -44,7 +44,7 @@ func solveBlock(header *wire.BlockHeader, targetDifficulty *big.Int) bool {
default: default:
hdr.Nonce = i hdr.Nonce = i
hash := hdr.BlockHash() hash := hdr.BlockHash()
if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 { if blockdag.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
select { select {
case results <- sbResult{true, i}: case results <- sbResult{true, i}:
return return
@ -116,7 +116,7 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32,
}) })
if len(mineTo) == 0 { if len(mineTo) == 0 {
tx.AddTxOut(&wire.TxOut{ tx.AddTxOut(&wire.TxOut{
Value: blockchain.CalcBlockSubsidy(nextBlockHeight, net), Value: blockdag.CalcBlockSubsidy(nextBlockHeight, net),
PkScript: pkScript, PkScript: pkScript,
}) })
} else { } else {
@ -181,7 +181,7 @@ func CreateBlock(prevBlock *btcutil.Block, inclusionTxs []*btcutil.Tx,
if inclusionTxs != nil { if inclusionTxs != nil {
blockTxns = append(blockTxns, inclusionTxs...) blockTxns = append(blockTxns, inclusionTxs...)
} }
merkles := blockchain.BuildMerkleTreeStore(blockTxns) merkles := blockdag.BuildMerkleTreeStore(blockTxns)
var block wire.MsgBlock var block wire.MsgBlock
block.Header = wire.BlockHeader{ block.Header = wire.BlockHeader{
Version: blockVersion, Version: blockVersion,

View File

@ -10,7 +10,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcec"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
@ -207,7 +207,7 @@ func (m *memWallet) ingestBlock(update *chainUpdate) {
} }
for _, tx := range update.filteredTxns { for _, tx := range update.filteredTxns {
mtx := tx.MsgTx() mtx := tx.MsgTx()
isCoinbase := blockchain.IsCoinBaseTx(mtx) isCoinbase := blockdag.IsCoinBaseTx(mtx)
txHash := mtx.TxHash() txHash := mtx.TxHash()
m.evalOutputs(mtx.TxOut, &txHash, isCoinbase, undo) m.evalOutputs(mtx.TxOut, &txHash, isCoinbase, undo)
m.evalInputs(mtx.TxIn, undo) m.evalInputs(mtx.TxIn, undo)

6
log.go
View File

@ -11,8 +11,8 @@ import (
"path/filepath" "path/filepath"
"github.com/daglabs/btcd/addrmgr" "github.com/daglabs/btcd/addrmgr"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/connmgr" "github.com/daglabs/btcd/connmgr"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/mempool" "github.com/daglabs/btcd/mempool"
@ -76,7 +76,7 @@ func init() {
addrmgr.UseLogger(amgrLog) addrmgr.UseLogger(amgrLog)
connmgr.UseLogger(cmgrLog) connmgr.UseLogger(cmgrLog)
database.UseLogger(bcdbLog) database.UseLogger(bcdbLog)
blockchain.UseLogger(chanLog) blockdag.UseLogger(chanLog)
indexers.UseLogger(indxLog) indexers.UseLogger(indxLog)
mining.UseLogger(minrLog) mining.UseLogger(minrLog)
cpuminer.UseLogger(minrLog) cpuminer.UseLogger(minrLog)

View File

@ -5,7 +5,7 @@
package mempool package mempool
import ( import (
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/wire" "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 // chainRuleError returns a RuleError that encapsulates the given
// blockchain.RuleError. // blockchain.RuleError.
func chainRuleError(chainErr blockchain.RuleError) RuleError { func chainRuleError(chainErr blockdag.RuleError) RuleError {
return RuleError{ return RuleError{
Err: chainErr, Err: chainErr,
} }
@ -68,26 +68,26 @@ func extractRejectCode(err error) (wire.RejectCode, bool) {
} }
switch err := err.(type) { switch err := err.(type) {
case blockchain.RuleError: case blockdag.RuleError:
// Convert the chain error to a reject code. // Convert the chain error to a reject code.
var code wire.RejectCode var code wire.RejectCode
switch err.ErrorCode { switch err.ErrorCode {
// Rejected due to duplicate. // Rejected due to duplicate.
case blockchain.ErrDuplicateBlock: case blockdag.ErrDuplicateBlock:
code = wire.RejectDuplicate code = wire.RejectDuplicate
// Rejected due to obsolete version. // Rejected due to obsolete version.
case blockchain.ErrBlockVersionTooOld: case blockdag.ErrBlockVersionTooOld:
code = wire.RejectObsolete code = wire.RejectObsolete
// Rejected due to checkpoint. // Rejected due to checkpoint.
case blockchain.ErrCheckpointTimeTooOld: case blockdag.ErrCheckpointTimeTooOld:
fallthrough fallthrough
case blockchain.ErrDifficultyTooLow: case blockdag.ErrDifficultyTooLow:
fallthrough fallthrough
case blockchain.ErrBadCheckpoint: case blockdag.ErrBadCheckpoint:
fallthrough fallthrough
case blockchain.ErrForkTooOld: case blockdag.ErrForkTooOld:
code = wire.RejectCheckpoint code = wire.RejectCheckpoint
// Everything else is due to the block or transaction being invalid. // Everything else is due to the block or transaction being invalid.

View File

@ -12,8 +12,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/btcjson"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
@ -57,7 +57,7 @@ type Config struct {
// FetchUtxoView defines the function to use to fetch unspent // FetchUtxoView defines the function to use to fetch unspent
// transaction output information. // 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 // BestHeight defines the function to use to access the block height of
// the current best chain. // the current best chain.
@ -71,7 +71,7 @@ type Config struct {
// CalcSequenceLock defines the function to use in order to generate // CalcSequenceLock defines the function to use in order to generate
// the current sequence lock for the given transaction using the passed // the current sequence lock for the given transaction using the passed
// utxo view. // 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 // IsDeploymentActive returns true if the target deploymentID is
// active, and false otherwise. The mempool uses this function to gauge // 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. // helper for maybeAcceptTransaction.
// //
// This function MUST be called with the mempool lock held (for writes). // 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 // Add the transaction to the pool and mark the referenced outpoints
// as spent by the pool. // as spent by the pool.
txD := &TxDesc{ txD := &TxDesc{
@ -585,7 +585,7 @@ func (mp *TxPool) CheckSpend(op wire.OutPoint) *btcutil.Tx {
// transaction pool. // transaction pool.
// //
// This function MUST be called with the mempool lock held (for reads). // 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) utxoView, err := mp.cfg.FetchUtxoView(tx)
if err != nil { if err != nil {
return nil, err 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 // Perform preliminary sanity checks on the transaction. This makes
// use of blockchain which contains the invariant rules for what // use of blockchain which contains the invariant rules for what
// transactions are allowed into blocks. // transactions are allowed into blocks.
err := blockchain.CheckTransactionSanity(tx) err := blockdag.CheckTransactionSanity(tx)
if err != nil { 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, chainRuleError(cerr)
} }
return nil, nil, err return nil, nil, err
} }
// A standalone transaction must not be a coinbase transaction. // 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", str := fmt.Sprintf("transaction %v is an individual coinbase",
txHash) txHash)
return nil, nil, txRuleError(wire.RejectInvalid, str) 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. // without needing to do a separate lookup.
utxoView, err := mp.fetchInputUtxos(tx) utxoView, err := mp.fetchInputUtxos(tx)
if err != nil { 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, chainRuleError(cerr)
} }
return nil, nil, err 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. // with respect to its defined relative lock times.
sequenceLock, err := mp.cfg.CalcSequenceLock(tx, utxoView) sequenceLock, err := mp.cfg.CalcSequenceLock(tx, utxoView)
if err != nil { 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, chainRuleError(cerr)
} }
return nil, nil, err return nil, nil, err
} }
if !blockchain.SequenceLockActive(sequenceLock, nextBlockHeight, if !blockdag.SequenceLockActive(sequenceLock, nextBlockHeight,
medianTimePast) { medianTimePast) {
return nil, nil, txRuleError(wire.RejectNonstandard, return nil, nil, txRuleError(wire.RejectNonstandard,
"transaction's sequence locks on inputs not met") "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. // rules in blockchain for what transactions are allowed into blocks.
// Also returns the fees associated with the transaction which will be // Also returns the fees associated with the transaction which will be
// used later. // used later.
txFee, err := blockchain.CheckTransactionInputs(tx, nextBlockHeight, txFee, err := blockdag.CheckTransactionInputs(tx, nextBlockHeight,
utxoView, mp.cfg.ChainParams) utxoView, mp.cfg.ChainParams)
if err != nil { 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, chainRuleError(cerr)
} }
return nil, nil, err 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 // the coinbase address itself can contain signature operations, the
// maximum allowed signature operations per transaction is less than // maximum allowed signature operations per transaction is less than
// the maximum allowed signature operations per block. // 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 err != nil {
if cerr, ok := err.(blockchain.RuleError); ok { if cerr, ok := err.(blockdag.RuleError); ok {
return nil, nil, chainRuleError(cerr) return nil, nil, chainRuleError(cerr)
} }
return nil, nil, err 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 // Verify crypto signatures for each input and reject the transaction if
// any don't verify. // any don't verify.
err = blockchain.ValidateTransactionScripts(tx, utxoView, err = blockdag.ValidateTransactionScripts(tx, utxoView,
txscript.StandardVerifyFlags, mp.cfg.SigCache) txscript.StandardVerifyFlags, mp.cfg.SigCache)
if err != nil { 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, chainRuleError(cerr)
} }
return nil, nil, err return nil, nil, err

View File

@ -12,7 +12,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcec"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
@ -26,7 +26,7 @@ import (
// transactions to appear as though they are spending completely valid utxos. // transactions to appear as though they are spending completely valid utxos.
type fakeChain struct { type fakeChain struct {
sync.RWMutex sync.RWMutex
utxos *blockchain.UtxoViewpoint utxos *blockdag.UtxoViewpoint
currentHeight int32 currentHeight int32
medianTimePast time.Time medianTimePast time.Time
} }
@ -37,7 +37,7 @@ type fakeChain struct {
// view can be examined for duplicate transactions. // view can be examined for duplicate transactions.
// //
// This function is safe for concurrent access however the returned view is NOT. // 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() s.RLock()
defer s.RUnlock() 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. // do not affect the fake chain's view.
// Add an entry for the tx itself to the new view. // Add an entry for the tx itself to the new view.
viewpoint := blockchain.NewUtxoViewpoint() viewpoint := blockdag.NewUtxoViewpoint()
prevOut := wire.OutPoint{Hash: *tx.Hash()} prevOut := wire.OutPoint{Hash: *tx.Hash()}
for txOutIdx := range tx.MsgTx().TxOut { for txOutIdx := range tx.MsgTx().TxOut {
prevOut.Index = uint32(txOutIdx) prevOut.Index = uint32(txOutIdx)
@ -98,9 +98,9 @@ func (s *fakeChain) SetMedianTimePast(mtp time.Time) {
// CalcSequenceLock returns the current sequence lock for the passed // CalcSequenceLock returns the current sequence lock for the passed
// transaction associated with the fake chain instance. // transaction associated with the fake chain instance.
func (s *fakeChain) CalcSequenceLock(tx *btcutil.Tx, 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, Seconds: -1,
BlockHeight: -1, BlockHeight: -1,
}, nil }, nil
@ -164,7 +164,7 @@ func (p *poolHarness) CreateCoinbaseTx(blockHeight int32, numOutputs uint32) (*b
SignatureScript: coinbaseScript, SignatureScript: coinbaseScript,
Sequence: wire.MaxTxInSequenceNum, Sequence: wire.MaxTxInSequenceNum,
}) })
totalInput := blockchain.CalcBlockSubsidy(blockHeight, p.chainParams) totalInput := blockdag.CalcBlockSubsidy(blockHeight, p.chainParams)
amountPerOutput := totalInput / int64(numOutputs) amountPerOutput := totalInput / int64(numOutputs)
remainder := totalInput - amountPerOutput*int64(numOutputs) remainder := totalInput - amountPerOutput*int64(numOutputs)
for i := uint32(0); i < numOutputs; i++ { 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. // Create a new fake chain and harness bound to it.
chain := &fakeChain{utxos: blockchain.NewUtxoViewpoint()} chain := &fakeChain{utxos: blockdag.NewUtxoViewpoint()}
harness := poolHarness{ harness := poolHarness{
signKey: signKey, signKey: signKey,
payAddr: payAddr, payAddr: payAddr,
@ -313,7 +313,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp
FreeTxRelayLimit: 15.0, FreeTxRelayLimit: 15.0,
MaxOrphanTxs: 5, MaxOrphanTxs: 5,
MaxOrphanTxSize: 1000, MaxOrphanTxSize: 1000,
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, MaxSigOpsPerTx: blockdag.MaxSigOpsPerBlock / 5,
MinRelayTxFee: 1000, // 1 Satoshi per byte MinRelayTxFee: 1000, // 1 Satoshi per byte
MaxTxVersion: 1, MaxTxVersion: 1,
}, },

View File

@ -8,7 +8,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/txscript" "github.com/daglabs/btcd/txscript"
"github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/wire"
"github.com/daglabs/btcutil" "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 // not perform those checks because the script engine already does this more
// accurately and concisely via the txscript.ScriptVerifyCleanStack and // accurately and concisely via the txscript.ScriptVerifyCleanStack and
// txscript.ScriptVerifySigPushOnly flags. // 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, // NOTE: The reference implementation also does a coinbase check here,
// but coinbases have already been rejected prior to calling this // but coinbases have already been rejected prior to calling this
// function so no need to recheck. // 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 // The transaction must be finalized to be standard and therefore
// considered for inclusion in a block. // considered for inclusion in a block.
if !blockchain.IsFinalizedTransaction(tx, height, medianTimePast) { if !blockdag.IsFinalizedTransaction(tx, height, medianTimePast) {
return txRuleError(wire.RejectNonstandard, return txRuleError(wire.RejectNonstandard,
"transaction is not finalized") "transaction is not finalized")
} }

View File

@ -12,7 +12,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/mining" "github.com/daglabs/btcd/mining"
@ -64,7 +64,7 @@ type Config struct {
// ProcessBlock defines the function to call with any solved blocks. // ProcessBlock defines the function to call with any solved blocks.
// It typically must run the provided block through the same set of // It typically must run the provided block through the same set of
// rules and handling as any other block coming from the network. // 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 // ConnectedCount defines the function to use to obtain how many other
// peers the server is connected to. This is used by the automatic // 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 // Process this block using the same rules as blocks coming from other
// nodes. This will in turn relay it to the network like normal. // 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 { if err != nil {
// Anything other than a rule violation is an unexpected error, // Anything other than a rule violation is an unexpected error,
// so log that error as an internal 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 "+ log.Errorf("Unexpected error while processing "+
"block submitted via CPU miner: %v", err) "block submitted via CPU miner: %v", err)
return false return false
@ -218,7 +218,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32,
// Create some convenience variables. // Create some convenience variables.
header := &msgBlock.Header header := &msgBlock.Header
targetDifficulty := blockchain.CompactToBig(header.Bits) targetDifficulty := blockdag.CompactToBig(header.Bits)
// Initial state. // Initial state.
lastGenerated := time.Now() 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 // The block is solved when the new block hash is less
// than the target difficulty. Yay! // than the target difficulty. Yay!
if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 { if blockdag.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
m.updateHashes <- hashesCompleted m.updateHashes <- hashesCompleted
return true return true
} }

View File

@ -9,7 +9,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/txscript" "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 // 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 // in viewB. It will replace any entries in viewB which also exist in viewA
// if the entry in viewA is spent. // 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() viewAEntries := viewA.Entries()
for outpoint, entryB := range viewB.Entries() { for outpoint, entryB := range viewB.Entries() {
if entryA, exists := viewAEntries[outpoint]; !exists || if entryA, exists := viewAEntries[outpoint]; !exists ||
@ -273,7 +273,7 @@ func createCoinbaseTx(params *chaincfg.Params, coinbaseScript []byte, nextBlockH
Sequence: wire.MaxTxInSequenceNum, Sequence: wire.MaxTxInSequenceNum,
}) })
tx.AddTxOut(&wire.TxOut{ tx.AddTxOut(&wire.TxOut{
Value: blockchain.CalcBlockSubsidy(nextBlockHeight, params), Value: blockdag.CalcBlockSubsidy(nextBlockHeight, params),
PkScript: pkScript, PkScript: pkScript,
}) })
return btcutil.NewTx(tx), nil 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 // spendTransaction updates the passed view by marking the inputs to the passed
// transaction as spent. It also adds all outputs in the passed transaction // transaction as spent. It also adds all outputs in the passed transaction
// which are not provably unspendable as available unspent transaction outputs. // 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 { for _, txIn := range tx.MsgTx().TxIn {
entry := utxoView.LookupEntry(txIn.PreviousOutPoint) entry := utxoView.LookupEntry(txIn.PreviousOutPoint)
if entry != nil { 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 // 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 // the median timestamp of the last several blocks per the chain consensus
// rules. // rules.
func MinimumMedianTime(chainState *blockchain.BestState) time.Time { func MinimumMedianTime(chainState *blockdag.BestState) time.Time {
return chainState.MedianTime.Add(time.Second) return chainState.MedianTime.Add(time.Second)
} }
// medianAdjustedTime returns the current time adjusted to ensure it is at least // 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 // one second after the median timestamp of the last several blocks per the
// chain consensus rules. // 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 // The timestamp for the block must not be before the median timestamp
// of the last several blocks. Thus, choose the maximum between the // of the last several blocks. Thus, choose the maximum between the
// current time and one second after the past median time. The current // current time and one second after the past median time. The current
@ -342,8 +342,8 @@ type BlkTmplGenerator struct {
policy *Policy policy *Policy
chainParams *chaincfg.Params chainParams *chaincfg.Params
txSource TxSource txSource TxSource
chain *blockchain.BlockChain chain *blockdag.BlockChain
timeSource blockchain.MedianTimeSource timeSource blockdag.MedianTimeSource
sigCache *txscript.SigCache sigCache *txscript.SigCache
} }
@ -354,8 +354,8 @@ type BlkTmplGenerator struct {
// templates are built on top of the current best chain and adhere to the // templates are built on top of the current best chain and adhere to the
// consensus rules. // consensus rules.
func NewBlkTmplGenerator(policy *Policy, params *chaincfg.Params, func NewBlkTmplGenerator(policy *Policy, params *chaincfg.Params,
txSource TxSource, chain *blockchain.BlockChain, txSource TxSource, chain *blockdag.BlockChain,
timeSource blockchain.MedianTimeSource, timeSource blockdag.MedianTimeSource,
sigCache *txscript.SigCache) *BlkTmplGenerator { sigCache *txscript.SigCache) *BlkTmplGenerator {
return &BlkTmplGenerator{ return &BlkTmplGenerator{
@ -453,7 +453,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*Bloc
if err != nil { if err != nil {
return nil, err return nil, err
} }
numCoinbaseSigOps := int64(blockchain.CountSigOps(coinbaseTx)) numCoinbaseSigOps := int64(blockdag.CountSigOps(coinbaseTx))
// Get the current source transactions and create a priority queue to // Get the current source transactions and create a priority queue to
// hold the transactions which are ready for inclusion into a block // hold the transactions which are ready for inclusion into a block
@ -471,7 +471,7 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress btcutil.Address) (*Bloc
// avoided. // avoided.
blockTxns := make([]*btcutil.Tx, 0, len(sourceTxns)) blockTxns := make([]*btcutil.Tx, 0, len(sourceTxns))
blockTxns = append(blockTxns, coinbaseTx) blockTxns = append(blockTxns, coinbaseTx)
blockUtxos := blockchain.NewUtxoViewpoint() blockUtxos := blockdag.NewUtxoViewpoint()
// dependers is used to track transactions which depend on another // dependers is used to track transactions which depend on another
// transaction in the source pool. This, in conjunction with the // 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 // A block can't have more than one coinbase or contain
// non-finalized transactions. // non-finalized transactions.
tx := txDesc.Tx tx := txDesc.Tx
if blockchain.IsCoinBase(tx) { if blockdag.IsCoinBase(tx) {
log.Tracef("Skipping coinbase tx %s", tx.Hash()) log.Tracef("Skipping coinbase tx %s", tx.Hash())
continue continue
} }
if !blockchain.IsFinalizedTransaction(tx, nextBlockHeight, if !blockdag.IsFinalizedTransaction(tx, nextBlockHeight,
g.timeSource.AdjustedTime()) { g.timeSource.AdjustedTime()) {
log.Tracef("Skipping non-finalized tx %s", tx.Hash()) log.Tracef("Skipping non-finalized tx %s", tx.Hash())
@ -615,15 +615,15 @@ mempoolLoop:
// Enforce maximum signature operations per block. Also check // Enforce maximum signature operations per block. Also check
// for overflow. // for overflow.
numSigOps := int64(blockchain.CountSigOps(tx)) numSigOps := int64(blockdag.CountSigOps(tx))
if blockSigOps+numSigOps < blockSigOps || if blockSigOps+numSigOps < blockSigOps ||
blockSigOps+numSigOps > blockchain.MaxSigOpsPerBlock { blockSigOps+numSigOps > blockdag.MaxSigOpsPerBlock {
log.Tracef("Skipping tx %s because it would exceed "+ log.Tracef("Skipping tx %s because it would exceed "+
"the maximum sigops per block", tx.Hash()) "the maximum sigops per block", tx.Hash())
logSkippedDeps(tx, deps) logSkippedDeps(tx, deps)
continue continue
} }
numP2SHSigOps, err := blockchain.CountP2SHSigOps(tx, false, numP2SHSigOps, err := blockdag.CountP2SHSigOps(tx, false,
blockUtxos) blockUtxos)
if err != nil { if err != nil {
log.Tracef("Skipping tx %s due to error in "+ log.Tracef("Skipping tx %s due to error in "+
@ -633,7 +633,7 @@ mempoolLoop:
} }
numSigOps += int64(numP2SHSigOps) numSigOps += int64(numP2SHSigOps)
if blockSigOps+numSigOps < blockSigOps || if blockSigOps+numSigOps < blockSigOps ||
blockSigOps+numSigOps > blockchain.MaxSigOpsPerBlock { blockSigOps+numSigOps > blockdag.MaxSigOpsPerBlock {
log.Tracef("Skipping tx %s because it would "+ log.Tracef("Skipping tx %s because it would "+
"exceed the maximum sigops per block", tx.Hash()) "exceed the maximum sigops per block", tx.Hash())
logSkippedDeps(tx, deps) logSkippedDeps(tx, deps)
@ -686,7 +686,7 @@ mempoolLoop:
// Ensure the transaction inputs pass all of the necessary // Ensure the transaction inputs pass all of the necessary
// preconditions before allowing it to be added to the block. // preconditions before allowing it to be added to the block.
_, err = blockchain.CheckTransactionInputs(tx, nextBlockHeight, _, err = blockdag.CheckTransactionInputs(tx, nextBlockHeight,
blockUtxos, g.chainParams) blockUtxos, g.chainParams)
if err != nil { if err != nil {
log.Tracef("Skipping tx %s due to error in "+ log.Tracef("Skipping tx %s due to error in "+
@ -694,7 +694,7 @@ mempoolLoop:
logSkippedDeps(tx, deps) logSkippedDeps(tx, deps)
continue continue
} }
err = blockchain.ValidateTransactionScripts(tx, blockUtxos, err = blockdag.ValidateTransactionScripts(tx, blockUtxos,
txscript.StandardVerifyFlags, g.sigCache) txscript.StandardVerifyFlags, g.sigCache)
if err != nil { if err != nil {
log.Tracef("Skipping tx %s due to error in "+ log.Tracef("Skipping tx %s due to error in "+
@ -760,7 +760,7 @@ mempoolLoop:
} }
// Create a new block ready to be solved. // Create a new block ready to be solved.
merkles := blockchain.BuildMerkleTreeStore(blockTxns) merkles := blockdag.BuildMerkleTreeStore(blockTxns)
var msgBlock wire.MsgBlock var msgBlock wire.MsgBlock
msgBlock.Header = wire.BlockHeader{ msgBlock.Header = wire.BlockHeader{
Version: nextBlockVersion, Version: nextBlockVersion,
@ -787,7 +787,7 @@ mempoolLoop:
log.Debugf("Created new block template (%d transactions, %d in fees, "+ log.Debugf("Created new block template (%d transactions, %d in fees, "+
"%d signature operations, %d bytes, target difficulty %064x)", "%d signature operations, %d bytes, target difficulty %064x)",
len(msgBlock.Transactions), totalFees, blockSigOps, blockSize, len(msgBlock.Transactions), totalFees, blockSigOps, blockSize,
blockchain.CompactToBig(msgBlock.Header.Bits)) blockdag.CompactToBig(msgBlock.Header.Bits))
return &BlockTemplate{ return &BlockTemplate{
Block: &msgBlock, Block: &msgBlock,
@ -832,11 +832,11 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight
if err != nil { if err != nil {
return err return err
} }
if len(coinbaseScript) > blockchain.MaxCoinbaseScriptLen { if len(coinbaseScript) > blockdag.MaxCoinbaseScriptLen {
return fmt.Errorf("coinbase transaction script length "+ return fmt.Errorf("coinbase transaction script length "+
"of %d is out of range (min: %d, max: %d)", "of %d is out of range (min: %d, max: %d)",
len(coinbaseScript), blockchain.MinCoinbaseScriptLen, len(coinbaseScript), blockdag.MinCoinbaseScriptLen,
blockchain.MaxCoinbaseScriptLen) blockdag.MaxCoinbaseScriptLen)
} }
msgBlock.Transactions[0].TxIn[0].SignatureScript = coinbaseScript 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. // Recalculate the merkle root with the updated extra nonce.
block := btcutil.NewBlock(msgBlock) block := btcutil.NewBlock(msgBlock)
merkles := blockchain.BuildMerkleTreeStore(block.Transactions()) merkles := blockdag.BuildMerkleTreeStore(block.Transactions())
msgBlock.Header.MerkleRoot = *merkles[len(merkles)-1] msgBlock.Header.MerkleRoot = *merkles[len(merkles)-1]
return nil return nil
} }
@ -857,7 +857,7 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight
// treated as immutable since it is shared by all callers. // treated as immutable since it is shared by all callers.
// //
// This function is safe for concurrent access. // This function is safe for concurrent access.
func (g *BlkTmplGenerator) BestSnapshot() *blockchain.BestState { func (g *BlkTmplGenerator) BestSnapshot() *blockdag.BestState {
return g.chain.BestSnapshot() return g.chain.BestSnapshot()
} }

View File

@ -5,7 +5,7 @@
package mining package mining
import ( import (
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/wire"
"github.com/daglabs/btcutil" "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 // 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, // which are currently in the mempool and hence not mined into a block yet,
// contribute no additional input age to the transaction. // 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 var totalInputAge float64
for _, txIn := range tx.TxIn { for _, txIn := range tx.TxIn {
// Don't attempt to accumulate the total input age if the // 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). // of each of its input values multiplied by their age (# of confirmations).
// Thus, the final formula for the priority is: // Thus, the final formula for the priority is:
// sum(inputValue * inputAge) / adjustedTxSize // 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 // In order to encourage spending multiple old unspent transaction
// outputs thereby reducing the total set, don't count the constant // outputs thereby reducing the total set, don't count the constant
// overhead for each input as well as enough bytes of the signature // overhead for each input as well as enough bytes of the signature

View File

@ -8,7 +8,7 @@ import (
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/wire"
"github.com/daglabs/btcutil" "github.com/daglabs/btcutil"
@ -42,12 +42,12 @@ func hexToBytes(s string) []byte {
// provided source transactions as if there were available at the respective // provided source transactions as if there were available at the respective
// block height specified in the heights slice. The length of the source txns // block height specified in the heights slice. The length of the source txns
// and source tx heights must match or it will panic. // 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) { if len(sourceTxns) != len(sourceTxHeights) {
panic("each transaction must have its block height specified") panic("each transaction must have its block height specified")
} }
view := blockchain.NewUtxoViewpoint() view := blockdag.NewUtxoViewpoint()
for i, tx := range sourceTxns { for i, tx := range sourceTxns {
view.AddTxOuts(btcutil.NewTx(tx), sourceTxHeights[i]) view.AddTxOuts(btcutil.NewTx(tx), sourceTxHeights[i])
} }
@ -119,7 +119,7 @@ func TestCalcPriority(t *testing.T) {
tests := []struct { tests := []struct {
name string // test description name string // test description
tx *wire.MsgTx // tx to calc priority for tx *wire.MsgTx // tx to calc priority for
utxoView *blockchain.UtxoViewpoint // inputs to tx utxoView *blockdag.UtxoViewpoint // inputs to tx
nextHeight int32 // height for priority calc nextHeight int32 // height for priority calc
want float64 // expected priority want float64 // expected priority
}{ }{

View File

@ -5,7 +5,7 @@
package netsync package netsync
import ( import (
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/mempool" "github.com/daglabs/btcd/mempool"
@ -30,7 +30,7 @@ type PeerNotifier interface {
// Config is a configuration struct used to initialize a new SyncManager. // Config is a configuration struct used to initialize a new SyncManager.
type Config struct { type Config struct {
PeerNotifier PeerNotifier PeerNotifier PeerNotifier
Chain *blockchain.BlockChain Chain *blockdag.BlockChain
TxMemPool *mempool.TxPool TxMemPool *mempool.TxPool
ChainParams *chaincfg.Params ChainParams *chaincfg.Params

View File

@ -11,7 +11,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
@ -103,7 +103,7 @@ type processBlockResponse struct {
// way to call ProcessBlock on the internal block chain instance. // way to call ProcessBlock on the internal block chain instance.
type processBlockMsg struct { type processBlockMsg struct {
block *btcutil.Block block *btcutil.Block
flags blockchain.BehaviorFlags flags blockdag.BehaviorFlags
reply chan processBlockResponse reply chan processBlockResponse
} }
@ -147,7 +147,7 @@ type SyncManager struct {
peerNotifier PeerNotifier peerNotifier PeerNotifier
started int32 started int32
shutdown int32 shutdown int32
chain *blockchain.BlockChain chain *blockdag.BlockChain
txMemPool *mempool.TxPool txMemPool *mempool.TxPool
chainParams *chaincfg.Params chainParams *chaincfg.Params
progressLogger *blockProgressLogger progressLogger *blockProgressLogger
@ -521,13 +521,13 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
// since it is needed to verify the next round of headers links // since it is needed to verify the next round of headers links
// properly. // properly.
isCheckpointBlock := false isCheckpointBlock := false
behaviorFlags := blockchain.BFNone behaviorFlags := blockdag.BFNone
if sm.headersFirstMode { if sm.headersFirstMode {
firstNodeEl := sm.headerList.Front() firstNodeEl := sm.headerList.Front()
if firstNodeEl != nil { if firstNodeEl != nil {
firstNode := firstNodeEl.Value.(*headerNode) firstNode := firstNodeEl.Value.(*headerNode)
if blockHash.IsEqual(firstNode.hash) { if blockHash.IsEqual(firstNode.hash) {
behaviorFlags |= blockchain.BFFastAdd behaviorFlags |= blockdag.BFFastAdd
if firstNode.hash.IsEqual(sm.nextCheckpoint.Hash) { if firstNode.hash.IsEqual(sm.nextCheckpoint.Hash) {
isCheckpointBlock = true isCheckpointBlock = true
} else { } else {
@ -551,7 +551,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
// rejected as opposed to something actually going wrong, so log // rejected as opposed to something actually going wrong, so log
// it as such. Otherwise, something really did go wrong, so log // it as such. Otherwise, something really did go wrong, so log
// it as an actual error. // 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, log.Infof("Rejected block %v from %s: %v", blockHash,
peer, err) peer, err)
} else { } else {
@ -590,9 +590,9 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
// Extraction is only attempted if the block's version is // Extraction is only attempted if the block's version is
// high enough (ver 2+). // high enough (ver 2+).
header := &bmsg.block.MsgBlock().Header header := &bmsg.block.MsgBlock().Header
if blockchain.ShouldHaveSerializedBlockHeight(header) { if blockdag.ShouldHaveSerializedBlockHeight(header) {
coinbaseTx := bmsg.block.Transactions()[0] coinbaseTx := bmsg.block.Transactions()[0]
cbHeight, err := blockchain.ExtractCoinbaseHeight(coinbaseTx) cbHeight, err := blockdag.ExtractCoinbaseHeight(coinbaseTx)
if err != nil { if err != nil {
log.Warnf("Unable to extract height from "+ log.Warnf("Unable to extract height from "+
"coinbase tx: %v", err) "coinbase tx: %v", err)
@ -663,7 +663,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
prevHash := sm.nextCheckpoint.Hash prevHash := sm.nextCheckpoint.Hash
sm.nextCheckpoint = sm.findNextHeaderCheckpoint(prevHeight) sm.nextCheckpoint = sm.findNextHeaderCheckpoint(prevHeight)
if sm.nextCheckpoint != nil { if sm.nextCheckpoint != nil {
locator := blockchain.BlockLocator([]*chainhash.Hash{prevHash}) locator := blockdag.BlockLocator([]*chainhash.Hash{prevHash})
err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash) err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash)
if err != nil { if err != nil {
log.Warnf("Failed to send getheaders message to "+ log.Warnf("Failed to send getheaders message to "+
@ -682,7 +682,7 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) {
sm.headersFirstMode = false sm.headersFirstMode = false
sm.headerList.Init() sm.headerList.Init()
log.Infof("Reached the final checkpoint -- switching to normal mode") 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) err = peer.PushGetBlocksMsg(locator, &zeroHash)
if err != nil { if err != nil {
log.Warnf("Failed to send getblocks message to peer %s: %v", 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 // This header is not a checkpoint, so request the next batch of
// headers starting from the latest known header and ending with the // headers starting from the latest known header and ending with the
// next checkpoint. // next checkpoint.
locator := blockchain.BlockLocator([]*chainhash.Hash{finalHash}) locator := blockdag.BlockLocator([]*chainhash.Hash{finalHash})
err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash) err := peer.PushGetHeadersMsg(locator, sm.nextCheckpoint.Hash)
if err != nil { if err != nil {
log.Warnf("Failed to send getheaders message to "+ log.Warnf("Failed to send getheaders message to "+
@ -1165,11 +1165,11 @@ out:
// handleBlockchainNotification handles notifications from blockchain. It does // handleBlockchainNotification handles notifications from blockchain. It does
// things such as request orphan block parents and relay accepted blocks to // things such as request orphan block parents and relay accepted blocks to
// connected peers. // connected peers.
func (sm *SyncManager) handleBlockchainNotification(notification *blockchain.Notification) { func (sm *SyncManager) handleBlockchainNotification(notification *blockdag.Notification) {
switch notification.Type { switch notification.Type {
// A block has been accepted into the block chain. Relay it to other // A block has been accepted into the block chain. Relay it to other
// peers. // peers.
case blockchain.NTBlockAccepted: case blockdag.NTBlockAccepted:
// Don't relay if we are not current. Other peers that are // Don't relay if we are not current. Other peers that are
// current should already know about it. // current should already know about it.
if !sm.current() { if !sm.current() {
@ -1187,7 +1187,7 @@ func (sm *SyncManager) handleBlockchainNotification(notification *blockchain.Not
sm.peerNotifier.RelayInventory(iv, block.MsgBlock().Header) sm.peerNotifier.RelayInventory(iv, block.MsgBlock().Header)
// A block has been connected to the main block chain. // A block has been connected to the main block chain.
case blockchain.NTBlockConnected: case blockdag.NTBlockConnected:
block, ok := notification.Data.(*btcutil.Block) block, ok := notification.Data.(*btcutil.Block)
if !ok { if !ok {
log.Warnf("Chain connected notification is not a block.") 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. // A block has been disconnected from the main block chain.
case blockchain.NTBlockDisconnected: case blockdag.NTBlockDisconnected:
block, ok := notification.Data.(*btcutil.Block) block, ok := notification.Data.(*btcutil.Block)
if !ok { if !ok {
log.Warnf("Chain disconnected notification is not a block.") 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 // ProcessBlock makes use of ProcessBlock on an internal instance of a block
// chain. // 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) reply := make(chan processBlockResponse, 1)
sm.msgChan <- processBlockMsg{block: block, flags: flags, reply: reply} sm.msgChan <- processBlockMsg{block: block, flags: flags, reply: reply}
response := <-reply response := <-reply

View File

@ -18,7 +18,7 @@ import (
"time" "time"
"github.com/btcsuite/go-socks/socks" "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"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/wire" "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. // and stop hash. It will ignore back-to-back duplicate requests.
// //
// This function is safe for concurrent access. // 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, // Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getblocks requests. // to use for filtering duplicate getblocks requests.
var beginHash *chainhash.Hash 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. // and stop hash. It will ignore back-to-back duplicate requests.
// //
// This function is safe for concurrent access. // 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, // Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getheaders requests. // to use for filtering duplicate getheaders requests.
var beginHash *chainhash.Hash var beginHash *chainhash.Hash

View File

@ -7,7 +7,7 @@ package main
import ( import (
"sync/atomic" "sync/atomic"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/mempool" "github.com/daglabs/btcd/mempool"
"github.com/daglabs/btcd/netsync" "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 // This function is safe for concurrent access and is part of the
// rpcserverSyncManager interface implementation. // 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) return b.syncMgr.ProcessBlock(block, flags)
} }

View File

@ -28,8 +28,8 @@ import (
"time" "time"
"github.com/btcsuite/websocket" "github.com/btcsuite/websocket"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/btcec"
"github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/btcjson"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
@ -334,12 +334,12 @@ type gbtWorkState struct {
minTimestamp time.Time minTimestamp time.Time
template *mining.BlockTemplate template *mining.BlockTemplate
notifyMap map[chainhash.Hash]map[int64]chan struct{} 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 // newGbtWorkState returns a new instance of a gbtWorkState with all internal
// fields initialized and ready to use. // fields initialized and ready to use.
func newGbtWorkState(timeSource blockchain.MedianTimeSource) *gbtWorkState { func newGbtWorkState(timeSource blockdag.MedianTimeSource) *gbtWorkState {
return &gbtWorkState{ return &gbtWorkState{
notifyMap: make(map[chainhash.Hash]map[int64]chan struct{}), notifyMap: make(map[chainhash.Hash]map[int64]chan struct{}),
timeSource: timeSource, timeSource: timeSource,
@ -639,7 +639,7 @@ func handleDebugLevel(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
func createVinList(mtx *wire.MsgTx) []btcjson.Vin { func createVinList(mtx *wire.MsgTx) []btcjson.Vin {
// Coinbase transactions only have a single txin by definition. // Coinbase transactions only have a single txin by definition.
vinList := make([]btcjson.Vin, len(mtx.TxIn)) vinList := make([]btcjson.Vin, len(mtx.TxIn))
if blockchain.IsCoinBaseTx(mtx) { if blockdag.IsCoinBaseTx(mtx) {
txIn := mtx.TxIn[0] txIn := mtx.TxIn[0]
vinList[0].Coinbase = hex.EncodeToString(txIn.SignatureScript) vinList[0].Coinbase = hex.EncodeToString(txIn.SignatureScript)
vinList[0].Sequence = txIn.Sequence 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 // 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 // work limit directly because the block difficulty is encoded in a block
// with the compact form which loses precision. // with the compact form which loses precision.
max := blockchain.CompactToBig(params.PowLimitBits) max := blockdag.CompactToBig(params.PowLimitBits)
target := blockchain.CompactToBig(bits) target := blockdag.CompactToBig(bits)
difficulty := new(big.Rat).SetFrac(max, target) difficulty := new(big.Rat).SetFrac(max, target)
outString := difficulty.FloatString(8) 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 // softForkStatus converts a ThresholdState state into a human readable string
// corresponding to the particular state. // corresponding to the particular state.
func softForkStatus(state blockchain.ThresholdState) (string, error) { func softForkStatus(state blockdag.ThresholdState) (string, error) {
switch state { switch state {
case blockchain.ThresholdDefined: case blockdag.ThresholdDefined:
return "defined", nil return "defined", nil
case blockchain.ThresholdStarted: case blockdag.ThresholdStarted:
return "started", nil return "started", nil
case blockchain.ThresholdLockedIn: case blockdag.ThresholdLockedIn:
return "lockedin", nil return "lockedin", nil
case blockchain.ThresholdActive: case blockdag.ThresholdActive:
return "active", nil return "active", nil
case blockchain.ThresholdFailed: case blockdag.ThresholdFailed:
return "failed", nil return "failed", nil
default: default:
return "", fmt.Errorf("unknown deployment state: %v", state) return "", fmt.Errorf("unknown deployment state: %v", state)
@ -1550,7 +1550,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
template = blkTemplate template = blkTemplate
msgBlock = template.Block msgBlock = template.Block
targetDifficulty = fmt.Sprintf("%064x", 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 // Get the minimum allowed timestamp for the block based on the
// median timestamp of the last several blocks per the chain // 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. // Update the merkle root.
block := btcutil.NewBlock(template.Block) block := btcutil.NewBlock(template.Block)
merkles := blockchain.BuildMerkleTreeStore(block.Transactions()) merkles := blockdag.BuildMerkleTreeStore(block.Transactions())
template.Block.Header.MerkleRoot = *merkles[len(merkles)-1] template.Block.Header.MerkleRoot = *merkles[len(merkles)-1]
} }
// Set locals for convenience. // Set locals for convenience.
msgBlock = template.Block msgBlock = template.Block
targetDifficulty = fmt.Sprintf("%064x", 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 // Update the time of the block template to the current time
// while accounting for the median time of the past several // while accounting for the median time of the past several
@ -1640,7 +1640,7 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
msgBlock := template.Block msgBlock := template.Block
header := &msgBlock.Header header := &msgBlock.Header
adjustedTime := state.timeSource.AdjustedTime() adjustedTime := state.timeSource.AdjustedTime()
maxTime := adjustedTime.Add(time.Second * blockchain.MaxTimeOffsetSeconds) maxTime := adjustedTime.Add(time.Second * blockdag.MaxTimeOffsetSeconds)
if header.Timestamp.After(maxTime) { if header.Timestamp.After(maxTime) {
return nil, &btcjson.RPCError{ return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCOutOfRange, Code: btcjson.ErrRPCOutOfRange,
@ -1704,14 +1704,14 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
// implied by the included or omission of fields: // implied by the included or omission of fields:
// Including MinTime -> time/decrement // Including MinTime -> time/decrement
// Omitting CoinbaseTxn -> coinbase, generation // 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) templateID := encodeTemplateID(state.prevHash, state.lastGenerated)
reply := btcjson.GetBlockTemplateResult{ reply := btcjson.GetBlockTemplateResult{
Bits: strconv.FormatInt(int64(header.Bits), 16), Bits: strconv.FormatInt(int64(header.Bits), 16),
CurTime: header.Timestamp.Unix(), CurTime: header.Timestamp.Unix(),
Height: int64(template.Height), Height: int64(template.Height),
PreviousHash: header.PrevBlock.String(), PreviousHash: header.PrevBlock.String(),
SigOpLimit: blockchain.MaxSigOpsPerBlock, SigOpLimit: blockdag.MaxSigOpsPerBlock,
SizeLimit: wire.MaxBlockPayload, SizeLimit: wire.MaxBlockPayload,
Transactions: transactions, Transactions: transactions,
Version: header.Version, Version: header.Version,
@ -1951,89 +1951,89 @@ func handleGetBlockTemplateRequest(s *rpcServer, request *btcjson.TemplateReques
func chainErrToGBTErrString(err error) string { func chainErrToGBTErrString(err error) string {
// When the passed error is not a RuleError, just return a generic // When the passed error is not a RuleError, just return a generic
// rejected string with the error text. // rejected string with the error text.
ruleErr, ok := err.(blockchain.RuleError) ruleErr, ok := err.(blockdag.RuleError)
if !ok { if !ok {
return "rejected: " + err.Error() return "rejected: " + err.Error()
} }
switch ruleErr.ErrorCode { switch ruleErr.ErrorCode {
case blockchain.ErrDuplicateBlock: case blockdag.ErrDuplicateBlock:
return "duplicate" return "duplicate"
case blockchain.ErrBlockTooBig: case blockdag.ErrBlockTooBig:
return "bad-blk-length" return "bad-blk-length"
case blockchain.ErrBlockVersionTooOld: case blockdag.ErrBlockVersionTooOld:
return "bad-version" return "bad-version"
case blockchain.ErrInvalidTime: case blockdag.ErrInvalidTime:
return "bad-time" return "bad-time"
case blockchain.ErrTimeTooOld: case blockdag.ErrTimeTooOld:
return "time-too-old" return "time-too-old"
case blockchain.ErrTimeTooNew: case blockdag.ErrTimeTooNew:
return "time-too-new" return "time-too-new"
case blockchain.ErrDifficultyTooLow: case blockdag.ErrDifficultyTooLow:
return "bad-diffbits" return "bad-diffbits"
case blockchain.ErrUnexpectedDifficulty: case blockdag.ErrUnexpectedDifficulty:
return "bad-diffbits" return "bad-diffbits"
case blockchain.ErrHighHash: case blockdag.ErrHighHash:
return "high-hash" return "high-hash"
case blockchain.ErrBadMerkleRoot: case blockdag.ErrBadMerkleRoot:
return "bad-txnmrklroot" return "bad-txnmrklroot"
case blockchain.ErrBadCheckpoint: case blockdag.ErrBadCheckpoint:
return "bad-checkpoint" return "bad-checkpoint"
case blockchain.ErrForkTooOld: case blockdag.ErrForkTooOld:
return "fork-too-old" return "fork-too-old"
case blockchain.ErrCheckpointTimeTooOld: case blockdag.ErrCheckpointTimeTooOld:
return "checkpoint-time-too-old" return "checkpoint-time-too-old"
case blockchain.ErrNoTransactions: case blockdag.ErrNoTransactions:
return "bad-txns-none" return "bad-txns-none"
case blockchain.ErrNoTxInputs: case blockdag.ErrNoTxInputs:
return "bad-txns-noinputs" return "bad-txns-noinputs"
case blockchain.ErrNoTxOutputs: case blockdag.ErrNoTxOutputs:
return "bad-txns-nooutputs" return "bad-txns-nooutputs"
case blockchain.ErrTxTooBig: case blockdag.ErrTxTooBig:
return "bad-txns-size" return "bad-txns-size"
case blockchain.ErrBadTxOutValue: case blockdag.ErrBadTxOutValue:
return "bad-txns-outputvalue" return "bad-txns-outputvalue"
case blockchain.ErrDuplicateTxInputs: case blockdag.ErrDuplicateTxInputs:
return "bad-txns-dupinputs" return "bad-txns-dupinputs"
case blockchain.ErrBadTxInput: case blockdag.ErrBadTxInput:
return "bad-txns-badinput" return "bad-txns-badinput"
case blockchain.ErrMissingTxOut: case blockdag.ErrMissingTxOut:
return "bad-txns-missinginput" return "bad-txns-missinginput"
case blockchain.ErrUnfinalizedTx: case blockdag.ErrUnfinalizedTx:
return "bad-txns-unfinalizedtx" return "bad-txns-unfinalizedtx"
case blockchain.ErrDuplicateTx: case blockdag.ErrDuplicateTx:
return "bad-txns-duplicate" return "bad-txns-duplicate"
case blockchain.ErrOverwriteTx: case blockdag.ErrOverwriteTx:
return "bad-txns-overwrite" return "bad-txns-overwrite"
case blockchain.ErrImmatureSpend: case blockdag.ErrImmatureSpend:
return "bad-txns-maturity" return "bad-txns-maturity"
case blockchain.ErrSpendTooHigh: case blockdag.ErrSpendTooHigh:
return "bad-txns-highspend" return "bad-txns-highspend"
case blockchain.ErrBadFees: case blockdag.ErrBadFees:
return "bad-txns-fees" return "bad-txns-fees"
case blockchain.ErrTooManySigOps: case blockdag.ErrTooManySigOps:
return "high-sigops" return "high-sigops"
case blockchain.ErrFirstTxNotCoinbase: case blockdag.ErrFirstTxNotCoinbase:
return "bad-txns-nocoinbase" return "bad-txns-nocoinbase"
case blockchain.ErrMultipleCoinbases: case blockdag.ErrMultipleCoinbases:
return "bad-txns-multicoinbase" return "bad-txns-multicoinbase"
case blockchain.ErrBadCoinbaseScriptLen: case blockdag.ErrBadCoinbaseScriptLen:
return "bad-cb-length" return "bad-cb-length"
case blockchain.ErrBadCoinbaseValue: case blockdag.ErrBadCoinbaseValue:
return "bad-cb-value" return "bad-cb-value"
case blockchain.ErrMissingCoinbaseHeight: case blockdag.ErrMissingCoinbaseHeight:
return "bad-cb-height" return "bad-cb-height"
case blockchain.ErrBadCoinbaseHeight: case blockdag.ErrBadCoinbaseHeight:
return "bad-cb-height" return "bad-cb-height"
case blockchain.ErrScriptMalformed: case blockdag.ErrScriptMalformed:
return "bad-script-malformed" return "bad-script-malformed"
case blockchain.ErrScriptValidation: case blockdag.ErrScriptValidation:
return "bad-script-validate" return "bad-script-validate"
case blockchain.ErrPreviousBlockUnknown: case blockdag.ErrPreviousBlockUnknown:
return "prev-blk-not-found" return "prev-blk-not-found"
case blockchain.ErrInvalidAncestorBlock: case blockdag.ErrInvalidAncestorBlock:
return "bad-prevblk" return "bad-prevblk"
case blockchain.ErrPrevBlockNotBest: case blockdag.ErrPrevBlockNotBest:
return "inconclusive-not-best-prvblk" 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 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) errStr := fmt.Sprintf("Failed to process block proposal: %v", err)
rpcsLog.Error(errStr) rpcsLog.Error(errStr)
return nil, &btcjson.RPCError{ return nil, &btcjson.RPCError{
@ -2407,7 +2407,7 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru
minTimestamp = header.Timestamp minTimestamp = header.Timestamp
maxTimestamp = minTimestamp maxTimestamp = minTimestamp
} else { } else {
totalWork.Add(totalWork, blockchain.CalcWork(header.Bits)) totalWork.Add(totalWork, blockdag.CalcWork(header.Bits))
if minTimestamp.After(header.Timestamp) { if minTimestamp.After(header.Timestamp) {
minTimestamp = header.Timestamp minTimestamp = header.Timestamp
@ -2658,7 +2658,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
confirmations = 0 confirmations = 0
value = txOut.Value value = txOut.Value
pkScript = txOut.PkScript pkScript = txOut.PkScript
isCoinbase = blockchain.IsCoinBaseTx(mtx) isCoinbase = blockdag.IsCoinBaseTx(mtx)
} else { } else {
out := wire.OutPoint{Hash: *txHash, Index: c.Vout} out := wire.OutPoint{Hash: *txHash, Index: c.Vout}
entry, err := s.cfg.Chain.FetchUtxoEntry(out) 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. // passed transaction.
func createVinListPrevOut(s *rpcServer, mtx *wire.MsgTx, chainParams *chaincfg.Params, vinExtra bool, filterAddrMap map[string]struct{}) ([]btcjson.VinPrevOut, error) { 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. // 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 // Only include the transaction if the filter map is empty
// because a coinbase input has no addresses and so would never // because a coinbase input has no addresses and so would never
// match a non-empty filter. // 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 // Process this block using the same rules as blocks coming from other
// nodes. This will in turn relay it to the network like normal. // 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 { if err != nil {
return fmt.Sprintf("rejected: %s", err.Error()), 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. // Level 1 does basic chain sanity checks.
if level > 0 { if level > 0 {
err := blockchain.CheckBlockSanity(block, err := blockdag.CheckBlockSanity(block,
s.cfg.ChainParams.PowLimit, s.cfg.TimeSource) s.cfg.ChainParams.PowLimit, s.cfg.TimeSource)
if err != nil { if err != nil {
rpcsLog.Errorf("Verify is unable to validate "+ rpcsLog.Errorf("Verify is unable to validate "+
@ -4158,7 +4158,7 @@ type rpcserverSyncManager interface {
// SubmitBlock submits the provided block to the network after // SubmitBlock submits the provided block to the network after
// processing it locally. // 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 pauses the sync manager until the returned channel is closed.
Pause() chan<- struct{} Pause() chan<- struct{}
@ -4197,8 +4197,8 @@ type rpcserverConfig struct {
// These fields allow the RPC server to interface with the local block // These fields allow the RPC server to interface with the local block
// chain data and state. // chain data and state.
TimeSource blockchain.MedianTimeSource TimeSource blockdag.MedianTimeSource
Chain *blockchain.BlockChain Chain *blockdag.BlockChain
ChainParams *chaincfg.Params ChainParams *chaincfg.Params
DB database.DB DB database.DB
@ -4252,9 +4252,9 @@ func newRPCServer(config *rpcserverConfig) (*rpcServer, error) {
// Callback for notifications from blockchain. It notifies clients that are // Callback for notifications from blockchain. It notifies clients that are
// long polling for changes or subscribed to websockets notifications. // 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 { switch notification.Type {
case blockchain.NTBlockAccepted: case blockdag.NTBlockAccepted:
block, ok := notification.Data.(*btcutil.Block) block, ok := notification.Data.(*btcutil.Block)
if !ok { if !ok {
rpcsLog.Warnf("Chain accepted notification is not a block.") 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. // their old block template to become stale.
s.gbtWorkState.NotifyBlockConnected(block.Hash()) s.gbtWorkState.NotifyBlockConnected(block.Hash())
case blockchain.NTBlockConnected: case blockdag.NTBlockConnected:
block, ok := notification.Data.(*btcutil.Block) block, ok := notification.Data.(*btcutil.Block)
if !ok { if !ok {
rpcsLog.Warnf("Chain connected notification is not a block.") 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. // Notify registered websocket clients of incoming block.
s.ntfnMgr.NotifyBlockConnected(block) s.ntfnMgr.NotifyBlockConnected(block)
case blockchain.NTBlockDisconnected: case blockdag.NTBlockDisconnected:
block, ok := notification.Data.(*btcutil.Block) block, ok := notification.Data.(*btcutil.Block)
if !ok { if !ok {
rpcsLog.Warnf("Chain disconnected notification is not a block.") rpcsLog.Warnf("Chain disconnected notification is not a block.")

View File

@ -22,7 +22,7 @@ import (
"golang.org/x/crypto/ripemd160" "golang.org/x/crypto/ripemd160"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/btcjson"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
@ -2156,7 +2156,7 @@ func rescanBlockFilter(filter *wsClientFilter, block *btcutil.Block, params *cha
added := false added := false
// Scan inputs if not a coinbase transaction. // Scan inputs if not a coinbase transaction.
if !blockchain.IsCoinBaseTx(msgTx) { if !blockdag.IsCoinBaseTx(msgTx) {
for _, input := range msgTx.TxIn { for _, input := range msgTx.TxIn {
if !filter.existsUnspentOutPoint(&input.PreviousOutPoint) { if !filter.existsUnspentOutPoint(&input.PreviousOutPoint) {
continue 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 // 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 // range of blocks. If this condition does not hold true, the JSON-RPC error
// for an unrecoverable reorganize is returned. // 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) { lastBlock *chainhash.Hash) ([]chainhash.Hash, error) {
hashList, err := chain.HeightRange(minBlock, maxBlock) hashList, err := chain.HeightRange(minBlock, maxBlock)

View File

@ -23,8 +23,8 @@ import (
"time" "time"
"github.com/daglabs/btcd/addrmgr" "github.com/daglabs/btcd/addrmgr"
"github.com/daglabs/btcd/blockchain" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockchain/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/chaincfg" "github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash" "github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/connmgr" "github.com/daglabs/btcd/connmgr"
@ -210,7 +210,7 @@ type server struct {
sigCache *txscript.SigCache sigCache *txscript.SigCache
rpcServer *rpcServer rpcServer *rpcServer
syncManager *netsync.SyncManager syncManager *netsync.SyncManager
chain *blockchain.BlockChain chain *blockdag.BlockChain
txMemPool *mempool.TxPool txMemPool *mempool.TxPool
cpuMiner *cpuminer.CPUMiner cpuMiner *cpuminer.CPUMiner
modifyRebroadcastInv chan interface{} modifyRebroadcastInv chan interface{}
@ -225,7 +225,7 @@ type server struct {
quit chan struct{} quit chan struct{}
nat NAT nat NAT
db database.DB db database.DB
timeSource blockchain.MedianTimeSource timeSource blockdag.MedianTimeSource
services wire.ServiceFlag services wire.ServiceFlag
// The following fields are used for optional indexes. They will be nil // 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), peerHeightsUpdate: make(chan updatePeerHeightsMsg),
nat: nat, nat: nat,
db: db, db: db,
timeSource: blockchain.NewMedianTime(), timeSource: blockdag.NewMedianTime(),
services: services, services: services,
sigCache: txscript.NewSigCache(cfg.SigCacheMaxSize), sigCache: txscript.NewSigCache(cfg.SigCacheMaxSize),
cfCheckptCaches: make(map[wire.FilterType][]cfHeaderKV), 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. // Create an index manager if any of the optional indexes are enabled.
var indexManager blockchain.IndexManager var indexManager blockdag.IndexManager
if len(indexes) > 0 { if len(indexes) > 0 {
indexManager = indexers.NewManager(db, indexes) 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. // Create a new block chain instance with the appropriate configuration.
var err error var err error
s.chain, err = blockchain.New(&blockchain.Config{ s.chain, err = blockdag.New(&blockdag.Config{
DB: s.db, DB: s.db,
Interrupt: interrupt, Interrupt: interrupt,
ChainParams: s.chainParams, ChainParams: s.chainParams,
@ -2533,7 +2533,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
FreeTxRelayLimit: cfg.FreeTxRelayLimit, FreeTxRelayLimit: cfg.FreeTxRelayLimit,
MaxOrphanTxs: cfg.MaxOrphanTxs, MaxOrphanTxs: cfg.MaxOrphanTxs,
MaxOrphanTxSize: defaultMaxOrphanTxSize, MaxOrphanTxSize: defaultMaxOrphanTxSize,
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, MaxSigOpsPerTx: blockdag.MaxSigOpsPerBlock / 5,
MinRelayTxFee: cfg.minRelayTxFee, MinRelayTxFee: cfg.minRelayTxFee,
MaxTxVersion: 2, MaxTxVersion: 2,
}, },
@ -2541,7 +2541,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
FetchUtxoView: s.chain.FetchUtxoView, FetchUtxoView: s.chain.FetchUtxoView,
BestHeight: func() int32 { return s.chain.BestSnapshot().Height }, BestHeight: func() int32 { return s.chain.BestSnapshot().Height },
MedianTimePast: func() time.Time { return s.chain.BestSnapshot().MedianTime }, 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) return s.chain.CalcSequenceLock(tx, view, true)
}, },
IsDeploymentActive: s.chain.IsDeploymentActive, IsDeploymentActive: s.chain.IsDeploymentActive,