Skip to content

Commit

Permalink
wire/blockheader: remove unneeded readBlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
cfromknecht committed May 1, 2019
1 parent 87918ca commit 7650dcc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 40 deletions.
28 changes: 0 additions & 28 deletions wire/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,34 +578,6 @@ func BenchmarkSerializeTx(b *testing.B) {
func BenchmarkReadBlockHeader(b *testing.B) {
b.ReportAllocs()

buf := []byte{
0x01, 0x00, 0x00, 0x00, // Version 1
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, // PrevBlock
0x3b, 0xa3, 0xed, 0xfd, 0x7a, 0x7b, 0x12, 0xb2,
0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a, // MerkleRoot
0x29, 0xab, 0x5f, 0x49, // Timestamp
0xff, 0xff, 0x00, 0x1d, // Bits
0xf3, 0xe0, 0x01, 0x00, // Nonce
0x00, // TxnCount Varint
}
r := bytes.NewReader(buf)
var header BlockHeader
for i := 0; i < b.N; i++ {
r.Seek(0, 0)
readBlockHeader(r, 0, &header)
}
}

// BenchmarkReadBlockHeaderBuf performs a benchmark on how long it takes to
// deserialize a block header.
func BenchmarkReadBlockHeaderBuf(b *testing.B) {
b.ReportAllocs()

buffer := binarySerializer.Borrow()
buf := []byte{
0x01, 0x00, 0x00, 0x00, // Version 1
Expand Down
13 changes: 2 additions & 11 deletions wire/blockheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (h *BlockHeader) BlockHash() chainhash.Hash {
// See Deserialize for decoding block headers stored to disk, such as in a
// database, as opposed to decoding block headers from the wire.
func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
return readBlockHeader(r, pver, h)
return readBlockHeaderBuf(r, pver, h, nil)
}

// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
Expand All @@ -79,7 +79,7 @@ func (h *BlockHeader) Deserialize(r io.Reader) error {
// At the current time, there is no difference between the wire encoding
// at protocol version 0 and the stable long-term storage format. As
// a result, make use of readBlockHeader.
return readBlockHeader(r, 0, h)
return readBlockHeaderBuf(r, 0, h, nil)
}

// Serialize encodes a block header from r into the receiver using a format
Expand Down Expand Up @@ -110,15 +110,6 @@ func NewBlockHeader(version int32, prevHash, merkleRootHash *chainhash.Hash,
}
}

// readBlockHeader reads a bitcoin block header from r. See Deserialize for
// decoding block headers stored to disk, such as in a database, as opposed to
// decoding from the wire.
//
// DEPRECATED: Use readBlockHeaderBuf instead.
func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error {
return readBlockHeaderBuf(r, pver, bh, nil)
}

// readBlockHeaderBuf reads a bitcoin block header from r. See Deserialize for
// decoding block headers stored to disk, such as in a database, as opposed to
// decoding from the wire.
Expand Down
2 changes: 1 addition & 1 deletion wire/blockheader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestBlockHeaderWire(t *testing.T) {
// Decode the block header from wire format.
var bh BlockHeader
rbuf := bytes.NewReader(test.buf)
err = readBlockHeader(rbuf, test.pver, &bh)
err = readBlockHeaderBuf(rbuf, test.pver, &bh, nil)
if err != nil {
t.Errorf("readBlockHeader #%d error %v", i, err)
continue
Expand Down

0 comments on commit 7650dcc

Please sign in to comment.