Skip to content

Commit

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

header := blockOne.Header
for i := 0; i < b.N; i++ {
writeBlockHeader(ioutil.Discard, 0, &header)
}
}

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

buf := binarySerializer.Borrow()
header := blockOne.Header
for i := 0; i < b.N; i++ {
Expand Down
15 changes: 3 additions & 12 deletions wire/blockheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (h *BlockHeader) BlockHash() chainhash.Hash {
// encode could fail except being out of memory which would cause a
// run-time panic.
buf := bytes.NewBuffer(make([]byte, 0, MaxBlockHeaderPayload))
_ = writeBlockHeader(buf, 0, h)
_ = writeBlockHeaderBuf(buf, 0, h, nil)

return chainhash.DoubleHashH(buf.Bytes())
}
Expand All @@ -69,7 +69,7 @@ func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) e
// See Serialize for encoding block headers to be stored to disk, such as in a
// database, as opposed to encoding block headers for the wire.
func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error {
return writeBlockHeader(w, pver, h)
return writeBlockHeaderBuf(w, pver, h, nil)
}

// Deserialize decodes a block header from r into the receiver using a format
Expand All @@ -89,7 +89,7 @@ func (h *BlockHeader) Serialize(w io.Writer) 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 writeBlockHeader.
return writeBlockHeader(w, 0, h)
return writeBlockHeaderBuf(w, 0, h, nil)
}

// NewBlockHeader returns a new BlockHeader using the provided version, previous
Expand Down Expand Up @@ -160,15 +160,6 @@ func readBlockHeaderBuf(r io.Reader, pver uint32, bh *BlockHeader, b []byte) err
return nil
}

// writeBlockHeader writes a bitcoin block header to w. See Serialize for
// encoding block headers to be stored to disk, such as in a database, as
// opposed to encoding for the wire.
//
// DEPRECATED: Use writeBlockHeaderBuf instead.
func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error {
return writeBlockHeaderBuf(w, pver, bh, nil)
}

// writeBlockHeaderBuf writes a bitcoin block header to w. See Serialize for
// encoding block headers to be stored to disk, such as in a database, as
// opposed to encoding for 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 @@ -135,7 +135,7 @@ func TestBlockHeaderWire(t *testing.T) {
for i, test := range tests {
// Encode to wire format.
var buf bytes.Buffer
err := writeBlockHeader(&buf, test.pver, test.in)
err := writeBlockHeaderBuf(&buf, test.pver, test.in, nil)
if err != nil {
t.Errorf("writeBlockHeader #%d error %v", i, err)
continue
Expand Down

0 comments on commit 8353a31

Please sign in to comment.