diff options
author | Sonic <sonic@cobinhood.com> | 2018-09-19 19:07:10 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:21:31 +0800 |
commit | bbd696f96d32b06b5bcffa1b97682d372b7eee31 (patch) | |
tree | 67e0a77155aa04c423a1c6999a5070c88bfa3ed8 | |
parent | d461a77d0c7c34c4d686c22f0c9d4bb77fd17569 (diff) | |
download | go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.tar go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.tar.gz go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.tar.bz2 go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.tar.lz go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.tar.xz go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.tar.zst go-tangerine-bbd696f96d32b06b5bcffa1b97682d372b7eee31.zip |
dex: introduce dex64 and remove eth62, eth63
-rw-r--r-- | dex/handler.go | 13 | ||||
-rw-r--r-- | dex/metrics.go | 8 | ||||
-rw-r--r-- | dex/protocol.go | 34 |
3 files changed, 37 insertions, 18 deletions
diff --git a/dex/handler.go b/dex/handler.go index b9a354f42..21609a561 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -123,11 +123,6 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne // Initiate a sub-protocol for every implemented version we can handle manager.SubProtocols = make([]p2p.Protocol, 0, len(ProtocolVersions)) for i, version := range ProtocolVersions { - // Skip protocol version if incompatible with the mode of operation - if mode == downloader.FastSync && version < eth63 { - continue - } - // Compatible; initialise the sub-protocol version := version // Closure for the run manager.SubProtocols = append(manager.SubProtocols, p2p.Protocol{ Name: ProtocolName, @@ -526,7 +521,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } } - case p.version >= eth63 && msg.Code == GetNodeDataMsg: + case msg.Code == GetNodeDataMsg: // Decode the retrieval message msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size)) if _, err := msgStream.List(); err != nil { @@ -553,7 +548,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } return p.SendNodeData(data) - case p.version >= eth63 && msg.Code == NodeDataMsg: + case msg.Code == NodeDataMsg: // A batch of node state data arrived to one of our previous requests var data [][]byte if err := msg.Decode(&data); err != nil { @@ -564,7 +559,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { log.Debug("Failed to deliver node state data", "err", err) } - case p.version >= eth63 && msg.Code == GetReceiptsMsg: + case msg.Code == GetReceiptsMsg: // Decode the retrieval message msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size)) if _, err := msgStream.List(); err != nil { @@ -600,7 +595,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } return p.SendReceiptsRLP(receipts) - case p.version >= eth63 && msg.Code == ReceiptsMsg: + case msg.Code == ReceiptsMsg: // A batch of receipts arrived to one of our previous requests var receipts [][]*types.Receipt if err := msg.Decode(&receipts); err != nil { diff --git a/dex/metrics.go b/dex/metrics.go index 8d923ed70..0aa88fff6 100644 --- a/dex/metrics.go +++ b/dex/metrics.go @@ -92,9 +92,9 @@ func (rw *meteredMsgReadWriter) ReadMsg() (p2p.Msg, error) { case msg.Code == BlockBodiesMsg: packets, traffic = reqBodyInPacketsMeter, reqBodyInTrafficMeter - case rw.version >= eth63 && msg.Code == NodeDataMsg: + case msg.Code == NodeDataMsg: packets, traffic = reqStateInPacketsMeter, reqStateInTrafficMeter - case rw.version >= eth63 && msg.Code == ReceiptsMsg: + case msg.Code == ReceiptsMsg: packets, traffic = reqReceiptInPacketsMeter, reqReceiptInTrafficMeter case msg.Code == NewBlockHashesMsg: @@ -119,9 +119,9 @@ func (rw *meteredMsgReadWriter) WriteMsg(msg p2p.Msg) error { case msg.Code == BlockBodiesMsg: packets, traffic = reqBodyOutPacketsMeter, reqBodyOutTrafficMeter - case rw.version >= eth63 && msg.Code == NodeDataMsg: + case msg.Code == NodeDataMsg: packets, traffic = reqStateOutPacketsMeter, reqStateOutTrafficMeter - case rw.version >= eth63 && msg.Code == ReceiptsMsg: + case msg.Code == ReceiptsMsg: packets, traffic = reqReceiptOutPacketsMeter, reqReceiptOutTrafficMeter case msg.Code == NewBlockHashesMsg: diff --git a/dex/protocol.go b/dex/protocol.go index de6354717..6452d854a 100644 --- a/dex/protocol.go +++ b/dex/protocol.go @@ -20,28 +20,30 @@ import ( "fmt" "io" "math/big" + "net" + "github.com/dexon-foundation/dexon/crypto/sha3" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/rlp" ) // Constants to match up protocol versions and messages const ( - eth62 = 62 - eth63 = 63 + dex64 = 64 ) // ProtocolName is the official short name of the protocol used during capability negotiation. -var ProtocolName = "eth" +var ProtocolName = "dex" // ProtocolVersions are the upported versions of the eth protocol (first is primary). -var ProtocolVersions = []uint{eth63, eth62} +var ProtocolVersions = []uint{dex64} // ProtocolLengths are the number of implemented message corresponding to different protocol versions. -var ProtocolLengths = []uint64{17, 8} +var ProtocolLengths = []uint64{18} const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message @@ -62,6 +64,9 @@ const ( NodeDataMsg = 0x0e GetReceiptsMsg = 0x0f ReceiptsMsg = 0x10 + + // Protocol messages belonging to dex/64 + NotaryNodeInfoMsg = 0x11 ) type errCode int @@ -181,3 +186,22 @@ type blockBody struct { // blockBodiesData is the network packet for block content distribution. type blockBodiesData []*blockBody + +// TODO(sonic): revisit this msg when dexon core SDK is finalized. +// notartyNodeInfo is the network packet for notary node ip info. +type notaryNodeInfo struct { + ID discover.NodeID + IP net.IP + UDP uint16 + TCP uint16 + Round uint64 + Sig []byte + Timestamp int64 +} + +func (n *notaryNodeInfo) Hash() (h common.Hash) { + hw := sha3.NewKeccak256() + rlp.Encode(hw, n) + hw.Sum(h[:0]) + return h +} |