From 8353a315d3a4019466da542e2a2dc27a01b0bc0d Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 1 May 2019 12:52:27 -0700 Subject: [PATCH] wire/blockheader: remove unneeded writeBlockHeader --- wire/bench_test.go | 11 ----------- wire/blockheader.go | 15 +++------------ wire/blockheader_test.go | 2 +- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/wire/bench_test.go b/wire/bench_test.go index 012af90c0e2..5330ae91aa4 100644 --- a/wire/bench_test.go +++ b/wire/bench_test.go @@ -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++ { diff --git a/wire/blockheader.go b/wire/blockheader.go index 5ec5f855e40..cf19a1bc88e 100644 --- a/wire/blockheader.go +++ b/wire/blockheader.go @@ -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()) } @@ -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 @@ -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 @@ -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. diff --git a/wire/blockheader_test.go b/wire/blockheader_test.go index 5705e32d869..80c91e9b14a 100644 --- a/wire/blockheader_test.go +++ b/wire/blockheader_test.go @@ -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