[NOD-530] Remove coinbase inputs and add blue score to payload (#752)

* [NOD-530] Remove coinbase inputs and add blue score to payload

* [NOD-530] Fix comment

* [NOD-530] Change util.Block private fields comments
This commit is contained in:
Ori Newman 2020-06-11 15:54:11 +03:00 committed by GitHub
parent b0d4a92e47
commit ba4a89488e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 293 additions and 364 deletions

View File

@ -105,8 +105,6 @@ func (dag *BlockDAG) maybeAcceptBlock(block *util.Block, flags BehaviorFlags) er
} }
} }
block.SetBlueScore(newNode.blueScore)
// Connect the passed block to the DAG. This also handles validation of the // Connect the passed block to the DAG. This also handles validation of the
// transaction scripts. // transaction scripts.
chainUpdates, err := dag.addBlock(newNode, block, selectedParentAnticone, flags) chainUpdates, err := dag.addBlock(newNode, block, selectedParentAnticone, flags)

View File

@ -11,14 +11,14 @@ import (
func TestBlockHeap(t *testing.T) { func TestBlockHeap(t *testing.T) {
// Create a new database and DAG instance to run tests against. // Create a new database and DAG instance to run tests against.
dag, teardownFunc, err := DAGSetup("TestBlockHeap", true, Config{ dag, teardownFunc, err := DAGSetup("TestBlockHeap", true, Config{
DAGParams: &dagconfig.MainnetParams, DAGParams: &dagconfig.SimnetParams,
}) })
if err != nil { if err != nil {
t.Fatalf("TestBlockHeap: Failed to setup DAG instance: %s", err) t.Fatalf("TestBlockHeap: Failed to setup DAG instance: %s", err)
} }
defer teardownFunc() defer teardownFunc()
block0Header := dagconfig.MainnetParams.GenesisBlock.Header block0Header := dagconfig.SimnetParams.GenesisBlock.Header
block0, _ := dag.newBlockNode(&block0Header, newBlockSet()) block0, _ := dag.newBlockNode(&block0Header, newBlockSet())
block100000Header := Block100000.Header block100000Header := Block100000.Header

View File

@ -5,15 +5,14 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"github.com/kaspanet/kaspad/dbaccess" "github.com/kaspanet/kaspad/dbaccess"
"github.com/kaspanet/kaspad/util/subnetworkid"
"github.com/pkg/errors"
"io"
"math"
"github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util"
"github.com/kaspanet/kaspad/util/coinbasepayload"
"github.com/kaspanet/kaspad/util/daghash" "github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/util/subnetworkid"
"github.com/kaspanet/kaspad/util/txsort" "github.com/kaspanet/kaspad/util/txsort"
"github.com/kaspanet/kaspad/wire" "github.com/kaspanet/kaspad/wire"
"github.com/pkg/errors"
"io"
) )
// compactFeeData is a specialized data type to store a compact list of fees // compactFeeData is a specialized data type to store a compact list of fees
@ -98,7 +97,10 @@ func (node *blockNode) validateCoinbaseTransaction(dag *BlockDAG, block *util.Bl
return nil return nil
} }
blockCoinbaseTx := block.CoinbaseTransaction().MsgTx() blockCoinbaseTx := block.CoinbaseTransaction().MsgTx()
scriptPubKey, extraData, err := DeserializeCoinbasePayload(blockCoinbaseTx) _, scriptPubKey, extraData, err := coinbasepayload.DeserializeCoinbasePayload(blockCoinbaseTx)
if errors.Is(err, coinbasepayload.ErrIncorrectScriptPubKeyLen) {
return ruleError(ErrBadCoinbaseTransaction, err.Error())
}
if err != nil { if err != nil {
return err return err
} }
@ -125,16 +127,15 @@ func (node *blockNode) expectedCoinbaseTransaction(dag *BlockDAG, txsAcceptanceD
txOuts := []*wire.TxOut{} txOuts := []*wire.TxOut{}
for _, blue := range node.blues { for _, blue := range node.blues {
txIn, txOut, err := coinbaseInputAndOutputForBlueBlock(dag, blue, txsAcceptanceData, bluesFeeData) txOut, err := coinbaseOutputForBlueBlock(dag, blue, txsAcceptanceData, bluesFeeData)
if err != nil { if err != nil {
return nil, err return nil, err
} }
txIns = append(txIns, txIn)
if txOut != nil { if txOut != nil {
txOuts = append(txOuts, txOut) txOuts = append(txOuts, txOut)
} }
} }
payload, err := SerializeCoinbasePayload(scriptPubKey, extraData) payload, err := coinbasepayload.SerializeCoinbasePayload(node.blueScore, scriptPubKey, extraData)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -143,83 +144,33 @@ func (node *blockNode) expectedCoinbaseTransaction(dag *BlockDAG, txsAcceptanceD
return util.NewTx(sortedCoinbaseTx), nil return util.NewTx(sortedCoinbaseTx), nil
} }
// SerializeCoinbasePayload builds the coinbase payload based on the provided scriptPubKey and extra data. // coinbaseOutputForBlueBlock calculates the output that should go into the coinbase transaction of blueBlock
func SerializeCoinbasePayload(scriptPubKey []byte, extraData []byte) ([]byte, error) { // If blueBlock gets no fee - returns nil for txOut
w := &bytes.Buffer{} func coinbaseOutputForBlueBlock(dag *BlockDAG, blueBlock *blockNode,
err := wire.WriteVarInt(w, uint64(len(scriptPubKey))) txsAcceptanceData MultiBlockTxsAcceptanceData, feeData map[daghash.Hash]compactFeeData) (*wire.TxOut, error) {
if err != nil {
return nil, err
}
_, err = w.Write(scriptPubKey)
if err != nil {
return nil, err
}
_, err = w.Write(extraData)
if err != nil {
return nil, err
}
return w.Bytes(), nil
}
// DeserializeCoinbasePayload deserialize the coinbase payload to its component (scriptPubKey and extra data).
func DeserializeCoinbasePayload(tx *wire.MsgTx) (scriptPubKey []byte, extraData []byte, err error) {
r := bytes.NewReader(tx.Payload)
scriptPubKeyLen, err := wire.ReadVarInt(r)
if err != nil {
return nil, nil, err
}
scriptPubKey = make([]byte, scriptPubKeyLen)
_, err = r.Read(scriptPubKey)
if err != nil {
return nil, nil, err
}
extraData = make([]byte, r.Len())
if r.Len() != 0 {
_, err = r.Read(extraData)
if err != nil {
return nil, nil, err
}
}
return scriptPubKey, extraData, nil
}
// feeInputAndOutputForBlueBlock calculates the input and output that should go into the coinbase transaction of blueBlock
// If blueBlock gets no fee - returns only txIn and nil for txOut
func coinbaseInputAndOutputForBlueBlock(dag *BlockDAG, blueBlock *blockNode,
txsAcceptanceData MultiBlockTxsAcceptanceData, feeData map[daghash.Hash]compactFeeData) (
*wire.TxIn, *wire.TxOut, error) {
blockTxsAcceptanceData, ok := txsAcceptanceData.FindAcceptanceData(blueBlock.hash) blockTxsAcceptanceData, ok := txsAcceptanceData.FindAcceptanceData(blueBlock.hash)
if !ok { if !ok {
return nil, nil, errors.Errorf("No txsAcceptanceData for block %s", blueBlock.hash) return nil, errors.Errorf("No txsAcceptanceData for block %s", blueBlock.hash)
} }
blockFeeData, ok := feeData[*blueBlock.hash] blockFeeData, ok := feeData[*blueBlock.hash]
if !ok { if !ok {
return nil, nil, errors.Errorf("No feeData for block %s", blueBlock.hash) return nil, errors.Errorf("No feeData for block %s", blueBlock.hash)
} }
if len(blockTxsAcceptanceData.TxAcceptanceData) != blockFeeData.Len() { if len(blockTxsAcceptanceData.TxAcceptanceData) != blockFeeData.Len() {
return nil, nil, errors.Errorf( return nil, errors.Errorf(
"length of accepted transaction data(%d) and fee data(%d) is not equal for block %s", "length of accepted transaction data(%d) and fee data(%d) is not equal for block %s",
len(blockTxsAcceptanceData.TxAcceptanceData), blockFeeData.Len(), blueBlock.hash) len(blockTxsAcceptanceData.TxAcceptanceData), blockFeeData.Len(), blueBlock.hash)
} }
txIn := &wire.TxIn{
SignatureScript: []byte{},
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID(*blueBlock.hash),
Index: math.MaxUint32,
},
Sequence: wire.MaxTxInSequenceNum,
}
totalFees := uint64(0) totalFees := uint64(0)
feeIterator := blockFeeData.iterator() feeIterator := blockFeeData.iterator()
for _, txAcceptanceData := range blockTxsAcceptanceData.TxAcceptanceData { for _, txAcceptanceData := range blockTxsAcceptanceData.TxAcceptanceData {
fee, err := feeIterator.next() fee, err := feeIterator.next()
if err != nil { if err != nil {
return nil, nil, errors.Errorf("Error retrieving fee from compactFeeData iterator: %s", err) return nil, errors.Errorf("Error retrieving fee from compactFeeData iterator: %s", err)
} }
if txAcceptanceData.IsAccepted { if txAcceptanceData.IsAccepted {
totalFees += fee totalFees += fee
@ -229,13 +180,13 @@ func coinbaseInputAndOutputForBlueBlock(dag *BlockDAG, blueBlock *blockNode,
totalReward := CalcBlockSubsidy(blueBlock.blueScore, dag.dagParams) + totalFees totalReward := CalcBlockSubsidy(blueBlock.blueScore, dag.dagParams) + totalFees
if totalReward == 0 { if totalReward == 0 {
return txIn, nil, nil return nil, nil
} }
// the ScriptPubKey for the coinbase is parsed from the coinbase payload // the ScriptPubKey for the coinbase is parsed from the coinbase payload
scriptPubKey, _, err := DeserializeCoinbasePayload(blockTxsAcceptanceData.TxAcceptanceData[0].Tx.MsgTx()) _, scriptPubKey, _, err := coinbasepayload.DeserializeCoinbasePayload(blockTxsAcceptanceData.TxAcceptanceData[0].Tx.MsgTx())
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
txOut := &wire.TxOut{ txOut := &wire.TxOut{
@ -243,5 +194,5 @@ func coinbaseInputAndOutputForBlueBlock(dag *BlockDAG, blueBlock *blockNode,
ScriptPubKey: scriptPubKey, ScriptPubKey: scriptPubKey,
} }
return txIn, txOut, nil return txOut, nil
} }

View File

@ -654,8 +654,6 @@ func (node *blockNode) selectedParentMultiset(dag *BlockDAG) (*secp256k1.MultiSe
} }
func addTxToMultiset(ms *secp256k1.MultiSet, tx *wire.MsgTx, pastUTXO UTXOSet, blockBlueScore uint64) (*secp256k1.MultiSet, error) { func addTxToMultiset(ms *secp256k1.MultiSet, tx *wire.MsgTx, pastUTXO UTXOSet, blockBlueScore uint64) (*secp256k1.MultiSet, error) {
isCoinbase := tx.IsCoinBase()
if !isCoinbase {
for _, txIn := range tx.TxIn { for _, txIn := range tx.TxIn {
entry, ok := pastUTXO.Get(txIn.PreviousOutpoint) entry, ok := pastUTXO.Get(txIn.PreviousOutpoint)
if !ok { if !ok {
@ -668,8 +666,8 @@ func addTxToMultiset(ms *secp256k1.MultiSet, tx *wire.MsgTx, pastUTXO UTXOSet, b
return nil, err return nil, err
} }
} }
}
isCoinbase := tx.IsCoinBase()
for i, txOut := range tx.TxOut { for i, txOut := range tx.TxOut {
outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i)) outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i))
entry := NewUTXOEntry(txOut, isCoinbase, blockBlueScore) entry := NewUTXOEntry(txOut, isCoinbase, blockBlueScore)

View File

@ -207,7 +207,7 @@ func TestIsKnownBlock(t *testing.T) {
{hash: dagconfig.SimnetParams.GenesisHash.String(), want: true}, {hash: dagconfig.SimnetParams.GenesisHash.String(), want: true},
// Block 3b should be present (as a second child of Block 2). // Block 3b should be present (as a second child of Block 2).
{hash: "2a697c985ab868ea95d84e6dcd7e88301296679149e73bca46eef2d0f2995944", want: true}, {hash: "2eb8903d3eb7f977ab329649f56f4125afa532662f7afe5dba0d4a3f1b93746f", want: true},
// Block 100000 should be present (as an orphan). // Block 100000 should be present (as an orphan).
{hash: "65b20b048a074793ebfd1196e49341c8d194dabfc6b44a4fd0c607406e122baf", want: true}, {hash: "65b20b048a074793ebfd1196e49341c8d194dabfc6b44a4fd0c607406e122baf", want: true},
@ -1264,7 +1264,7 @@ func TestDoubleSpends(t *testing.T) {
func TestUTXOCommitment(t *testing.T) { func TestUTXOCommitment(t *testing.T) {
// Create a new database and dag instance to run tests against. // Create a new database and dag instance to run tests against.
params := dagconfig.DevnetParams params := dagconfig.SimnetParams
params.BlockCoinbaseMaturity = 0 params.BlockCoinbaseMaturity = 0
dag, teardownFunc, err := DAGSetup("TestUTXOCommitment", true, Config{ dag, teardownFunc, err := DAGSetup("TestUTXOCommitment", true, Config{
DAGParams: &params, DAGParams: &params,

View File

@ -33,7 +33,7 @@ func TestGHOSTDAG(t *testing.T) {
}{ }{
{ {
k: 3, k: 3,
expectedReds: []string{"F", "G", "H", "I", "O", "P"}, expectedReds: []string{"F", "G", "H", "I", "N", "Q"},
dagData: []*testBlockData{ dagData: []*testBlockData{
{ {
parents: []string{"A"}, parents: []string{"A"},
@ -166,7 +166,7 @@ func TestGHOSTDAG(t *testing.T) {
id: "T", id: "T",
expectedScore: 13, expectedScore: 13,
expectedSelectedParent: "S", expectedSelectedParent: "S",
expectedBlues: []string{"S", "Q", "N"}, expectedBlues: []string{"S", "O", "P"},
}, },
}, },
}, },

View File

@ -179,11 +179,6 @@ func newTxValidator(utxoSet UTXOSet, flags txscript.ScriptFlags, sigCache *txscr
// ValidateTransactionScripts validates the scripts for the passed transaction // ValidateTransactionScripts validates the scripts for the passed transaction
// using multiple goroutines. // using multiple goroutines.
func ValidateTransactionScripts(tx *util.Tx, utxoSet UTXOSet, flags txscript.ScriptFlags, sigCache *txscript.SigCache) error { func ValidateTransactionScripts(tx *util.Tx, utxoSet UTXOSet, flags txscript.ScriptFlags, sigCache *txscript.SigCache) error {
// Don't validate coinbase transaction scripts.
if tx.IsCoinBase() {
return nil
}
// Collect all of the transaction inputs and required information for // Collect all of the transaction inputs and required information for
// validation. // validation.
txIns := tx.MsgTx().TxIn txIns := tx.MsgTx().TxIn
@ -213,10 +208,6 @@ func checkBlockScripts(block *blockNode, utxoSet UTXOSet, transactions []*util.T
} }
txValItems := make([]*txValidateItem, 0, numInputs) txValItems := make([]*txValidateItem, 0, numInputs)
for _, tx := range transactions { for _, tx := range transactions {
// Skip coinbase transactions.
if tx.IsCoinBase() {
continue
}
for txInIdx, txIn := range tx.MsgTx().TxIn { for txInIdx, txIn := range tx.MsgTx().TxIn {
txVI := &txValidateItem{ txVI := &txValidateItem{
txInIndex: txInIdx, txInIndex: txInIdx,

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -457,8 +457,6 @@ func (fus *FullUTXOSet) WithDiff(other *UTXODiff) (UTXOSet, error) {
// //
// This function MUST be called with the DAG lock held. // This function MUST be called with the DAG lock held.
func (fus *FullUTXOSet) AddTx(tx *wire.MsgTx, blueScore uint64) (isAccepted bool, err error) { func (fus *FullUTXOSet) AddTx(tx *wire.MsgTx, blueScore uint64) (isAccepted bool, err error) {
isCoinbase := tx.IsCoinBase()
if !isCoinbase {
if !fus.containsInputs(tx) { if !fus.containsInputs(tx) {
return false, nil return false, nil
} }
@ -466,8 +464,8 @@ func (fus *FullUTXOSet) AddTx(tx *wire.MsgTx, blueScore uint64) (isAccepted bool
for _, txIn := range tx.TxIn { for _, txIn := range tx.TxIn {
fus.remove(txIn.PreviousOutpoint) fus.remove(txIn.PreviousOutpoint)
} }
}
isCoinbase := tx.IsCoinBase()
for i, txOut := range tx.TxOut { for i, txOut := range tx.TxOut {
outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i)) outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i))
entry := NewUTXOEntry(txOut, isCoinbase, blueScore) entry := NewUTXOEntry(txOut, isCoinbase, blueScore)
@ -543,12 +541,11 @@ func (dus *DiffUTXOSet) WithDiff(other *UTXODiff) (UTXOSet, error) {
// If dus.UTXODiff.useMultiset is true, this function MUST be // If dus.UTXODiff.useMultiset is true, this function MUST be
// called with the DAG lock held. // called with the DAG lock held.
func (dus *DiffUTXOSet) AddTx(tx *wire.MsgTx, blockBlueScore uint64) (bool, error) { func (dus *DiffUTXOSet) AddTx(tx *wire.MsgTx, blockBlueScore uint64) (bool, error) {
isCoinbase := tx.IsCoinBase() if !dus.containsInputs(tx) {
if !isCoinbase && !dus.containsInputs(tx) {
return false, nil return false, nil
} }
err := dus.appendTx(tx, blockBlueScore, isCoinbase) err := dus.appendTx(tx, blockBlueScore)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -556,20 +553,19 @@ func (dus *DiffUTXOSet) AddTx(tx *wire.MsgTx, blockBlueScore uint64) (bool, erro
return true, nil return true, nil
} }
func (dus *DiffUTXOSet) appendTx(tx *wire.MsgTx, blockBlueScore uint64, isCoinbase bool) error { func (dus *DiffUTXOSet) appendTx(tx *wire.MsgTx, blockBlueScore uint64) error {
if !isCoinbase {
for _, txIn := range tx.TxIn { for _, txIn := range tx.TxIn {
entry, ok := dus.Get(txIn.PreviousOutpoint) entry, ok := dus.Get(txIn.PreviousOutpoint)
if !ok { if !ok {
return errors.Errorf("Couldn't find entry for outpoint %s", txIn.PreviousOutpoint) return errors.Errorf("couldn't find entry for outpoint %s", txIn.PreviousOutpoint)
} }
err := dus.UTXODiff.RemoveEntry(txIn.PreviousOutpoint, entry) err := dus.UTXODiff.RemoveEntry(txIn.PreviousOutpoint, entry)
if err != nil { if err != nil {
return err return err
} }
} }
}
isCoinbase := tx.IsCoinBase()
for i, txOut := range tx.TxOut { for i, txOut := range tx.TxOut {
outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i)) outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i))
entry := NewUTXOEntry(txOut, isCoinbase, blockBlueScore) entry := NewUTXOEntry(txOut, isCoinbase, blockBlueScore)

View File

@ -1,7 +1,6 @@
package blockdag package blockdag
import ( import (
"math"
"reflect" "reflect"
"testing" "testing"
@ -947,12 +946,9 @@ func TestUTXOSetDiffRules(t *testing.T) {
// TestDiffUTXOSet_addTx makes sure that diffUTXOSet addTx works as expected // TestDiffUTXOSet_addTx makes sure that diffUTXOSet addTx works as expected
func TestDiffUTXOSet_addTx(t *testing.T) { func TestDiffUTXOSet_addTx(t *testing.T) {
// coinbaseTX is coinbase. As such, it has exactly one input with hash zero and MaxUInt32 index
txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000")
txIn0 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: wire.Outpoint{TxID: *txID0, Index: math.MaxUint32}, Sequence: 0}
txOut0 := &wire.TxOut{ScriptPubKey: []byte{0}, Value: 10} txOut0 := &wire.TxOut{ScriptPubKey: []byte{0}, Value: 10}
utxoEntry0 := NewUTXOEntry(txOut0, true, 0) utxoEntry0 := NewUTXOEntry(txOut0, true, 0)
coinbaseTX := wire.NewSubnetworkMsgTx(1, []*wire.TxIn{txIn0}, []*wire.TxOut{txOut0}, subnetworkid.SubnetworkIDCoinbase, 0, nil) coinbaseTX := wire.NewSubnetworkMsgTx(1, []*wire.TxIn{}, []*wire.TxOut{txOut0}, subnetworkid.SubnetworkIDCoinbase, 0, nil)
// transaction1 spends coinbaseTX // transaction1 spends coinbaseTX
id1 := coinbaseTX.TxID() id1 := coinbaseTX.TxID()

View File

@ -5,7 +5,6 @@
package dagconfig package dagconfig
import ( import (
"math"
"time" "time"
"github.com/kaspanet/kaspad/util/daghash" "github.com/kaspanet/kaspad/util/daghash"
@ -13,22 +12,10 @@ import (
"github.com/kaspanet/kaspad/wire" "github.com/kaspanet/kaspad/wire"
) )
var genesisTxIns = []*wire.TxIn{
{
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID{},
Index: math.MaxUint32,
},
SignatureScript: []byte{
0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48,
0x2f, 0x62, 0x74, 0x63, 0x64, 0x2f,
},
Sequence: math.MaxUint64,
},
}
var genesisTxOuts = []*wire.TxOut{} var genesisTxOuts = []*wire.TxOut{}
var genesisTxPayload = []byte{ var genesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x17, // Varint 0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
@ -37,24 +24,24 @@ var genesisTxPayload = []byte{
// genesisCoinbaseTx is the coinbase transaction for the genesis blocks for // genesisCoinbaseTx is the coinbase transaction for the genesis blocks for
// the main network. // the main network.
var genesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, genesisTxIns, genesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, genesisTxPayload) var genesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, []*wire.TxIn{}, genesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, genesisTxPayload)
// genesisHash is the hash of the first block in the block DAG for the main // genesisHash is the hash of the first block in the block DAG for the main
// network (genesis block). // network (genesis block).
var genesisHash = daghash.Hash{ var genesisHash = daghash.Hash{
0x9c, 0xf9, 0x7d, 0xd6, 0xbc, 0x25, 0xb2, 0xb8, 0xb3, 0x5d, 0x34, 0x3c, 0xf6, 0xbb, 0xd5, 0xaf,
0x6c, 0xd0, 0xe1, 0x9e, 0x3a, 0x2f, 0xab, 0x3d, 0x40, 0x4b, 0xff, 0x3f, 0x83, 0x27, 0x71, 0x1e,
0x3e, 0x3f, 0x4d, 0x95, 0x09, 0x85, 0x8f, 0x99, 0xe1, 0x83, 0xf6, 0x41, 0x32, 0x8c, 0xba, 0xe6,
0xc8, 0xe4, 0xc2, 0x15, 0x78, 0xac, 0x79, 0x6a, 0xd3, 0xba, 0x13, 0xef, 0x7b, 0x7e, 0x61, 0x65,
} }
// genesisMerkleRoot is the hash of the first transaction in the genesis block // genesisMerkleRoot is the hash of the first transaction in the genesis block
// for the main network. // for the main network.
var genesisMerkleRoot = daghash.Hash{ var genesisMerkleRoot = daghash.Hash{
0x72, 0x10, 0x35, 0x85, 0xdd, 0xac, 0x82, 0x5c, 0xca, 0x85, 0x56, 0x27, 0xc7, 0x6a, 0xb5, 0x7a,
0x49, 0x13, 0x9f, 0xc0, 0x0e, 0x37, 0xc0, 0x45, 0x26, 0x1d, 0x63, 0x62, 0x1e, 0x57, 0x21, 0xf0,
0x71, 0xdf, 0xd9, 0xf6, 0x36, 0xdf, 0x4c, 0x42, 0x5e, 0x60, 0x1f, 0xee, 0x1d, 0x4d, 0xaa, 0x53,
0x72, 0x7b, 0x9e, 0x86, 0xdd, 0x37, 0xd2, 0xbd, 0x72, 0xe1, 0x16, 0xda, 0x4b, 0xb3, 0xd8, 0x0e,
} }
// genesisBlock defines the genesis block of the block DAG which serves as the // genesisBlock defines the genesis block of the block DAG which serves as the
@ -66,29 +53,17 @@ var genesisBlock = wire.MsgBlock{
HashMerkleRoot: &genesisMerkleRoot, HashMerkleRoot: &genesisMerkleRoot,
AcceptedIDMerkleRoot: &daghash.Hash{}, AcceptedIDMerkleRoot: &daghash.Hash{},
UTXOCommitment: &daghash.ZeroHash, UTXOCommitment: &daghash.ZeroHash,
Timestamp: time.Unix(0x5ece5ba4, 0), Timestamp: time.Unix(0x5edf4ce0, 0),
Bits: 0x207fffff, Bits: 0x207fffff,
Nonce: 0, Nonce: 0,
}, },
Transactions: []*wire.MsgTx{genesisCoinbaseTx}, Transactions: []*wire.MsgTx{genesisCoinbaseTx},
} }
var devnetGenesisTxIns = []*wire.TxIn{
{
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID{},
Index: math.MaxUint32,
},
SignatureScript: []byte{
0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48,
0x2f, 0x62, 0x74, 0x63, 0x64, 0x2f,
},
Sequence: math.MaxUint64,
},
}
var devnetGenesisTxOuts = []*wire.TxOut{} var devnetGenesisTxOuts = []*wire.TxOut{}
var devnetGenesisTxPayload = []byte{ var devnetGenesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x17, // Varint 0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
@ -98,24 +73,24 @@ var devnetGenesisTxPayload = []byte{
// devnetGenesisCoinbaseTx is the coinbase transaction for the genesis blocks for // devnetGenesisCoinbaseTx is the coinbase transaction for the genesis blocks for
// the development network. // the development network.
var devnetGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, devnetGenesisTxIns, devnetGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, devnetGenesisTxPayload) var devnetGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, []*wire.TxIn{}, devnetGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, devnetGenesisTxPayload)
// devGenesisHash is the hash of the first block in the block DAG for the development // devGenesisHash is the hash of the first block in the block DAG for the development
// network (genesis block). // network (genesis block).
var devnetGenesisHash = daghash.Hash{ var devnetGenesisHash = daghash.Hash{
0xd3, 0xc0, 0xf4, 0xa7, 0x91, 0xa2, 0x2e, 0x27, 0x50, 0x92, 0xd1, 0x1f, 0xaa, 0xba, 0xd3, 0x58,
0x90, 0x38, 0x6d, 0x47, 0x7b, 0x26, 0x15, 0xaf, 0xa8, 0x22, 0xd7, 0xec, 0x8e, 0xe3, 0xf4, 0x26,
0xaf, 0xa6, 0x3a, 0xad, 0xd5, 0xfa, 0x37, 0xf3, 0x17, 0x18, 0x74, 0xd7, 0x87, 0x05, 0x9d, 0xed,
0x5e, 0x70, 0xfb, 0xfc, 0x07, 0x31, 0x00, 0x00, 0x33, 0xcd, 0xe1, 0x26, 0x1a, 0x69, 0x00, 0x00,
} }
// devnetGenesisMerkleRoot is the hash of the first transaction in the genesis block // devnetGenesisMerkleRoot is the hash of the first transaction in the genesis block
// for the devopment network. // for the devopment network.
var devnetGenesisMerkleRoot = daghash.Hash{ var devnetGenesisMerkleRoot = daghash.Hash{
0x16, 0x0a, 0xc6, 0x8b, 0x77, 0x08, 0xf4, 0x96, 0x68, 0x60, 0xe7, 0x77, 0x47, 0x74, 0x7f, 0xd5,
0xa3, 0x07, 0x05, 0xbc, 0x92, 0xda, 0xee, 0x73, 0x55, 0x58, 0x8a, 0xb5, 0xc2, 0x29, 0x0c, 0xa6,
0x26, 0x5e, 0xd0, 0x85, 0x78, 0xa2, 0x5d, 0x02, 0x65, 0x44, 0xb4, 0x4f, 0xfa, 0x31, 0x7a, 0xfa,
0x49, 0x8a, 0x2a, 0x22, 0xef, 0x41, 0xc9, 0xc3, 0x55, 0xe0, 0xcf, 0xac, 0x9c, 0x86, 0x30, 0x2a,
} }
// devnetGenesisBlock defines the genesis block of the block DAG which serves as the // devnetGenesisBlock defines the genesis block of the block DAG which serves as the
@ -127,29 +102,17 @@ var devnetGenesisBlock = wire.MsgBlock{
HashMerkleRoot: &devnetGenesisMerkleRoot, HashMerkleRoot: &devnetGenesisMerkleRoot,
AcceptedIDMerkleRoot: &daghash.Hash{}, AcceptedIDMerkleRoot: &daghash.Hash{},
UTXOCommitment: &daghash.ZeroHash, UTXOCommitment: &daghash.ZeroHash,
Timestamp: time.Unix(0x5ece5ba4, 0), Timestamp: time.Unix(0x5edf4ce0, 0),
Bits: 0x1e7fffff, Bits: 0x1e7fffff,
Nonce: 0x227e6, Nonce: 0xb3ed,
}, },
Transactions: []*wire.MsgTx{devnetGenesisCoinbaseTx}, Transactions: []*wire.MsgTx{devnetGenesisCoinbaseTx},
} }
var regtestGenesisTxIns = []*wire.TxIn{
{
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID{},
Index: math.MaxUint32,
},
SignatureScript: []byte{
0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48,
0x2f, 0x62, 0x74, 0x63, 0x64, 0x2f,
},
Sequence: math.MaxUint64,
},
}
var regtestGenesisTxOuts = []*wire.TxOut{} var regtestGenesisTxOuts = []*wire.TxOut{}
var regtestGenesisTxPayload = []byte{ var regtestGenesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x17, // Varint 0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
@ -159,24 +122,24 @@ var regtestGenesisTxPayload = []byte{
// regtestGenesisCoinbaseTx is the coinbase transaction for // regtestGenesisCoinbaseTx is the coinbase transaction for
// the genesis blocks for the regtest network. // the genesis blocks for the regtest network.
var regtestGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, regtestGenesisTxIns, regtestGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, regtestGenesisTxPayload) var regtestGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, []*wire.TxIn{}, regtestGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, regtestGenesisTxPayload)
// devGenesisHash is the hash of the first block in the block DAG for the development // devGenesisHash is the hash of the first block in the block DAG for the development
// network (genesis block). // network (genesis block).
var regtestGenesisHash = daghash.Hash{ var regtestGenesisHash = daghash.Hash{
0xc7, 0x7f, 0x3f, 0xb1, 0xe8, 0xf8, 0xcf, 0xa4, 0xf8, 0x1d, 0xe9, 0x86, 0xa5, 0x60, 0xe0, 0x34,
0xf5, 0x6e, 0xeb, 0x9a, 0x35, 0xd4, 0x58, 0x10, 0x0f, 0x02, 0xaa, 0x8d, 0xea, 0x6f, 0x1f, 0xc6,
0xc8, 0xd6, 0x6d, 0x07, 0x76, 0x53, 0x75, 0xa2, 0x2a, 0xb4, 0x77, 0xbd, 0xca, 0xed, 0xad, 0x3c,
0x73, 0xc0, 0x4e, 0xeb, 0xed, 0x61, 0x00, 0x00, 0x99, 0xe6, 0x98, 0x7c, 0x7b, 0x5e, 0x00, 0x00,
} }
// regtestGenesisMerkleRoot is the hash of the first transaction in the genesis block // regtestGenesisMerkleRoot is the hash of the first transaction in the genesis block
// for the regtest. // for the regtest.
var regtestGenesisMerkleRoot = daghash.Hash{ var regtestGenesisMerkleRoot = daghash.Hash{
0x3a, 0x9f, 0x62, 0xc9, 0x2b, 0x16, 0x17, 0xb3, 0x1e, 0x08, 0xae, 0x1f, 0x43, 0xf5, 0xfc, 0x24,
0x41, 0x6d, 0x9e, 0x2d, 0x87, 0x93, 0xfd, 0x72, 0xe6, 0xec, 0x54, 0x5b, 0xf7, 0x52, 0x99, 0xe4,
0x77, 0x4d, 0x1d, 0x6f, 0x6d, 0x38, 0x5b, 0xf1, 0xcc, 0x4c, 0xa0, 0x79, 0x41, 0xfc, 0xbe, 0x76,
0x24, 0x1b, 0xdc, 0x96, 0xce, 0xbf, 0xa1, 0x09, 0x72, 0x4c, 0x7e, 0xd8, 0xa3, 0x43, 0x65, 0x94,
} }
// regtestGenesisBlock defines the genesis block of the block DAG which serves as the // regtestGenesisBlock defines the genesis block of the block DAG which serves as the
@ -188,29 +151,17 @@ var regtestGenesisBlock = wire.MsgBlock{
HashMerkleRoot: &regtestGenesisMerkleRoot, HashMerkleRoot: &regtestGenesisMerkleRoot,
AcceptedIDMerkleRoot: &daghash.Hash{}, AcceptedIDMerkleRoot: &daghash.Hash{},
UTXOCommitment: &daghash.ZeroHash, UTXOCommitment: &daghash.ZeroHash,
Timestamp: time.Unix(0x5ece5ba4, 0), Timestamp: time.Unix(0x5edf4ce0, 0),
Bits: 0x1e7fffff, Bits: 0x1e7fffff,
Nonce: 0x31516, Nonce: 0x4a78,
}, },
Transactions: []*wire.MsgTx{regtestGenesisCoinbaseTx}, Transactions: []*wire.MsgTx{regtestGenesisCoinbaseTx},
} }
var simnetGenesisTxIns = []*wire.TxIn{
{
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID{},
Index: math.MaxUint32,
},
SignatureScript: []byte{
0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48,
0x2f, 0x62, 0x74, 0x63, 0x64, 0x2f,
},
Sequence: math.MaxUint64,
},
}
var simnetGenesisTxOuts = []*wire.TxOut{} var simnetGenesisTxOuts = []*wire.TxOut{}
var simnetGenesisTxPayload = []byte{ var simnetGenesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x17, // Varint 0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
@ -219,24 +170,24 @@ var simnetGenesisTxPayload = []byte{
} }
// simnetGenesisCoinbaseTx is the coinbase transaction for the simnet genesis block. // simnetGenesisCoinbaseTx is the coinbase transaction for the simnet genesis block.
var simnetGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, simnetGenesisTxIns, simnetGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, simnetGenesisTxPayload) var simnetGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, []*wire.TxIn{}, simnetGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, simnetGenesisTxPayload)
// simnetGenesisHash is the hash of the first block in the block DAG for // simnetGenesisHash is the hash of the first block in the block DAG for
// the simnet (genesis block). // the simnet (genesis block).
var simnetGenesisHash = daghash.Hash{ var simnetGenesisHash = daghash.Hash{
0x2b, 0x7b, 0x81, 0x60, 0x79, 0x74, 0x83, 0x0a, 0x34, 0x43, 0xed, 0xdc, 0xab, 0x0c, 0x39, 0x53,
0x33, 0x71, 0x88, 0x2d, 0x67, 0x7e, 0x06, 0x7b, 0xa2, 0xc5, 0x6d, 0x12, 0x4b, 0xc2, 0x41, 0x1c,
0x58, 0x87, 0xa3, 0x2b, 0xed, 0xa7, 0x65, 0xb9, 0x1a, 0x05, 0x24, 0xb4, 0xff, 0xeb, 0xe8, 0xbd,
0x13, 0x1b, 0xce, 0x49, 0xa5, 0x56, 0xe4, 0x44, 0xee, 0x6e, 0x9a, 0x77, 0xc7, 0xbb, 0x70, 0x7d,
} }
// simnetGenesisMerkleRoot is the hash of the first transaction in the genesis block // simnetGenesisMerkleRoot is the hash of the first transaction in the genesis block
// for the devopment network. // for the devopment network.
var simnetGenesisMerkleRoot = daghash.Hash{ var simnetGenesisMerkleRoot = daghash.Hash{
0xb0, 0x1c, 0x3b, 0x9e, 0x0d, 0x9a, 0xc0, 0x80, 0x47, 0x52, 0xc7, 0x23, 0x70, 0x4d, 0x89, 0x17,
0x0a, 0x08, 0x42, 0x50, 0x02, 0xa3, 0xea, 0xdb, 0xbd, 0x44, 0x26, 0xfa, 0x82, 0x7e, 0x1b, 0xa9,
0xed, 0xc8, 0xd0, 0xad, 0x35, 0x03, 0xd8, 0x0e, 0xc6, 0x46, 0x1a, 0x37, 0x5a, 0x73, 0x88, 0x09,
0x11, 0x3c, 0x7b, 0xb2, 0xb5, 0x20, 0xe5, 0x84, 0xe8, 0x17, 0xff, 0xb1, 0xdb, 0x1a, 0xb3, 0x3f,
} }
// simnetGenesisBlock defines the genesis block of the block DAG which serves as the // simnetGenesisBlock defines the genesis block of the block DAG which serves as the
@ -248,53 +199,41 @@ var simnetGenesisBlock = wire.MsgBlock{
HashMerkleRoot: &simnetGenesisMerkleRoot, HashMerkleRoot: &simnetGenesisMerkleRoot,
AcceptedIDMerkleRoot: &daghash.Hash{}, AcceptedIDMerkleRoot: &daghash.Hash{},
UTXOCommitment: &daghash.ZeroHash, UTXOCommitment: &daghash.ZeroHash,
Timestamp: time.Unix(0x5ece5ba5, 0), Timestamp: time.Unix(0x5ede5261, 0),
Bits: 0x207fffff, Bits: 0x207fffff,
Nonce: 0x0, Nonce: 0x2,
}, },
Transactions: []*wire.MsgTx{simnetGenesisCoinbaseTx}, Transactions: []*wire.MsgTx{simnetGenesisCoinbaseTx},
} }
var testnetGenesisTxIns = []*wire.TxIn{
{
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID{},
Index: math.MaxUint32,
},
SignatureScript: []byte{
0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48,
0x2f, 0x62, 0x74, 0x63, 0x64, 0x2f,
},
Sequence: math.MaxUint64,
},
}
var testnetGenesisTxOuts = []*wire.TxOut{} var testnetGenesisTxOuts = []*wire.TxOut{}
var testnetGenesisTxPayload = []byte{ var testnetGenesisTxPayload = []byte{
0x00, // Blue score
0x01, // Varint 0x01, // Varint
0x00, // OP-FALSE 0x00, // OP-FALSE
0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, // kaspa-testnet 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, // kaspa-testnet
} }
// testnetGenesisCoinbaseTx is the coinbase transaction for the testnet genesis block. // testnetGenesisCoinbaseTx is the coinbase transaction for the testnet genesis block.
var testnetGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, testnetGenesisTxIns, testnetGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, testnetGenesisTxPayload) var testnetGenesisCoinbaseTx = wire.NewSubnetworkMsgTx(1, []*wire.TxIn{}, testnetGenesisTxOuts, subnetworkid.SubnetworkIDCoinbase, 0, testnetGenesisTxPayload)
// testnetGenesisHash is the hash of the first block in the block DAG for the test // testnetGenesisHash is the hash of the first block in the block DAG for the test
// network (genesis block). // network (genesis block).
var testnetGenesisHash = daghash.Hash{ var testnetGenesisHash = daghash.Hash{
0x6b, 0xac, 0xe2, 0xfc, 0x1d, 0x1c, 0xaf, 0x38, 0x16, 0xf0, 0xfa, 0xaf, 0xb5, 0xe9, 0x99, 0x0f,
0x72, 0x0b, 0x9d, 0xf5, 0xcc, 0x2b, 0xf4, 0x6d, 0x4a, 0x32, 0xbc, 0xa3, 0x08, 0x9c, 0x65, 0xe4,
0xf4, 0x2c, 0x05, 0xf9, 0x3d, 0x94, 0xb1, 0xc6, 0xdd, 0x0d, 0x14, 0x2d, 0x8c, 0x2b, 0x4f, 0x32,
0x6a, 0xea, 0x1b, 0x81, 0x4c, 0x22, 0x00, 0x00, 0xa3, 0xcf, 0x3b, 0x85, 0x77, 0x24, 0x00, 0x00,
} }
// testnetGenesisMerkleRoot is the hash of the first transaction in the genesis block // testnetGenesisMerkleRoot is the hash of the first transaction in the genesis block
// for testnet. // for testnet.
var testnetGenesisMerkleRoot = daghash.Hash{ var testnetGenesisMerkleRoot = daghash.Hash{
0x88, 0x05, 0xd0, 0xe7, 0x8f, 0x41, 0x77, 0x39, 0x1a, 0xbb, 0x24, 0x6b, 0x72, 0x29, 0xb3, 0xd5,
0x2c, 0xb6, 0xbb, 0xb4, 0x19, 0xa8, 0x48, 0x4a, 0x5f, 0x9c, 0x2b, 0xf3, 0xd1, 0x30, 0x67, 0xd5,
0xdf, 0x77, 0xb0, 0x82, 0xd6, 0x70, 0xd8, 0x24, 0xbe, 0x52, 0x5c, 0xde, 0x67, 0x57, 0xbe, 0xb7,
0x6a, 0x36, 0x05, 0xaa, 0xbd, 0x7a, 0xd1, 0x62, 0x7e, 0x7f, 0x9f, 0x05, 0xf8, 0xd5, 0xec, 0x8c,
} }
// testnetGenesisBlock defines the genesis block of the block DAG which serves as the // testnetGenesisBlock defines the genesis block of the block DAG which serves as the
@ -306,9 +245,9 @@ var testnetGenesisBlock = wire.MsgBlock{
HashMerkleRoot: &testnetGenesisMerkleRoot, HashMerkleRoot: &testnetGenesisMerkleRoot,
AcceptedIDMerkleRoot: &daghash.ZeroHash, AcceptedIDMerkleRoot: &daghash.ZeroHash,
UTXOCommitment: &daghash.ZeroHash, UTXOCommitment: &daghash.ZeroHash,
Timestamp: time.Unix(0x5ece5ba4, 0), Timestamp: time.Unix(0x5ede4dbc, 0),
Bits: 0x1e7fffff, Bits: 0x1e7fffff,
Nonce: 0x6d249, Nonce: 0x6f12,
}, },
Transactions: []*wire.MsgTx{testnetGenesisCoinbaseTx}, Transactions: []*wire.MsgTx{testnetGenesisCoinbaseTx},
} }

View File

@ -148,116 +148,101 @@ func TestDevnetGenesisBlock(t *testing.T) {
// genesisBlockBytes are the wire encoded bytes for the genesis block of the // genesisBlockBytes are the wire encoded bytes for the genesis block of the
// main network as of protocol version 1. // main network as of protocol version 1.
var genesisBlockBytes = []byte{ var genesisBlockBytes = []byte{
0x00, 0x00, 0x00, 0x10, 0x00, 0x72, 0x10, 0x35, 0x85, 0xdd, 0xac, 0x82, 0x5c, 0x49, 0x13, 0x9f, 0x00, 0x00, 0x00, 0x10, 0x00, 0xca, 0x85, 0x56, 0x27, 0xc7, 0x6a, 0xb5, 0x7a, 0x26, 0x1d, 0x63,
0xc0, 0x0e, 0x37, 0xc0, 0x45, 0x71, 0xdf, 0xd9, 0xf6, 0x36, 0xdf, 0x4c, 0x42, 0x72, 0x7b, 0x9e, 0x62, 0x1e, 0x57, 0x21, 0xf0, 0x5e, 0x60, 0x1f, 0xee, 0x1d, 0x4d, 0xaa, 0x53, 0x72, 0xe1, 0x16,
0x86, 0xdd, 0x37, 0xd2, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0x4b, 0xb3, 0xd8, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x5b, 0xce, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x4c, 0xdf, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x41, 0xe6, 0x78, 0x1d, 0xf7, 0xb3, 0x39, 0x66, 0x4d, 0x1a, 0x03,
0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63, 0x97, 0x63, 0xc7, 0x2c, 0xfc, 0x70, 0xd7, 0x75, 0xb6, 0xd9, 0xfc, 0x1a, 0x96, 0xf0, 0xac, 0x07,
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xfa, 0x26, 0x38, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xa9, 0x14,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0x7e, 0xba,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd2, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
0xea, 0x82, 0x4e, 0xb8, 0x87, 0x42, 0xd0, 0x6d, 0x1f, 0x8d, 0xc3, 0xad, 0x9f, 0x43, 0x9e, 0xed,
0x6f, 0x43, 0x3c, 0x02, 0x71, 0x71, 0x69, 0xfb, 0xbc, 0x91, 0x44, 0xac, 0xf1, 0x93, 0xd3, 0x18,
0x17, 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71,
0xc7, 0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
} }
// regtestGenesisBlockBytes are the wire encoded bytes for the genesis block of // regtestGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the regression test network as of protocol version 1. // the regression test network as of protocol version 1.
var regtestGenesisBlockBytes = []byte{ var regtestGenesisBlockBytes = []byte{
0x00, 0x00, 0x00, 0x10, 0x00, 0x3a, 0x9f, 0x62, 0xc9, 0x2b, 0x16, 0x17, 0xb3, 0x41, 0x6d, 0x9e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1e, 0x08, 0xae, 0x1f, 0x43, 0xf5, 0xfc, 0x24, 0xe6, 0xec, 0x54,
0x2d, 0x87, 0x93, 0xfd, 0x72, 0x77, 0x4d, 0x1d, 0x6f, 0x6d, 0x38, 0x5b, 0xf1, 0x24, 0x1b, 0xdc, 0x5b, 0xf7, 0x52, 0x99, 0xe4, 0xcc, 0x4c, 0xa0, 0x79, 0x41, 0xfc, 0xbe, 0x76, 0x72, 0x4c, 0x7e,
0x96, 0xce, 0xbf, 0xa1, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xa3, 0x43, 0x65, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x5b, 0xce, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x4c, 0xdf, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f,
0x1e, 0x16, 0x15, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x78, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xc4, 0x87, 0x77, 0xf2, 0xe7, 0x5d, 0xf7, 0xff, 0x2d, 0xbb, 0xb6,
0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63, 0x2a, 0x73, 0x1f, 0x54, 0x36, 0x33, 0xa7, 0x99, 0xad, 0xb1, 0x09, 0x65, 0xc0, 0xf0, 0xf4, 0x53,
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, 0xfb, 0x88, 0xae, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xa9, 0x14,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0x7e, 0xba,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xed, 0x30, 0xcd, 0x5a, 0x4b, 0x87, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x72, 0x65, 0x67, 0x74, 0x65,
0x32, 0xec, 0xb4, 0xf8, 0x3c, 0x7a, 0x32, 0x0f, 0xd2, 0xe5, 0x24, 0x77, 0x89, 0x43, 0x3a, 0x78, 0x73, 0x74,
0x0a, 0xda, 0x68, 0x2d, 0xf6, 0xaa, 0xb1, 0x19, 0xdd, 0xd8, 0x97, 0x15, 0x4b, 0xcb, 0x42, 0x25,
0x17, 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71,
0xc7, 0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x72, 0x65,
0x67, 0x74, 0x65, 0x73, 0x74,
} }
// testnetGenesisBlockBytes are the wire encoded bytes for the genesis block of // testnetGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the test network as of protocol version 1. // the test network as of protocol version 1.
var testnetGenesisBlockBytes = []byte{ var testnetGenesisBlockBytes = []byte{
0x00, 0x00, 0x00, 0x10, 0x00, 0x88, 0x05, 0xd0, 0xe7, 0x8f, 0x41, 0x77, 0x39, 0x2c, 0xb6, 0xbb, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1a, 0xbb, 0x24, 0x6b, 0x72, 0x29, 0xb3, 0xd5, 0x5f, 0x9c, 0x2b,
0xb4, 0x19, 0xa8, 0x48, 0x4a, 0xdf, 0x77, 0xb0, 0x82, 0xd6, 0x70, 0xd8, 0x24, 0x6a, 0x36, 0x05, 0xf3, 0xd1, 0x30, 0x67, 0xd5, 0xbe, 0x52, 0x5c, 0xde, 0x67, 0x57, 0xbe, 0xb7, 0x7e, 0x7f, 0x9f,
0xaa, 0xbd, 0x7a, 0xd1, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xf8, 0xd5, 0xec, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x5b, 0xce, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x4d, 0xde, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f,
0x1e, 0x49, 0xd2, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x12, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x53, 0x02, 0xe8, 0xa9, 0xb9, 0x5d, 0x7c, 0x58, 0x91, 0x9c, 0x87,
0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63, 0xb9, 0x1d, 0x68, 0x5a, 0x7e, 0x07, 0xbe, 0xd4, 0xb2, 0x94, 0x6d, 0xdf, 0x5a, 0x97, 0x9f, 0xec,
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0xdf, 0x87, 0x34, 0x10, 0x00, 0x01, 0x00, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x74, 0x65,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x74, 0x6e, 0x65, 0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc,
0x72, 0xe6, 0x7e, 0x37, 0xa1, 0x34, 0x89, 0x23, 0x24, 0xaf, 0xae, 0x99, 0x1f, 0x89, 0x09, 0x41,
0x1a, 0x4d, 0x58, 0xfe, 0x5a, 0x04, 0xb0, 0x3e, 0xeb, 0x1b, 0x5b, 0xb8, 0x65, 0xa8, 0x65, 0x0f,
0x01, 0x00, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74,
} }
// simnetGenesisBlockBytes are the wire encoded bytes for the genesis block of // simnetGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the simulation test network as of protocol version 1. // the simulation test network as of protocol version 1.
var simnetGenesisBlockBytes = []byte{ var simnetGenesisBlockBytes = []byte{
0x00, 0x00, 0x00, 0x10, 0x00, 0xb0, 0x1c, 0x3b, 0x9e, 0x0d, 0x9a, 0xc0, 0x80, 0x0a, 0x08, 0x42, 0x00, 0x00, 0x00, 0x10, 0x00, 0x47, 0x52, 0xc7, 0x23, 0x70, 0x4d, 0x89, 0x17, 0xbd, 0x44, 0x26,
0x50, 0x02, 0xa3, 0xea, 0xdb, 0xed, 0xc8, 0xd0, 0xad, 0x35, 0x03, 0xd8, 0x0e, 0x11, 0x3c, 0x7b, 0xfa, 0x82, 0x7e, 0x1b, 0xa9, 0xc6, 0x46, 0x1a, 0x37, 0x5a, 0x73, 0x88, 0x09, 0xe8, 0x17, 0xff,
0xb2, 0xb5, 0x20, 0xe5, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0xdb, 0x1a, 0xb3, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x5b, 0xce, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x52, 0xde, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd9, 0x39, 0x5f, 0x40, 0x2a, 0x5e, 0x24, 0x09, 0x1b, 0x9a, 0x4b, 0xdf,
0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63, 0x7f, 0x0c, 0x03, 0x7f, 0xf1, 0xd2, 0x48, 0x8c, 0x26, 0xb0, 0xa3, 0x74, 0x60, 0xd9, 0x48, 0x18,
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x33, 0x22, 0x64, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xa9, 0x14,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0x7e, 0xba,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x30, 0xcd, 0x5a, 0x4b, 0x87, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x73, 0x69, 0x6d, 0x6e, 0x65,
0x48, 0xd3, 0x23, 0x9c, 0xf9, 0x88, 0x2b, 0x63, 0xc7, 0x33, 0x0f, 0xa3, 0x64, 0xf2, 0xdb, 0x39, 0x74,
0x73, 0x5f, 0x2b, 0xa8, 0xd5, 0x7b, 0x5c, 0x31, 0x68, 0xc9, 0x63, 0x37, 0x5c, 0xe7, 0x41, 0x24,
0x17, 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71,
0xc7, 0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x73, 0x69,
0x6d, 0x6e, 0x65, 0x74,
} }
// devnetGenesisBlockBytes are the wire encoded bytes for the genesis block of // devnetGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the development network as of protocol version 1. // the development network as of protocol version 1.
var devnetGenesisBlockBytes = []byte{ var devnetGenesisBlockBytes = []byte{
0x00, 0x00, 0x00, 0x10, 0x00, 0x16, 0x0a, 0xc6, 0x8b, 0x77, 0x08, 0xf4, 0x96, 0xa3, 0x07, 0x05, 0x00, 0x00, 0x00, 0x10, 0x00, 0x68, 0x60, 0xe7, 0x77, 0x47, 0x74, 0x7f, 0xd5, 0x55, 0x58, 0x8a,
0xbc, 0x92, 0xda, 0xee, 0x73, 0x26, 0x5e, 0xd0, 0x85, 0x78, 0xa2, 0x5d, 0x02, 0x49, 0x8a, 0x2a, 0xb5, 0xc2, 0x29, 0x0c, 0xa6, 0x65, 0x44, 0xb4, 0x4f, 0xfa, 0x31, 0x7a, 0xfa, 0x55, 0xe0, 0xcf,
0x22, 0xef, 0x41, 0xc9, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xac, 0x9c, 0x86, 0x30, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x5b, 0xce, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x4c, 0xdf, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f,
0x1e, 0xe6, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0xed, 0xb3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x1c, 0x05, 0x21, 0x10, 0x45, 0x61, 0xed, 0xc6, 0x0b, 0xdc, 0x85,
0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x0b, 0x2f, 0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63, 0xc0, 0x0a, 0x70, 0x2b, 0x15, 0xd5, 0x3c, 0x07, 0xb0, 0x54, 0x4f, 0x5b, 0x1a, 0x04, 0xcd, 0x49,
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x7b, 0xd6, 0x27, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xa9, 0x14,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7, 0x7e, 0xba,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x30, 0xcd, 0x5a, 0x4b, 0x87, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x64, 0x65, 0x76, 0x6e, 0x65,
0xc7, 0x0c, 0x02, 0x9e, 0xb2, 0x2e, 0xb3, 0xad, 0x24, 0x10, 0xfe, 0x2c, 0xdb, 0x8e, 0x1d, 0xde, 0x74,
0x81, 0x5b, 0xbb, 0x42, 0xfe, 0xb4, 0x93, 0xd6, 0xe3, 0xbe, 0x86, 0x02, 0xe6, 0x3a, 0x65, 0x24,
0x17, 0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, 0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71,
0xc7, 0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x64, 0x65,
0x76, 0x6e, 0x65, 0x74,
} }

View File

@ -849,7 +849,7 @@ func TestDoubleSpendsFromDAG(t *testing.T) {
//TestFetchTransaction checks that FetchTransaction //TestFetchTransaction checks that FetchTransaction
//returns only transaction from the main pool and not from the orphan pool //returns only transaction from the main pool and not from the orphan pool
func TestFetchTransaction(t *testing.T) { func TestFetchTransaction(t *testing.T) {
tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestFetchTransaction") tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestFetchTransaction")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -895,7 +895,7 @@ func TestFetchTransaction(t *testing.T) {
// they are all orphans. Finally, it adds the linking transaction and ensures // they are all orphans. Finally, it adds the linking transaction and ensures
// the entire orphan chain is moved to the transaction pool. // the entire orphan chain is moved to the transaction pool.
func TestSimpleOrphanChain(t *testing.T) { func TestSimpleOrphanChain(t *testing.T) {
tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestSimpleOrphanChain") tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestSimpleOrphanChain")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -955,7 +955,7 @@ func TestSimpleOrphanChain(t *testing.T) {
// TestOrphanReject ensures that orphans are properly rejected when the allow // TestOrphanReject ensures that orphans are properly rejected when the allow
// orphans flag is not set on ProcessTransaction. // orphans flag is not set on ProcessTransaction.
func TestOrphanReject(t *testing.T) { func TestOrphanReject(t *testing.T) {
tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestOrphanReject") tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestOrphanReject")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1009,7 +1009,7 @@ func TestOrphanReject(t *testing.T) {
// it will check if we are beyond nextExpireScan, and if so, it will remove // it will check if we are beyond nextExpireScan, and if so, it will remove
// all expired orphan transactions // all expired orphan transactions
func TestOrphanExpiration(t *testing.T) { func TestOrphanExpiration(t *testing.T) {
tc, _, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestOrphanExpiration") tc, _, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestOrphanExpiration")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1071,7 +1071,7 @@ func TestOrphanExpiration(t *testing.T) {
//TestMaxOrphanTxSize ensures that a transaction that is //TestMaxOrphanTxSize ensures that a transaction that is
//bigger than MaxOrphanTxSize will get rejected //bigger than MaxOrphanTxSize will get rejected
func TestMaxOrphanTxSize(t *testing.T) { func TestMaxOrphanTxSize(t *testing.T) {
tc, _, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestMaxOrphanTxSize") tc, _, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestMaxOrphanTxSize")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1098,7 +1098,7 @@ func TestMaxOrphanTxSize(t *testing.T) {
} }
func TestRemoveTransaction(t *testing.T) { func TestRemoveTransaction(t *testing.T) {
tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 2, "TestRemoveTransaction") tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 2, "TestRemoveTransaction")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1141,7 +1141,7 @@ func TestRemoveTransaction(t *testing.T) {
// TestOrphanEviction ensures that exceeding the maximum number of orphans // TestOrphanEviction ensures that exceeding the maximum number of orphans
// evicts entries to make room for the new ones. // evicts entries to make room for the new ones.
func TestOrphanEviction(t *testing.T) { func TestOrphanEviction(t *testing.T) {
tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestOrphanEviction") tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestOrphanEviction")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1202,7 +1202,7 @@ func TestOrphanEviction(t *testing.T) {
// Attempt to remove orphans by tag, // Attempt to remove orphans by tag,
// and ensure the state of all other orphans are unaffected. // and ensure the state of all other orphans are unaffected.
func TestRemoveOrphansByTag(t *testing.T) { func TestRemoveOrphansByTag(t *testing.T) {
tc, _, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestRemoveOrphansByTag") tc, _, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestRemoveOrphansByTag")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1255,7 +1255,7 @@ func TestRemoveOrphansByTag(t *testing.T) {
// redeems it and when there is not. // redeems it and when there is not.
func TestBasicOrphanRemoval(t *testing.T) { func TestBasicOrphanRemoval(t *testing.T) {
const maxOrphans = 4 const maxOrphans = 4
tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestBasicOrphanRemoval") tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestBasicOrphanRemoval")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1329,7 +1329,7 @@ func TestBasicOrphanRemoval(t *testing.T) {
// from other orphans) are removed as expected. // from other orphans) are removed as expected.
func TestOrphanChainRemoval(t *testing.T) { func TestOrphanChainRemoval(t *testing.T) {
const maxOrphans = 10 const maxOrphans = 10
tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestOrphanChainRemoval") tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestOrphanChainRemoval")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1394,7 +1394,7 @@ func TestOrphanChainRemoval(t *testing.T) {
// output that is spend by another transaction entering the pool are removed. // output that is spend by another transaction entering the pool are removed.
func TestMultiInputOrphanDoubleSpend(t *testing.T) { func TestMultiInputOrphanDoubleSpend(t *testing.T) {
const maxOrphans = 4 const maxOrphans = 4
tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestMultiInputOrphanDoubleSpend") tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestMultiInputOrphanDoubleSpend")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1478,7 +1478,7 @@ func TestMultiInputOrphanDoubleSpend(t *testing.T) {
// TestCheckSpend tests that CheckSpend returns the expected spends found in // TestCheckSpend tests that CheckSpend returns the expected spends found in
// the mempool. // the mempool.
func TestCheckSpend(t *testing.T) { func TestCheckSpend(t *testing.T) {
tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestCheckSpend") tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestCheckSpend")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1544,7 +1544,7 @@ func TestCheckSpend(t *testing.T) {
} }
func TestCount(t *testing.T) { func TestCount(t *testing.T) {
tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 1, "TestCount") tc, outputs, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 1, "TestCount")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1647,7 +1647,7 @@ func TestExtractRejectCode(t *testing.T) {
// TestHandleNewBlock // TestHandleNewBlock
func TestHandleNewBlock(t *testing.T) { func TestHandleNewBlock(t *testing.T) {
tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.MainnetParams, 2, "TestHandleNewBlock") tc, spendableOuts, teardownFunc, err := newPoolHarness(t, &dagconfig.SimnetParams, 2, "TestHandleNewBlock")
if err != nil { if err != nil {
t.Fatalf("unable to create test pool: %v", err) t.Fatalf("unable to create test pool: %v", err)
} }
@ -1770,21 +1770,7 @@ var dummyBlock = wire.MsgBlock{
Transactions: []*wire.MsgTx{ Transactions: []*wire.MsgTx{
{ {
Version: 1, Version: 1,
TxIn: []*wire.TxIn{ TxIn: []*wire.TxIn{},
{
PreviousOutpoint: wire.Outpoint{
TxID: daghash.TxID{
0x9b, 0x22, 0x59, 0x44, 0x66, 0xf0, 0xbe, 0x50,
0x7c, 0x1c, 0x8a, 0xf6, 0x06, 0x27, 0xe6, 0x33,
0x38, 0x7e, 0xd1, 0xd5, 0x8c, 0x42, 0x59, 0x1a,
0x31, 0xac, 0x9a, 0xa6, 0x2e, 0xd5, 0x2b, 0x0f,
},
Index: 0xffffffff,
},
SignatureScript: nil,
Sequence: math.MaxUint64,
},
},
TxOut: []*wire.TxOut{ TxOut: []*wire.TxOut{
{ {
Value: 0x12a05f200, // 5000000000 Value: 0x12a05f200, // 5000000000
@ -1797,7 +1783,10 @@ var dummyBlock = wire.MsgBlock{
}, },
LockTime: 0, LockTime: 0,
SubnetworkID: *subnetworkid.SubnetworkIDCoinbase, SubnetworkID: *subnetworkid.SubnetworkIDCoinbase,
Payload: []byte{0x00}, Payload: []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
},
PayloadHash: &daghash.Hash{ PayloadHash: &daghash.Hash{
0x14, 0x06, 0xe0, 0x58, 0x81, 0xe2, 0x99, 0x36, 0x14, 0x06, 0xe0, 0x58, 0x81, 0xe2, 0x99, 0x36,
0x77, 0x66, 0xd3, 0x13, 0xe2, 0x6c, 0x05, 0x56, 0x77, 0x66, 0xd3, 0x13, 0xe2, 0x6c, 0x05, 0x56,

View File

@ -629,7 +629,13 @@ func (m *wsNotificationManager) notifyFilteredBlockAdded(clients map[chan struct
"added notification: %s", err) "added notification: %s", err)
return return
} }
ntfn := rpcmodel.NewFilteredBlockAddedNtfn(block.BlueScore(), hex.EncodeToString(w.Bytes()), nil) blueScore, err := block.BlueScore()
if err != nil {
log.Errorf("Failed to deserialize blue score for filtered block "+
"added notification: %s", err)
return
}
ntfn := rpcmodel.NewFilteredBlockAddedNtfn(blueScore, hex.EncodeToString(w.Bytes()), nil)
// Search for relevant transactions for each client and save them // Search for relevant transactions for each client and save them
// serialized in hex encoding for the notification. // serialized in hex encoding for the notification.

View File

@ -7,6 +7,7 @@ package util
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/kaspanet/kaspad/util/coinbasepayload"
"io" "io"
"time" "time"
@ -33,12 +34,23 @@ func (e OutOfRangeError) Error() string {
// transactions on their first access so subsequent accesses don't have to // transactions on their first access so subsequent accesses don't have to
// repeat the relatively expensive hashing operations. // repeat the relatively expensive hashing operations.
type Block struct { type Block struct {
msgBlock *wire.MsgBlock // Underlying MsgBlock // Underlying MsgBlock
serializedBlock []byte // Serialized bytes for the block msgBlock *wire.MsgBlock
blockHash *daghash.Hash // Cached block hash
transactions []*Tx // Transactions // Serialized bytes for the block. This is used only internally, and .Hash() should be used anywhere.
txnsGenerated bool // ALL wrapped transactions generated serializedBlock []byte
blueScore uint64 // Blue score
// Cached block hash. This is used only internally, and .Hash() should be used anywhere.
blockHash *daghash.Hash
// Transactions. This is used only internally, and .Transactions() should be used anywhere.
transactions []*Tx
// ALL wrapped transactions generated
txnsGenerated bool
// Blue score. This is used only internally, and .BlueScore() should be used anywhere.
blueScore *uint64
} }
// MsgBlock returns the underlying wire.MsgBlock for the Block. // MsgBlock returns the underlying wire.MsgBlock for the Block.
@ -200,13 +212,15 @@ func (b *Block) Timestamp() time.Time {
} }
// BlueScore returns this block's blue score. // BlueScore returns this block's blue score.
func (b *Block) BlueScore() uint64 { func (b *Block) BlueScore() (uint64, error) {
return b.blueScore if b.blueScore == nil {
} blueScore, _, _, err := coinbasepayload.DeserializeCoinbasePayload(b.CoinbaseTransaction().MsgTx())
if err != nil {
// SetBlueScore sets the blue score of the block. return 0, err
func (b *Block) SetBlueScore(blueScore uint64) { }
b.blueScore = blueScore b.blueScore = &blueScore
}
return *b.blueScore, nil
} }
// NewBlock returns a new instance of a kaspa block given an underlying // NewBlock returns a new instance of a kaspa block given an underlying

View File

@ -0,0 +1,66 @@
package coinbasepayload
import (
"bytes"
"encoding/binary"
"github.com/kaspanet/kaspad/util/binaryserializer"
"github.com/kaspanet/kaspad/wire"
"github.com/pkg/errors"
)
var byteOrder = binary.LittleEndian
// SerializeCoinbasePayload builds the coinbase payload based on the provided scriptPubKey and extra data.
func SerializeCoinbasePayload(blueScore uint64, scriptPubKey []byte, extraData []byte) ([]byte, error) {
w := &bytes.Buffer{}
err := binaryserializer.PutUint64(w, byteOrder, blueScore)
if err != nil {
return nil, err
}
err = wire.WriteVarInt(w, uint64(len(scriptPubKey)))
if err != nil {
return nil, err
}
_, err = w.Write(scriptPubKey)
if err != nil {
return nil, err
}
_, err = w.Write(extraData)
if err != nil {
return nil, err
}
return w.Bytes(), nil
}
// ErrIncorrectScriptPubKeyLen indicates that the script pub key length is not as expected.
var ErrIncorrectScriptPubKeyLen = errors.New("incorrect script pub key length")
// DeserializeCoinbasePayload deserializes the coinbase payload to its component (scriptPubKey and extra data).
func DeserializeCoinbasePayload(tx *wire.MsgTx) (blueScore uint64, scriptPubKey []byte, extraData []byte, err error) {
r := bytes.NewReader(tx.Payload)
blueScore, err = binaryserializer.Uint64(r, byteOrder)
if err != nil {
return 0, nil, nil, err
}
scriptPubKeyLen, err := wire.ReadVarInt(r)
if err != nil {
return 0, nil, nil, err
}
scriptPubKey = make([]byte, scriptPubKeyLen)
n, err := r.Read(scriptPubKey)
if err != nil {
return 0, nil, nil, err
}
if uint64(n) != scriptPubKeyLen {
return 0, nil, nil,
errors.Wrapf(ErrIncorrectScriptPubKeyLen, "expected %d bytes in script pub key but got %d", scriptPubKeyLen, n)
}
extraData = make([]byte, r.Len())
if r.Len() != 0 {
_, err = r.Read(extraData)
if err != nil {
return 0, nil, nil, err
}
}
return blueScore, scriptPubKey, extraData, nil
}