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
// license that can be found in the LICENSE file.
package blockchain
package blockdag
import (
"fmt"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package blockchain_test
package blockdag_test
import (
"bytes"
@ -12,8 +12,8 @@ import (
"path/filepath"
"testing"
"github.com/daglabs/btcd/blockchain"
"github.com/daglabs/btcd/blockchain/fullblocktests"
"github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockdag/fullblocktests"
"github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/database"
@ -60,7 +60,7 @@ func isSupportedDbType(dbType string) bool {
// chainSetup is used to create a new db and chain instance with the genesis
// block already inserted. In addition to the new chain instance, it returns
// a teardown function the caller should invoke when done testing to clean up.
func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain, func(), error) {
func chainSetup(dbName string, params *chaincfg.Params) (*blockdag.BlockChain, func(), error) {
if !isSupportedDbType(testDbType) {
return nil, nil, fmt.Errorf("unsupported db type %v", testDbType)
}
@ -114,11 +114,11 @@ func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain,
paramsCopy := *params
// Create the main chain instance.
chain, err := blockchain.New(&blockchain.Config{
chain, err := blockdag.New(&blockdag.Config{
DB: db,
ChainParams: &paramsCopy,
Checkpoints: nil,
TimeSource: blockchain.NewMedianTime(),
TimeSource: blockdag.NewMedianTime(),
SigCache: txscript.NewSigCache(1000),
})
if err != nil {
@ -157,7 +157,7 @@ func TestFullBlocks(t *testing.T) {
item.Name, block.Hash(), blockHeight)
isMainChain, isOrphan, err := chain.ProcessBlock(block,
blockchain.BFNone)
blockdag.BFNone)
if err != nil {
t.Fatalf("block %q (hash %s, height %d) should "+
"have been accepted: %v", item.Name,
@ -190,7 +190,7 @@ func TestFullBlocks(t *testing.T) {
t.Logf("Testing block %s (hash %s, height %d)",
item.Name, block.Hash(), blockHeight)
_, _, err := chain.ProcessBlock(block, blockchain.BFNone)
_, _, err := chain.ProcessBlock(block, blockdag.BFNone)
if err == nil {
t.Fatalf("block %q (hash %s, height %d) should not "+
"have been accepted", item.Name, block.Hash(),
@ -199,7 +199,7 @@ func TestFullBlocks(t *testing.T) {
// Ensure the error code is of the expected type and the reject
// code matches the value specified in the test instance.
rerr, ok := err.(blockchain.RuleError)
rerr, ok := err.(blockdag.RuleError)
if !ok {
t.Fatalf("block %q (hash %s, height %d) returned "+
"unexpected error type -- got %T, want "+
@ -247,10 +247,10 @@ func TestFullBlocks(t *testing.T) {
t.Logf("Testing block %s (hash %s, height %d)",
item.Name, block.Hash(), blockHeight)
_, isOrphan, err := chain.ProcessBlock(block, blockchain.BFNone)
_, isOrphan, err := chain.ProcessBlock(block, blockdag.BFNone)
if err != nil {
// Ensure the error code is of the expected type.
if _, ok := err.(blockchain.RuleError); !ok {
if _, ok := err.(blockdag.RuleError); !ok {
t.Fatalf("block %q (hash %s, height %d) "+
"returned unexpected error type -- "+
"got %T, want blockchain.RuleError",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ var genesisCoinbaseTx = wire.MsgTx{
0x6b, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x65, 0x63, /* |k of sec|*/
0x6f, 0x6e, 0x64, 0x20, 0x62, 0x61, 0x69, 0x6c, /* |ond bail| */
0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/
0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
},
Sequence: 0xffffffff,
},
@ -48,7 +48,7 @@ var genesisCoinbaseTx = wire.MsgTx{
0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, /* |8..U....| */
0x12, 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, /* |..\8M...| */
0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, /* |.W.Lp+k.| */
0x1d, 0x5f, 0xac, /* |._.| */
0x1d, 0x5f, 0xac, /* |._.| */
},
},
},
@ -58,10 +58,10 @@ var genesisCoinbaseTx = wire.MsgTx{
// genesisHash is the hash of the first block in the block chain for the main
// network (genesis block).
var genesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
0x82, 0xdc, 0xbd, 0xe6, 0x88, 0x37, 0x74, 0x5b,
0x78, 0x6b, 0x03, 0x1d, 0xa3, 0x48, 0x3c, 0x45,
0x3f, 0xc3, 0x2e, 0xd4, 0x53, 0x5b, 0x6f, 0x26,
0x26, 0xb0, 0x48, 0x4f, 0x09, 0x00, 0x00, 0x00,
})
// genesisMerkleRoot is the hash of the first transaction in the genesis block
@ -77,12 +77,13 @@ var genesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet
// public transaction ledger for the main network.
var genesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: genesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 18:15:05 +0000 UTC
Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000]
Nonce: 0x7c2bac1d, // 2083236893
Version: 1,
NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: genesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(0x5b28c4c8, 0), // 2018-06-19 08:54:32 +0000 UTC
Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Nonce: 0xc0192550, // 2148484547
},
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
// regression test network (genesis block).
var regTestGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59,
0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf,
0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f,
0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f,
0x7c, 0x03, 0x27, 0x80, 0x78, 0xfc, 0xe8, 0xed,
0xcd, 0xfc, 0x3d, 0xe1, 0x63, 0x45, 0x4c, 0x03,
0x0f, 0xef, 0x38, 0x16, 0xec, 0x54, 0x61, 0x6f,
0xca, 0xc9, 0x58, 0x12, 0xb4, 0x6a, 0x15, 0x08,
})
// regTestGenesisMerkleRoot is the hash of the first transaction in the genesis
@ -105,12 +106,13 @@ var regTestGenesisMerkleRoot = genesisMerkleRoot
// as the public transaction ledger for the regression test network.
var regTestGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Nonce: 2,
Version: 1,
NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(0x5b28c636, 0), // 2018-06-19 09:00:38 +0000 UTC
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Nonce: 1,
},
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
// test network (version 3).
var testNet3GenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71,
0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae,
0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad,
0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00,
0x91, 0x1c, 0xe0, 0x47, 0x77, 0xad, 0x5e, 0xc5,
0x60, 0x10, 0x21, 0x32, 0x51, 0x1b, 0x39, 0x06,
0x24, 0xb3, 0xbf, 0x08, 0x8e, 0x04, 0x8c, 0xd3,
0x80, 0xb4, 0x83, 0x83, 0xed, 0x00, 0x00, 0x00,
})
// testNet3GenesisMerkleRoot is the hash of the first transaction in the genesis
@ -133,12 +135,13 @@ var testNet3GenesisMerkleRoot = genesisMerkleRoot
// serves as the public transaction ledger for the test network (version 3).
var testNet3GenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC
Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000]
Nonce: 0x18aea41a, // 414098458
Version: 1,
NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(0x5b28c706, 0), // 2018-06-19 09:04:06 +0000 UTC
Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Nonce: 0x802f1b3b, // 2150570811
},
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
// simulation test network.
var simNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a,
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
0x0d, 0x11, 0x6d, 0x5c, 0xbd, 0x86, 0x3e, 0x68,
0xc1, 0x5b, 0x71, 0xfe, 0x20, 0x70, 0x0f, 0xd0,
0x08, 0x49, 0x88, 0x1b, 0x32, 0xb5, 0xbd, 0x13,
0x17, 0xbe, 0x75, 0xe7, 0x29, 0x46, 0xdd, 0x03,
0x01, 0x92, 0x90, 0xf1, 0xca, 0x8a, 0x88, 0x11,
})
// simNetGenesisMerkleRoot is the hash of the first transaction in the genesis
@ -161,12 +164,13 @@ var simNetGenesisMerkleRoot = genesisMerkleRoot
// as the public transaction ledger for the simulation test network.
var simNetGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: simNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1401292357, 0), // 2014-05-28 15:52:37 +0000 UTC
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Nonce: 2,
Version: 1,
NumPrevBlocks: 0,
PrevBlocks: []chainhash.Hash{},
MerkleRoot: simNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(0x5b28c7ec, 0), // 2018-06-19 09:07:56 +0000 UTC
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Nonce: 0x9ffffffb, // 2684354555
},
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
// main network as of protocol version 60002.
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, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */
0x4b, 0x1e, 0x5e, 0x4a, 0x29, 0xab, 0x5f, 0x49, /* |K.^J)._I| */
0xff, 0xff, 0x00, 0x1d, 0x1d, 0xac, 0x2b, 0x7c, /* |......+|| */
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, 0xff, 0xff, /* |........| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */
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, /* |.....| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
}
// regTestGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the regression test network as of protocol version 60002.
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, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */
0x4b, 0x1e, 0x5e, 0x4a, 0xda, 0xe5, 0x49, 0x4d, /* |K.^J)._I| */
0xff, 0xff, 0x7f, 0x20, 0x02, 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, 0xff, 0xff, /* |........| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */
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, /* |.....| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
}
// testNet3GenesisBlockBytes are the wire encoded bytes for the genesis block of
// the test network (version 3) as of protocol version 60002.
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, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */
0x4b, 0x1e, 0x5e, 0x4a, 0xda, 0xe5, 0x49, 0x4d, /* |K.^J)._I| */
0xff, 0xff, 0x00, 0x1d, 0x1a, 0xa4, 0xae, 0x18, /* |......+|| */
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, 0xff, 0xff, /* |........| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */
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, /* |.....| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
}
// simNetGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the simulation test network as of protocol version 70002.
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, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */
0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */
0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */
0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */
0x4b, 0x1e, 0x5e, 0x4a, 0x45, 0x06, 0x86, 0x53, /* |K.^J)._I| */
0xff, 0xff, 0x7f, 0x20, 0x02, 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, 0xff, 0xff, /* |........| */
0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, 0x1d, /* |..M.....| */
0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */
0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */
0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */
0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */
0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */
0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */
0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */
0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */
0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */
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, /* |.....| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, /* |s.......| */
0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, /* |.*....CA| */
0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, /* |.g....UH| */
0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, /* |'.g..q0.| */
0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, /* |.\..(.9.| */
0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, /* |.yb...a.| */
0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, /* |.I..?L.8| */
0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, /* |..U.....| */
0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, /* |.\8M....| */
0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, /* |W.Lp+k..| */
0x5f, 0xac, 0x00, 0x00, 0x00, 0x00, /* |_.....| */
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

6
log.go
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@ import (
"time"
"github.com/btcsuite/go-socks/socks"
"github.com/daglabs/btcd/blockchain"
"github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/wire"
@ -904,7 +904,7 @@ func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, er
// and stop hash. It will ignore back-to-back duplicate requests.
//
// This function is safe for concurrent access.
func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
func (p *Peer) PushGetBlocksMsg(locator blockdag.BlockLocator, stopHash *chainhash.Hash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getblocks requests.
var beginHash *chainhash.Hash
@ -948,7 +948,7 @@ func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chain
// and stop hash. It will ignore back-to-back duplicate requests.
//
// This function is safe for concurrent access.
func (p *Peer) PushGetHeadersMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
func (p *Peer) PushGetHeadersMsg(locator blockdag.BlockLocator, stopHash *chainhash.Hash) error {
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getheaders requests.
var beginHash *chainhash.Hash

View File

@ -7,7 +7,7 @@ package main
import (
"sync/atomic"
"github.com/daglabs/btcd/blockchain"
"github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/chaincfg/chainhash"
"github.com/daglabs/btcd/mempool"
"github.com/daglabs/btcd/netsync"
@ -247,7 +247,7 @@ func (b *rpcSyncMgr) IsCurrent() bool {
//
// This function is safe for concurrent access and is part of the
// rpcserverSyncManager interface implementation.
func (b *rpcSyncMgr) SubmitBlock(block *btcutil.Block, flags blockchain.BehaviorFlags) (bool, error) {
func (b *rpcSyncMgr) SubmitBlock(block *btcutil.Block, flags blockdag.BehaviorFlags) (bool, error) {
return b.syncMgr.ProcessBlock(block, flags)
}

View File

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

View File

@ -22,7 +22,7 @@ import (
"golang.org/x/crypto/ripemd160"
"github.com/daglabs/btcd/blockchain"
"github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcjson"
"github.com/daglabs/btcd/chaincfg"
"github.com/daglabs/btcd/chaincfg/chainhash"
@ -2156,7 +2156,7 @@ func rescanBlockFilter(filter *wsClientFilter, block *btcutil.Block, params *cha
added := false
// Scan inputs if not a coinbase transaction.
if !blockchain.IsCoinBaseTx(msgTx) {
if !blockdag.IsCoinBaseTx(msgTx) {
for _, input := range msgTx.TxIn {
if !filter.existsUnspentOutPoint(&input.PreviousOutPoint) {
continue
@ -2274,7 +2274,7 @@ func handleRescanBlocks(wsc *wsClient, icmd interface{}) (interface{}, error) {
// verifies that the new range of blocks is on the same fork as a previous
// range of blocks. If this condition does not hold true, the JSON-RPC error
// for an unrecoverable reorganize is returned.
func recoverFromReorg(chain *blockchain.BlockChain, minBlock, maxBlock int32,
func recoverFromReorg(chain *blockdag.BlockChain, minBlock, maxBlock int32,
lastBlock *chainhash.Hash) ([]chainhash.Hash, error) {
hashList, err := chain.HeightRange(minBlock, maxBlock)

View File

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