mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-24 15:02:32 +00:00
[NOD-177] Remove idMerkleRoot (#299)
* [NOD-177] Removed references to idMerkleRoot. * [NOD-177] Generated new genesis hashes. * [NOD-177] Generated new blk_ blocks. * [NOD-177] Fixed TestHaveBlock. * [NOD-177] Fixed The rest of the tests. * [NOD-177] Fixed a couple of comments and a duplicate test. * [NOD-177] Fixed blocks1-256.bz2.
This commit is contained in:
parent
5c5491e1e4
commit
b1d3ca0206
@ -102,7 +102,6 @@ type blockNode struct {
|
||||
nonce uint64
|
||||
timestamp int64
|
||||
hashMerkleRoot *daghash.Hash
|
||||
idMerkleRoot *daghash.Hash
|
||||
acceptedIDMerkleRoot *daghash.Hash
|
||||
utxoCommitment *daghash.Hash
|
||||
|
||||
@ -131,7 +130,6 @@ func initBlockNode(node *blockNode, blockHeader *wire.BlockHeader, parents block
|
||||
node.nonce = blockHeader.Nonce
|
||||
node.timestamp = blockHeader.Timestamp.Unix()
|
||||
node.hashMerkleRoot = blockHeader.HashMerkleRoot
|
||||
node.idMerkleRoot = blockHeader.IDMerkleRoot
|
||||
node.acceptedIDMerkleRoot = blockHeader.AcceptedIDMerkleRoot
|
||||
node.utxoCommitment = blockHeader.UTXOCommitment
|
||||
} else {
|
||||
@ -183,7 +181,6 @@ func (node *blockNode) Header() *wire.BlockHeader {
|
||||
Version: node.version,
|
||||
ParentHashes: node.ParentHashes(),
|
||||
HashMerkleRoot: node.hashMerkleRoot,
|
||||
IDMerkleRoot: node.idMerkleRoot,
|
||||
AcceptedIDMerkleRoot: node.acceptedIDMerkleRoot,
|
||||
UTXOCommitment: node.utxoCommitment,
|
||||
Timestamp: time.Unix(node.timestamp, 0),
|
||||
|
@ -205,7 +205,6 @@ func newTestNode(parents blockSet, blockVersion int32, bits uint32, timestamp ti
|
||||
Bits: bits,
|
||||
Timestamp: timestamp,
|
||||
HashMerkleRoot: &daghash.ZeroHash,
|
||||
IDMerkleRoot: &daghash.ZeroHash,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
}
|
||||
|
@ -174,8 +174,7 @@ func TestHaveBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
// Insert an orphan block.
|
||||
isOrphan, err = dag.ProcessBlock(util.NewBlock(&Block100000),
|
||||
BFNoPoWCheck)
|
||||
isOrphan, err = dag.ProcessBlock(util.NewBlock(&Block100000), BFNoPoWCheck)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to process block: %v", err)
|
||||
}
|
||||
@ -192,10 +191,10 @@ func TestHaveBlock(t *testing.T) {
|
||||
{hash: dagconfig.SimNetParams.GenesisHash.String(), want: true},
|
||||
|
||||
// Block 3b should be present (as a second child of Block 2).
|
||||
{hash: "6733a86f4e3a46c0d4df76d6fbfab88eacadf8e44f54eb544a18d6b95570510c", want: true},
|
||||
{hash: "3f2ded16b7115e69a48cee5f4be743ff23ad8d41da16d059c38cc83d14459863", want: true},
|
||||
|
||||
// Block 100000 should be present (as an orphan).
|
||||
{hash: "18bcf45b8c0dbccd7690a728f3486c6d5fc84971688f89f4554297b6a278e554", want: true},
|
||||
{hash: "4e530ee9f967de3b2cd47ac5cd00109bb9ed7b0e30a60485c94badad29ecb4ce", want: true},
|
||||
|
||||
// Random hashes should not be available.
|
||||
{hash: "123", want: false},
|
||||
@ -555,7 +554,6 @@ func chainedNodes(parents blockSet, numNodes int) []*blockNode {
|
||||
// synthetic tests to work.
|
||||
header := wire.BlockHeader{
|
||||
Nonce: testNoncePrng.Uint64(),
|
||||
IDMerkleRoot: &daghash.ZeroHash,
|
||||
HashMerkleRoot: &daghash.ZeroHash,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
@ -919,7 +917,6 @@ func TestValidateFeeTransaction(t *testing.T) {
|
||||
Bits: dag.genesis.Header().Bits,
|
||||
ParentHashes: parentHashes,
|
||||
HashMerkleRoot: BuildHashMerkleTreeStore(utilTxs).Root(),
|
||||
IDMerkleRoot: BuildIDMerkleTreeStore(utilTxs).Root(),
|
||||
AcceptedIDMerkleRoot: acceptedIDMerkleRoot,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
},
|
||||
|
@ -623,7 +623,6 @@ func (dag *BlockDAG) deserializeBlockNode(blockRow []byte) (*blockNode, error) {
|
||||
nonce: header.Nonce,
|
||||
timestamp: header.Timestamp.Unix(),
|
||||
hashMerkleRoot: header.HashMerkleRoot,
|
||||
idMerkleRoot: header.IDMerkleRoot,
|
||||
acceptedIDMerkleRoot: header.AcceptedIDMerkleRoot,
|
||||
utxoCommitment: header.UTXOCommitment,
|
||||
}
|
||||
|
@ -67,5 +67,5 @@ func ExampleBlockDAG_ProcessBlock() {
|
||||
fmt.Printf("Block accepted. Is it an orphan?: %v", isOrphan)
|
||||
|
||||
// Output:
|
||||
// Failed to process block: already have block 5804d0207bdbfd88dd035271fab95944585eb57017b0709d5a0a10a7edb37795
|
||||
// Failed to process block: already have block 63bbcfdd699ffd8cb19878564b14d3af8ba4d7ee4d1dd54925a7c21d5b5b5fdc
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
package blockdag
|
||||
|
||||
import (
|
||||
"github.com/daglabs/btcd/util/daghash"
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/util"
|
||||
@ -24,8 +25,11 @@ func TestMerkle(t *testing.T) {
|
||||
|
||||
idMerkleTree := BuildIDMerkleTreeStore(block.Transactions())
|
||||
calculatedIDMerkleRoot := idMerkleTree.Root()
|
||||
wantIDMerkleRoot := Block100000.Header.IDMerkleRoot
|
||||
if !wantIDMerkleRoot.IsEqual(calculatedIDMerkleRoot) {
|
||||
wantIDMerkleRoot, err := daghash.NewHashFromStr("65308857c92c4e5dd3c5e61b73d6b78a87456b5f8f16b13c1e02c47768a0b881")
|
||||
if err != nil {
|
||||
t.Errorf("BuildIDMerkleTreeStore: unexpected error: %s", err)
|
||||
}
|
||||
if !calculatedIDMerkleRoot.IsEqual(wantIDMerkleRoot) {
|
||||
t.Errorf("BuildIDMerkleTreeStore: ID merkle root mismatch - "+
|
||||
"got %v, want %v", calculatedIDMerkleRoot, wantIDMerkleRoot)
|
||||
}
|
||||
|
BIN
blockdag/testdata/blk_0_to_4.dat
vendored
BIN
blockdag/testdata/blk_0_to_4.dat
vendored
Binary file not shown.
BIN
blockdag/testdata/blk_3A.dat
vendored
BIN
blockdag/testdata/blk_3A.dat
vendored
Binary file not shown.
BIN
blockdag/testdata/blk_3B.dat
vendored
BIN
blockdag/testdata/blk_3B.dat
vendored
Binary file not shown.
BIN
blockdag/testdata/blk_3C.dat
vendored
BIN
blockdag/testdata/blk_3C.dat
vendored
Binary file not shown.
BIN
blockdag/testdata/blk_3D.dat
vendored
BIN
blockdag/testdata/blk_3D.dat
vendored
Binary file not shown.
@ -563,15 +563,6 @@ func (dag *BlockDAG) checkBlockSanity(block *util.Block, flags BehaviorFlags) er
|
||||
return ruleError(ErrBadMerkleRoot, str)
|
||||
}
|
||||
|
||||
idMerkleTree := BuildIDMerkleTreeStore(block.Transactions())
|
||||
calculatedIDMerkleRoot := idMerkleTree.Root()
|
||||
if !header.IDMerkleRoot.IsEqual(calculatedIDMerkleRoot) {
|
||||
str := fmt.Sprintf("block ID merkle root is invalid - block "+
|
||||
"header indicates %s, but calculated value is %s",
|
||||
header.IDMerkleRoot, calculatedIDMerkleRoot)
|
||||
return ruleError(ErrBadMerkleRoot, str)
|
||||
}
|
||||
|
||||
// Check for duplicate transactions. This check will be fairly quick
|
||||
// since the transaction IDs are already cached due to building the
|
||||
// merkle tree above.
|
||||
|
@ -222,12 +222,6 @@ func TestCheckBlockSanity(t *testing.T) {
|
||||
0x48, 0x3e, 0x8b, 0xe1, 0xcf, 0xdc, 0x20, 0xba,
|
||||
0xae, 0xec, 0x0a, 0x2f, 0xe4, 0x85, 0x31, 0x30,
|
||||
},
|
||||
IDMerkleRoot: &daghash.Hash{
|
||||
0x4e, 0x06, 0xba, 0x64, 0xd7, 0x61, 0xda, 0x25,
|
||||
0x1a, 0x0e, 0x21, 0xd4, 0x64, 0x49, 0x02, 0xa2,
|
||||
0x80, 0xf7, 0x00, 0xe3, 0x16, 0x3d, 0x04, 0x95,
|
||||
0x5b, 0x7e, 0xaf, 0x84, 0x7e, 0x1b, 0x6b, 0x06,
|
||||
},
|
||||
AcceptedIDMerkleRoot: &daghash.Hash{
|
||||
0x80, 0xf7, 0x00, 0xe3, 0x16, 0x3d, 0x04, 0x95,
|
||||
0x5b, 0x7e, 0xaf, 0x84, 0x7e, 0x1b, 0x6b, 0x06,
|
||||
@ -242,7 +236,7 @@ func TestCheckBlockSanity(t *testing.T) {
|
||||
},
|
||||
Timestamp: time.Unix(0x5cd18053, 0),
|
||||
Bits: 0x207fffff,
|
||||
Nonce: 0x0,
|
||||
Nonce: 0x1,
|
||||
},
|
||||
Transactions: []*wire.MsgTx{
|
||||
{
|
||||
@ -526,7 +520,7 @@ func TestCheckSerializedHeight(t *testing.T) {
|
||||
msgTx := coinbaseTx.Copy()
|
||||
msgTx.TxIn[0].SignatureScript = test.sigScript
|
||||
|
||||
msgBlock := wire.NewMsgBlock(wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0))
|
||||
msgBlock := wire.NewMsgBlock(wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0))
|
||||
msgBlock.AddTransaction(msgTx)
|
||||
block := util.NewBlock(msgBlock)
|
||||
block.SetHeight(test.wantHeight)
|
||||
@ -634,7 +628,6 @@ func TestValidateParents(t *testing.T) {
|
||||
c := generateNode(genesisNode)
|
||||
|
||||
fakeBlockHeader := &wire.BlockHeader{
|
||||
IDMerkleRoot: &daghash.ZeroHash,
|
||||
HashMerkleRoot: &daghash.ZeroHash,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
@ -770,12 +763,6 @@ var Block100000 = wire.MsgBlock{
|
||||
0x6f, 0x22, 0xfa, 0x60, 0x36, 0x80, 0x99, 0xc3,
|
||||
0x6e, 0x39, 0x14, 0x9b, 0xcc, 0x1f, 0x31, 0xa9,
|
||||
},
|
||||
IDMerkleRoot: &daghash.Hash{
|
||||
0x81, 0xb8, 0xa0, 0x68, 0x77, 0xc4, 0x02, 0x1e,
|
||||
0x3c, 0xb1, 0x16, 0x8f, 0x5f, 0x6b, 0x45, 0x87,
|
||||
0x8a, 0xb7, 0xd6, 0x73, 0x1b, 0xe6, 0xc5, 0xd3,
|
||||
0x5d, 0x4e, 0x2c, 0xc9, 0x57, 0x88, 0x30, 0x65,
|
||||
},
|
||||
AcceptedIDMerkleRoot: &daghash.Hash{
|
||||
0x8a, 0xb7, 0xd6, 0x73, 0x1b, 0xe6, 0xc5, 0xd3,
|
||||
0x5d, 0x4e, 0x2c, 0xc9, 0x57, 0x88, 0x30, 0x65,
|
||||
@ -1068,12 +1055,6 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
|
||||
0xf3, 0x2d, 0xd1, 0x05, 0x64, 0xb5, 0x16, 0x76,
|
||||
0xe4, 0x66, 0x7d, 0x51, 0x53, 0x18, 0x6d, 0xb1,
|
||||
},
|
||||
IDMerkleRoot: &daghash.Hash{
|
||||
0x0b, 0x79, 0xf5, 0x29, 0x6d, 0x1c, 0xaa, 0x90,
|
||||
0x2f, 0x01, 0xd4, 0x83, 0x9b, 0x2a, 0x04, 0x5e,
|
||||
0xa0, 0x69, 0x2d, 0x16, 0xb5, 0xd7, 0xe4, 0xf3,
|
||||
0xcd, 0xc7, 0xc9, 0xaf, 0xfb, 0xd2, 0x1b, 0x85,
|
||||
},
|
||||
AcceptedIDMerkleRoot: &daghash.Hash{
|
||||
0xa0, 0x69, 0x2d, 0x16, 0xb5, 0xd7, 0xe4, 0xf3,
|
||||
0xcd, 0xc7, 0xc9, 0xaf, 0xfb, 0xd2, 0x1b, 0x85,
|
||||
@ -1088,7 +1069,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
|
||||
},
|
||||
Timestamp: time.Unix(0x5cd16eaa, 0),
|
||||
Bits: 0x207fffff,
|
||||
Nonce: 0x2,
|
||||
Nonce: 0x0,
|
||||
},
|
||||
Transactions: []*wire.MsgTx{
|
||||
{
|
||||
|
@ -16,7 +16,6 @@ type GetBlockHeaderVerboseResult struct {
|
||||
Version int32 `json:"version"`
|
||||
VersionHex string `json:"versionHex"`
|
||||
HashMerkleRoot string `json:"hashMerkleRoot"`
|
||||
IDMerkleRoot string `json:"idMerkleRoot"`
|
||||
AcceptedIDMerkleRoot string `json:"acceptedIdMerkleRoot"`
|
||||
Time int64 `json:"time"`
|
||||
Nonce uint64 `json:"nonce"`
|
||||
@ -37,7 +36,6 @@ type GetBlockVerboseResult struct {
|
||||
Version int32 `json:"version"`
|
||||
VersionHex string `json:"versionHex"`
|
||||
HashMerkleRoot string `json:"hashMerkleRoot"`
|
||||
IDMerkleRoot string `json:"idMerkleRoot"`
|
||||
AcceptedIDMerkleRoot string `json:"acceptedIdMerkleRoot"`
|
||||
Tx []string `json:"tx,omitempty"`
|
||||
RawTx []TxRawResult `json:"rawRx,omitempty"`
|
||||
|
@ -41,10 +41,10 @@ var genesisCoinbaseTx = wire.NewNativeMsgTx(1, genesisTxIns, genesisTxOuts)
|
||||
// genesisHash is the hash of the first block in the block chain for the main
|
||||
// network (genesis block).
|
||||
var genesisHash = daghash.Hash([daghash.HashSize]byte{
|
||||
0x95, 0x77, 0xb3, 0xed, 0xa7, 0x10, 0x0a, 0x5a,
|
||||
0x9d, 0x70, 0xb0, 0x17, 0x70, 0xb5, 0x5e, 0x58,
|
||||
0x44, 0x59, 0xb9, 0xfa, 0x71, 0x52, 0x03, 0xdd,
|
||||
0x88, 0xfd, 0xdb, 0x7b, 0x20, 0xd0, 0x04, 0x58,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25,
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
})
|
||||
|
||||
// genesisMerkleRoot is the hash of the first transaction in the genesis block
|
||||
@ -63,12 +63,11 @@ var genesisBlock = wire.MsgBlock{
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{},
|
||||
HashMerkleRoot: &genesisMerkleRoot,
|
||||
IDMerkleRoot: &genesisMerkleRoot,
|
||||
AcceptedIDMerkleRoot: &daghash.Hash{},
|
||||
UTXOCommitment: &daghash.Hash{},
|
||||
Timestamp: time.Unix(0x5cd83da0, 0),
|
||||
Timestamp: time.Unix(0x5cdac4b0, 0),
|
||||
Bits: 0x207fffff,
|
||||
Nonce: 0x1,
|
||||
Nonce: 0x0,
|
||||
},
|
||||
Transactions: []*wire.MsgTx{genesisCoinbaseTx},
|
||||
}
|
||||
@ -119,10 +118,10 @@ var devNetGenesisCoinbaseTx = genesisCoinbaseTx
|
||||
// devGenesisHash is the hash of the first block in the block chain for the development
|
||||
// network (genesis block).
|
||||
var devNetGenesisHash = daghash.Hash([daghash.HashSize]byte{
|
||||
0x53, 0x68, 0x95, 0xd4, 0xf7, 0xc7, 0x3b, 0x94,
|
||||
0x64, 0xfa, 0x98, 0xc7, 0xcb, 0x92, 0x53, 0x71,
|
||||
0x5e, 0x14, 0xd1, 0x83, 0x01, 0xd4, 0x1e, 0x17,
|
||||
0xd4, 0xc4, 0xd3, 0x50, 0xa7, 0x64, 0x00, 0x00,
|
||||
0xab, 0x03, 0xe2, 0x8e, 0xd4, 0x66, 0xf9, 0x75,
|
||||
0x21, 0xd8, 0x8b, 0x49, 0xb2, 0xb4, 0xeb, 0xc6,
|
||||
0x4a, 0x03, 0xbf, 0x9b, 0x41, 0xcb, 0x36, 0x79,
|
||||
0x33, 0x03, 0xc4, 0x4d, 0x37, 0x17, 0x00, 0x00,
|
||||
})
|
||||
|
||||
// devNetGenesisMerkleRoot is the hash of the first transaction in the genesis block
|
||||
@ -136,12 +135,11 @@ var devNetGenesisBlock = wire.MsgBlock{
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{},
|
||||
HashMerkleRoot: &devNetGenesisMerkleRoot,
|
||||
IDMerkleRoot: &devNetGenesisMerkleRoot,
|
||||
AcceptedIDMerkleRoot: &daghash.Hash{},
|
||||
UTXOCommitment: &daghash.Hash{},
|
||||
Timestamp: time.Unix(0x5cd83da0, 0),
|
||||
Timestamp: time.Unix(0x5cdac4b0, 0),
|
||||
Bits: 0x1e7fffff,
|
||||
Nonce: 0xfe2a,
|
||||
Nonce: 0xc79c,
|
||||
},
|
||||
Transactions: []*wire.MsgTx{devNetGenesisCoinbaseTx},
|
||||
}
|
||||
|
@ -121,39 +121,35 @@ 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, 0xd4, 0xdc, 0x8b,
|
||||
0xb8, 0x76, 0x57, 0x9d, 0x7d, 0xe9, 0x9d, 0xae,
|
||||
0xdb, 0xf8, 0x22, 0xd2, 0x0d, 0xa2, 0xe0, 0xbb,
|
||||
0xbe, 0xed, 0xb0, 0xdb, 0xba, 0xeb, 0x18, 0x4d,
|
||||
0x42, 0x01, 0xff, 0xed, 0x9d, 0xd4, 0xdc, 0x8b,
|
||||
0xb8, 0x76, 0x57, 0x9d, 0x7d, 0xe9, 0x9d, 0xae,
|
||||
0xdb, 0xf8, 0x22, 0xd2, 0x0d, 0xa2, 0xe0, 0xbb,
|
||||
0xbe, 0xed, 0xb0, 0xdb, 0xba, 0xeb, 0x18, 0x4d,
|
||||
0x42, 0x01, 0xff, 0xed, 0x9d, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x3d, 0xd8,
|
||||
0x5c, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f,
|
||||
0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 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, 0x0e, 0x00, 0x00, 0x0b, 0x2f,
|
||||
0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63,
|
||||
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, 0x2a, 0x01,
|
||||
0x00, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xdc, 0x8b, /* |........| */
|
||||
0xb8, 0x76, 0x57, 0x9d, 0x7d, 0xe9, 0x9d, 0xae, /* |.vW.}...| */
|
||||
0xdb, 0xf8, 0x22, 0xd2, 0x0d, 0xa2, 0xe0, 0xbb, /* |..".....| */
|
||||
0xbe, 0xed, 0xb0, 0xdb, 0xba, 0xeb, 0x18, 0x4d, /* |.......M| */
|
||||
0x42, 0x01, 0xff, 0xed, 0x9d, 0x00, 0x00, 0x00, /* |B.......| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0xc4, 0xda, /* |........| */
|
||||
0x5c, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, /* |\.......| */
|
||||
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x0e, 0x00, 0x00, 0x0b, 0x2f, /* |......./| */
|
||||
0x50, 0x32, 0x53, 0x48, 0x2f, 0x62, 0x74, 0x63, /* |P2SH/btc| */
|
||||
0x64, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* |d/......| */
|
||||
0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, 0x2a, 0x01, /* |......*.| */
|
||||
0x00, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00, 0x00, /* |....Q...| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
|
||||
0x00, /* |.| */
|
||||
}
|
||||
|
||||
// regTestGenesisBlockBytes are the wire encoded bytes for the genesis block of
|
||||
|
@ -175,5 +175,5 @@ func Example_blockStorageAndRetrieval() {
|
||||
fmt.Printf("Serialized block size: %d bytes\n", len(loadedBlockBytes))
|
||||
|
||||
// Output:
|
||||
// Serialized block size: 257 bytes
|
||||
// Serialized block size: 225 bytes
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
|
||||
func TestDeleteFile(t *testing.T) {
|
||||
testBlock := util.NewBlock(wire.NewMsgBlock(
|
||||
wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)))
|
||||
wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)))
|
||||
|
||||
tests := []struct {
|
||||
fileNum uint32
|
||||
@ -69,7 +69,7 @@ func TestDeleteFile(t *testing.T) {
|
||||
// and makes sure no panic occurs, as well as ensures the writeCursor was updated correctly.
|
||||
func TestHandleRollbackErrors(t *testing.T) {
|
||||
testBlock := util.NewBlock(wire.NewMsgBlock(
|
||||
wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)))
|
||||
wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)))
|
||||
|
||||
testBlockSize := uint32(testBlock.MsgBlock().SerializeSize())
|
||||
tests := []struct {
|
||||
|
@ -553,7 +553,7 @@ func TestForEachBucket(t *testing.T) {
|
||||
// TestStoreBlockErrors tests all error-cases in *tx.StoreBlock().
|
||||
// The non-error-cases are tested in the more general tests.
|
||||
func TestStoreBlockErrors(t *testing.T) {
|
||||
testBlock := util.NewBlock(wire.NewMsgBlock(wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)))
|
||||
testBlock := util.NewBlock(wire.NewMsgBlock(wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -716,7 +716,7 @@ func TestWritePendingAndCommitErrors(t *testing.T) {
|
||||
rollbackCalled = false
|
||||
err = pdb.Update(func(dbTx database.Tx) error {
|
||||
return dbTx.StoreBlock(util.NewBlock(wire.NewMsgBlock(
|
||||
wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0))))
|
||||
wire.NewBlockHeader(1, []*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0))))
|
||||
})
|
||||
if err == nil {
|
||||
t.Errorf("No error returned when blockIdx.Put() should have returned an error")
|
||||
|
BIN
database/testdata/blocks1-256.bz2
vendored
BIN
database/testdata/blocks1-256.bz2
vendored
Binary file not shown.
1
database/testdata/generator.go
vendored
1
database/testdata/generator.go
vendored
@ -47,7 +47,6 @@ func generateBlock(parent *wire.MsgBlock) *wire.MsgBlock {
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{parent.BlockHash()},
|
||||
HashMerkleRoot: &genesisMerkleRoot,
|
||||
IDMerkleRoot: &daghash.ZeroHash,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
Timestamp: time.Unix(0x5b28c4c8, 0), // 2018-06-19 08:54:32 +0000 UTC
|
||||
|
@ -183,13 +183,11 @@ func CreateBlock(parentBlock *util.Block, inclusionTxs []*util.Tx,
|
||||
blockTxns = append(blockTxns, inclusionTxs...)
|
||||
}
|
||||
hashMerkleTree := blockdag.BuildHashMerkleTreeStore(blockTxns)
|
||||
idMerkleTree := blockdag.BuildIDMerkleTreeStore(blockTxns)
|
||||
var block wire.MsgBlock
|
||||
block.Header = wire.BlockHeader{
|
||||
Version: blockVersion,
|
||||
ParentHashes: []*daghash.Hash{parentHash},
|
||||
HashMerkleRoot: hashMerkleTree.Root(),
|
||||
IDMerkleRoot: idMerkleTree.Root(),
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
Timestamp: ts,
|
||||
|
@ -71,7 +71,6 @@ func (eft *estimateFeeTester) newBlock(txs []*wire.MsgTx) {
|
||||
|
||||
block := util.NewBlock(&wire.MsgBlock{
|
||||
Header: wire.BlockHeader{
|
||||
IDMerkleRoot: &daghash.ZeroHash,
|
||||
HashMerkleRoot: &daghash.ZeroHash,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
|
@ -652,7 +652,6 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe
|
||||
|
||||
// Create a new block ready to be solved.
|
||||
hashMerkleTree := blockdag.BuildHashMerkleTreeStore(blockTxns)
|
||||
idMerkleTree := blockdag.BuildIDMerkleTreeStore(blockTxns)
|
||||
acceptedIDMerkleRoot, err := g.dag.NextAcceptedIDMerkleRoot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -662,7 +661,6 @@ func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress util.Address) (*BlockTe
|
||||
Version: nextBlockVersion,
|
||||
ParentHashes: g.dag.TipHashes(),
|
||||
HashMerkleRoot: hashMerkleTree.Root(),
|
||||
IDMerkleRoot: idMerkleTree.Root(),
|
||||
AcceptedIDMerkleRoot: acceptedIDMerkleRoot,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
Timestamp: ts,
|
||||
@ -747,8 +745,6 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight
|
||||
block := util.NewBlock(msgBlock)
|
||||
hashMerkleTree := blockdag.BuildHashMerkleTreeStore(block.Transactions())
|
||||
msgBlock.Header.HashMerkleRoot = hashMerkleTree.Root()
|
||||
idMerkleTree := blockdag.BuildIDMerkleTreeStore(block.Transactions())
|
||||
msgBlock.Header.IDMerkleRoot = idMerkleTree.Root()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func parseBlock(template *btcjson.GetBlockTemplateResult) (*util.Block, error) {
|
||||
bits := uint32(bitsInt64)
|
||||
|
||||
// parse rest of block
|
||||
msgBlock := wire.NewMsgBlock(wire.NewBlockHeader(template.Version, parentHashes, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, uint32(bits), 0))
|
||||
msgBlock := wire.NewMsgBlock(wire.NewBlockHeader(template.Version, parentHashes, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, uint32(bits), 0))
|
||||
|
||||
for i, txResult := range append([]btcjson.GetBlockTemplateResultTx{*template.CoinbaseTxn}, template.Transactions...) {
|
||||
reader := hex.NewDecoder(strings.NewReader(txResult.Data))
|
||||
@ -127,7 +127,6 @@ func solveLoop(newTemplateChan chan *btcjson.GetBlockTemplateResult, foundBlock
|
||||
msgBlock := block.MsgBlock()
|
||||
|
||||
msgBlock.Header.HashMerkleRoot = blockdag.BuildHashMerkleTreeStore(block.Transactions()).Root()
|
||||
msgBlock.Header.IDMerkleRoot = blockdag.BuildIDMerkleTreeStore(block.Transactions()).Root()
|
||||
|
||||
go solveBlock(block, stopOldTemplateSolving, foundBlock)
|
||||
}
|
||||
|
@ -115,7 +115,6 @@ func PrepareBlockForTest(dag *blockdag.BlockDAG, params *dagconfig.Params, paren
|
||||
utilTxs[i] = util.NewTx(tx)
|
||||
}
|
||||
template.Block.Header.HashMerkleRoot = blockdag.BuildHashMerkleTreeStore(utilTxs).Root()
|
||||
template.Block.Header.IDMerkleRoot = blockdag.BuildIDMerkleTreeStore(utilTxs).Root()
|
||||
|
||||
acceptedIDMerkleRoot, err := dag.NextAcceptedIDMerkleRoot()
|
||||
if err != nil {
|
||||
|
@ -494,7 +494,7 @@ func TestPeerListeners(t *testing.T) {
|
||||
{
|
||||
"OnBlock",
|
||||
wire.NewMsgBlock(wire.NewBlockHeader(1,
|
||||
[]*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 1, 1)),
|
||||
[]*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 1, 1)),
|
||||
},
|
||||
{
|
||||
"OnInv",
|
||||
@ -560,7 +560,7 @@ func TestPeerListeners(t *testing.T) {
|
||||
{
|
||||
"OnMerkleBlock",
|
||||
wire.NewMsgMerkleBlock(wire.NewBlockHeader(1,
|
||||
[]*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 1, 1)),
|
||||
[]*daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 1, 1)),
|
||||
},
|
||||
// only one version message is allowed
|
||||
// only one verack message is allowed
|
||||
|
@ -1198,7 +1198,6 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
|
||||
Version: blockHeader.Version,
|
||||
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
|
||||
HashMerkleRoot: blockHeader.HashMerkleRoot.String(),
|
||||
IDMerkleRoot: blockHeader.IDMerkleRoot.String(),
|
||||
AcceptedIDMerkleRoot: blockHeader.AcceptedIDMerkleRoot.String(),
|
||||
ParentHashes: daghash.Strings(blockHeader.ParentHashes),
|
||||
Nonce: blockHeader.Nonce,
|
||||
@ -1401,7 +1400,6 @@ func handleGetBlockHeader(s *Server, cmd interface{}, closeChan <-chan struct{})
|
||||
Version: blockHeader.Version,
|
||||
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
|
||||
HashMerkleRoot: blockHeader.HashMerkleRoot.String(),
|
||||
IDMerkleRoot: blockHeader.IDMerkleRoot.String(),
|
||||
AcceptedIDMerkleRoot: blockHeader.AcceptedIDMerkleRoot.String(),
|
||||
NextHashes: nextHashStrings,
|
||||
ParentHashes: daghash.Strings(blockHeader.ParentHashes),
|
||||
@ -1680,8 +1678,6 @@ func (state *gbtWorkState) updateBlockTemplate(s *Server, useCoinbaseValue bool)
|
||||
block := util.NewBlock(template.Block)
|
||||
hashMerkleTree := blockdag.BuildHashMerkleTreeStore(block.Transactions())
|
||||
template.Block.Header.HashMerkleRoot = hashMerkleTree.Root()
|
||||
idMerkleTree := blockdag.BuildIDMerkleTreeStore(block.Transactions())
|
||||
template.Block.Header.IDMerkleRoot = idMerkleTree.Root()
|
||||
}
|
||||
|
||||
// Set locals for convenience.
|
||||
|
@ -242,7 +242,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"getBlockVerboseResult-version": "The block version",
|
||||
"getBlockVerboseResult-versionHex": "The block version in hexadecimal",
|
||||
"getBlockVerboseResult-hashMerkleRoot": "Merkle tree reference to hash of all transactions for the block",
|
||||
"getBlockVerboseResult-idMerkleRoot": "Merkle tree reference to hash of all transactions' IDs for the block",
|
||||
"getBlockVerboseResult-acceptedIdMerkleRoot": "Merkle tree reference to hash all transactions accepted form the block blues",
|
||||
"getBlockVerboseResult-tx": "The transaction hashes (only when verbosetx=false)",
|
||||
"getBlockVerboseResult-rawRx": "The transactions as JSON objects (only when verbosetx=true)",
|
||||
@ -277,7 +276,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"getBlockHeaderVerboseResult-version": "The block version",
|
||||
"getBlockHeaderVerboseResult-versionHex": "The block version in hexadecimal",
|
||||
"getBlockHeaderVerboseResult-hashMerkleRoot": "Merkle tree reference to hash of all transactions for the block",
|
||||
"getBlockHeaderVerboseResult-idMerkleRoot": "Merkle tree reference to hash of all transactions' IDs for the block",
|
||||
"getBlockHeaderVerboseResult-acceptedIdMerkleRoot": "Merkle tree reference to hash all transactions accepted form the block blues",
|
||||
"getBlockHeaderVerboseResult-time": "The block time in seconds since 1 Jan 1970 GMT",
|
||||
"getBlockHeaderVerboseResult-nonce": "The block nonce",
|
||||
|
@ -38,7 +38,7 @@ func TestBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hash for block 100,000.
|
||||
wantHashStr := "df1b3cc747f665f36df84bdaa54a9ea695fbe12e102156fc1fc61d89366bc2d7"
|
||||
wantHashStr := "839a8e072e6d402128f6f9a32ffc012e471e071e8ef8405552b1e58ef7b681f0"
|
||||
wantHash, err := daghash.NewHashFromStr(wantHashStr)
|
||||
if err != nil {
|
||||
t.Errorf("NewHashFromStr: %v", err)
|
||||
@ -147,10 +147,10 @@ func TestBlock(t *testing.T) {
|
||||
|
||||
// Transaction offsets and length for the transaction in Block100000.
|
||||
wantTxLocs := []wire.TxLoc{
|
||||
{TxStart: 218, TxLen: 163},
|
||||
{TxStart: 381, TxLen: 287},
|
||||
{TxStart: 668, TxLen: 285},
|
||||
{TxStart: 953, TxLen: 253},
|
||||
{TxStart: 186, TxLen: 163},
|
||||
{TxStart: 349, TxLen: 287},
|
||||
{TxStart: 636, TxLen: 285},
|
||||
{TxStart: 921, TxLen: 253},
|
||||
}
|
||||
|
||||
// Ensure the transaction location information is accurate.
|
||||
@ -259,7 +259,7 @@ func TestBlockErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
// Truncate the block byte buffer to force errors.
|
||||
shortBytes := block100000Bytes[:218]
|
||||
shortBytes := block100000Bytes[:186]
|
||||
_, err = util.NewBlockFromBytes(shortBytes)
|
||||
if err != io.EOF {
|
||||
t.Errorf("NewBlockFromBytes: did not get expected error - "+
|
||||
@ -325,12 +325,6 @@ var Block100000 = wire.MsgBlock{
|
||||
0x28, 0xc3, 0x06, 0x7c, 0xc3, 0x8d, 0x48, 0x85,
|
||||
0xef, 0xb5, 0xa4, 0xac, 0x42, 0x47, 0xe9, 0xf3,
|
||||
}, // f3e94742aca4b5ef85488dc37c06c3282295ffec960994b2c0d5ac2a25a95766
|
||||
IDMerkleRoot: &daghash.Hash{
|
||||
0x66, 0x57, 0xa9, 0x25, 0x2a, 0xac, 0xd5, 0xc0,
|
||||
0xb2, 0x94, 0x09, 0x96, 0xec, 0xff, 0x95, 0x22,
|
||||
0x28, 0xc3, 0x06, 0x7c, 0xc3, 0x8d, 0x48, 0x85,
|
||||
0xef, 0xb5, 0xa4, 0xac, 0x42, 0x47, 0xe9, 0xf3,
|
||||
}, // f3e94742aca4b5ef85488dc37c06c3282295ffec960994b2c0d5ac2a25a95766
|
||||
AcceptedIDMerkleRoot: &daghash.Hash{
|
||||
0x28, 0xc3, 0x06, 0x7c, 0xc3, 0x8d, 0x48, 0x85,
|
||||
0xef, 0xb5, 0xa4, 0xac, 0x42, 0x47, 0xe9, 0xf3,
|
||||
|
@ -537,9 +537,6 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) {
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, 0x65, 0x9C, 0x79, // HashMerkleRoot
|
||||
0x3C, 0xE3, 0x70, 0xD9, 0x5F, 0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11,
|
||||
0x7B, 0x3C, 0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, 0x65, 0x9C, 0x79, // Fake IDMerkleRoot. TODO: (Ori) Replace to a real IDMerkleRoot
|
||||
0x3C, 0xE3, 0x70, 0xD9, 0x5F, 0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11,
|
||||
0x7B, 0x3C, 0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x3C, 0xE3, 0x70, 0xD9, 0x5F, 0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, // AcceptedIDMerkleRoot
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, 0x65, 0x9C, 0x79,
|
||||
0x7B, 0x3C, 0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
|
@ -25,9 +25,6 @@ func TestMerkleBlock3(t *testing.T) {
|
||||
0xB5, 0x0C, 0xC0, 0x69, 0xD6, 0xA3, 0xE3, 0x3E, 0x3F, 0xF8, 0x4A, // HashMerkleRoot
|
||||
0x5C, 0x41, 0xD9, 0xD3, 0xFE, 0xBE, 0x7C, 0x77, 0x0F, 0xDC, 0xC9,
|
||||
0x6B, 0x2C, 0x3F, 0xF6, 0x0A, 0xBE, 0x18, 0x4F, 0x19, 0x63,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, 0x65, 0x9C, 0x79, // Fake IDMerkleRoot. TODO: (Ori) Replace to a real IDMerkleRoot
|
||||
0x3C, 0xE3, 0x70, 0xD9, 0x5F, 0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11,
|
||||
0x7B, 0x3C, 0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x3C, 0xE3, 0x70, 0xD9, 0x5F, 0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, // AcceptedIDMerkleRoot
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, 0x65, 0x9C, 0x79,
|
||||
0x7B, 0x3C, 0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
@ -84,11 +81,7 @@ func TestMerkleBlock3(t *testing.T) {
|
||||
0x69, 0xd6, 0xa3, 0xe3, 0x3e, 0x3f, 0xf8, 0x4a,
|
||||
0x5c, 0x41, 0xd9, 0xd3, 0xfe, 0xbe, 0x7c, 0x77,
|
||||
0x0f, 0xdc, 0xc9, 0x6b, 0x2c, 0x3f, 0xf6, 0x0a,
|
||||
0xbe, 0x18, 0x4f, 0x19, 0x63, 0x7f, 0x16, 0xc5,
|
||||
0x96, 0x2e, 0x8b, 0xd9, 0x63, 0x65, 0x9c, 0x79,
|
||||
0x3c, 0xe3, 0x70, 0xd9, 0x5f, 0x09, 0x3b, 0xc7,
|
||||
0xe3, 0x67, 0x11, 0x7b, 0x3c, 0x30, 0xc1, 0xf8,
|
||||
0xfd, 0xd0, 0xd9, 0x72, 0x87, 0x3c, 0xe3, 0x70,
|
||||
0xbe, 0x18, 0x4f, 0x19, 0x63, 0x3c, 0xe3, 0x70,
|
||||
0xd9, 0x5f, 0x09, 0x3b, 0xc7, 0xe3, 0x67, 0x11,
|
||||
0x7f, 0x16, 0xc5, 0x96, 0x2e, 0x8b, 0xd9, 0x63,
|
||||
0x65, 0x9c, 0x79, 0x7b, 0x3c, 0x30, 0xc1, 0xf8,
|
||||
|
@ -15,10 +15,10 @@ import (
|
||||
// mainNetGenesisHash is the hash of the first block in the block chain for the
|
||||
// main network (genesis block).
|
||||
var mainNetGenesisHash = Hash([HashSize]byte{
|
||||
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,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25,
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
})
|
||||
|
||||
// TestHash tests the Hash API.
|
||||
@ -151,14 +151,14 @@ func TestNewHashFromStr(t *testing.T) {
|
||||
}{
|
||||
// Genesis hash.
|
||||
{
|
||||
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
|
||||
"63bbcfdd699ffd8cb19878564b14d3af8ba4d7ee4d1dd54925a7c21d5b5b5fdc",
|
||||
mainNetGenesisHash,
|
||||
nil,
|
||||
},
|
||||
|
||||
// Genesis hash with stripped leading zeros.
|
||||
{
|
||||
"19d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
|
||||
"63bbcfdd699ffd8cb19878564b14d3af8ba4d7ee4d1dd54925a7c21d5b5b5fdc",
|
||||
mainNetGenesisHash,
|
||||
nil,
|
||||
},
|
||||
|
@ -426,7 +426,7 @@ func BenchmarkDecodeHeaders(b *testing.B) {
|
||||
}
|
||||
parentHashes[i] = hash
|
||||
}
|
||||
m.AddBlockHeader(NewBlockHeader(1, parentHashes, hash, hash, hash, hash, 0, uint64(i)))
|
||||
m.AddBlockHeader(NewBlockHeader(1, parentHashes, hash, hash, hash, 0, uint64(i)))
|
||||
}
|
||||
|
||||
// Serialize it so the bytes are available to test the decode below.
|
||||
@ -572,7 +572,7 @@ func BenchmarkDecodeMerkleBlock(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatalf("NewHashFromStr: unexpected error: %v", err)
|
||||
}
|
||||
m.Header = *NewBlockHeader(1, []*daghash.Hash{hash}, hash, hash, hash, hash, 0, uint64(10000))
|
||||
m.Header = *NewBlockHeader(1, []*daghash.Hash{hash}, hash, hash, hash, 0, uint64(10000))
|
||||
for i := 0; i < 105; i++ {
|
||||
hash, err := daghash.NewHashFromStr(fmt.Sprintf("%x", i))
|
||||
if err != nil {
|
||||
|
@ -15,11 +15,11 @@ import (
|
||||
// BaseBlockHeaderPayload is the base number of bytes a block header can be,
|
||||
// not including the list of parent block headers.
|
||||
// Version 4 bytes + Timestamp 8 bytes + Bits 4 bytes + Nonce 8 bytes +
|
||||
// + NumParentBlocks 1 byte + HashMerkleRoot hash + IDMerkleRoot hash +
|
||||
// + NumParentBlocks 1 byte + HashMerkleRoot hash +
|
||||
// + AcceptedIDMerkleRoot hash + UTXOCommitment hash.
|
||||
// To get total size of block header len(ParentHashes) * daghash.HashSize should be
|
||||
// added to this value
|
||||
const BaseBlockHeaderPayload = 25 + 4*(daghash.HashSize)
|
||||
const BaseBlockHeaderPayload = 25 + 3*(daghash.HashSize)
|
||||
|
||||
// MaxNumParentBlocks is the maximum number of parent blocks a block can reference.
|
||||
// Currently set to 255 as the maximum number NumParentBlocks can be due to it being a byte
|
||||
@ -41,9 +41,6 @@ type BlockHeader struct {
|
||||
// HashMerkleRoot is the merkle tree reference to hash of all transactions for the block.
|
||||
HashMerkleRoot *daghash.Hash
|
||||
|
||||
// IDMerkleRoot is the merkle tree reference to hash of all transactions' IDs for the block.
|
||||
IDMerkleRoot *daghash.Hash
|
||||
|
||||
// AcceptedIDMerkleRoot is merkle tree reference to hash all transactions
|
||||
// accepted form the block.Blues
|
||||
AcceptedIDMerkleRoot *daghash.Hash
|
||||
@ -126,12 +123,10 @@ func (h *BlockHeader) SerializeSize() int {
|
||||
}
|
||||
|
||||
// NewBlockHeader returns a new BlockHeader using the provided version, previous
|
||||
// block hash, hash merkle root, ID merkle root difficulty bits, and nonce used to generate the
|
||||
// block hash, hash merkle root, accepted ID merkle root, difficulty bits, and nonce used to generate the
|
||||
// block with defaults or calclulated values for the remaining fields.
|
||||
func NewBlockHeader(version int32, parentHashes []*daghash.Hash, hashMerkleRoot *daghash.Hash,
|
||||
idMerkleRoot *daghash.Hash, acceptedIDMerkleRoot *daghash.Hash,
|
||||
utxoCommitment *daghash.Hash,
|
||||
bits uint32, nonce uint64) *BlockHeader {
|
||||
acceptedIDMerkleRoot *daghash.Hash, utxoCommitment *daghash.Hash, bits uint32, nonce uint64) *BlockHeader {
|
||||
|
||||
// Limit the timestamp to one second precision since the protocol
|
||||
// doesn't support better.
|
||||
@ -139,7 +134,6 @@ func NewBlockHeader(version int32, parentHashes []*daghash.Hash, hashMerkleRoot
|
||||
Version: version,
|
||||
ParentHashes: parentHashes,
|
||||
HashMerkleRoot: hashMerkleRoot,
|
||||
IDMerkleRoot: idMerkleRoot,
|
||||
AcceptedIDMerkleRoot: acceptedIDMerkleRoot,
|
||||
UTXOCommitment: utxoCommitment,
|
||||
Timestamp: time.Unix(time.Now().Unix(), 0),
|
||||
@ -168,12 +162,10 @@ func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error {
|
||||
bh.ParentHashes[i] = hash
|
||||
}
|
||||
bh.HashMerkleRoot = &daghash.Hash{}
|
||||
bh.IDMerkleRoot = &daghash.Hash{}
|
||||
bh.AcceptedIDMerkleRoot = &daghash.Hash{}
|
||||
bh.UTXOCommitment = &daghash.Hash{}
|
||||
return readElements(r, bh.HashMerkleRoot, bh.IDMerkleRoot,
|
||||
bh.AcceptedIDMerkleRoot, bh.UTXOCommitment, (*int64Time)(&bh.Timestamp),
|
||||
&bh.Bits, &bh.Nonce)
|
||||
return readElements(r, bh.HashMerkleRoot, bh.AcceptedIDMerkleRoot, bh.UTXOCommitment,
|
||||
(*int64Time)(&bh.Timestamp), &bh.Bits, &bh.Nonce)
|
||||
}
|
||||
|
||||
// writeBlockHeader writes a bitcoin block header to w. See Serialize for
|
||||
@ -189,6 +181,5 @@ func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return writeElements(w, bh.HashMerkleRoot, bh.IDMerkleRoot,
|
||||
bh.AcceptedIDMerkleRoot, bh.UTXOCommitment, sec, bh.Bits, bh.Nonce)
|
||||
return writeElements(w, bh.HashMerkleRoot, bh.AcceptedIDMerkleRoot, bh.UTXOCommitment, sec, bh.Bits, bh.Nonce)
|
||||
}
|
||||
|
@ -25,11 +25,9 @@ func TestBlockHeader(t *testing.T) {
|
||||
hashes := []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash}
|
||||
|
||||
merkleHash := mainNetGenesisMerkleRoot
|
||||
idMerkleRoot := exampleIDMerkleRoot
|
||||
acceptedIDMerkleRoot := exampleAcceptedIDMerkleRoot
|
||||
bits := uint32(0x1d00ffff)
|
||||
bh := NewBlockHeader(1, hashes, merkleHash, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, exampleUTXOCommitment, bits, nonce)
|
||||
bh := NewBlockHeader(1, hashes, merkleHash, acceptedIDMerkleRoot, exampleUTXOCommitment, bits, nonce)
|
||||
|
||||
// Ensure we get the same data back out.
|
||||
if !reflect.DeepEqual(bh.ParentHashes, hashes) {
|
||||
@ -62,7 +60,6 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
|
||||
HashMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
IDMerkleRoot: exampleIDMerkleRoot,
|
||||
AcceptedIDMerkleRoot: exampleAcceptedIDMerkleRoot,
|
||||
UTXOCommitment: exampleUTXOCommitment,
|
||||
Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST
|
||||
@ -74,10 +71,10 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
baseBlockHdrEncoded := []byte{
|
||||
0x01, 0x00, 0x00, 0x00, // Version 1
|
||||
0x02, // NumParentBlocks
|
||||
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, // mainNetGenesisHash
|
||||
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
|
||||
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
|
||||
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25, // mainNetGenesisHash
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a, // simNetGenesisHash
|
||||
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
|
||||
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
|
||||
@ -86,10 +83,6 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
0x32, 0x51, 0x8a, 0x88, 0xc3, 0x1b, 0xc8, 0x7f,
|
||||
0x61, 0x8f, 0x76, 0x67, 0x3e, 0x2c, 0xc7, 0x7a,
|
||||
0xb2, 0x12, 0x7b, 0x7a, 0xfd, 0xed, 0xa3, 0x3b,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -183,7 +176,6 @@ func TestBlockHeaderSerialize(t *testing.T) {
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
|
||||
HashMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
IDMerkleRoot: exampleIDMerkleRoot,
|
||||
AcceptedIDMerkleRoot: exampleAcceptedIDMerkleRoot,
|
||||
UTXOCommitment: exampleUTXOCommitment,
|
||||
Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST
|
||||
@ -195,10 +187,10 @@ func TestBlockHeaderSerialize(t *testing.T) {
|
||||
baseBlockHdrEncoded := []byte{
|
||||
0x01, 0x00, 0x00, 0x00, // Version 1
|
||||
0x02, // NumParentBlocks
|
||||
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, // mainNetGenesisHash
|
||||
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
|
||||
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
|
||||
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25, // mainNetGenesisHash
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a, // simNetGenesisHash
|
||||
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
|
||||
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
|
||||
@ -207,10 +199,6 @@ func TestBlockHeaderSerialize(t *testing.T) {
|
||||
0x32, 0x51, 0x8a, 0x88, 0xc3, 0x1b, 0xc8, 0x7f,
|
||||
0x61, 0x8f, 0x76, 0x67, 0x3e, 0x2c, 0xc7, 0x7a,
|
||||
0xb2, 0x12, 0x7b, 0x7a, 0xfd, 0xed, 0xa3, 0x3b,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -277,7 +265,6 @@ func TestBlockHeaderSerializeSize(t *testing.T) {
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
|
||||
HashMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
IDMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
Timestamp: timestamp,
|
||||
@ -289,7 +276,6 @@ func TestBlockHeaderSerializeSize(t *testing.T) {
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{},
|
||||
HashMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
IDMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
AcceptedIDMerkleRoot: &daghash.ZeroHash,
|
||||
UTXOCommitment: &daghash.ZeroHash,
|
||||
Timestamp: timestamp,
|
||||
@ -301,10 +287,10 @@ func TestBlockHeaderSerializeSize(t *testing.T) {
|
||||
size int // Expected serialized size
|
||||
}{
|
||||
// Block with no transactions.
|
||||
{genesisBlockHdr, 153},
|
||||
{genesisBlockHdr, 121},
|
||||
|
||||
// First block in the mainnet block DAG.
|
||||
{baseBlockHdr, 217},
|
||||
{baseBlockHdr, 185},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
// mainNetGenesisHash is the hash of the first block in the block chain for the
|
||||
// main network (genesis block).
|
||||
var mainNetGenesisHash = &daghash.Hash{
|
||||
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,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25,
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
}
|
||||
|
||||
// simNetGenesisHash is the hash of the first block in the block chain for the
|
||||
@ -42,13 +42,6 @@ var mainNetGenesisMerkleRoot = &daghash.Hash{
|
||||
0xb2, 0x12, 0x7b, 0x7a, 0xfd, 0xed, 0xa3, 0x3b,
|
||||
}
|
||||
|
||||
var exampleIDMerkleRoot = &daghash.Hash{
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
}
|
||||
|
||||
var exampleAcceptedIDMerkleRoot = &daghash.Hash{
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
|
@ -68,7 +68,7 @@ func TestMessage(t *testing.T) {
|
||||
msgFilterAdd := NewMsgFilterAdd([]byte{0x01})
|
||||
msgFilterClear := NewMsgFilterClear()
|
||||
msgFilterLoad := NewMsgFilterLoad([]byte{0x01}, 10, 0, BloomUpdateNone)
|
||||
bh := NewBlockHeader(1, []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)
|
||||
bh := NewBlockHeader(1, []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash}, &daghash.Hash{}, &daghash.Hash{}, &daghash.Hash{}, 0, 0)
|
||||
msgMerkleBlock := NewMsgMerkleBlock(bh)
|
||||
msgReject := NewMsgReject("block", RejectDuplicate, "duplicate block")
|
||||
msgGetCFilters := NewMsgGetCFilters(GCSFilterExtended, 0, &daghash.Hash{})
|
||||
@ -91,7 +91,7 @@ func TestMessage(t *testing.T) {
|
||||
{msgGetAddr, msgGetAddr, pver, MainNet, 26},
|
||||
{msgAddr, msgAddr, pver, MainNet, 27},
|
||||
{msgGetBlocks, msgGetBlocks, pver, MainNet, 61},
|
||||
{msgBlock, msgBlock, pver, MainNet, 404},
|
||||
{msgBlock, msgBlock, pver, MainNet, 372},
|
||||
{msgInv, msgInv, pver, MainNet, 25},
|
||||
{msgGetData, msgGetData, pver, MainNet, 25},
|
||||
{msgNotFound, msgNotFound, pver, MainNet, 25},
|
||||
@ -107,7 +107,7 @@ func TestMessage(t *testing.T) {
|
||||
{msgFilterAdd, msgFilterAdd, pver, MainNet, 26},
|
||||
{msgFilterClear, msgFilterClear, pver, MainNet, 24},
|
||||
{msgFilterLoad, msgFilterLoad, pver, MainNet, 35},
|
||||
{msgMerkleBlock, msgMerkleBlock, pver, MainNet, 247},
|
||||
{msgMerkleBlock, msgMerkleBlock, pver, MainNet, 215},
|
||||
{msgReject, msgReject, pver, MainNet, 79},
|
||||
{msgGetCFilters, msgGetCFilters, pver, MainNet, 65},
|
||||
{msgGetCFHeaders, msgGetCFHeaders, pver, MainNet, 65},
|
||||
|
@ -25,13 +25,11 @@ func TestBlock(t *testing.T) {
|
||||
// Block 1 header.
|
||||
parentHashes := blockOne.Header.ParentHashes
|
||||
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||
idMerkleRoot := blockOne.Header.IDMerkleRoot
|
||||
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||
bits := blockOne.Header.Bits
|
||||
nonce := blockOne.Header.Nonce
|
||||
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
|
||||
// Ensure the command is expected value.
|
||||
wantCmd := "block"
|
||||
@ -77,7 +75,7 @@ func TestBlock(t *testing.T) {
|
||||
// TestBlockHash tests the ability to generate the hash of a block accurately.
|
||||
func TestBlockHash(t *testing.T) {
|
||||
// Block 1 hash.
|
||||
hashStr := "8a3a27a37c9e3342b4b38ae9ef29e59fe37b59618adafbf36a106b6d62f80654"
|
||||
hashStr := "22e72b61a572bfb32b8739f4e5db3eebe9870e394288467958e93e4a3d3b749f"
|
||||
wantHash, err := daghash.NewHashFromStr(hashStr)
|
||||
if err != nil {
|
||||
t.Errorf("NewHashFromStr: %v", err)
|
||||
@ -221,22 +219,20 @@ func TestBlockWireErrors(t *testing.T) {
|
||||
{&blockOne, blockOneBytes, pver, 37, io.ErrShortWrite, io.EOF},
|
||||
// Force error in hash merkle root.
|
||||
{&blockOne, blockOneBytes, pver, 69, io.ErrShortWrite, io.EOF},
|
||||
// Force error in ID merkle root.
|
||||
{&blockOne, blockOneBytes, pver, 101, io.ErrShortWrite, io.EOF},
|
||||
// Force error in accepted ID merkle root.
|
||||
{&blockOne, blockOneBytes, pver, 133, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 101, io.ErrShortWrite, io.EOF},
|
||||
// Force error in utxo commitment.
|
||||
{&blockOne, blockOneBytes, pver, 165, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 133, io.ErrShortWrite, io.EOF},
|
||||
// Force error in timestamp.
|
||||
{&blockOne, blockOneBytes, pver, 197, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 165, io.ErrShortWrite, io.EOF},
|
||||
// Force error in difficulty bits.
|
||||
{&blockOne, blockOneBytes, pver, 205, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 173, io.ErrShortWrite, io.EOF},
|
||||
// Force error in header nonce.
|
||||
{&blockOne, blockOneBytes, pver, 209, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 177, io.ErrShortWrite, io.EOF},
|
||||
// Force error in transaction count.
|
||||
{&blockOne, blockOneBytes, pver, 217, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 185, io.ErrShortWrite, io.EOF},
|
||||
// Force error in transactions.
|
||||
{&blockOne, blockOneBytes, pver, 218, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, pver, 186, io.ErrShortWrite, io.EOF},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
@ -349,22 +345,20 @@ func TestBlockSerializeErrors(t *testing.T) {
|
||||
{&blockOne, blockOneBytes, 37, io.ErrShortWrite, io.EOF},
|
||||
// Force error in hash merkle root.
|
||||
{&blockOne, blockOneBytes, 69, io.ErrShortWrite, io.EOF},
|
||||
// Force error in ID merkle root.
|
||||
{&blockOne, blockOneBytes, 101, io.ErrShortWrite, io.EOF},
|
||||
// Force error in accepted ID merkle root.
|
||||
{&blockOne, blockOneBytes, 133, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 101, io.ErrShortWrite, io.EOF},
|
||||
// Force error in utxo commitment.
|
||||
{&blockOne, blockOneBytes, 165, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 133, io.ErrShortWrite, io.EOF},
|
||||
// Force error in timestamp.
|
||||
{&blockOne, blockOneBytes, 197, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 165, io.ErrShortWrite, io.EOF},
|
||||
// Force error in difficulty bits.
|
||||
{&blockOne, blockOneBytes, 205, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 173, io.ErrShortWrite, io.EOF},
|
||||
// Force error in header nonce.
|
||||
{&blockOne, blockOneBytes, 209, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 177, io.ErrShortWrite, io.EOF},
|
||||
// Force error in transaction count.
|
||||
{&blockOne, blockOneBytes, 217, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 185, io.ErrShortWrite, io.EOF},
|
||||
// Force error in transactions.
|
||||
{&blockOne, blockOneBytes, 218, io.ErrShortWrite, io.EOF},
|
||||
{&blockOne, blockOneBytes, 186, io.ErrShortWrite, io.EOF},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
@ -428,10 +422,6 @@ func TestBlockOverflowErrors(t *testing.T) {
|
||||
0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
|
||||
0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
|
||||
0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -492,7 +482,7 @@ func TestBlockSerializeSize(t *testing.T) {
|
||||
size int // Expected serialized size
|
||||
}{
|
||||
// Block with no transactions.
|
||||
{noTxBlock, 218},
|
||||
{noTxBlock, 186},
|
||||
|
||||
// First block in the mainnet block chain.
|
||||
{&blockOne, len(blockOneBytes)},
|
||||
@ -516,7 +506,6 @@ var blockOne = MsgBlock{
|
||||
Version: 1,
|
||||
ParentHashes: []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash},
|
||||
HashMerkleRoot: mainNetGenesisMerkleRoot,
|
||||
IDMerkleRoot: exampleIDMerkleRoot,
|
||||
AcceptedIDMerkleRoot: exampleAcceptedIDMerkleRoot,
|
||||
UTXOCommitment: exampleUTXOCommitment,
|
||||
Timestamp: time.Unix(0x4966bc61, 0), // 2009-01-08 20:54:25 -0600 CST
|
||||
@ -562,10 +551,10 @@ var blockOne = MsgBlock{
|
||||
var blockOneBytes = []byte{
|
||||
0x01, 0x00, 0x00, 0x00, // Version 1
|
||||
0x02, // NumParentBlocks
|
||||
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, // mainNetGenesisHash
|
||||
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
|
||||
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
|
||||
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25, // mainNetGenesisHash
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a, // simNetGenesisHash
|
||||
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
|
||||
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
|
||||
@ -574,10 +563,6 @@ var blockOneBytes = []byte{
|
||||
0x32, 0x51, 0x8a, 0x88, 0xc3, 0x1b, 0xc8, 0x7f,
|
||||
0x61, 0x8f, 0x76, 0x67, 0x3e, 0x2c, 0xc7, 0x7a,
|
||||
0xb2, 0x12, 0x7b, 0x7a, 0xfd, 0xed, 0xa3, 0x3b,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // Fake IDMerkleRoot. TODO: (Ori) Replace to a real IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -622,5 +607,5 @@ var blockOneBytes = []byte{
|
||||
|
||||
// Transaction location information for block one transactions.
|
||||
var blockOneTxLocs = []TxLoc{
|
||||
{TxStart: 218, TxLen: 162},
|
||||
{TxStart: 186, TxLen: 162},
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func TestHeaders(t *testing.T) {
|
||||
// Ensure max payload is expected value for latest protocol version.
|
||||
// Num headers (varInt) + max allowed headers (header length + 1 byte
|
||||
// for the number of transactions which is always 0).
|
||||
wantPayload := uint32(16628009)
|
||||
wantPayload := uint32(16564009)
|
||||
maxPayload := msg.MaxPayloadLength(pver)
|
||||
if maxPayload != wantPayload {
|
||||
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||
@ -63,13 +63,11 @@ func TestHeaders(t *testing.T) {
|
||||
func TestHeadersWire(t *testing.T) {
|
||||
hashes := []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash}
|
||||
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||
idMerkleRoot := blockOne.Header.IDMerkleRoot
|
||||
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||
bits := uint32(0x1d00ffff)
|
||||
nonce := uint64(0x9962e301)
|
||||
bh := NewBlockHeader(1, hashes, hashMerkleRoot, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh := NewBlockHeader(1, hashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh.Version = blockOne.Header.Version
|
||||
bh.Timestamp = blockOne.Header.Timestamp
|
||||
|
||||
@ -86,10 +84,10 @@ func TestHeadersWire(t *testing.T) {
|
||||
0x01, // VarInt for number of headers.
|
||||
0x01, 0x00, 0x00, 0x00, // Version 1
|
||||
0x02, // NumParentBlocks
|
||||
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, // mainNetGenesisHash
|
||||
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
|
||||
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
|
||||
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25, // mainNetGenesisHash
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a, // simNetGenesisHash
|
||||
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
|
||||
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
|
||||
@ -98,10 +96,6 @@ func TestHeadersWire(t *testing.T) {
|
||||
0x32, 0x51, 0x8a, 0x88, 0xc3, 0x1b, 0xc8, 0x7f,
|
||||
0x61, 0x8f, 0x76, 0x67, 0x3e, 0x2c, 0xc7, 0x7a,
|
||||
0xb2, 0x12, 0x7b, 0x7a, 0xfd, 0xed, 0xa3, 0x3b,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -178,13 +172,11 @@ func TestHeadersWireErrors(t *testing.T) {
|
||||
|
||||
hashes := []*daghash.Hash{mainNetGenesisHash, simNetGenesisHash}
|
||||
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||
idMerkleRoot := blockOne.Header.IDMerkleRoot
|
||||
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||
bits := uint32(0x1d00ffff)
|
||||
nonce := uint64(0x9962e301)
|
||||
bh := NewBlockHeader(1, hashes, hashMerkleRoot, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh := NewBlockHeader(1, hashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh.Version = blockOne.Header.Version
|
||||
bh.Timestamp = blockOne.Header.Timestamp
|
||||
|
||||
@ -207,10 +199,6 @@ func TestHeadersWireErrors(t *testing.T) {
|
||||
0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
|
||||
0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
|
||||
0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -238,8 +226,7 @@ func TestHeadersWireErrors(t *testing.T) {
|
||||
|
||||
// Intentionally invalid block header that has a transaction count used
|
||||
// to force errors.
|
||||
bhTrans := NewBlockHeader(1, hashes, hashMerkleRoot, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bhTrans := NewBlockHeader(1, hashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bhTrans.Version = blockOne.Header.Version
|
||||
bhTrans.Timestamp = blockOne.Header.Timestamp
|
||||
|
||||
@ -261,10 +248,6 @@ func TestHeadersWireErrors(t *testing.T) {
|
||||
0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
|
||||
0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
|
||||
0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
@ -295,7 +278,7 @@ func TestHeadersWireErrors(t *testing.T) {
|
||||
// Force error with greater than max headers.
|
||||
{maxHeaders, maxHeadersEncoded, pver, 3, wireErr, wireErr},
|
||||
// Force error with number of transactions.
|
||||
{transHeader, transHeaderEncoded, pver, 210, io.ErrShortWrite, io.EOF},
|
||||
{transHeader, transHeaderEncoded, pver, 178, io.ErrShortWrite, io.EOF},
|
||||
// Force error with included transactions.
|
||||
{transHeader, transHeaderEncoded, pver, len(transHeaderEncoded), nil, wireErr},
|
||||
}
|
||||
|
@ -23,13 +23,11 @@ func TestMerkleBlock(t *testing.T) {
|
||||
// Block 1 header.
|
||||
parentHashes := blockOne.Header.ParentHashes
|
||||
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||
idMerkleRoot := blockOne.Header.IDMerkleRoot
|
||||
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||
bits := blockOne.Header.Bits
|
||||
nonce := blockOne.Header.Nonce
|
||||
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
|
||||
// Ensure the command is expected value.
|
||||
wantCmd := "merkleblock"
|
||||
@ -119,13 +117,11 @@ func TestMerkleBlockCrossProtocol(t *testing.T) {
|
||||
// Block 1 header.
|
||||
parentHashes := blockOne.Header.ParentHashes
|
||||
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||
idMerkleRoot := blockOne.Header.IDMerkleRoot
|
||||
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||
bits := blockOne.Header.Bits
|
||||
nonce := blockOne.Header.Nonce
|
||||
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, idMerkleRoot,
|
||||
acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||
|
||||
msg := NewMsgMerkleBlock(bh)
|
||||
|
||||
@ -207,28 +203,26 @@ func TestMerkleBlockWireErrors(t *testing.T) {
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 37, io.ErrShortWrite, io.EOF},
|
||||
// Force error in hash merkle root.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 69, io.ErrShortWrite, io.EOF},
|
||||
// Force error in hash merkle root.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 101, io.ErrShortWrite, io.EOF},
|
||||
// Force error in accepted ID merkle root.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 133, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 101, io.ErrShortWrite, io.EOF},
|
||||
// Force error in utxo commitment.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 165, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 133, io.ErrShortWrite, io.EOF},
|
||||
// Force error in timestamp.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 197, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 165, io.ErrShortWrite, io.EOF},
|
||||
// Force error in difficulty bits.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 205, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 173, io.ErrShortWrite, io.EOF},
|
||||
// Force error in header nonce.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 209, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 177, io.ErrShortWrite, io.EOF},
|
||||
// Force error in transaction count.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 217, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 185, io.ErrShortWrite, io.EOF},
|
||||
// Force error in num hashes.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 221, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 189, io.ErrShortWrite, io.EOF},
|
||||
// Force error in hashes.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 222, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 190, io.ErrShortWrite, io.EOF},
|
||||
// Force error in num flag bytes.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 254, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 222, io.ErrShortWrite, io.EOF},
|
||||
// Force error in flag bytes.
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 255, io.ErrShortWrite, io.EOF},
|
||||
{&merkleBlockOne, merkleBlockOneBytes, pver, 223, io.ErrShortWrite, io.EOF},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
@ -285,7 +279,7 @@ func TestMerkleBlockOverflowErrors(t *testing.T) {
|
||||
// allowed tx hashes.
|
||||
var buf bytes.Buffer
|
||||
WriteVarInt(&buf, maxTxPerBlock+1)
|
||||
numHashesOffset := 221
|
||||
numHashesOffset := 189
|
||||
exceedMaxHashes := make([]byte, numHashesOffset)
|
||||
copy(exceedMaxHashes, merkleBlockOneBytes[:numHashesOffset])
|
||||
spew.Dump(exceedMaxHashes)
|
||||
@ -295,7 +289,7 @@ func TestMerkleBlockOverflowErrors(t *testing.T) {
|
||||
// allowed flag bytes.
|
||||
buf.Reset()
|
||||
WriteVarInt(&buf, maxFlagsPerMerkleBlock+1)
|
||||
numFlagBytesOffset := 254
|
||||
numFlagBytesOffset := 222
|
||||
exceedMaxFlagBytes := make([]byte, numFlagBytesOffset)
|
||||
copy(exceedMaxFlagBytes, merkleBlockOneBytes[:numFlagBytesOffset])
|
||||
exceedMaxFlagBytes = append(exceedMaxFlagBytes, buf.Bytes()...)
|
||||
@ -337,7 +331,6 @@ var merkleBlockOne = MsgMerkleBlock{
|
||||
0x7b, 0xa1, 0xa3, 0xc3, 0x54, 0x0b, 0xf7, 0xb1,
|
||||
0xcd, 0xb6, 0x06, 0xe8, 0x57, 0x23, 0x3e, 0x0e,
|
||||
},
|
||||
IDMerkleRoot: exampleIDMerkleRoot,
|
||||
AcceptedIDMerkleRoot: exampleAcceptedIDMerkleRoot,
|
||||
UTXOCommitment: exampleUTXOCommitment,
|
||||
Timestamp: time.Unix(0x4966bc61, 0), // 2009-01-08 20:54:25 -0600 CST
|
||||
@ -361,10 +354,10 @@ var merkleBlockOne = MsgMerkleBlock{
|
||||
var merkleBlockOneBytes = []byte{
|
||||
0x01, 0x00, 0x00, 0x00, // Version 1
|
||||
0x02, // NumParentBlocks
|
||||
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, // mainNetGenesisHash
|
||||
0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
|
||||
0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
|
||||
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25, // mainNetGenesisHash
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63,
|
||||
0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a, // simNetGenesisHash
|
||||
0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
|
||||
0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
|
||||
@ -373,10 +366,6 @@ var merkleBlockOneBytes = []byte{
|
||||
0xbb, 0xbe, 0x68, 0x0e, 0x1f, 0xee, 0x14, 0x67,
|
||||
0x7b, 0xa1, 0xa3, 0xc3, 0x54, 0x0b, 0xf7, 0xb1,
|
||||
0xcd, 0xb6, 0x06, 0xe8, 0x57, 0x23, 0x3e, 0x0e,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63, // IDMerkleRoot
|
||||
0x65, 0x9C, 0x79, 0x3C, 0xE3, 0x70, 0xD9, 0x5F,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C,
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x09, 0x3B, 0xC7, 0xE3, 0x67, 0x11, 0x7B, 0x3C, // AcceptedIDMerkleRoot
|
||||
0x30, 0xC1, 0xF8, 0xFD, 0xD0, 0xD9, 0x72, 0x87,
|
||||
0x7F, 0x16, 0xC5, 0x96, 0x2E, 0x8B, 0xD9, 0x63,
|
||||
|
@ -174,10 +174,10 @@ func TestRejectWire(t *testing.T) {
|
||||
0x12, // RejectDuplicate
|
||||
0x0f, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61,
|
||||
0x74, 0x65, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, // "duplicate block"
|
||||
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, // mainNetGenesisHash
|
||||
0xdc, 0x5f, 0x5b, 0x5b, 0x1d, 0xc2, 0xa7, 0x25,
|
||||
0x49, 0xd5, 0x1d, 0x4d, 0xee, 0xd7, 0xa4, 0x8b,
|
||||
0xaf, 0xd3, 0x14, 0x4b, 0x56, 0x78, 0x98, 0xb1,
|
||||
0x8c, 0xfd, 0x9f, 0x69, 0xdd, 0xcf, 0xbb, 0x63, // mainNetGenesisHash
|
||||
},
|
||||
ProtocolVersion,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user