Skip to content

Commit

Permalink
Changed the protocol version from ETH66 to QUAI1
Browse files Browse the repository at this point in the history
Dropped support to ETH65 protocol version
  • Loading branch information
gameofpointers committed Sep 23, 2023
1 parent 413761b commit 1081fda
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 135 deletions.
4 changes: 2 additions & 2 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, entropy *
d.mux.Post(DoneEvent{latest})
}
}()
if p.version < eth.ETH65 {
return fmt.Errorf("%w: advertized %d < required %d", errTooOld, p.version, eth.ETH65)
if p.version < eth.QUAI1 {
return fmt.Errorf("%w: advertized %d < required %d", errTooOld, p.version, eth.QUAI1)
}
mode := d.getMode()

Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (ps *peerSet) HeaderIdlePeers() ([]*peerConnection, int) {
throughput := func(p *peerConnection) int {
return p.rates.Capacity(eth.BlockHeadersMsg, time.Second)
}
return ps.idlePeers(eth.ETH65, eth.ETH66, idle, throughput)
return ps.idlePeers(eth.QUAI1, eth.QUAI1, idle, throughput)
}

// BodyIdlePeers retrieves a flat list of all the currently body-idle peers within
Expand All @@ -348,7 +348,7 @@ func (ps *peerSet) BodyIdlePeers() ([]*peerConnection, int) {
throughput := func(p *peerConnection) int {
return p.rates.Capacity(eth.BlockBodiesMsg, time.Second)
}
return ps.idlePeers(eth.ETH65, eth.ETH66, idle, throughput)
return ps.idlePeers(eth.QUAI1, eth.QUAI1, idle, throughput)
}

// idlePeers retrieves a flat list of all currently idle peers satisfying the
Expand Down
26 changes: 7 additions & 19 deletions eth/protocols/eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,12 @@ type Decoder interface {
Time() time.Time
}

var eth65 = map[uint64]msgHandler{
GetBlockHeadersMsg: handleGetBlockHeaders,
BlockHeadersMsg: handleBlockHeaders,
GetBlockBodiesMsg: handleGetBlockBodies,
BlockBodiesMsg: handleBlockBodies,
var quai1 = map[uint64]msgHandler{
NewBlockHashesMsg: handleNewBlockhashes,
NewBlockMsg: handleNewBlock,
TransactionsMsg: handleTransactions,
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
GetPooledTransactionsMsg: handleGetPooledTransactions,
PooledTransactionsMsg: handlePooledTransactions,
GetBlockMsg: handleGetBlock,
}

var eth66 = map[uint64]msgHandler{
NewBlockHashesMsg: handleNewBlockhashes,
NewBlockMsg: handleNewBlock,
TransactionsMsg: handleTransactions,
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
// eth66 messages with request-id
// quai1 messages with request-id
GetBlockHeadersMsg: handleGetBlockHeaders66,
BlockHeadersMsg: handleBlockHeaders66,
GetBlockBodiesMsg: handleGetBlockBodies66,
Expand All @@ -205,9 +191,11 @@ func handleMessage(backend Backend, peer *Peer) error {
}
defer msg.Discard()

var handlers = eth65
if peer.Version() >= ETH66 {
handlers = eth66
var handlers map[uint64]msgHandler
if peer.Version() >= QUAI1 {
handlers = quai1
} else {
return fmt.Errorf("protocol version not supported")
}
// Track the amount of time it takes to serve the request and run the handler
if metrics.Enabled {
Expand Down
99 changes: 0 additions & 99 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ import (
"github.com/dominant-strategies/go-quai/trie"
)

// handleGetBlockHeaders handles Block header query, collect the requested headers and reply
func handleGetBlockHeaders(backend Backend, msg Decoder, peer *Peer) error {
// Decode the complex header query
var query GetBlockHeadersPacket
if err := msg.Decode(&query); err != nil {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
response := answerGetBlockHeadersQuery(backend, &query, peer)
return peer.SendBlockHeaders(response)
}

// handleGetBlockHeaders66 is the eth/66 version of handleGetBlockHeaders
func handleGetBlockHeaders66(backend Backend, msg Decoder, peer *Peer) error {
// Decode the complex header query
Expand Down Expand Up @@ -119,16 +108,6 @@ func answerGetBlockHeadersQuery(backend Backend, query *GetBlockHeadersPacket, p
return headers
}

func handleGetBlockBodies(backend Backend, msg Decoder, peer *Peer) error {
// Decode the block body retrieval message
var query GetBlockBodiesPacket
if err := msg.Decode(&query); err != nil {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
response := answerGetBlockBodiesQuery(backend, query, peer)
return peer.SendBlockBodiesRLP(response)
}

func handleGetBlockBodies66(backend Backend, msg Decoder, peer *Peer) error {
// Decode the block body retrieval message
var query GetBlockBodiesPacket66
Expand Down Expand Up @@ -157,22 +136,6 @@ func answerGetBlockBodiesQuery(backend Backend, query GetBlockBodiesPacket, peer
return bodies
}

func handleGetBlock(backend Backend, msg Decoder, peer *Peer) error {
// Decode the block retrieval message
var query GetBlockPacket
if err := msg.Decode(&query); err != nil {
fmt.Println("Error decoding the message", err)
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
log.Info("Got a block fetch request eth/65: ", "Hash", query.Hash)
// check if we have the requested block in the database.
response := backend.Core().GetBlockOrCandidateByHash(query.Hash)
if response != nil {
return peer.SendNewBlock(response)
}
return nil
}

func handleGetBlock66(backend Backend, msg Decoder, peer *Peer) error {
// Decode the block retrieval message
var query GetBlockPacket66
Expand Down Expand Up @@ -252,15 +215,6 @@ func handleNewBlock(backend Backend, msg Decoder, peer *Peer) error {
return backend.Handle(peer, ann)
}

func handleBlockHeaders(backend Backend, msg Decoder, peer *Peer) error {
// A batch of headers arrived to one of our previous requests
res := new(BlockHeadersPacket)
if err := msg.Decode(res); err != nil {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
return backend.Handle(peer, res)
}

func handleBlockHeaders66(backend Backend, msg Decoder, peer *Peer) error {
// A batch of headers arrived to one of our previous requests
res := new(BlockHeadersPacket66)
Expand All @@ -272,15 +226,6 @@ func handleBlockHeaders66(backend Backend, msg Decoder, peer *Peer) error {
return backend.Handle(peer, &res.BlockHeadersPacket)
}

func handleBlockBodies(backend Backend, msg Decoder, peer *Peer) error {
// A batch of block bodies arrived to one of our previous requests
res := new(BlockBodiesPacket)
if err := msg.Decode(res); err != nil {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
return backend.Handle(peer, res)
}

func handleBlockBodies66(backend Backend, msg Decoder, peer *Peer) error {
// A batch of block bodies arrived to one of our previous requests
res := new(BlockBodiesPacket66)
Expand Down Expand Up @@ -316,23 +261,6 @@ func handleNewPooledTransactionHashes(backend Backend, msg Decoder, peer *Peer)
return backend.Handle(peer, ann)
}

func handleGetPooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
nodeCtx := common.NodeLocation.Context()
if nodeCtx != common.ZONE_CTX {
return errors.New("transactions are only handled in zone")
}
if !backend.Core().Slice().ProcessingState() {
return nil
}
// Decode the pooled transactions retrieval message
var query GetPooledTransactionsPacket
if err := msg.Decode(&query); err != nil {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
hashes, txs := answerGetPooledTransactions(backend, query, peer)
return peer.SendPooledTransactionsRLP(hashes, txs)
}

func handleGetPooledTransactions66(backend Backend, msg Decoder, peer *Peer) error {
// Decode the pooled transactions retrieval message
var query GetPooledTransactionsPacket66
Expand Down Expand Up @@ -398,33 +326,6 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
return backend.Handle(peer, &txs)
}

func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
nodeCtx := common.NodeLocation.Context()
if nodeCtx != common.ZONE_CTX {
return errors.New("transactions are only handled in zone")
}
if !backend.Core().Slice().ProcessingState() {
return nil
}
// Transactions arrived, make sure we have a valid and fresh chain to handle them
if !backend.AcceptTxs() {
return nil
}
// Transactions can be processed, parse all of them and deliver to the pool
var txs PooledTransactionsPacket
if err := msg.Decode(&txs); err != nil {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
for i, tx := range txs {
// Validate and mark the remote transaction
if tx == nil {
return fmt.Errorf("%w: transaction %d is nil", errDecode, i)
}
peer.markTransaction(tx.Hash())
}
return backend.Handle(peer, &txs)
}

func handlePooledTransactions66(backend Backend, msg Decoder, peer *Peer) error {
nodeCtx := common.NodeLocation.Context()
if nodeCtx != common.ZONE_CTX {
Expand Down
14 changes: 7 additions & 7 deletions eth/protocols/eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter, txpool TxPool) *Pe
// Start up all the broadcasters
go peer.broadcastBlocks()
go peer.broadcastTransactions()
if version >= ETH65 {
if version >= QUAI1 {
go peer.announceTransactions()
}
return peer
Expand Down Expand Up @@ -394,7 +394,7 @@ func (p *Peer) RequestOneHeader(hash common.Hash) error {
Dom: false,
Reverse: false,
}
if p.Version() >= ETH66 {
if p.Version() >= QUAI1 {
id := rand.Uint64()

requestTracker.Track(p.id, p.version, GetBlockHeadersMsg, BlockHeadersMsg, id)
Expand All @@ -417,7 +417,7 @@ func (p *Peer) RequestHeadersByHash(origin common.Hash, amount int, skip uint64,
Dom: dom,
Reverse: reverse,
}
if p.Version() >= ETH66 {
if p.Version() >= QUAI1 {
id := rand.Uint64()

requestTracker.Track(p.id, p.version, GetBlockHeadersMsg, BlockHeadersMsg, id)
Expand All @@ -436,7 +436,7 @@ func (p *Peer) RequestBlockByHash(hash common.Hash) error {
query := GetBlockPacket{
Hash: hash,
}
if p.Version() >= ETH66 {
if p.Version() >= QUAI1 {
id := rand.Uint64()

requestTracker.Track(p.id, p.version, GetBlockMsg, NewBlockMsg, id)
Expand All @@ -460,7 +460,7 @@ func (p *Peer) RequestHeadersByNumber(origin uint64, amount int, skip uint64, to
Dom: dom,
Reverse: reverse,
}
if p.Version() >= ETH66 {
if p.Version() >= QUAI1 {
id := rand.Uint64()

requestTracker.Track(p.id, p.version, GetBlockHeadersMsg, BlockHeadersMsg, id)
Expand Down Expand Up @@ -488,7 +488,7 @@ func (p *Peer) ExpectRequestHeadersByNumber(origin uint64, amount int, dom bool,
// specified.
func (p *Peer) RequestBodies(hashes []common.Hash) error {
p.Log().Debug("Fetching batch of block bodies", "count", len(hashes))
if p.Version() >= ETH66 {
if p.Version() >= QUAI1 {
id := rand.Uint64()

requestTracker.Track(p.id, p.version, GetBlockBodiesMsg, BlockBodiesMsg, id)
Expand All @@ -503,7 +503,7 @@ func (p *Peer) RequestBodies(hashes []common.Hash) error {
// RequestTxs fetches a batch of transactions from a remote node.
func (p *Peer) RequestTxs(hashes []common.Hash) error {
p.Log().Debug("Fetching batch of transactions", "count", len(hashes))
if p.Version() >= ETH66 {
if p.Version() >= QUAI1 {
id := rand.Uint64()

requestTracker.Track(p.id, p.version, GetPooledTransactionsMsg, PooledTransactionsMsg, id)
Expand Down
7 changes: 3 additions & 4 deletions eth/protocols/eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import (

// Constants to match up protocol versions and messages
const (
ETH65 = 65
ETH66 = 66
QUAI1 = 100
)

// ProtocolName is the official short name of the `quai` protocol used during
Expand All @@ -40,11 +39,11 @@ const c_ProtocolName = "quai"

// ProtocolVersions are the supported versions of the `eth` protocol (first
// is primary).
var ProtocolVersions = []uint{ETH66, ETH65}
var ProtocolVersions = []uint{QUAI1}

// protocolLengths are the number of implemented message corresponding to
// different protocol versions.
var protocolLengths = map[uint]uint64{ETH66: 12, ETH65: 12}
var protocolLengths = map[uint]uint64{QUAI1: 12}

// maxMessageSize is the maximum cap on the size of a protocol message.
const maxMessageSize = 10 * 1024 * 1024
Expand Down
4 changes: 2 additions & 2 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (h *handler) syncTransactions(p *eth.Peer) {
// The eth/65 protocol introduces proper transaction announcements, so instead
// of dripping transactions across multiple peers, just send the entire list as
// an announcement and let the remote side decide what they need (likely nothing).
if p.Version() >= eth.ETH65 {
if p.Version() >= eth.QUAI1 {
hashes := make([]common.Hash, len(txs))
for i, tx := range txs {
hashes[i] = tx.Hash()
Expand Down Expand Up @@ -92,7 +92,7 @@ func (h *handler) txsyncLoop64() {

// send starts a sending a pack of transactions from the sync.
send := func(s *txsync) {
if s.p.Version() >= eth.ETH65 {
if s.p.Version() >= eth.QUAI1 {
panic("initial transaction syncer running on eth/65+")
}
// Fill pack with transactions up to the target size.
Expand Down

0 comments on commit 1081fda

Please sign in to comment.