From 4e7f502753546efa47d58ab770a5c275e7b41c77 Mon Sep 17 00:00:00 2001 From: wz Date: Fri, 10 May 2019 10:49:40 +0800 Subject: [PATCH] Add BlockWitness (#54) * Add BlockWitness * modify test and Add BlockWitness for proto * add unit test * modify code format * modify review * Modify unit test --- protocol/bc/bc.pb.go | 119 +++++++++++++++++--------------- protocol/bc/bc.proto | 1 + protocol/bc/blockheader.go | 3 +- protocol/bc/types/block_header.go | 9 +++ protocol/bc/types/block_header_test.go | 95 +++++++++++++++++++++++++ protocol/bc/types/block_test.go | 9 ++- protocol/bc/types/block_witness.go | 22 ++++++ protocol/bc/types/block_witness_test.go | 60 ++++++++++++++++ protocol/bc/types/map.go | 2 +- 9 files changed, 260 insertions(+), 60 deletions(-) create mode 100644 protocol/bc/types/block_witness.go create mode 100644 protocol/bc/types/block_witness_test.go diff --git a/protocol/bc/bc.pb.go b/protocol/bc/bc.pb.go index 07773bd6..9982f79a 100644 --- a/protocol/bc/bc.pb.go +++ b/protocol/bc/bc.pb.go @@ -272,6 +272,7 @@ type BlockHeader struct { TransactionsRoot *Hash `protobuf:"bytes,5,opt,name=transactions_root,json=transactionsRoot" json:"transactions_root,omitempty"` TransactionStatusHash *Hash `protobuf:"bytes,6,opt,name=transaction_status_hash,json=transactionStatusHash" json:"transaction_status_hash,omitempty"` TransactionStatus *TransactionStatus `protobuf:"bytes,7,opt,name=transaction_status,json=transactionStatus" json:"transaction_status,omitempty"` + WitnessArguments [][]byte `protobuf:"bytes,8,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"` } func (m *BlockHeader) Reset() { *m = BlockHeader{} } @@ -328,6 +329,13 @@ func (m *BlockHeader) GetTransactionStatus() *TransactionStatus { return nil } +func (m *BlockHeader) GetWitnessArguments() [][]byte { + if m != nil { + return m.WitnessArguments + } + return nil +} + type TxHeader struct { Version uint64 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"` SerializedSize uint64 `protobuf:"varint,2,opt,name=serialized_size,json=serializedSize" json:"serialized_size,omitempty"` @@ -647,61 +655,62 @@ func init() { func init() { proto.RegisterFile("bc.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 894 bytes of a gzipped FileDescriptorProto + // 903 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xdb, 0x46, - 0x10, 0x86, 0x28, 0x5a, 0x92, 0x47, 0x8e, 0x65, 0xad, 0x93, 0x94, 0x08, 0x52, 0x34, 0x20, 0x90, - 0xba, 0x45, 0x01, 0xc3, 0x96, 0xd3, 0xf6, 0xd2, 0x43, 0xdd, 0xba, 0x69, 0x74, 0x30, 0x52, 0xac, + 0x10, 0x86, 0x28, 0x5a, 0xa2, 0x47, 0x89, 0x65, 0xad, 0x93, 0x94, 0x08, 0x52, 0xd4, 0x20, 0x90, + 0x3a, 0x45, 0x01, 0xc3, 0x96, 0xd3, 0xf6, 0xd2, 0x43, 0xdd, 0xba, 0x69, 0x74, 0x30, 0x52, 0xac, 0x0d, 0x5f, 0x89, 0x15, 0xb9, 0x92, 0x16, 0xa5, 0xb8, 0xea, 0xee, 0x52, 0x75, 0x7c, 0xeb, 0x43, - 0xf4, 0x59, 0xfa, 0x08, 0x3d, 0xf5, 0xd2, 0x27, 0x2a, 0x76, 0xb8, 0x14, 0xa9, 0x9f, 0xfc, 0x18, - 0x45, 0x6e, 0x9a, 0xbf, 0x6f, 0x66, 0xbe, 0x9d, 0x19, 0x0a, 0x3a, 0xa3, 0xf8, 0x78, 0xae, 0xa4, - 0x91, 0xc4, 0x1b, 0xc5, 0xe1, 0x4b, 0xf0, 0x5f, 0x31, 0x3d, 0x25, 0xfb, 0xe0, 0x2d, 0x4e, 0x82, - 0xc6, 0xb3, 0xc6, 0x17, 0x2d, 0xea, 0x2d, 0x4e, 0x50, 0x3e, 0x0d, 0x3c, 0x27, 0x9f, 0xa2, 0x3c, - 0x08, 0x9a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xc3, 0x2d, 0x15, 0xb8, 0x95, 0xde, 0x5e, 0x00, 0xd9, 0x2c, 0xc0, 0xae, - 0x0c, 0x53, 0x23, 0x61, 0x14, 0x53, 0x6f, 0xdc, 0x9d, 0xae, 0x14, 0xe1, 0x1f, 0x0d, 0x68, 0xbd, - 0xce, 0xcd, 0x3c, 0x37, 0xe4, 0x08, 0x5a, 0x05, 0x47, 0x2e, 0xc5, 0x06, 0x85, 0xce, 0x4c, 0x5e, - 0x40, 0x2f, 0x96, 0x99, 0x51, 0x32, 0x8d, 0xde, 0xc1, 0xe4, 0xbe, 0xf3, 0x29, 0x2f, 0x66, 0x00, - 0x6d, 0xa9, 0x12, 0x91, 0xb1, 0xd4, 0x8d, 0x62, 0x29, 0x86, 0xaf, 0x01, 0x28, 0x37, 0x42, 0x71, - 0xcb, 0xc1, 0x87, 0x97, 0x51, 0x03, 0xf4, 0x56, 0x01, 0xff, 0xf2, 0xa0, 0x33, 0x74, 0x07, 0xdb, - 0x8e, 0x79, 0x26, 0xed, 0x79, 0xc7, 0x85, 0x5e, 0x3f, 0x88, 0xbb, 0x68, 0xc3, 0x25, 0xfe, 0xc0, - 0xb3, 0xf8, 0x96, 0x67, 0x69, 0xde, 0xf3, 0x59, 0x2e, 0x21, 0x58, 0x8e, 0x05, 0x7e, 0xd3, 0x92, - 0xe5, 0x47, 0x09, 0x0f, 0x5b, 0x77, 0x70, 0xb8, 0x2c, 0xa0, 0xfa, 0x5e, 0xd1, 0xc7, 0xe5, 0xc8, - 0xac, 0x7d, 0xc7, 0xb6, 0x4e, 0xd9, 0xce, 0xf6, 0x29, 0xab, 0x33, 0xd7, 0x5a, 0x65, 0xee, 0xef, - 0x06, 0xec, 0x5c, 0xcd, 0x79, 0x96, 0x90, 0x13, 0xe8, 0xe9, 0x39, 0xcf, 0x4c, 0x24, 0x71, 0x3a, - 0xaa, 0x4f, 0x6e, 0xc5, 0xdd, 0x03, 0x74, 0x28, 0xa6, 0x67, 0x98, 0xbc, 0x8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0x1b, 0x00, 0xca, 0x8d, 0x50, 0xdc, 0x72, 0xf0, 0xe1, 0x69, 0xd4, 0x00, 0xbd, + 0x55, 0xc0, 0x3f, 0x3d, 0x08, 0x06, 0xee, 0xba, 0xdb, 0x31, 0xcf, 0xa5, 0xfd, 0x16, 0xe0, 0xf6, + 0xaf, 0x5f, 0xcf, 0x5d, 0xb4, 0xe1, 0xc6, 0x7f, 0xe0, 0x0d, 0xbd, 0xa7, 0x2d, 0xcd, 0x8f, 0x6c, + 0xcb, 0x25, 0x84, 0x8b, 0xb1, 0xc0, 0x0f, 0x60, 0xba, 0xf8, 0x82, 0xe1, 0x15, 0xec, 0xf4, 0x0f, + 0x16, 0x09, 0x2c, 0x3f, 0x6e, 0xf4, 0x49, 0x35, 0x32, 0x6b, 0x1f, 0xbd, 0xad, 0x53, 0xb6, 0xb3, + 0x7d, 0xca, 0xea, 0xcc, 0xb5, 0x56, 0x99, 0xfb, 0xab, 0x01, 0x3b, 0x57, 0x33, 0x9e, 0xa7, 0xe4, + 0x04, 0xba, 0x7a, 0xc6, 0x73, 0x13, 0x4b, 0x9c, 0x8e, 0xe5, 0xf7, 0x79, 0xc9, 0xdd, 0x43, 0x74, + 0x28, 0xa7, 0x67, 0x90, 0xde, 0x47, 0x8c, 0xf7, 0x91, 0xc4, 0x6c, 0xad, 0xa4, 0xf9, 0xfe, 0x4a, + 0xfc, 0x95, 0x4a, 0x86, 0x2d, 0xfc, 0x0f, 0x75, 0xf6, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, + 0xac, 0x41, 0xa8, 0x4f, 0x09, 0x00, 0x00, } diff --git a/protocol/bc/bc.proto b/protocol/bc/bc.proto index de7a9485..d1c9d8da 100644 --- a/protocol/bc/bc.proto +++ b/protocol/bc/bc.proto @@ -56,6 +56,7 @@ message BlockHeader { Hash transactions_root = 5; Hash transaction_status_hash = 6; TransactionStatus transaction_status = 7; + repeated bytes witness_arguments = 8; } message TxHeader { diff --git a/protocol/bc/blockheader.go b/protocol/bc/blockheader.go index 2d912bd0..cc424aeb 100644 --- a/protocol/bc/blockheader.go +++ b/protocol/bc/blockheader.go @@ -17,7 +17,7 @@ func (bh *BlockHeader) writeForHash(w io.Writer) { // NewBlockHeader creates a new BlockHeader and populates // its body. -func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestamp uint64, transactionsRoot, transactionStatusHash *Hash) *BlockHeader { +func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestamp uint64, transactionsRoot, transactionStatusHash *Hash, witness [][]byte) *BlockHeader { return &BlockHeader{ Version: version, Height: height, @@ -26,5 +26,6 @@ func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestamp uin TransactionsRoot: transactionsRoot, TransactionStatusHash: transactionStatusHash, TransactionStatus: nil, + WitnessArguments: witness, } } diff --git a/protocol/bc/types/block_header.go b/protocol/bc/types/block_header.go index ab531578..7df4c379 100644 --- a/protocol/bc/types/block_header.go +++ b/protocol/bc/types/block_header.go @@ -19,6 +19,7 @@ type BlockHeader struct { PreviousBlockHash bc.Hash // The hash of the previous block. Timestamp uint64 // The time of the block in seconds. BlockCommitment + BlockWitness } // Time returns the time represented by the Timestamp in block header. @@ -84,6 +85,10 @@ func (bh *BlockHeader) readFrom(r *blockchain.Reader) (serflag uint8, err error) if _, err = blockchain.ReadExtensibleString(r, bh.BlockCommitment.readFrom); err != nil { return 0, err } + + if _, err = blockchain.ReadExtensibleString(r, bh.BlockWitness.readFrom); err != nil { + return 0, err + } return } @@ -113,5 +118,9 @@ func (bh *BlockHeader) writeTo(w io.Writer, serflags uint8) (err error) { if _, err = blockchain.WriteExtensibleString(w, nil, bh.BlockCommitment.writeTo); err != nil { return err } + + if _, err = blockchain.WriteExtensibleString(w, nil, bh.BlockWitness.writeTo); err != nil { + return err + } return nil } diff --git a/protocol/bc/types/block_header_test.go b/protocol/bc/types/block_header_test.go index 6bbd5b45..4a9237a9 100644 --- a/protocol/bc/types/block_header_test.go +++ b/protocol/bc/types/block_header_test.go @@ -24,6 +24,7 @@ func TestBlockHeader(t *testing.T) { TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, } wantHex := strings.Join([]string{ @@ -35,6 +36,7 @@ func TestBlockHeader(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash + "040102beef", //BlockWitness }, "") gotHex := testutil.Serialize(t, blockHeader) @@ -73,6 +75,7 @@ func TestMarshalBlockHeader(t *testing.T) { TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, wantHex: strings.Join([]string{ "01", // serialization flags @@ -83,6 +86,7 @@ func TestMarshalBlockHeader(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash + "040102beef", //BlockWitness }, ""), }, { @@ -95,6 +99,7 @@ func TestMarshalBlockHeader(t *testing.T) { TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, wantError: blockchain.ErrRange, }, @@ -108,6 +113,7 @@ func TestMarshalBlockHeader(t *testing.T) { TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, wantError: blockchain.ErrRange, }, @@ -117,6 +123,7 @@ func TestMarshalBlockHeader(t *testing.T) { Height: 9223372036854775807, // MaxInt64(9223372036854775807) PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"), Timestamp: 1528945000, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, wantHex: strings.Join([]string{ "01", // serialization flags @@ -127,6 +134,87 @@ func TestMarshalBlockHeader(t *testing.T) { "40", // commitment extensible field length "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash + "040102beef", //BlockWitness + }, ""), + }, + { + blockHeader: &BlockHeader{ + Version: 1, + Height: 9223372036854775807, // MaxInt64(9223372036854775807) + PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"), + Timestamp: 1528945000, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{0xab, 0xcd}, []byte{0xcd, 0x68}}}, + }, + wantHex: strings.Join([]string{ + "01", // serialization flags + "01", // version + "ffffffffffffffff7f", // block height + "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash + "e8b287d905", // timestamp + "40", // commitment extensible field length + "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root + "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash + "0a0302beef02abcd02cd68", //BlockWitness + }, ""), + }, + { + blockHeader: &BlockHeader{ + Version: 1, + Height: 9223372036854775807, // MaxInt64(9223372036854775807) + PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"), + Timestamp: 1528945000, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, nil, []byte{0xcd, 0x68}}}, + }, + wantHex: strings.Join([]string{ + "01", // serialization flags + "01", // version + "ffffffffffffffff7f", // block height + "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash + "e8b287d905", // timestamp + "40", // commitment extensible field length + "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root + "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash + "080302beef0002cd68", //BlockWitness + }, ""), + }, + { + blockHeader: &BlockHeader{ + Version: 1, + Height: 9223372036854775807, // MaxInt64(9223372036854775807) + PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"), + Timestamp: 1528945000, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{}, []byte{0xcd, 0x68}}}, + }, + wantHex: strings.Join([]string{ + "01", // serialization flags + "01", // version + "ffffffffffffffff7f", // block height + "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash + "e8b287d905", // timestamp + "40", // commitment extensible field length + "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root + "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash + "080302beef0002cd68", //BlockWitness + }, ""), + }, + { + blockHeader: &BlockHeader{ + Version: 1, + Height: 9223372036854775807, // MaxInt64(9223372036854775807) + PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"), + Timestamp: 1528945000, + BlockWitness: BlockWitness{Witness: [][]byte{}}, + }, + wantHex: strings.Join([]string{ + "01", // serialization flags + "01", // version + "ffffffffffffffff7f", // block height + "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash + "e8b287d905", // timestamp + "40", // commitment extensible field length + "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root + "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash + "0100", //BlockWitness }, ""), }, } @@ -170,6 +258,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash + "040102beef", //BlockWitness }, ""), wantBlockHeader: &BlockHeader{ Version: 1, @@ -180,6 +269,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, }, { @@ -192,6 +282,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash + "040102beef", //BlockWitness }, ""), wantBlockHeader: &BlockHeader{ Version: 1, @@ -202,6 +293,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, }, { @@ -240,6 +332,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash + "040102beef", //BlockWitness }, ""), wantError: errors.New("binary: varint overflows a 64-bit integer"), }, @@ -266,6 +359,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash + "040102beef", //BlockWitness }, ""), wantBlockHeader: &BlockHeader{ Version: 1, @@ -276,6 +370,7 @@ func TestUnmarshalBlockHeader(t *testing.T) { TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, }, } diff --git a/protocol/bc/types/block_test.go b/protocol/bc/types/block_test.go index 872e9939..f2f562bd 100644 --- a/protocol/bc/types/block_test.go +++ b/protocol/bc/types/block_test.go @@ -38,7 +38,8 @@ func TestBlock(t *testing.T) { "40", // commitment extensible field length "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash - "00", // num transactions + "0100", //BlockWitness + "00", // num transactions }, ""), hash: testutil.MustDecodeHash("ba63a0f8e9a7e5f93e3ec7ce49f07276c065bdf75e270984d9390bee0b3de027"), }, @@ -53,6 +54,7 @@ func TestBlock(t *testing.T) { TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), }, + BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, }, Transactions: []*Tx{ NewTx(TxData{ @@ -89,7 +91,8 @@ func TestBlock(t *testing.T) { "40", // commitment extensible field length "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash - "02", // num transactions + "040102beef", //BlockWitness + "02", // num transactions "07018e0502012a00056e6f6e6365a69849e11add96ac7053aad22ba2349a4abf5feb0475a0afcadff4e128be76cf92c30f380f6173736574446566696e6974696f6e010f69737375616e636550726f6772616d020a617267756d656e7473310a617267756d656e74733201540152fad5195a0c8e3b590b86a3c0a95e7529565888508aecca96e9aeda633002f409ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92c30f03010c7370656e6450726f6772616d17020a617267756d656e7473330a617267756d656e747334010129a69849e11add96ac7053aad22ba2349a4abf5feb0475a0afcadff4e128be76cf92c30f01047472756500", "07010001010b020961726269747261727900020129ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92c30f01047472756500012affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92c30f010566616c736500", }, ""), @@ -136,7 +139,7 @@ func TestReadFrom(t *testing.T) { wantBlock Block }{ { - rawBlock: "03018b5f3077f24528e94ecfc4491bb2e9ed6264a632a9a4b86b00c88093ca545d14a137d4f5e1e4054035a2d11158f47a5c5267630b2b6cf9e9a5f79a598085a2572a68defeb8013ad26978a65b4ee5b6f4914fe5c05000459a803ecf59132604e5d334d64249c5e50a0207010001010802060031323137310001013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff809df3b49a010116001437e1aec83a4e6587ca9609e4e5aa728db700744900070100020160015e4b5cb973f5bef4eadde4c89b92ee73312b940e84164da0594149554cc8a2adeaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c480c1240201160014cb9f2391bafe2bc1159b2c4c8a0f17ba1b4dd94e6302405760b15cc09e543437c4e3aad05bf073e82ebdb214beccb5f4473653dfc0a9d5ae59fb149de19eb71c1c1399594757aeea4dd6327ca2790ef919bd20caa86104201381d35e235813ad1e62f9a602c82abee90565639cc4573568206b55bcd2aed90130000840142084606f20ca7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f402b001467b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a207b7d2c0a2020226e616d65223a2022222c0a20202273796d626f6c223a2022220a7d0125ae2054a71277cc162eb3eb21b5bd9fe54402829a53b294deaed91692a2cd8a081f9c5151ad0140621c2c3554da50d2a492d9d78be7c6159359d8f5f0b93a054ce0133617a61d85c532aff449b97a3ec2804ca5fe12b4d54aa6e8c3215c33d04abee9c9abdfdb0302013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c0d1e123011600144b61da45324299e40dacc255e2ea07dfce3a56d200013e7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f4020116001437e1aec83a4e6587ca9609e4e5aa728db700744900", + rawBlock: "03018b5f3077f24528e94ecfc4491bb2e9ed6264a632a9a4b86b00c88093ca545d14a137d4f5e1e4054035a2d11158f47a5c5267630b2b6cf9e9a5f79a598085a2572a68defeb8013ad26978a65b4ee5b6f4914fe5c05000459a803ecf59132604e5d334d64249c5e50a01000207010001010802060031323137310001013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff809df3b49a010116001437e1aec83a4e6587ca9609e4e5aa728db700744900070100020160015e4b5cb973f5bef4eadde4c89b92ee73312b940e84164da0594149554cc8a2adeaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c480c1240201160014cb9f2391bafe2bc1159b2c4c8a0f17ba1b4dd94e6302405760b15cc09e543437c4e3aad05bf073e82ebdb214beccb5f4473653dfc0a9d5ae59fb149de19eb71c1c1399594757aeea4dd6327ca2790ef919bd20caa86104201381d35e235813ad1e62f9a602c82abee90565639cc4573568206b55bcd2aed90130000840142084606f20ca7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f402b001467b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a207b7d2c0a2020226e616d65223a2022222c0a20202273796d626f6c223a2022220a7d0125ae2054a71277cc162eb3eb21b5bd9fe54402829a53b294deaed91692a2cd8a081f9c5151ad0140621c2c3554da50d2a492d9d78be7c6159359d8f5f0b93a054ce0133617a61d85c532aff449b97a3ec2804ca5fe12b4d54aa6e8c3215c33d04abee9c9abdfdb0302013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c0d1e123011600144b61da45324299e40dacc255e2ea07dfce3a56d200013e7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f4020116001437e1aec83a4e6587ca9609e4e5aa728db700744900", wantBlock: Block{ BlockHeader: BlockHeader{ Version: 1, diff --git a/protocol/bc/types/block_witness.go b/protocol/bc/types/block_witness.go new file mode 100644 index 00000000..e4bb2ac7 --- /dev/null +++ b/protocol/bc/types/block_witness.go @@ -0,0 +1,22 @@ +package types + +import ( + "io" + + "github.com/vapor/encoding/blockchain" +) + +type BlockWitness struct { + // Witness is a vector of arguments for validating this block. + Witness [][]byte +} + +func (bw *BlockWitness) writeTo(w io.Writer) error { + _, err := blockchain.WriteVarstrList(w, bw.Witness) + return err +} + +func (bw *BlockWitness) readFrom(r *blockchain.Reader) (err error) { + bw.Witness, err = blockchain.ReadVarstrList(r) + return err +} diff --git a/protocol/bc/types/block_witness_test.go b/protocol/bc/types/block_witness_test.go new file mode 100644 index 00000000..048a629c --- /dev/null +++ b/protocol/bc/types/block_witness_test.go @@ -0,0 +1,60 @@ +package types + +import ( + "bytes" + "encoding/hex" + "testing" + + "github.com/vapor/encoding/blockchain" + "github.com/vapor/testutil" +) + +func TestReadWriteBlockWitness(t *testing.T) { + cases := []struct { + bw BlockWitness + hexString string + }{ + { + bw: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}}, + hexString: "0102beef", + }, + { + bw: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{0xab, 0xcd}, []byte{0xcd, 0x68}}}, + hexString: "0302beef02abcd02cd68", + }, + { + bw: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, nil, []byte{0xcd, 0x68}}}, + hexString: "0302beef0002cd68", + }, + { + bw: BlockWitness{Witness: [][]byte{[]byte{}}}, + hexString: "0100", + }, + { + bw: BlockWitness{}, + hexString: "00", + }, + } + + for _, c := range cases { + buff := []byte{} + buffer := bytes.NewBuffer(buff) + if err := c.bw.writeTo(buffer); err != nil { + t.Fatal(err) + } + + hexString := hex.EncodeToString(buffer.Bytes()) + if hexString != c.hexString { + t.Errorf("test write block commitment fail, got:%s, want:%s", hexString, c.hexString) + } + + bc := &BlockWitness{} + if err := bc.readFrom(blockchain.NewReader(buffer.Bytes())); err != nil { + t.Fatal(err) + } + + if !testutil.DeepEqual(*bc, c.bw) { + t.Errorf("test read block commitment fail, got:%v, want:%v", *bc, c.bw) + } + } +} diff --git a/protocol/bc/types/map.go b/protocol/bc/types/map.go index a1a23a9a..7bbf9a2c 100644 --- a/protocol/bc/types/map.go +++ b/protocol/bc/types/map.go @@ -174,7 +174,7 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash } func mapBlockHeader(old *BlockHeader) (bc.Hash, *bc.BlockHeader) { - bh := bc.NewBlockHeader(old.Version, old.Height, &old.PreviousBlockHash, old.Timestamp, &old.TransactionsMerkleRoot, &old.TransactionStatusHash) + bh := bc.NewBlockHeader(old.Version, old.Height, &old.PreviousBlockHash, old.Timestamp, &old.TransactionsMerkleRoot, &old.TransactionStatusHash, old.Witness) return bc.EntryID(bh), bh } -- 2.11.0