[DEV-244] Remove BlockHeader.NumParentBlocks and use a method instead (#121)

This commit is contained in:
Ori Newman 2018-11-06 11:26:59 +02:00 committed by Svarog
parent 8a234bf4a3
commit 05d46e7c01
13 changed files with 118 additions and 136 deletions

View File

@ -163,13 +163,12 @@ func newBlockNode(blockHeader *wire.BlockHeader, parents blockSet, phantomK uint
func (node *blockNode) Header() *wire.BlockHeader { func (node *blockNode) Header() *wire.BlockHeader {
// No lock is needed because all accessed fields are immutable. // No lock is needed because all accessed fields are immutable.
return &wire.BlockHeader{ return &wire.BlockHeader{
Version: node.version, Version: node.version,
NumParentBlocks: byte(len(node.parents)), ParentHashes: node.ParentHashes(),
ParentHashes: node.ParentHashes(), MerkleRoot: node.merkleRoot,
MerkleRoot: node.merkleRoot, Timestamp: time.Unix(node.timestamp, 0),
Timestamp: time.Unix(node.timestamp, 0), Bits: node.bits,
Bits: node.bits, Nonce: node.nonce,
Nonce: node.nonce,
} }
} }

View File

@ -509,13 +509,12 @@ func (g *testGenerator) nextBlock(blockName string, spend *spendableOut, mungers
block := wire.MsgBlock{ block := wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 1, // TODO: (Stas) This is wrong. Modified only to satisfy compilation. ParentHashes: []daghash.Hash{g.tip.BlockHash()}, // TODO: (Stas) This is wrong. Modified only to satisfy compilation.
ParentHashes: []daghash.Hash{g.tip.BlockHash()}, // TODO: (Stas) This is wrong. Modified only to satisfy compilation. MerkleRoot: calcMerkleRoot(txns),
MerkleRoot: calcMerkleRoot(txns), Bits: g.params.PowLimitBits,
Bits: g.params.PowLimitBits, Timestamp: ts,
Timestamp: ts, Nonce: 0, // To be solved.
Nonce: 0, // To be solved.
}, },
Transactions: txns, Transactions: txns,
} }

View File

@ -54,13 +54,12 @@ var (
// as the public transaction ledger for the regression test network. // as the public transaction ledger for the regression test network.
regTestGenesisBlock = wire.MsgBlock{ regTestGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: *newHashFromStr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"),
MerkleRoot: *newHashFromStr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"), Timestamp: time.Unix(0x5b28c636, 0), // 2018-06-19 09:00:38 +0000 UTC
Timestamp: time.Unix(0x5b28c636, 0), // 2018-06-19 09:00:38 +0000 UTC Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000] Nonce: 1,
Nonce: 1,
}, },
Transactions: []*wire.MsgTx{{ Transactions: []*wire.MsgTx{{
Version: 1, Version: 1,

View File

@ -431,7 +431,7 @@ func checkBlockHeaderSanity(header *wire.BlockHeader, powLimit *big.Int, timeSou
//checkBlockParentsOrder ensures that the block's parents are ordered by hash //checkBlockParentsOrder ensures that the block's parents are ordered by hash
func checkBlockParentsOrder(header *wire.BlockHeader) error { func checkBlockParentsOrder(header *wire.BlockHeader) error {
sortedHashes := make([]daghash.Hash, 0, len(header.ParentHashes)) sortedHashes := make([]daghash.Hash, 0, header.NumParentBlocks())
for _, hash := range header.ParentHashes { for _, hash := range header.ParentHashes {
sortedHashes = append(sortedHashes, hash) sortedHashes = append(sortedHashes, hash)
} }

View File

@ -169,8 +169,7 @@ func TestCheckBlockSanity(t *testing.T) {
var invalidParentsOrderBlock = wire.MsgBlock{ var invalidParentsOrderBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2,
ParentHashes: []daghash.Hash{ ParentHashes: []daghash.Hash{
[32]byte{ // Make go vet happy. [32]byte{ // Make go vet happy.
0x4b, 0xb0, 0x75, 0x35, 0xdf, 0xd5, 0x8e, 0x0b, 0x4b, 0xb0, 0x75, 0x35, 0xdf, 0xd5, 0x8e, 0x0b,
@ -610,8 +609,7 @@ func TestValidateParents(t *testing.T) {
// test Block operations. // test Block operations.
var Block100000 = wire.MsgBlock{ var Block100000 = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2,
ParentHashes: []daghash.Hash{ ParentHashes: []daghash.Hash{
[32]byte{ // Make go vet happy. [32]byte{ // Make go vet happy.
0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95, 0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95,

View File

@ -78,13 +78,12 @@ var genesisMerkleRoot = daghash.Hash([daghash.HashSize]byte{ // Make go vet happ
// public transaction ledger for the main network. // public transaction ledger for the main network.
var genesisBlock = wire.MsgBlock{ var genesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: genesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
MerkleRoot: genesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b Timestamp: time.Unix(0x5bbe076c, 0), // 2018-10-10 14:06:36 +0000 UTC
Timestamp: time.Unix(0x5bbe076c, 0), // 2018-10-10 14:06:36 +0000 UTC Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000] Nonce: 0x80000000000d8796, // 9223372036855662486
Nonce: 0x80000000000d8796, // 9223372036855662486
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }
@ -107,13 +106,12 @@ var regTestGenesisMerkleRoot = genesisMerkleRoot
// as the public transaction ledger for the regression test network. // as the public transaction ledger for the regression test network.
var regTestGenesisBlock = wire.MsgBlock{ var regTestGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b Timestamp: time.Unix(0x5bbe0d4b, 0), // 2018-06-19 09:00:38 +0000 UTC
Timestamp: time.Unix(0x5bbe0d4b, 0), // 2018-06-19 09:00:38 +0000 UTC Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000] Nonce: 0x00000000,
Nonce: 0x00000000,
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }
@ -136,13 +134,12 @@ var testNet3GenesisMerkleRoot = genesisMerkleRoot
// serves as the public transaction ledger for the test network (version 3). // serves as the public transaction ledger for the test network (version 3).
var testNet3GenesisBlock = wire.MsgBlock{ var testNet3GenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b Timestamp: time.Unix(0x5bbe0e49, 0), // 2018-06-19 09:04:06 +0000 UTC
Timestamp: time.Unix(0x5bbe0e49, 0), // 2018-06-19 09:04:06 +0000 UTC Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000] Nonce: 0xc00000000032560b, // 2150570811
Nonce: 0xc00000000032560b, // 2150570811
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }
@ -165,13 +162,12 @@ var simNetGenesisMerkleRoot = genesisMerkleRoot
// as the public transaction ledger for the simulation test network. // as the public transaction ledger for the simulation test network.
var simNetGenesisBlock = wire.MsgBlock{ var simNetGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: simNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
MerkleRoot: simNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b Timestamp: time.Unix(0x5bbe00fe, 0), // 2018-10-10 13:39:10 +0000 UTC
Timestamp: time.Unix(0x5bbe00fe, 0), // 2018-10-10 13:39:10 +0000 UTC Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000] Nonce: 0xdffffffffffffffc, // 1610612733
Nonce: 0xdffffffffffffffc, // 1610612733
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }

View File

@ -44,13 +44,12 @@ func generateBlocks(out *os.File, numBlocks int) {
func generateBlock(parent *wire.MsgBlock) *wire.MsgBlock { func generateBlock(parent *wire.MsgBlock) *wire.MsgBlock {
return &wire.MsgBlock{ return &wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 1, ParentHashes: []daghash.Hash{parent.BlockHash()},
ParentHashes: []daghash.Hash{parent.BlockHash()}, MerkleRoot: genesisMerkleRoot,
MerkleRoot: genesisMerkleRoot, Timestamp: time.Unix(0x5b28c4c8, 0), // 2018-06-19 08:54:32 +0000 UTC
Timestamp: time.Unix(0x5b28c4c8, 0), // 2018-06-19 08:54:32 +0000 UTC Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000]
Bits: 0x1e00ffff, // 503382015 [000000ffff000000000000000000000000000000000000000000000000000000] Nonce: 0xc0192550, // 2148484547
Nonce: 0xc0192550, // 2148484547
}, },
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
} }

View File

@ -715,12 +715,11 @@ mempoolLoop:
merkles := blockdag.BuildMerkleTreeStore(blockTxns) merkles := blockdag.BuildMerkleTreeStore(blockTxns)
var msgBlock wire.MsgBlock var msgBlock wire.MsgBlock
msgBlock.Header = wire.BlockHeader{ msgBlock.Header = wire.BlockHeader{
Version: nextBlockVersion, Version: nextBlockVersion,
NumParentBlocks: byte(len(g.dag.TipHashes())), ParentHashes: g.dag.TipHashes(),
ParentHashes: g.dag.TipHashes(), MerkleRoot: *merkles[len(merkles)-1],
MerkleRoot: *merkles[len(merkles)-1], Timestamp: ts,
Timestamp: ts, Bits: reqDifficulty,
Bits: reqDifficulty,
} }
for _, tx := range blockTxns { for _, tx := range blockTxns {
if err := msgBlock.AddTransaction(tx.MsgTx()); err != nil { if err := msgBlock.AddTransaction(tx.MsgTx()); err != nil {

View File

@ -304,8 +304,7 @@ func TestBlockErrors(t *testing.T) {
// test Block operations. // test Block operations.
var Block100000 = wire.MsgBlock{ var Block100000 = wire.MsgBlock{
Header: wire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2,
ParentHashes: []daghash.Hash{ ParentHashes: []daghash.Hash{
[32]byte{ // Make go vet happy. [32]byte{ // Make go vet happy.
0x82, 0xdc, 0xbd, 0xe6, 0x88, 0x37, 0x74, 0x5b, 0x82, 0xdc, 0xbd, 0xe6, 0x88, 0x37, 0x74, 0x5b,

View File

@ -34,9 +34,6 @@ type BlockHeader struct {
// Version of the block. This is not the same as the protocol version. // Version of the block. This is not the same as the protocol version.
Version int32 Version int32
// Number of entries in ParentHashes
NumParentBlocks byte
// Hashes of the parent block headers in the blockDAG. // Hashes of the parent block headers in the blockDAG.
ParentHashes []daghash.Hash ParentHashes []daghash.Hash
@ -53,13 +50,18 @@ type BlockHeader struct {
Nonce uint64 Nonce uint64
} }
// NumParentBlocks return the number of entries in ParentHashes
func (h *BlockHeader) NumParentBlocks() byte {
return byte(len(h.ParentHashes))
}
// BlockHash computes the block identifier hash for the given block header. // BlockHash computes the block identifier hash for the given block header.
func (h *BlockHeader) BlockHash() daghash.Hash { func (h *BlockHeader) BlockHash() daghash.Hash {
// Encode the header and double sha256 everything prior to the number of // Encode the header and double sha256 everything prior to the number of
// transactions. Ignore the error returns since there is no way the // transactions. Ignore the error returns since there is no way the
// encode could fail except being out of memory which would cause a // encode could fail except being out of memory which would cause a
// run-time panic. // run-time panic.
buf := bytes.NewBuffer(make([]byte, 0, BaseBlockHeaderPayload+len(h.ParentHashes))) buf := bytes.NewBuffer(make([]byte, 0, BaseBlockHeaderPayload+h.NumParentBlocks()))
_ = writeBlockHeader(buf, 0, h) _ = writeBlockHeader(buf, 0, h)
return daghash.DoubleHashH(buf.Bytes()) return daghash.DoubleHashH(buf.Bytes())
@ -67,7 +69,7 @@ func (h *BlockHeader) BlockHash() daghash.Hash {
// SelectedParentHash returns the hash of the selected block header. // SelectedParentHash returns the hash of the selected block header.
func (h *BlockHeader) SelectedParentHash() *daghash.Hash { func (h *BlockHeader) SelectedParentHash() *daghash.Hash {
if h.NumParentBlocks == 0 { if h.NumParentBlocks() == 0 {
return nil return nil
} }
@ -76,7 +78,7 @@ func (h *BlockHeader) SelectedParentHash() *daghash.Hash {
// IsGenesis returns true iff this block is a genesis block // IsGenesis returns true iff this block is a genesis block
func (h *BlockHeader) IsGenesis() bool { func (h *BlockHeader) IsGenesis() bool {
return h.NumParentBlocks == 0 return h.NumParentBlocks() == 0
} }
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
@ -118,7 +120,7 @@ func (h *BlockHeader) Serialize(w io.Writer) error {
// SerializeSize returns the number of bytes it would take to serialize the // SerializeSize returns the number of bytes it would take to serialize the
// block header. // block header.
func (h *BlockHeader) SerializeSize() int { func (h *BlockHeader) SerializeSize() int {
return BaseBlockHeaderPayload + int(h.NumParentBlocks)*daghash.HashSize return BaseBlockHeaderPayload + int(h.NumParentBlocks())*daghash.HashSize
} }
// NewBlockHeader returns a new BlockHeader using the provided version, previous // NewBlockHeader returns a new BlockHeader using the provided version, previous
@ -130,13 +132,12 @@ func NewBlockHeader(version int32, parentHashes []daghash.Hash, merkleRootHash *
// Limit the timestamp to one second precision since the protocol // Limit the timestamp to one second precision since the protocol
// doesn't support better. // doesn't support better.
return &BlockHeader{ return &BlockHeader{
Version: version, Version: version,
NumParentBlocks: byte(len(parentHashes)), ParentHashes: parentHashes,
ParentHashes: parentHashes, MerkleRoot: *merkleRootHash,
MerkleRoot: *merkleRootHash, Timestamp: time.Unix(time.Now().Unix(), 0),
Timestamp: time.Unix(time.Now().Unix(), 0), Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
} }
@ -144,13 +145,14 @@ func NewBlockHeader(version int32, parentHashes []daghash.Hash, merkleRootHash *
// decoding block headers stored to disk, such as in a database, as opposed to // decoding block headers stored to disk, such as in a database, as opposed to
// decoding from the wire. // decoding from the wire.
func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error { func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error {
err := readElements(r, &bh.Version, &bh.NumParentBlocks) var numParentBlocks byte
err := readElements(r, &bh.Version, &numParentBlocks)
if err != nil { if err != nil {
return err return err
} }
bh.ParentHashes = make([]daghash.Hash, bh.NumParentBlocks) bh.ParentHashes = make([]daghash.Hash, numParentBlocks)
for i := byte(0); i < bh.NumParentBlocks; i++ { for i := byte(0); i < numParentBlocks; i++ {
err := readElement(r, &bh.ParentHashes[i]) err := readElement(r, &bh.ParentHashes[i])
if err != nil { if err != nil {
return err return err
@ -164,6 +166,6 @@ func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error {
// opposed to encoding for the wire. // opposed to encoding for the wire.
func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error { func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error {
sec := int64(bh.Timestamp.Unix()) sec := int64(bh.Timestamp.Unix())
return writeElements(w, bh.Version, bh.NumParentBlocks, &bh.ParentHashes, &bh.MerkleRoot, return writeElements(w, bh.Version, bh.NumParentBlocks(), &bh.ParentHashes, &bh.MerkleRoot,
sec, bh.Bits, bh.Nonce) sec, bh.Bits, bh.Nonce)
} }

View File

@ -55,13 +55,12 @@ func TestBlockHeaderWire(t *testing.T) {
// baseBlockHdr is used in the various tests as a baseline BlockHeader. // baseBlockHdr is used in the various tests as a baseline BlockHeader.
bits := uint32(0x1d00ffff) bits := uint32(0x1d00ffff)
baseBlockHdr := &BlockHeader{ baseBlockHdr := &BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2, ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, MerkleRoot: mainNetGenesisMerkleRoot,
MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST
Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
// baseBlockHdrEncoded is the wire encoded bytes of baseBlockHdr. // baseBlockHdrEncoded is the wire encoded bytes of baseBlockHdr.
@ -194,13 +193,12 @@ func TestBlockHeaderSerialize(t *testing.T) {
// baseBlockHdr is used in the various tests as a baseline BlockHeader. // baseBlockHdr is used in the various tests as a baseline BlockHeader.
bits := uint32(0x1d00ffff) bits := uint32(0x1d00ffff)
baseBlockHdr := &BlockHeader{ baseBlockHdr := &BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2, ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, MerkleRoot: mainNetGenesisMerkleRoot,
MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST
Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
// baseBlockHdrEncoded is the wire encoded bytes of baseBlockHdr. // baseBlockHdrEncoded is the wire encoded bytes of baseBlockHdr.
@ -274,23 +272,21 @@ func TestBlockHeaderSerializeSize(t *testing.T) {
bits := uint32(0x1d00ffff) bits := uint32(0x1d00ffff)
timestamp := time.Unix(0x495fab29, 0) // 2009-01-03 12:15:05 -0600 CST timestamp := time.Unix(0x495fab29, 0) // 2009-01-03 12:15:05 -0600 CST
baseBlockHdr := &BlockHeader{ baseBlockHdr := &BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2, ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, MerkleRoot: mainNetGenesisMerkleRoot,
MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: timestamp,
Timestamp: timestamp, Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
genesisBlockHdr := &BlockHeader{ genesisBlockHdr := &BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: mainNetGenesisMerkleRoot,
MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: timestamp,
Timestamp: timestamp, Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
tests := []struct { tests := []struct {
in *BlockHeader // Block header to encode in *BlockHeader // Block header to encode
@ -321,22 +317,20 @@ func TestIsGenesis(t *testing.T) {
timestamp := time.Unix(0x495fab29, 0) // 2009-01-03 12:15:05 -0600 CST timestamp := time.Unix(0x495fab29, 0) // 2009-01-03 12:15:05 -0600 CST
baseBlockHdr := &BlockHeader{ baseBlockHdr := &BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2, ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, MerkleRoot: mainNetGenesisMerkleRoot,
MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: timestamp,
Timestamp: timestamp, Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
genesisBlockHdr := &BlockHeader{ genesisBlockHdr := &BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 0, ParentHashes: []daghash.Hash{},
ParentHashes: []daghash.Hash{}, MerkleRoot: mainNetGenesisMerkleRoot,
MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: timestamp,
Timestamp: timestamp, Bits: bits,
Bits: bits, Nonce: nonce,
Nonce: nonce,
} }
tests := []struct { tests := []struct {

View File

@ -491,10 +491,9 @@ func TestBlockSerializeSize(t *testing.T) {
// blockOne is the first block in the mainnet block chain. // blockOne is the first block in the mainnet block chain.
var blockOne = MsgBlock{ var blockOne = MsgBlock{
Header: BlockHeader{ Header: BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2, ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, MerkleRoot: daghash.Hash(mainNetGenesisMerkleRoot),
MerkleRoot: daghash.Hash(mainNetGenesisMerkleRoot),
Timestamp: time.Unix(0x4966bc61, 0), // 2009-01-08 20:54:25 -0600 CST Timestamp: time.Unix(0x4966bc61, 0), // 2009-01-08 20:54:25 -0600 CST
Bits: 0x1d00ffff, // 486604799 Bits: 0x1d00ffff, // 486604799

View File

@ -337,9 +337,8 @@ func TestMerkleBlockOverflowErrors(t *testing.T) {
// where the first transaction matches. // where the first transaction matches.
var merkleBlockOne = MsgMerkleBlock{ var merkleBlockOne = MsgMerkleBlock{
Header: BlockHeader{ Header: BlockHeader{
Version: 1, Version: 1,
NumParentBlocks: 2, ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
ParentHashes: []daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
MerkleRoot: daghash.Hash([daghash.HashSize]byte{ // Make go vet happy. MerkleRoot: daghash.Hash([daghash.HashSize]byte{ // Make go vet happy.
0x98, 0x20, 0x51, 0xfd, 0x1e, 0x4b, 0xa7, 0x44, 0x98, 0x20, 0x51, 0xfd, 0x1e, 0x4b, 0xa7, 0x44,
0xbb, 0xbe, 0x68, 0x0e, 0x1f, 0xee, 0x14, 0x67, 0xbb, 0xbe, 0x68, 0x0e, 0x1f, 0xee, 0x14, 0x67,