diff --git a/peer/peer.go b/peer/peer.go index 220905ed3..3363c64a7 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -9,7 +9,6 @@ import ( "container/list" "errors" "fmt" - "github.com/daglabs/btcd/util/subnetworkid" "io" "math/rand" "net" @@ -18,6 +17,8 @@ import ( "sync/atomic" "time" + "github.com/daglabs/btcd/util/subnetworkid" + "github.com/btcsuite/go-socks/socks" "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/dagconfig" @@ -29,11 +30,11 @@ import ( const ( // MaxProtocolVersion is the max protocol version the peer supports. - MaxProtocolVersion = wire.FeeFilterVersion + MaxProtocolVersion = wire.ProtocolVersion // minAcceptableProtocolVersion is the lowest protocol version that a // connected peer may support. - minAcceptableProtocolVersion = wire.MultipleAddressVersion + minAcceptableProtocolVersion = wire.ProtocolVersion // outputBufferSize is the number of elements the output channels use. outputBufferSize = 50 @@ -997,12 +998,6 @@ func (p *Peer) PushGetHeadersMsg(locator blockdag.BlockLocator, stopHash *daghas // // This function is safe for concurrent access. func (p *Peer) PushRejectMsg(command string, code wire.RejectCode, reason string, hash *daghash.Hash, wait bool) { - // Don't bother sending the reject message if the protocol version - // is too low. - if p.VersionKnown() && p.ProtocolVersion() < wire.RejectVersion { - return - } - msg := wire.NewMsgReject(command, code, reason) if command == wire.CmdTx || command == wire.CmdBlock { if hash == nil { @@ -1094,17 +1089,12 @@ func (p *Peer) handleRemoteVersionMsg(msg *wire.MsgVersion) error { // message. For older clients, it does nothing and anything other than failure // is considered a successful ping. func (p *Peer) handlePingMsg(msg *wire.MsgPing) { - // Only reply with pong if the message is from a new enough client. - if p.ProtocolVersion() > wire.BIP0031Version { - // Include nonce from ping so pong can be identified. - p.QueueMessage(wire.NewMsgPong(msg.Nonce), nil) - } + // Include nonce from ping so pong can be identified. + p.QueueMessage(wire.NewMsgPong(msg.Nonce), nil) } // handlePongMsg is invoked when a peer receives a pong bitcoin message. It -// updates the ping statistics as required for recent clients (protocol -// version > BIP0031Version). There is no effect for older clients or when a -// ping was not previously sent. +// updates the ping statistics as required for recent clients. func (p *Peer) handlePongMsg(msg *wire.MsgPong) { // Arguably we could use a buffered channel here sending data // in a fifo manner whenever we send a ping, or a list keeping track of @@ -1113,15 +1103,13 @@ func (p *Peer) handlePongMsg(msg *wire.MsgPong) { // and overlapping pings will be ignored. It is unlikely to occur // without large usage of the ping rpc call since we ping infrequently // enough that if they overlap we would have timed out the peer. - if p.ProtocolVersion() > wire.BIP0031Version { - p.statsMtx.Lock() - if p.lastPingNonce != 0 && msg.Nonce == p.lastPingNonce { - p.lastPingMicros = time.Since(p.lastPingTime).Nanoseconds() - p.lastPingMicros /= 1000 // convert to usec. - p.lastPingNonce = 0 - } - p.statsMtx.Unlock() + p.statsMtx.Lock() + if p.lastPingNonce != 0 && msg.Nonce == p.lastPingNonce { + p.lastPingMicros = time.Since(p.lastPingTime).Nanoseconds() + p.lastPingMicros /= 1000 // convert to usec. + p.lastPingNonce = 0 } + p.statsMtx.Unlock() } // readMessage reads the next bitcoin message from the peer with logging. @@ -1835,14 +1823,10 @@ out: case msg := <-p.sendQueue: switch m := msg.msg.(type) { case *wire.MsgPing: - // Only expects a pong message in later protocol - // versions. Also set up statistics. - if p.ProtocolVersion() > wire.BIP0031Version { - p.statsMtx.Lock() - p.lastPingNonce = m.Nonce - p.lastPingTime = time.Now() - p.statsMtx.Unlock() - } + p.statsMtx.Lock() + p.lastPingNonce = m.Nonce + p.lastPingTime = time.Now() + p.statsMtx.Unlock() } p.stallControl <- stallControlMsg{sccSendMessage, msg.msg} diff --git a/peer/peer_test.go b/peer/peer_test.go index 7010d2ea6..c6f04f705 100644 --- a/peer/peer_test.go +++ b/peer/peer_test.go @@ -227,7 +227,7 @@ func TestPeerConnection(t *testing.T) { UserAgentVersion: "1.0", UserAgentComments: []string{"comment"}, DAGParams: &dagconfig.MainNetParams, - ProtocolVersion: wire.RejectVersion, // Configure with older version + ProtocolVersion: wire.ProtocolVersion, // Configure with older version Services: 0, SubnetworkID: &wire.SubnetworkIDSupportsAll, } @@ -237,6 +237,7 @@ func TestPeerConnection(t *testing.T) { UserAgentVersion: "1.0", UserAgentComments: []string{"comment"}, DAGParams: &dagconfig.MainNetParams, + ProtocolVersion: wire.ProtocolVersion + 1, Services: wire.SFNodeNetwork, SubnetworkID: &wire.SubnetworkIDSupportsAll, } @@ -244,7 +245,7 @@ func TestPeerConnection(t *testing.T) { wantStats1 := peerStats{ wantUserAgent: wire.DefaultUserAgent + "peer:1.0(comment)/", wantServices: 0, - wantProtocolVersion: wire.RejectVersion, + wantProtocolVersion: wire.ProtocolVersion, wantConnected: true, wantVersionKnown: true, wantVerAckReceived: true, @@ -258,7 +259,7 @@ func TestPeerConnection(t *testing.T) { wantStats2 := peerStats{ wantUserAgent: wire.DefaultUserAgent + "peer:1.0(comment)/", wantServices: wire.SFNodeNetwork, - wantProtocolVersion: wire.RejectVersion, + wantProtocolVersion: wire.ProtocolVersion, wantConnected: true, wantVersionKnown: true, wantVerAckReceived: true, @@ -808,9 +809,9 @@ func TestUnsupportedVersionPeer(t *testing.T) { t.Fatal("Peer did not send version message") } - // Remote peer writes version message advertising invalid protocol version 1 + // Remote peer writes version message advertising invalid protocol version 0 invalidVersionMsg := wire.NewMsgVersion(remoteNA, localNA, 0, 0, &wire.SubnetworkIDSupportsAll) - invalidVersionMsg.ProtocolVersion = 1 + invalidVersionMsg.ProtocolVersion = 0 _, err = wire.WriteMessageN( remoteConn.Writer, diff --git a/server/p2p/p2p.go b/server/p2p/p2p.go index 1ce205347..0bb87d182 100644 --- a/server/p2p/p2p.go +++ b/server/p2p/p2p.go @@ -420,11 +420,8 @@ func (sp *Peer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) { } // Request known addresses if the server address manager needs - // more and the peer has a protocol version new enough to - // include a timestamp with addresses. - hasTimestamp := sp.ProtocolVersion() >= - wire.NetAddressTimeVersion - if addrManager.NeedMoreAddresses() && hasTimestamp { + // more. + if addrManager.NeedMoreAddresses() { sp.QueueMessage(wire.NewMsgGetAddr(), nil) } @@ -555,13 +552,10 @@ func (sp *Peer) OnInv(_ *peer.Peer, msg *wire.MsgInv) { if invVect.Type == wire.InvTypeTx { peerLog.Tracef("Ignoring tx %v in inv from %v -- "+ "blocksonly enabled", invVect.Hash, sp) - if sp.ProtocolVersion() >= wire.BIP0037Version { - peerLog.Infof("Peer %v is announcing "+ - "transactions -- disconnecting", sp) - sp.Disconnect() - return - } - continue + peerLog.Infof("Peer %v is announcing "+ + "transactions -- disconnecting", sp) + sp.Disconnect() + return } err := newInv.AddInvVect(invVect) if err != nil { @@ -968,16 +962,11 @@ func (sp *Peer) OnGetCFCheckpt(_ *peer.Peer, msg *wire.MsgGetCFCheckpt) { // it will be banned since it is intentionally violating the protocol. func (sp *Peer) enforceNodeBloomFlag(cmd string) bool { if sp.server.services&wire.SFNodeBloom != wire.SFNodeBloom { - // Ban the peer if the protocol version is high enough that the - // peer is knowingly violating the protocol and banning is - // enabled. - // // NOTE: Even though the addBanScore function already examines // whether or not banning is enabled, it is checked here as well // to ensure the violation is logged and the peer is // disconnected regardless. - if sp.ProtocolVersion() >= wire.BIP0111Version && - !config.MainConfig().DisableBanning { + if !config.MainConfig().DisableBanning { // Disconnect the peer regardless of whether it was // banned. @@ -1119,11 +1108,6 @@ func (sp *Peer) OnAddr(_ *peer.Peer, msg *wire.MsgAddr) { return } - // Ignore old style addresses which don't include a timestamp. - if sp.ProtocolVersion() < wire.NetAddressTimeVersion { - return - } - // A message that has no addresses is invalid. if len(msg.AddrList) == 0 { peerLog.Errorf("Command [%s] from %s does not contain any addresses", diff --git a/wire/blockheader_test.go b/wire/blockheader_test.go index 502c1de92..fa7b2a8da 100644 --- a/wire/blockheader_test.go +++ b/wire/blockheader_test.go @@ -51,7 +51,7 @@ func TestBlockHeader(t *testing.T) { // protocol versions. func TestBlockHeaderWire(t *testing.T) { nonce := uint64(123123) // 0x000000000001e0f3 - pver := uint32(70001) + pver := ProtocolVersion // baseBlockHdr is used in the various tests as a baseline BlockHeader. bits := uint32(0x1d00ffff) @@ -103,38 +103,6 @@ func TestBlockHeaderWire(t *testing.T) { baseBlockHdrEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version. - { - baseBlockHdr, - baseBlockHdr, - baseBlockHdrEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version. - { - baseBlockHdr, - baseBlockHdr, - baseBlockHdrEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion. - { - baseBlockHdr, - baseBlockHdr, - baseBlockHdrEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion. - { - baseBlockHdr, - baseBlockHdr, - baseBlockHdrEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/invvect_test.go b/wire/invvect_test.go index 22a69889d..dfc233556 100644 --- a/wire/invvect_test.go +++ b/wire/invvect_test.go @@ -139,102 +139,6 @@ func TestInvVectWire(t *testing.T) { blockInvVectEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version error inventory vector. - { - errInvVect, - errInvVect, - errInvVectEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version tx inventory vector. - { - txInvVect, - txInvVect, - txInvVectEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version block inventory vector. - { - blockInvVect, - blockInvVect, - blockInvVectEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version error inventory vector. - { - errInvVect, - errInvVect, - errInvVectEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version tx inventory vector. - { - txInvVect, - txInvVect, - txInvVectEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version block inventory vector. - { - blockInvVect, - blockInvVect, - blockInvVectEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion error inventory vector. - { - errInvVect, - errInvVect, - errInvVectEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion tx inventory vector. - { - txInvVect, - txInvVect, - txInvVectEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion block inventory vector. - { - blockInvVect, - blockInvVect, - blockInvVectEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion error inventory vector. - { - errInvVect, - errInvVect, - errInvVectEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion tx inventory vector. - { - txInvVect, - txInvVect, - txInvVectEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion block inventory vector. - { - blockInvVect, - blockInvVect, - blockInvVectEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgaddr.go b/wire/msgaddr.go index f64f9267d..77222f039 100644 --- a/wire/msgaddr.go +++ b/wire/msgaddr.go @@ -89,12 +89,6 @@ func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32) error { // Protocol versions before MultipleAddressVersion only allowed 1 address // per message. count := len(msg.AddrList) - if pver < MultipleAddressVersion && count > 1 { - str := fmt.Sprintf("too many addresses for message of "+ - "protocol version %v [count %v, max 1]", pver, count) - return messageError("MsgAddr.BtcEncode", str) - - } if count > MaxAddrPerMsg { str := fmt.Sprintf("too many addresses for message "+ "[count %v, max %v]", count, MaxAddrPerMsg) @@ -125,11 +119,6 @@ func (msg *MsgAddr) Command() string { // MaxPayloadLength returns the maximum length the payload can be for the // receiver. This is part of the Message interface implementation. func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32 { - if pver < MultipleAddressVersion { - // Num addresses (varInt) + a single net addresses. - return MaxVarIntPayload + maxNetAddressPayload(pver) - } - // Num addresses (varInt) + max allowed addresses. return MaxVarIntPayload + (MaxAddrPerMsg * maxNetAddressPayload(pver)) } diff --git a/wire/msgaddr_test.go b/wire/msgaddr_test.go index 82b6c0b93..d8db3a3b2 100644 --- a/wire/msgaddr_test.go +++ b/wire/msgaddr_test.go @@ -71,30 +71,6 @@ func TestAddr(t *testing.T) { t.Errorf("AddAddresses: expected error on too many addresses " + "not received") } - - // Ensure max payload is expected value for protocol versions before - // timestamp was added to NetAddress. - // Num addresses (varInt) + max allowed addresses. - pver = NetAddressTimeVersion - 1 - wantPayload = uint32(26009) - maxPayload = msg.MaxPayloadLength(pver) - if maxPayload != wantPayload { - t.Errorf("MaxPayloadLength: wrong max payload length for "+ - "protocol version %d - got %v, want %v", pver, - maxPayload, wantPayload) - } - - // Ensure max payload is expected value for protocol versions before - // multiple addresses were allowed. - // Num addresses (varInt) + a single net addresses. - pver = MultipleAddressVersion - 1 - wantPayload = uint32(35) - maxPayload = msg.MaxPayloadLength(pver) - if maxPayload != wantPayload { - t.Errorf("MaxPayloadLength: wrong max payload length for "+ - "protocol version %d - got %v, want %v", pver, - maxPayload, wantPayload) - } } // TestAddrWire tests the MsgAddr wire encode and decode for various numbers @@ -159,14 +135,6 @@ func TestAddrWire(t *testing.T) { multiAddrEncoded, ProtocolVersion, }, - - // Protocol version MultipleAddressVersion-1 with no addresses. - { - noAddr, - noAddr, - noAddrEncoded, - MultipleAddressVersion - 1, - }, } t.Logf("Running %d tests", len(tests)) @@ -204,7 +172,6 @@ func TestAddrWire(t *testing.T) { // of MsgAddr to confirm error paths work correctly. func TestAddrWireErrors(t *testing.T) { pver := ProtocolVersion - pverMA := MultipleAddressVersion wireErr := &MessageError{} // A couple of NetAddresses to use for testing. @@ -265,9 +232,6 @@ func TestAddrWireErrors(t *testing.T) { {baseAddr, baseAddrEncoded, pver, 1, io.ErrShortWrite, io.EOF}, // Force error with greater than max inventory vectors. {maxAddr, maxAddrEncoded, pver, 3, wireErr, wireErr}, - // Force error with greater than max inventory vectors for - // protocol versions before multiple addresses were allowed. - {maxAddr, maxAddrEncoded, pverMA - 1, 3, wireErr, wireErr}, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgalert_test.go b/wire/msgalert_test.go index 82c3ccce5..a5e503700 100644 --- a/wire/msgalert_test.go +++ b/wire/msgalert_test.go @@ -106,38 +106,6 @@ func TestMsgAlertWire(t *testing.T) { baseMsgAlertEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version. - { - baseMsgAlert, - baseMsgAlert, - baseMsgAlertEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version. - { - baseMsgAlert, - baseMsgAlert, - baseMsgAlertEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion. - { - baseMsgAlert, - baseMsgAlert, - baseMsgAlertEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion. - { - baseMsgAlert, - baseMsgAlert, - baseMsgAlertEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgblock_test.go b/wire/msgblock_test.go index 685df96da..090219eec 100644 --- a/wire/msgblock_test.go +++ b/wire/msgblock_test.go @@ -6,13 +6,14 @@ package wire import ( "bytes" - "github.com/daglabs/btcd/util/subnetworkid" "io" "math" "reflect" "testing" "time" + "github.com/daglabs/btcd/util/subnetworkid" + "github.com/daglabs/btcd/dagconfig/daghash" "github.com/davecgh/go-spew/spew" ) @@ -163,42 +164,6 @@ func TestBlockWire(t *testing.T) { blockOneTxLocs, ProtocolVersion, }, - - // Protocol version BIP0035Version. - { - &blockOne, - &blockOne, - blockOneBytes, - blockOneTxLocs, - BIP0035Version, - }, - - // Protocol version BIP0031Version. - { - &blockOne, - &blockOne, - blockOneBytes, - blockOneTxLocs, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion. - { - &blockOne, - &blockOne, - blockOneBytes, - blockOneTxLocs, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion. - { - &blockOne, - &blockOne, - blockOneBytes, - blockOneTxLocs, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) @@ -235,10 +200,7 @@ func TestBlockWire(t *testing.T) { // TestBlockWireErrors performs negative tests against wire encode and decode // of MsgBlock to confirm error paths work correctly. func TestBlockWireErrors(t *testing.T) { - // Use protocol version 60002 specifically here instead of the latest - // because the test data is using bytes encoded with that protocol - // version. - pver := uint32(60002) + pver := ProtocolVersion tests := []struct { in *MsgBlock // Value to encode @@ -433,10 +395,7 @@ func TestBlockSerializeErrors(t *testing.T) { // are handled properly. This could otherwise potentially be used as an attack // vector. func TestBlockOverflowErrors(t *testing.T) { - // Use protocol version 70001 specifically here instead of the latest - // protocol version because the test data is using bytes encoded with - // that version. - pver := uint32(70001) + pver := ProtocolVersion tests := []struct { buf []byte // Wire encoding diff --git a/wire/msgfeefilter.go b/wire/msgfeefilter.go index 0162f8387..1c8e69427 100644 --- a/wire/msgfeefilter.go +++ b/wire/msgfeefilter.go @@ -5,7 +5,6 @@ package wire import ( - "fmt" "io" ) @@ -22,24 +21,12 @@ type MsgFeeFilter struct { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgFeeFilter) BtcDecode(r io.Reader, pver uint32) error { - if pver < FeeFilterVersion { - str := fmt.Sprintf("feefilter message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFeeFilter.BtcDecode", str) - } - return readElement(r, &msg.MinFee) } // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgFeeFilter) BtcEncode(w io.Writer, pver uint32) error { - if pver < FeeFilterVersion { - str := fmt.Sprintf("feefilter message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFeeFilter.BtcEncode", str) - } - return writeElement(w, msg.MinFee) } diff --git a/wire/msgfeefilter_test.go b/wire/msgfeefilter_test.go index 029462406..1923a120c 100644 --- a/wire/msgfeefilter_test.go +++ b/wire/msgfeefilter_test.go @@ -77,14 +77,6 @@ func TestFeeFilterWire(t *testing.T) { []byte{0xf3, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}, ProtocolVersion, }, - - // Protocol version FeeFilterVersion - { - MsgFeeFilter{MinFee: 456456}, // 0x6f708 - MsgFeeFilter{MinFee: 456456}, // 0x6f708 - []byte{0x08, 0xf7, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}, - FeeFilterVersion, - }, } t.Logf("Running %d tests", len(tests)) @@ -122,8 +114,6 @@ func TestFeeFilterWire(t *testing.T) { // of MsgFeeFilter to confirm error paths work correctly. func TestFeeFilterWireErrors(t *testing.T) { pver := ProtocolVersion - pverNoFeeFilter := FeeFilterVersion - 1 - wireErr := &MessageError{} baseFeeFilter := NewMsgFeeFilter(123123) // 0x1e0f3 baseFeeFilterEncoded := []byte{ @@ -141,8 +131,6 @@ func TestFeeFilterWireErrors(t *testing.T) { // Latest protocol version with intentional read/write errors. // Force error in minfee. {baseFeeFilter, baseFeeFilterEncoded, pver, 0, io.ErrShortWrite, io.EOF}, - // Force error due to unsupported protocol version. - {baseFeeFilter, baseFeeFilterEncoded, pverNoFeeFilter, 4, wireErr, wireErr}, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgfilteradd.go b/wire/msgfilteradd.go index b9e8a8697..795269547 100644 --- a/wire/msgfilteradd.go +++ b/wire/msgfilteradd.go @@ -28,12 +28,6 @@ type MsgFilterAdd struct { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgFilterAdd) BtcDecode(r io.Reader, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("filteradd message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFilterAdd.BtcDecode", str) - } - var err error msg.Data, err = ReadVarBytes(r, pver, MaxFilterAddDataSize, "filteradd data") @@ -43,12 +37,6 @@ func (msg *MsgFilterAdd) BtcDecode(r io.Reader, pver uint32) error { // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgFilterAdd) BtcEncode(w io.Writer, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("filteradd message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFilterAdd.BtcEncode", str) - } - size := len(msg.Data) if size > MaxFilterAddDataSize { str := fmt.Sprintf("filteradd size too large for message "+ diff --git a/wire/msgfilteradd_test.go b/wire/msgfilteradd_test.go index 1d1f1bf09..ba36a2e42 100644 --- a/wire/msgfilteradd_test.go +++ b/wire/msgfilteradd_test.go @@ -50,8 +50,7 @@ func TestFilterAddLatest(t *testing.T) { } } -// TestFilterAddCrossProtocol tests the MsgFilterAdd API when encoding with the -// latest protocol version and decoding with BIP0031Version. +// TestFilterAddCrossProtocol tests the MsgFilterAdd API. func TestFilterAddCrossProtocol(t *testing.T) { data := []byte{0x01, 0x02} msg := NewMsgFilterAdd(data) @@ -66,20 +65,6 @@ func TestFilterAddCrossProtocol(t *testing.T) { t.Errorf("encode of MsgFilterAdd failed %v err <%v>", msg, err) } - // Decode with old protocol version. - var readmsg MsgFilterAdd - err = readmsg.BtcDecode(&buf, BIP0031Version) - if err == nil { - t.Errorf("decode of MsgFilterAdd succeeded when it shouldn't "+ - "have %v", msg) - } - - // Since one of the protocol versions doesn't support the filteradd - // message, make sure the data didn't get encoded and decoded back out. - if bytes.Equal(msg.Data, readmsg.Data) { - t.Error("should not get same data for cross protocol") - } - } // TestFilterAddMaxDataSize tests the MsgFilterAdd API maximum data size. @@ -108,8 +93,6 @@ func TestFilterAddMaxDataSize(t *testing.T) { // of MsgFilterAdd to confirm error paths work correctly. func TestFilterAddWireErrors(t *testing.T) { pver := ProtocolVersion - pverNoFilterAdd := BIP0037Version - 1 - wireErr := &MessageError{} baseData := []byte{0x01, 0x02, 0x03, 0x04} baseFilterAdd := NewMsgFilterAdd(baseData) @@ -128,8 +111,6 @@ func TestFilterAddWireErrors(t *testing.T) { {baseFilterAdd, baseFilterAddEncoded, pver, 0, io.ErrShortWrite, io.EOF}, // Force error in data. {baseFilterAdd, baseFilterAddEncoded, pver, 1, io.ErrShortWrite, io.EOF}, - // Force error due to unsupported protocol version. - {baseFilterAdd, baseFilterAddEncoded, pverNoFilterAdd, 5, wireErr, wireErr}, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgfilterclear.go b/wire/msgfilterclear.go index b82d6b85c..132cf4967 100644 --- a/wire/msgfilterclear.go +++ b/wire/msgfilterclear.go @@ -5,7 +5,6 @@ package wire import ( - "fmt" "io" ) @@ -19,24 +18,12 @@ type MsgFilterClear struct{} // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgFilterClear) BtcDecode(r io.Reader, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("filterclear message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFilterClear.BtcDecode", str) - } - return nil } // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgFilterClear) BtcEncode(w io.Writer, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("filterclear message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFilterClear.BtcEncode", str) - } - return nil } diff --git a/wire/msgfilterclear_test.go b/wire/msgfilterclear_test.go index 1962e6142..1e6532833 100644 --- a/wire/msgfilterclear_test.go +++ b/wire/msgfilterclear_test.go @@ -36,8 +36,7 @@ func TestFilterClearLatest(t *testing.T) { } } -// TestFilterClearCrossProtocol tests the MsgFilterClear API when encoding with -// the latest protocol version and decoding with BIP0031Version. +// TestFilterClearCrossProtocol tests the MsgFilterClear API. func TestFilterClearCrossProtocol(t *testing.T) { msg := NewMsgFilterClear() @@ -47,14 +46,6 @@ func TestFilterClearCrossProtocol(t *testing.T) { if err != nil { t.Errorf("encode of MsgFilterClear failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - var readmsg MsgFilterClear - err = readmsg.BtcDecode(&buf, BIP0031Version) - if err == nil { - t.Errorf("decode of MsgFilterClear succeeded when it "+ - "shouldn't have %v", msg) - } } // TestFilterClearWire tests the MsgFilterClear wire encode and decode for @@ -76,22 +67,6 @@ func TestFilterClearWire(t *testing.T) { msgFilterClearEncoded, ProtocolVersion, }, - - // Protocol version BIP0037Version + 1. - { - msgFilterClear, - msgFilterClear, - msgFilterClearEncoded, - BIP0037Version + 1, - }, - - // Protocol version BIP0037Version. - { - msgFilterClear, - msgFilterClear, - msgFilterClearEncoded, - BIP0037Version, - }, } t.Logf("Running %d tests", len(tests)) @@ -124,70 +99,3 @@ func TestFilterClearWire(t *testing.T) { } } } - -// TestFilterClearWireErrors performs negative tests against wire encode and -// decode of MsgFilterClear to confirm error paths work correctly. -func TestFilterClearWireErrors(t *testing.T) { - pverNoFilterClear := BIP0037Version - 1 - wireErr := &MessageError{} - - baseFilterClear := NewMsgFilterClear() - baseFilterClearEncoded := []byte{} - - tests := []struct { - in *MsgFilterClear // Value to encode - buf []byte // Wire encoding - pver uint32 // Protocol version for wire encoding - max int // Max size of fixed buffer to induce errors - writeErr error // Expected write error - readErr error // Expected read error - }{ - // Force error due to unsupported protocol version. - { - baseFilterClear, baseFilterClearEncoded, pverNoFilterClear, 4, wireErr, wireErr, - }, - } - - t.Logf("Running %d tests", len(tests)) - for i, test := range tests { - // Encode to wire format. - w := newFixedWriter(test.max) - err := test.in.BtcEncode(w, test.pver) - if reflect.TypeOf(err) != reflect.TypeOf(test.writeErr) { - t.Errorf("BtcEncode #%d wrong error got: %v, want: %v", - i, err, test.writeErr) - continue - } - - // For errors which are not of type MessageError, check them for - // equality. - if _, ok := err.(*MessageError); !ok { - if err != test.writeErr { - t.Errorf("BtcEncode #%d wrong error got: %v, "+ - "want: %v", i, err, test.writeErr) - continue - } - } - - // Decode from wire format. - var msg MsgFilterClear - r := newFixedReader(test.max, test.buf) - err = msg.BtcDecode(r, test.pver) - if reflect.TypeOf(err) != reflect.TypeOf(test.readErr) { - t.Errorf("BtcDecode #%d wrong error got: %v, want: %v", - i, err, test.readErr) - continue - } - - // For errors which are not of type MessageError, check them for - // equality. - if _, ok := err.(*MessageError); !ok { - if err != test.readErr { - t.Errorf("BtcDecode #%d wrong error got: %v, "+ - "want: %v", i, err, test.readErr) - continue - } - } - - } -} diff --git a/wire/msgfilterload.go b/wire/msgfilterload.go index 80374194f..dc28a5972 100644 --- a/wire/msgfilterload.go +++ b/wire/msgfilterload.go @@ -52,12 +52,6 @@ type MsgFilterLoad struct { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgFilterLoad) BtcDecode(r io.Reader, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("filterload message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFilterLoad.BtcDecode", str) - } - var err error msg.Filter, err = ReadVarBytes(r, pver, MaxFilterLoadFilterSize, "filterload filter size") @@ -82,12 +76,6 @@ func (msg *MsgFilterLoad) BtcDecode(r io.Reader, pver uint32) error { // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgFilterLoad) BtcEncode(w io.Writer, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("filterload message invalid for protocol "+ - "version %d", pver) - return messageError("MsgFilterLoad.BtcEncode", str) - } - size := len(msg.Filter) if size > MaxFilterLoadFilterSize { str := fmt.Sprintf("filterload filter size too large for message "+ diff --git a/wire/msgfilterload_test.go b/wire/msgfilterload_test.go index 231169ebd..2b372e062 100644 --- a/wire/msgfilterload_test.go +++ b/wire/msgfilterload_test.go @@ -50,8 +50,7 @@ func TestFilterLoadLatest(t *testing.T) { } } -// TestFilterLoadCrossProtocol tests the MsgFilterLoad API when encoding with -// the latest protocol version and decoding with BIP0031Version. +// TestFilterLoadCrossProtocol tests the MsgFilterLoad API. func TestFilterLoadCrossProtocol(t *testing.T) { data := []byte{0x01, 0x02} msg := NewMsgFilterLoad(data, 10, 0, 0) @@ -63,14 +62,6 @@ func TestFilterLoadCrossProtocol(t *testing.T) { t.Errorf("encode of NewMsgFilterLoad failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - var readmsg MsgFilterLoad - err = readmsg.BtcDecode(&buf, BIP0031Version) - if err == nil { - t.Errorf("decode of MsgFilterLoad succeeded when it shouldn't have %v", - msg) - } } // TestFilterLoadMaxFilterSize tests the MsgFilterLoad API maximum filter size. @@ -128,8 +119,6 @@ func TestFilterLoadMaxHashFuncsSize(t *testing.T) { // of MsgFilterLoad to confirm error paths work correctly. func TestFilterLoadWireErrors(t *testing.T) { pver := ProtocolVersion - pverNoFilterLoad := BIP0037Version - 1 - wireErr := &MessageError{} baseFilter := []byte{0x01, 0x02, 0x03, 0x04} baseFilterLoad := NewMsgFilterLoad(baseFilter, 10, 0, BloomUpdateNone) @@ -168,10 +157,6 @@ func TestFilterLoadWireErrors(t *testing.T) { { baseFilterLoad, baseFilterLoadEncoded, pver, 13, io.ErrShortWrite, io.EOF, }, - // Force error due to unsupported protocol version. - { - baseFilterLoad, baseFilterLoadEncoded, pverNoFilterLoad, 10, wireErr, wireErr, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msggetaddr_test.go b/wire/msggetaddr_test.go index a5427322d..04586b5e1 100644 --- a/wire/msggetaddr_test.go +++ b/wire/msggetaddr_test.go @@ -54,38 +54,6 @@ func TestGetAddrWire(t *testing.T) { msgGetAddrEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version. - { - msgGetAddr, - msgGetAddr, - msgGetAddrEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version. - { - msgGetAddr, - msgGetAddr, - msgGetAddrEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion. - { - msgGetAddr, - msgGetAddr, - msgGetAddrEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion. - { - msgGetAddr, - msgGetAddr, - msgGetAddrEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msggetblocks_test.go b/wire/msggetblocks_test.go index d7335640c..7bbde6626 100644 --- a/wire/msggetblocks_test.go +++ b/wire/msggetblocks_test.go @@ -84,7 +84,7 @@ func TestGetBlocks(t *testing.T) { // numbers of block locator hashes and protocol versions. func TestGetBlocksWire(t *testing.T) { // Set protocol inside getblocks message. - pver := uint32(60002) + pver := uint32(1) // Block 99499 hash. hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" @@ -111,7 +111,7 @@ func TestGetBlocksWire(t *testing.T) { noLocators := NewMsgGetBlocks(&daghash.Hash{}) noLocators.ProtocolVersion = pver noLocatorsEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0x00, // Varint for number of block locator hashes 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -125,7 +125,7 @@ func TestGetBlocksWire(t *testing.T) { multiLocators.AddBlockLocatorHash(hashLocator) multiLocators.ProtocolVersion = pver multiLocatorsEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0x02, // Varint for number of block locator hashes 0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63, 0xd2, 0x20, 0xcc, 0x69, 0x12, 0x83, 0xcb, 0x65, @@ -162,70 +162,6 @@ func TestGetBlocksWire(t *testing.T) { multiLocatorsEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Versionwith multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) @@ -262,10 +198,10 @@ func TestGetBlocksWire(t *testing.T) { // TestGetBlocksWireErrors performs negative tests against wire encode and // decode of MsgGetBlocks to confirm error paths work correctly. func TestGetBlocksWireErrors(t *testing.T) { - // Set protocol inside getheaders message. Use protocol version 60002 + // Set protocol inside getheaders message. Use protocol version 1 // specifically here instead of the latest because the test data is // using bytes encoded with that protocol version. - pver := uint32(60002) + pver := uint32(1) wireErr := &MessageError{} // Block 99499 hash. @@ -295,7 +231,7 @@ func TestGetBlocksWireErrors(t *testing.T) { baseGetBlocks.AddBlockLocatorHash(hashLocator2) baseGetBlocks.AddBlockLocatorHash(hashLocator) baseGetBlocksEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0x02, // Varint for number of block locator hashes 0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63, 0xd2, 0x20, 0xcc, 0x69, 0x12, 0x83, 0xcb, 0x65, @@ -320,7 +256,7 @@ func TestGetBlocksWireErrors(t *testing.T) { maxGetBlocks.BlockLocatorHashes = append(maxGetBlocks.BlockLocatorHashes, &mainNetGenesisHash) maxGetBlocksEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501) } diff --git a/wire/msggetdata_test.go b/wire/msggetdata_test.go index 946d289ac..e08db1530 100644 --- a/wire/msggetdata_test.go +++ b/wire/msggetdata_test.go @@ -133,70 +133,6 @@ func TestGetDataWire(t *testing.T) { MultiInvEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msggetheaders_test.go b/wire/msggetheaders_test.go index 3bdd246c1..e36a84fe4 100644 --- a/wire/msggetheaders_test.go +++ b/wire/msggetheaders_test.go @@ -70,10 +70,10 @@ func TestGetHeaders(t *testing.T) { // TestGetHeadersWire tests the MsgGetHeaders wire encode and decode for various // numbers of block locator hashes and protocol versions. func TestGetHeadersWire(t *testing.T) { - // Set protocol inside getheaders message. Use protocol version 60002 + // Set protocol inside getheaders message. Use protocol version 1 // specifically here instead of the latest because the test data is // using bytes encoded with that protocol version. - pver := uint32(60002) + pver := uint32(1) // Block 99499 hash. hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535" @@ -100,7 +100,7 @@ func TestGetHeadersWire(t *testing.T) { noLocators := NewMsgGetHeaders() noLocators.ProtocolVersion = pver noLocatorsEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0x00, // Varint for number of block locator hashes 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -115,7 +115,7 @@ func TestGetHeadersWire(t *testing.T) { multiLocators.AddBlockLocatorHash(hashLocator2) multiLocators.AddBlockLocatorHash(hashLocator) multiLocatorsEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0x02, // Varint for number of block locator hashes 0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63, 0xd2, 0x20, 0xcc, 0x69, 0x12, 0x83, 0xcb, 0x65, @@ -152,70 +152,6 @@ func TestGetHeadersWire(t *testing.T) { multiLocatorsEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Versionwith multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion with no block locators. - { - noLocators, - noLocators, - noLocatorsEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion multiple block locators. - { - multiLocators, - multiLocators, - multiLocatorsEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) @@ -252,10 +188,10 @@ func TestGetHeadersWire(t *testing.T) { // TestGetHeadersWireErrors performs negative tests against wire encode and // decode of MsgGetHeaders to confirm error paths work correctly. func TestGetHeadersWireErrors(t *testing.T) { - // Set protocol inside getheaders message. Use protocol version 60002 + // Set protocol inside getheaders message. Use protocol version 1 // specifically here instead of the latest because the test data is // using bytes encoded with that protocol version. - pver := uint32(60002) + pver := ProtocolVersion wireErr := &MessageError{} // Block 99499 hash. @@ -286,7 +222,7 @@ func TestGetHeadersWireErrors(t *testing.T) { baseGetHeaders.AddBlockLocatorHash(hashLocator2) baseGetHeaders.AddBlockLocatorHash(hashLocator) baseGetHeadersEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0x02, // Varint for number of block locator hashes 0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63, 0xd2, 0x20, 0xcc, 0x69, 0x12, 0x83, 0xcb, 0x65, @@ -311,7 +247,7 @@ func TestGetHeadersWireErrors(t *testing.T) { maxGetHeaders.BlockLocatorHashes = append(maxGetHeaders.BlockLocatorHashes, &mainNetGenesisHash) maxGetHeadersEncoded := []byte{ - 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 + 0x01, 0x00, 0x00, 0x00, // Protocol version 1 0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501) } diff --git a/wire/msgheaders_test.go b/wire/msgheaders_test.go index 98d4d4341..328f342fc 100644 --- a/wire/msgheaders_test.go +++ b/wire/msgheaders_test.go @@ -16,7 +16,7 @@ import ( // TestHeaders tests the MsgHeaders API. func TestHeaders(t *testing.T) { - pver := uint32(60002) + pver := ProtocolVersion // Ensure the command is expected value. wantCmd := "headers" @@ -126,69 +126,6 @@ func TestHeadersWire(t *testing.T) { oneHeaderEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version with no headers. - { - noHeaders, - noHeaders, - noHeadersEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with one header. - { - oneHeader, - oneHeader, - oneHeaderEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version with no headers. - { - noHeaders, - noHeaders, - noHeadersEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version with one header. - { - oneHeader, - oneHeader, - oneHeaderEncoded, - BIP0031Version, - }, - // Protocol version NetAddressTimeVersion with no headers. - { - noHeaders, - noHeaders, - noHeadersEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion with one header. - { - oneHeader, - oneHeader, - oneHeaderEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion with no headers. - { - noHeaders, - noHeaders, - noHeadersEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion with one header. - { - oneHeader, - oneHeader, - oneHeaderEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msginv_test.go b/wire/msginv_test.go index 0ddb2353e..cdcf5d1fb 100644 --- a/wire/msginv_test.go +++ b/wire/msginv_test.go @@ -133,70 +133,6 @@ func TestInvWire(t *testing.T) { MultiInvEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgmempool.go b/wire/msgmempool.go index f6b08c2e4..9a3974927 100644 --- a/wire/msgmempool.go +++ b/wire/msgmempool.go @@ -5,7 +5,6 @@ package wire import ( - "fmt" "io" ) @@ -20,24 +19,12 @@ type MsgMemPool struct{} // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgMemPool) BtcDecode(r io.Reader, pver uint32) error { - if pver < BIP0035Version { - str := fmt.Sprintf("mempool message invalid for protocol "+ - "version %d", pver) - return messageError("MsgMemPool.BtcDecode", str) - } - return nil } // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgMemPool) BtcEncode(w io.Writer, pver uint32) error { - if pver < BIP0035Version { - str := fmt.Sprintf("mempool message invalid for protocol "+ - "version %d", pver) - return messageError("MsgMemPool.BtcEncode", str) - } - return nil } diff --git a/wire/msgmempool_test.go b/wire/msgmempool_test.go index 5d05e7212..cb49b998b 100644 --- a/wire/msgmempool_test.go +++ b/wire/msgmempool_test.go @@ -36,27 +36,10 @@ func TestMemPool(t *testing.T) { t.Errorf("encode of MsgMemPool failed %v err <%v>", msg, err) } - // Older protocol versions should fail encode since message didn't - // exist yet. - oldPver := BIP0035Version - 1 - err = msg.BtcEncode(&buf, oldPver) - if err == nil { - s := "encode of MsgMemPool passed for old protocol version %v err <%v>" - t.Errorf(s, msg, err) - } - // Test decode with latest protocol version. readmsg := NewMsgMemPool() err = readmsg.BtcDecode(&buf, pver) if err != nil { t.Errorf("decode of MsgMemPool failed [%v] err <%v>", buf, err) } - - // Older protocol versions should fail decode since message didn't - // exist yet. - err = readmsg.BtcDecode(&buf, oldPver) - if err == nil { - s := "decode of MsgMemPool passed for old protocol version %v err <%v>" - t.Errorf(s, msg, err) - } } diff --git a/wire/msgmerkleblock.go b/wire/msgmerkleblock.go index bdfa76afc..a6d5f2fc4 100644 --- a/wire/msgmerkleblock.go +++ b/wire/msgmerkleblock.go @@ -43,12 +43,6 @@ func (msg *MsgMerkleBlock) AddTxHash(hash *daghash.Hash) error { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("merkleblock message invalid for protocol "+ - "version %d", pver) - return messageError("MsgMerkleBlock.BtcDecode", str) - } - err := readBlockHeader(r, pver, &msg.Header) if err != nil { return err @@ -91,12 +85,6 @@ func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error { // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32) error { - if pver < BIP0037Version { - str := fmt.Sprintf("merkleblock message invalid for protocol "+ - "version %d", pver) - return messageError("MsgMerkleBlock.BtcEncode", str) - } - // Read num transaction hashes and limit to max. numHashes := len(msg.Hashes) if numHashes > maxTxPerBlock { diff --git a/wire/msgmerkleblock_test.go b/wire/msgmerkleblock_test.go index 334536a9e..dfb93356d 100644 --- a/wire/msgmerkleblock_test.go +++ b/wire/msgmerkleblock_test.go @@ -130,14 +130,6 @@ func TestMerkleBlockCrossProtocol(t *testing.T) { t.Errorf("encode of NewMsgFilterLoad failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - var readmsg MsgFilterLoad - err = readmsg.BtcDecode(&buf, BIP0031Version) - if err == nil { - t.Errorf("decode of MsgFilterLoad succeeded when it shouldn't have %v", - msg) - } } // TestMerkleBlockWire tests the MsgMerkleBlock wire encode and decode for @@ -153,11 +145,6 @@ func TestMerkleBlockWire(t *testing.T) { { &merkleBlockOne, &merkleBlockOne, merkleBlockOneBytes, ProtocolVersion, }, - - // Protocol version BIP0037Version. - { - &merkleBlockOne, &merkleBlockOne, merkleBlockOneBytes, BIP0037Version, - }, } t.Logf("Running %d tests", len(tests)) @@ -194,12 +181,7 @@ func TestMerkleBlockWire(t *testing.T) { // TestMerkleBlockWireErrors performs negative tests against wire encode and // decode of MsgBlock to confirm error paths work correctly. func TestMerkleBlockWireErrors(t *testing.T) { - // Use protocol version 70001 specifically here instead of the latest - // because the test data is using bytes encoded with that protocol - // version. - pver := uint32(70001) - pverNoMerkleBlock := BIP0037Version - 1 - wireErr := &MessageError{} + pver := ProtocolVersion tests := []struct { in *MsgMerkleBlock // Value to encode @@ -237,8 +219,6 @@ func TestMerkleBlockWireErrors(t *testing.T) { {&merkleBlockOne, merkleBlockOneBytes, pver, 190, io.ErrShortWrite, io.EOF}, // Force error in flag bytes. {&merkleBlockOne, merkleBlockOneBytes, pver, 191, io.ErrShortWrite, io.EOF}, - // Force error due to unsupported protocol version. - {&merkleBlockOne, merkleBlockOneBytes, pverNoMerkleBlock, 191, wireErr, wireErr}, } t.Logf("Running %d tests", len(tests)) @@ -289,10 +269,7 @@ func TestMerkleBlockWireErrors(t *testing.T) { // number of hashes and flags are handled properly. This could otherwise // potentially be used as an attack vector. func TestMerkleBlockOverflowErrors(t *testing.T) { - // Use protocol version 70001 specifically here instead of the latest - // protocol version because the test data is using bytes encoded with - // that version. - pver := uint32(70001) + pver := ProtocolVersion // Create bytes for a merkle block that claims to have more than the max // allowed tx hashes. diff --git a/wire/msgnotfound_test.go b/wire/msgnotfound_test.go index 2dfabbea9..3f86a42e6 100644 --- a/wire/msgnotfound_test.go +++ b/wire/msgnotfound_test.go @@ -124,70 +124,6 @@ func TestNotFoundWire(t *testing.T) { MultiInvEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion no inv vectors. - { - NoInv, - NoInv, - NoInvEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion with multiple inv vectors. - { - MultiInv, - MultiInv, - MultiInvEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgping.go b/wire/msgping.go index c9e3f646b..af07f8ca9 100644 --- a/wire/msgping.go +++ b/wire/msgping.go @@ -28,14 +28,9 @@ type MsgPing struct { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgPing) BtcDecode(r io.Reader, pver uint32) error { - // There was no nonce for BIP0031Version and earlier. - // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER - // the version unlike most others. - if pver > BIP0031Version { - err := readElement(r, &msg.Nonce) - if err != nil { - return err - } + err := readElement(r, &msg.Nonce) + if err != nil { + return err } return nil @@ -44,14 +39,9 @@ func (msg *MsgPing) BtcDecode(r io.Reader, pver uint32) error { // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgPing) BtcEncode(w io.Writer, pver uint32) error { - // There was no nonce for BIP0031Version and earlier. - // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER - // the version unlike most others. - if pver > BIP0031Version { - err := writeElement(w, msg.Nonce) - if err != nil { - return err - } + err := writeElement(w, msg.Nonce) + if err != nil { + return err } return nil @@ -66,16 +56,8 @@ func (msg *MsgPing) Command() string { // MaxPayloadLength returns the maximum length the payload can be for the // receiver. This is part of the Message interface implementation. func (msg *MsgPing) MaxPayloadLength(pver uint32) uint32 { - plen := uint32(0) - // There was no nonce for BIP0031Version and earlier. - // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER - // the version unlike most others. - if pver > BIP0031Version { - // Nonce 8 bytes. - plen += 8 - } - - return plen + // Nonce 8 bytes. + return uint32(8) } // NewMsgPing returns a new bitcoin ping message that conforms to the Message diff --git a/wire/msgping_test.go b/wire/msgping_test.go index 7a00dafc7..b44c21fe6 100644 --- a/wire/msgping_test.go +++ b/wire/msgping_test.go @@ -45,52 +45,6 @@ func TestPing(t *testing.T) { } } -// TestPingBIP0031 tests the MsgPing API against the protocol version -// BIP0031Version. -func TestPingBIP0031(t *testing.T) { - // Use the protocol version just prior to BIP0031Version changes. - pver := BIP0031Version - - nonce, err := RandomUint64() - if err != nil { - t.Errorf("RandomUint64: Error generating nonce: %v", err) - } - msg := NewMsgPing(nonce) - if msg.Nonce != nonce { - t.Errorf("NewMsgPing: wrong nonce - got %v, want %v", - msg.Nonce, nonce) - } - - // Ensure max payload is expected value for old protocol version. - wantPayload := uint32(0) - maxPayload := msg.MaxPayloadLength(pver) - if maxPayload != wantPayload { - t.Errorf("MaxPayloadLength: wrong max payload length for "+ - "protocol version %d - got %v, want %v", pver, - maxPayload, wantPayload) - } - - // Test encode with old protocol version. - var buf bytes.Buffer - err = msg.BtcEncode(&buf, pver) - if err != nil { - t.Errorf("encode of MsgPing failed %v err <%v>", msg, err) - } - - // Test decode with old protocol version. - readmsg := NewMsgPing(0) - err = readmsg.BtcDecode(&buf, pver) - if err != nil { - t.Errorf("decode of MsgPing failed [%v] err <%v>", buf, err) - } - - // Since this protocol version doesn't support the nonce, make sure - // it didn't get encoded and decoded back out. - if msg.Nonce == readmsg.Nonce { - t.Errorf("Should not get same nonce for protocol version %d", pver) - } -} - // TestPingCrossProtocol tests the MsgPing API when encoding with the latest // protocol version and decoding with BIP0031Version. func TestPingCrossProtocol(t *testing.T) { @@ -110,19 +64,6 @@ func TestPingCrossProtocol(t *testing.T) { if err != nil { t.Errorf("encode of MsgPing failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - readmsg := NewMsgPing(0) - err = readmsg.BtcDecode(&buf, BIP0031Version) - if err != nil { - t.Errorf("decode of MsgPing failed [%v] err <%v>", buf, err) - } - - // Since one of the protocol versions doesn't support the nonce, make - // sure it didn't get encoded and decoded back out. - if msg.Nonce == readmsg.Nonce { - t.Error("Should not get same nonce for cross protocol") - } } // TestPingWire tests the MsgPing wire encode and decode for various protocol @@ -141,22 +82,6 @@ func TestPingWire(t *testing.T) { []byte{0xf3, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}, ProtocolVersion, }, - - // Protocol version BIP0031Version+1 - { - MsgPing{Nonce: 456456}, // 0x6f708 - MsgPing{Nonce: 456456}, // 0x6f708 - []byte{0x08, 0xf7, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}, - BIP0031Version + 1, - }, - - // Protocol version BIP0031Version - { - MsgPing{Nonce: 789789}, // 0xc0d1d - MsgPing{Nonce: 0}, // No nonce for pver - []byte{}, // No nonce for pver - BIP0031Version, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgpong.go b/wire/msgpong.go index 9fd02721f..95d57a21c 100644 --- a/wire/msgpong.go +++ b/wire/msgpong.go @@ -5,7 +5,6 @@ package wire import ( - "fmt" "io" ) @@ -23,28 +22,12 @@ type MsgPong struct { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgPong) BtcDecode(r io.Reader, pver uint32) error { - // NOTE: <= is not a mistake here. The BIP0031 was defined as AFTER - // the version unlike most others. - if pver <= BIP0031Version { - str := fmt.Sprintf("pong message invalid for protocol "+ - "version %d", pver) - return messageError("MsgPong.BtcDecode", str) - } - return readElement(r, &msg.Nonce) } // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgPong) BtcEncode(w io.Writer, pver uint32) error { - // NOTE: <= is not a mistake here. The BIP0031 was defined as AFTER - // the version unlike most others. - if pver <= BIP0031Version { - str := fmt.Sprintf("pong message invalid for protocol "+ - "version %d", pver) - return messageError("MsgPong.BtcEncode", str) - } - return writeElement(w, msg.Nonce) } @@ -57,16 +40,8 @@ func (msg *MsgPong) Command() string { // MaxPayloadLength returns the maximum length the payload can be for the // receiver. This is part of the Message interface implementation. func (msg *MsgPong) MaxPayloadLength(pver uint32) uint32 { - plen := uint32(0) - // The pong message did not exist for BIP0031Version and earlier. - // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER - // the version unlike most others. - if pver > BIP0031Version { - // Nonce 8 bytes. - plen += 8 - } - - return plen + // Nonce 8 bytes. + return uint32(8) } // NewMsgPong returns a new bitcoin pong message that conforms to the Message diff --git a/wire/msgpong_test.go b/wire/msgpong_test.go index a6684c08d..7df9b9d50 100644 --- a/wire/msgpong_test.go +++ b/wire/msgpong_test.go @@ -63,51 +63,6 @@ func TestPongLatest(t *testing.T) { } } -// TestPongBIP0031 tests the MsgPong API against the protocol version -// BIP0031Version. -func TestPongBIP0031(t *testing.T) { - // Use the protocol version just prior to BIP0031Version changes. - pver := BIP0031Version - - nonce, err := RandomUint64() - if err != nil { - t.Errorf("Error generating nonce: %v", err) - } - msg := NewMsgPong(nonce) - if msg.Nonce != nonce { - t.Errorf("Should get same nonce back out.") - } - - // Ensure max payload is expected value for old protocol version. - size := msg.MaxPayloadLength(pver) - if size != 0 { - t.Errorf("Max length should be 0 for pong protocol version %d.", - pver) - } - - // Test encode with old protocol version. - var buf bytes.Buffer - err = msg.BtcEncode(&buf, pver) - if err == nil { - t.Errorf("encode of MsgPong succeeded when it shouldn't have %v", - msg) - } - - // Test decode with old protocol version. - readmsg := NewMsgPong(0) - err = readmsg.BtcDecode(&buf, pver) - if err == nil { - t.Errorf("decode of MsgPong succeeded when it shouldn't have %v", - spew.Sdump(buf)) - } - - // Since this protocol version doesn't support pong, make sure the - // nonce didn't get encoded and decoded back out. - if msg.Nonce == readmsg.Nonce { - t.Errorf("Should not get same nonce for protocol version %d", pver) - } -} - // TestPongCrossProtocol tests the MsgPong API when encoding with the latest // protocol version and decoding with BIP0031Version. func TestPongCrossProtocol(t *testing.T) { @@ -126,20 +81,6 @@ func TestPongCrossProtocol(t *testing.T) { if err != nil { t.Errorf("encode of MsgPong failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - readmsg := NewMsgPong(0) - err = readmsg.BtcDecode(&buf, BIP0031Version) - if err == nil { - t.Errorf("encode of MsgPong succeeded when it shouldn't have %v", - msg) - } - - // Since one of the protocol versions doesn't support the pong message, - // make sure the nonce didn't get encoded and decoded back out. - if msg.Nonce == readmsg.Nonce { - t.Error("Should not get same nonce for cross protocol") - } } // TestPongWire tests the MsgPong wire encode and decode for various protocol @@ -158,14 +99,6 @@ func TestPongWire(t *testing.T) { []byte{0xf3, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}, ProtocolVersion, }, - - // Protocol version BIP0031Version+1 - { - MsgPong{Nonce: 456456}, // 0x6f708 - MsgPong{Nonce: 456456}, // 0x6f708 - []byte{0x08, 0xf7, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}, - BIP0031Version + 1, - }, } t.Logf("Running %d tests", len(tests)) @@ -203,8 +136,6 @@ func TestPongWire(t *testing.T) { // of MsgPong to confirm error paths work correctly. func TestPongWireErrors(t *testing.T) { pver := ProtocolVersion - pverNoPong := BIP0031Version - wireErr := &MessageError{} basePong := NewMsgPong(123123) // 0x1e0f3 basePongEncoded := []byte{ @@ -222,8 +153,6 @@ func TestPongWireErrors(t *testing.T) { // Latest protocol version with intentional read/write errors. // Force error in nonce. {basePong, basePongEncoded, pver, 0, io.ErrShortWrite, io.EOF}, - // Force error due to unsupported protocol version. - {basePong, basePongEncoded, pverNoPong, 4, wireErr, wireErr}, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgreject.go b/wire/msgreject.go index d998ee79a..c146d8126 100644 --- a/wire/msgreject.go +++ b/wire/msgreject.go @@ -74,12 +74,6 @@ type MsgReject struct { // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgReject) BtcDecode(r io.Reader, pver uint32) error { - if pver < RejectVersion { - str := fmt.Sprintf("reject message invalid for protocol "+ - "version %d", pver) - return messageError("MsgReject.BtcDecode", str) - } - // Command that was rejected. cmd, err := ReadVarString(r, pver) if err != nil { @@ -116,12 +110,6 @@ func (msg *MsgReject) BtcDecode(r io.Reader, pver uint32) error { // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgReject) BtcEncode(w io.Writer, pver uint32) error { - if pver < RejectVersion { - str := fmt.Sprintf("reject message invalid for protocol "+ - "version %d", pver) - return messageError("MsgReject.BtcEncode", str) - } - // Command that was rejected. err := WriteVarString(w, pver, msg.Cmd) if err != nil { @@ -162,17 +150,10 @@ func (msg *MsgReject) Command() string { // MaxPayloadLength returns the maximum length the payload can be for the // receiver. This is part of the Message interface implementation. func (msg *MsgReject) MaxPayloadLength(pver uint32) uint32 { - plen := uint32(0) - // The reject message did not exist before protocol version - // RejectVersion. - if pver >= RejectVersion { - // Unfortunately the bitcoin protocol does not enforce a sane - // limit on the length of the reason, so the max payload is the - // overall maximum message payload. - plen = MaxMessagePayload - } - - return plen + // Unfortunately the bitcoin protocol does not enforce a sane + // limit on the length of the reason, so the max payload is the + // overall maximum message payload. + return uint32(MaxMessagePayload) } // NewMsgReject returns a new bitcoin reject message that conforms to the diff --git a/wire/msgreject_test.go b/wire/msgreject_test.go index 610801a88..4a2fe2416 100644 --- a/wire/msgreject_test.go +++ b/wire/msgreject_test.go @@ -118,67 +118,7 @@ func TestRejectLatest(t *testing.T) { } } -// TestRejectBeforeAdded tests the MsgReject API against a protocol version -// before the version which introduced it (RejectVersion). -func TestRejectBeforeAdded(t *testing.T) { - // Use the protocol version just prior to RejectVersion. - pver := RejectVersion - 1 - - // Create reject message data. - rejCommand := (&MsgBlock{}).Command() - rejCode := RejectDuplicate - rejReason := "duplicate block" - rejHash := mainNetGenesisHash - - msg := NewMsgReject(rejCommand, rejCode, rejReason) - msg.Hash = rejHash - - // Ensure max payload is expected value for old protocol version. - size := msg.MaxPayloadLength(pver) - if size != 0 { - t.Errorf("Max length should be 0 for reject protocol version %d.", - pver) - } - - // Test encode with old protocol version. - var buf bytes.Buffer - err := msg.BtcEncode(&buf, pver) - if err == nil { - t.Errorf("encode of MsgReject succeeded when it shouldn't "+ - "have %v", msg) - } - - // // Test decode with old protocol version. - readMsg := MsgReject{} - err = readMsg.BtcDecode(&buf, pver) - if err == nil { - t.Errorf("decode of MsgReject succeeded when it shouldn't "+ - "have %v", spew.Sdump(buf.Bytes())) - } - - // Since this protocol version doesn't support reject, make sure various - // fields didn't get encoded and decoded back out. - if msg.Cmd == readMsg.Cmd { - t.Errorf("Should not get same reject command for protocol "+ - "version %d", pver) - } - if msg.Code == readMsg.Code { - t.Errorf("Should not get same reject code for protocol "+ - "version %d", pver) - } - if msg.Reason == readMsg.Reason { - t.Errorf("Should not get same reject reason for protocol "+ - "version %d", pver) - } - if msg.Hash == readMsg.Hash { - t.Errorf("Should not get same reject hash for protocol "+ - "version %d", pver) - } -} - -// TestRejectCrossProtocol tests the MsgReject API when encoding with the latest -// protocol version and decoded with a version before the version which -// introduced it (RejectVersion). +// TestRejectCrossProtocol tests the MsgReject API. func TestRejectCrossProtocol(t *testing.T) { // Create reject message data. rejCommand := (&MsgBlock{}).Command() @@ -195,30 +135,6 @@ func TestRejectCrossProtocol(t *testing.T) { if err != nil { t.Errorf("encode of MsgReject failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - readMsg := MsgReject{} - err = readMsg.BtcDecode(&buf, RejectVersion-1) - if err == nil { - t.Errorf("encode of MsgReject succeeded when it shouldn't "+ - "have %v", msg) - } - - // Since one of the protocol versions doesn't support the reject - // message, make sure the various fields didn't get encoded and decoded - // back out. - if msg.Cmd == readMsg.Cmd { - t.Errorf("Should not get same reject command for cross protocol") - } - if msg.Code == readMsg.Code { - t.Errorf("Should not get same reject code for cross protocol") - } - if msg.Reason == readMsg.Reason { - t.Errorf("Should not get same reject reason for cross protocol") - } - if msg.Hash == readMsg.Hash { - t.Errorf("Should not get same reject hash for cross protocol") - } } // TestRejectWire tests the MsgReject wire encode and decode for various @@ -302,8 +218,6 @@ func TestRejectWire(t *testing.T) { // of MsgReject to confirm error paths work correctly. func TestRejectWireErrors(t *testing.T) { pver := ProtocolVersion - pverNoReject := RejectVersion - 1 - wireErr := &MessageError{} baseReject := NewMsgReject("block", RejectDuplicate, "duplicate block") baseReject.Hash = mainNetGenesisHash @@ -335,8 +249,6 @@ func TestRejectWireErrors(t *testing.T) { {baseReject, baseRejectEncoded, pver, 7, io.ErrShortWrite, io.EOF}, // Force error in reject hash. {baseReject, baseRejectEncoded, pver, 23, io.ErrShortWrite, io.EOF}, - // Force error due to unsupported protocol version. - {baseReject, baseRejectEncoded, pverNoReject, 6, wireErr, wireErr}, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgsendheaders.go b/wire/msgsendheaders.go index 532e4aa1d..3f64791cb 100644 --- a/wire/msgsendheaders.go +++ b/wire/msgsendheaders.go @@ -5,7 +5,6 @@ package wire import ( - "fmt" "io" ) @@ -20,24 +19,12 @@ type MsgSendHeaders struct{} // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. func (msg *MsgSendHeaders) BtcDecode(r io.Reader, pver uint32) error { - if pver < SendHeadersVersion { - str := fmt.Sprintf("sendheaders message invalid for protocol "+ - "version %d", pver) - return messageError("MsgSendHeaders.BtcDecode", str) - } - return nil } // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. func (msg *MsgSendHeaders) BtcEncode(w io.Writer, pver uint32) error { - if pver < SendHeadersVersion { - str := fmt.Sprintf("sendheaders message invalid for protocol "+ - "version %d", pver) - return messageError("MsgSendHeaders.BtcEncode", str) - } - return nil } diff --git a/wire/msgsendheaders_test.go b/wire/msgsendheaders_test.go index ed6505098..2c8ddd8bb 100644 --- a/wire/msgsendheaders_test.go +++ b/wire/msgsendheaders_test.go @@ -42,16 +42,6 @@ func TestSendHeaders(t *testing.T) { err) } - // Older protocol versions should fail encode since message didn't - // exist yet. - oldPver := SendHeadersVersion - 1 - err = msg.BtcEncode(&buf, oldPver) - if err == nil { - s := "encode of MsgSendHeaders passed for old protocol " + - "version %v err <%v>" - t.Errorf(s, msg, err) - } - // Test decode with latest protocol version. readmsg := NewMsgSendHeaders() err = readmsg.BtcDecode(&buf, pver) @@ -59,40 +49,6 @@ func TestSendHeaders(t *testing.T) { t.Errorf("decode of MsgSendHeaders failed [%v] err <%v>", buf, err) } - - // Older protocol versions should fail decode since message didn't - // exist yet. - err = readmsg.BtcDecode(&buf, oldPver) - if err == nil { - s := "decode of MsgSendHeaders passed for old protocol " + - "version %v err <%v>" - t.Errorf(s, msg, err) - } -} - -// TestSendHeadersBIP0130 tests the MsgSendHeaders API against the protocol -// prior to version SendHeadersVersion. -func TestSendHeadersBIP0130(t *testing.T) { - // Use the protocol version just prior to SendHeadersVersion changes. - pver := SendHeadersVersion - 1 - - msg := NewMsgSendHeaders() - - // Test encode with old protocol version. - var buf bytes.Buffer - err := msg.BtcEncode(&buf, pver) - if err == nil { - t.Errorf("encode of MsgSendHeaders succeeded when it should " + - "have failed") - } - - // Test decode with old protocol version. - readmsg := NewMsgSendHeaders() - err = readmsg.BtcDecode(&buf, pver) - if err == nil { - t.Errorf("decode of MsgSendHeaders succeeded when it should " + - "have failed") - } } // TestSendHeadersCrossProtocol tests the MsgSendHeaders API when encoding with @@ -107,14 +63,6 @@ func TestSendHeadersCrossProtocol(t *testing.T) { t.Errorf("encode of MsgSendHeaders failed %v err <%v>", msg, err) } - - // Decode with old protocol version. - readmsg := NewMsgSendHeaders() - err = readmsg.BtcDecode(&buf, SendHeadersVersion) - if err != nil { - t.Errorf("decode of MsgSendHeaders failed [%v] err <%v>", buf, - err) - } } // TestSendHeadersWire tests the MsgSendHeaders wire encode and decode for @@ -136,22 +84,6 @@ func TestSendHeadersWire(t *testing.T) { msgSendHeadersEncoded, ProtocolVersion, }, - - // Protocol version SendHeadersVersion+1 - { - msgSendHeaders, - msgSendHeaders, - msgSendHeadersEncoded, - SendHeadersVersion + 1, - }, - - // Protocol version SendHeadersVersion - { - msgSendHeaders, - msgSendHeaders, - msgSendHeadersEncoded, - SendHeadersVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgtx_test.go b/wire/msgtx_test.go index f7deb4550..69ca17950 100644 --- a/wire/msgtx_test.go +++ b/wire/msgtx_test.go @@ -299,70 +299,6 @@ func TestTxWire(t *testing.T) { multiTxEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version with no transactions. - { - noTx, - noTx, - noTxEncoded, - BIP0035Version, - }, - - // Protocol version BIP0035Version with multiple transactions. - { - multiTx, - multiTx, - multiTxEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version with no transactions. - { - noTx, - noTx, - noTxEncoded, - BIP0031Version, - }, - - // Protocol version BIP0031Version with multiple transactions. - { - multiTx, - multiTx, - multiTxEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion with no transactions. - { - noTx, - noTx, - noTxEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion with multiple transactions. - { - multiTx, - multiTx, - multiTxEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion with no transactions. - { - noTx, - noTx, - noTxEncoded, - MultipleAddressVersion, - }, - - // Protocol version MultipleAddressVersion with multiple transactions. - { - multiTx, - multiTx, - multiTxEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) @@ -399,10 +335,7 @@ func TestTxWire(t *testing.T) { // TestTxWireErrors performs negative tests against wire encode and decode // of MsgTx to confirm error paths work correctly. func TestTxWireErrors(t *testing.T) { - // Use protocol version 60002 specifically here instead of the latest - // because the test data is using bytes encoded with that protocol - // version. - pver := uint32(60002) + pver := ProtocolVersion tests := []struct { in *MsgTx // Value to encode @@ -717,10 +650,7 @@ func TestTxSerializeErrors(t *testing.T) { // of inputs and outputs are handled properly. This could otherwise potentially // be used as an attack vector. func TestTxOverflowErrors(t *testing.T) { - // Use protocol version 70001 and transaction version 1 specifically - // here instead of the latest values because the test data is using - // bytes encoded with those versions. - pver := uint32(70001) + pver := ProtocolVersion txVer := uint32(1) tests := []struct { diff --git a/wire/msgverack_test.go b/wire/msgverack_test.go index 05066f5b4..7ac8a1b7d 100644 --- a/wire/msgverack_test.go +++ b/wire/msgverack_test.go @@ -53,38 +53,6 @@ func TestVerAckWire(t *testing.T) { msgVerAckEncoded, ProtocolVersion, }, - - // Protocol version BIP0035Version. - { - msgVerAck, - msgVerAck, - msgVerAckEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version. - { - msgVerAck, - msgVerAck, - msgVerAckEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion. - { - msgVerAck, - msgVerAck, - msgVerAckEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion. - { - msgVerAck, - msgVerAck, - msgVerAckEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/msgversion.go b/wire/msgversion.go index bfbcf59ae..af5c28ca6 100644 --- a/wire/msgversion.go +++ b/wire/msgversion.go @@ -7,10 +7,11 @@ package wire import ( "bytes" "fmt" - "github.com/daglabs/btcd/util/subnetworkid" "io" "strings" "time" + + "github.com/daglabs/btcd/util/subnetworkid" ) // MaxUserAgentLen is the maximum allowed length for the user agent field in a @@ -200,14 +201,11 @@ func (msg *MsgVersion) BtcEncode(w io.Writer, pver uint32) error { return err } - // There was no relay transactions field before BIP0037Version. Also, - // the wire encoding for the field is true when transactions should be + // The wire encoding for the field is true when transactions should be // relayed, so reverse it from the DisableRelayTx field. - if pver >= BIP0037Version { - err = writeElement(w, !msg.DisableRelayTx) - if err != nil { - return err - } + err = writeElement(w, !msg.DisableRelayTx) + if err != nil { + return err } return nil } diff --git a/wire/msgversion_test.go b/wire/msgversion_test.go index c4d493aa9..225b77174 100644 --- a/wire/msgversion_test.go +++ b/wire/msgversion_test.go @@ -151,56 +151,6 @@ func TestVersionWire(t *testing.T) { baseVersionBIP0037Encoded, ProtocolVersion, }, - - // Protocol version BIP0037Version with relay transactions field - // true. - { - baseVersionBIP0037, - baseVersionBIP0037, - baseVersionBIP0037Encoded, - BIP0037Version, - }, - - // Protocol version BIP0037Version with relay transactions field - // false. - { - verRelayTxFalse, - verRelayTxFalse, - verRelayTxFalseEncoded, - BIP0037Version, - }, - - // Protocol version BIP0035Version. - { - baseVersion, - baseVersion, - baseVersionEncoded, - BIP0035Version, - }, - - // Protocol version BIP0031Version. - { - baseVersion, - baseVersion, - baseVersionEncoded, - BIP0031Version, - }, - - // Protocol version NetAddressTimeVersion. - { - baseVersion, - baseVersion, - baseVersionEncoded, - NetAddressTimeVersion, - }, - - // Protocol version MultipleAddressVersion. - { - baseVersion, - baseVersion, - baseVersionEncoded, - MultipleAddressVersion, - }, } t.Logf("Running %d tests", len(tests)) @@ -237,10 +187,7 @@ func TestVersionWire(t *testing.T) { // TestVersionWireErrors performs negative tests against wire encode and // decode of MsgGetHeaders to confirm error paths work correctly. func TestVersionWireErrors(t *testing.T) { - // Use protocol version 60002 specifically here instead of the latest - // because the test data is using bytes encoded with that protocol - // version. - pver := uint32(60002) + pver := ProtocolVersion wireErr := &MessageError{} // Ensure calling MsgVersion.BtcDecode with a non *bytes.Buffer returns @@ -303,12 +250,6 @@ func TestVersionWireErrors(t *testing.T) { {baseVersion, baseVersionEncoded, pver, 102, io.ErrShortWrite, io.ErrUnexpectedEOF}, // Force error in last block. {baseVersion, baseVersionEncoded, pver, 118, io.ErrShortWrite, io.ErrUnexpectedEOF}, - // Force error in relay tx - no read error should happen since - // it's optional. - { - baseVersionBIP0037, baseVersionBIP0037Encoded, - BIP0037Version, 121, io.ErrShortWrite, nil, - }, // Force error due to user agent too big {exceedUAVer, exceedUAVerEncoded, pver, newLen, wireErr, wireErr}, } diff --git a/wire/netaddress.go b/wire/netaddress.go index 7e24c2d08..92c1f5d21 100644 --- a/wire/netaddress.go +++ b/wire/netaddress.go @@ -14,16 +14,8 @@ import ( // maxNetAddressPayload returns the max payload size for a bitcoin NetAddress // based on the protocol version. func maxNetAddressPayload(pver uint32) uint32 { - // Services 8 bytes + ip 16 bytes + port 2 bytes. - plen := uint32(26) - - // NetAddressTimeVersion added a timestamp field. - if pver >= NetAddressTimeVersion { - // Timestamp 8 bytes. - plen += 8 - } - - return plen + // Services 8 bytes + ip 16 bytes + port 2 bytes + timestamp 8 bytes. + return uint32(34) } // NetAddress defines information about a peer on the network including the time @@ -88,7 +80,7 @@ func NewNetAddress(addr *net.TCPAddr, services ServiceFlag) *NetAddress { func readNetAddress(r io.Reader, pver uint32, na *NetAddress, ts bool) error { var ip [16]byte - if ts && pver >= NetAddressTimeVersion { + if ts { err := readElement(r, (*int64Time)(&na.Timestamp)) if err != nil { return err @@ -118,8 +110,7 @@ func readNetAddress(r io.Reader, pver uint32, na *NetAddress, ts bool) error { // version and whether or not the timestamp is included per ts. Some messages // like version do not include the timestamp. func writeNetAddress(w io.Writer, pver uint32, na *NetAddress, ts bool) error { - // Timestamp wasn't added until protocol version >= NetAddressTimeVersion. - if ts && pver >= NetAddressTimeVersion { + if ts { err := writeElement(w, int64(na.Timestamp.Unix())) if err != nil { return err diff --git a/wire/netaddress_test.go b/wire/netaddress_test.go index 5d49d2b0a..1c2f6837c 100644 --- a/wire/netaddress_test.go +++ b/wire/netaddress_test.go @@ -58,17 +58,6 @@ func TestNetAddress(t *testing.T) { "protocol version %d - got %v, want %v", pver, maxPayload, wantPayload) } - - // Protocol version before NetAddressTimeVersion when timestamp was - // added. Ensure max payload is expected value for it. - pver = NetAddressTimeVersion - 1 - wantPayload = 26 - maxPayload = maxNetAddressPayload(pver) - if maxPayload != wantPayload { - t.Errorf("maxNetAddressPayload: wrong max payload length for "+ - "protocol version %d - got %v, want %v", pver, - maxPayload, wantPayload) - } } // TestNetAddressWire tests the NetAddress wire encode and decode for various @@ -128,45 +117,6 @@ func TestNetAddressWire(t *testing.T) { baseNetAddrEncoded, ProtocolVersion, }, - - // Protocol version NetAddressTimeVersion without ts flag. - { - baseNetAddr, - baseNetAddrNoTS, - false, - baseNetAddrNoTSEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion with ts flag. - { - baseNetAddr, - baseNetAddr, - true, - baseNetAddrEncoded, - NetAddressTimeVersion, - }, - - // Protocol version NetAddressTimeVersion-1 without ts flag. - { - baseNetAddr, - baseNetAddrNoTS, - false, - baseNetAddrNoTSEncoded, - NetAddressTimeVersion - 1, - }, - - // Protocol version NetAddressTimeVersion-1 with timestamp. - // Even though the timestamp flag is set, this shouldn't have a - // timestamp since it is a protocol version before it was - // added. - { - baseNetAddr, - baseNetAddrNoTS, - true, - baseNetAddrNoTSEncoded, - NetAddressTimeVersion - 1, - }, } t.Logf("Running %d tests", len(tests)) @@ -204,7 +154,6 @@ func TestNetAddressWire(t *testing.T) { // decode NetAddress to confirm error paths work correctly. func TestNetAddressWireErrors(t *testing.T) { pver := ProtocolVersion - pverNAT := NetAddressTimeVersion - 1 // baseNetAddr is used in the various tests as a baseline NetAddress. baseNetAddr := NetAddress{ @@ -242,16 +191,6 @@ func TestNetAddressWireErrors(t *testing.T) { {&baseNetAddr, []byte{}, pver, false, 8, io.ErrShortWrite, io.EOF}, // Force errors on port. {&baseNetAddr, []byte{}, pver, false, 24, io.ErrShortWrite, io.EOF}, - - // Protocol version before NetAddressTimeVersion with timestamp - // flag set (should not have timestamp due to old protocol - // version) and intentional read/write errors. - // Force errors on services. - {&baseNetAddr, []byte{}, pverNAT, true, 0, io.ErrShortWrite, io.EOF}, - // Force errors on ip. - {&baseNetAddr, []byte{}, pverNAT, true, 8, io.ErrShortWrite, io.EOF}, - // Force errors on port. - {&baseNetAddr, []byte{}, pverNAT, true, 24, io.ErrShortWrite, io.EOF}, } t.Logf("Running %d tests", len(tests)) diff --git a/wire/protocol.go b/wire/protocol.go index 2547a7891..a645225f4 100644 --- a/wire/protocol.go +++ b/wire/protocol.go @@ -13,44 +13,7 @@ import ( // XXX pedro: we will probably need to bump this. const ( // ProtocolVersion is the latest protocol version this package supports. - ProtocolVersion uint32 = 70013 - - // MultipleAddressVersion is the protocol version which added multiple - // addresses per message (pver >= MultipleAddressVersion). - MultipleAddressVersion uint32 = 209 - - // NetAddressTimeVersion is the protocol version which added the - // timestamp field (pver >= NetAddressTimeVersion). - NetAddressTimeVersion uint32 = 31402 - - // BIP0031Version is the protocol version AFTER which a pong message - // and nonce field in ping were added (pver > BIP0031Version). - BIP0031Version uint32 = 60000 - - // BIP0035Version is the protocol version which added the mempool - // message (pver >= BIP0035Version). - BIP0035Version uint32 = 60002 - - // BIP0037Version is the protocol version which added new connection - // bloom filtering related messages and extended the version message - // with a relay flag (pver >= BIP0037Version). - BIP0037Version uint32 = 70001 - - // RejectVersion is the protocol version which added a new reject - // message. - RejectVersion uint32 = 70002 - - // BIP0111Version is the protocol version which added the SFNodeBloom - // service flag. - BIP0111Version uint32 = 70011 - - // SendHeadersVersion is the protocol version which added a new - // sendheaders message. - SendHeadersVersion uint32 = 70012 - - // FeeFilterVersion is the protocol version which added a new - // feefilter message. - FeeFilterVersion uint32 = 70013 + ProtocolVersion uint32 = 1 ) // ServiceFlag identifies services supported by a bitcoin peer.