Skip to content

Commit b5c7bd5

Browse files
committed
enable bft and better protocol version check
1 parent ebb9a63 commit b5c7bd5

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

eth/downloader/peer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func (ps *peerSet) HeaderIdlePeers() ([]*peerConnection, int) {
477477
defer p.lock.RUnlock()
478478
return p.headerThroughput
479479
}
480-
return ps.idlePeers(62, 101, idle, throughput)
480+
return ps.idlePeers(62, 200, idle, throughput)
481481
}
482482

483483
// BodyIdlePeers retrieves a flat list of all the currently body-idle peers within
@@ -491,7 +491,7 @@ func (ps *peerSet) BodyIdlePeers() ([]*peerConnection, int) {
491491
defer p.lock.RUnlock()
492492
return p.blockThroughput
493493
}
494-
return ps.idlePeers(62, 101, idle, throughput)
494+
return ps.idlePeers(62, 200, idle, throughput)
495495
}
496496

497497
// ReceiptIdlePeers retrieves a flat list of all the currently receipt-idle peers
@@ -505,7 +505,7 @@ func (ps *peerSet) ReceiptIdlePeers() ([]*peerConnection, int) {
505505
defer p.lock.RUnlock()
506506
return p.receiptThroughput
507507
}
508-
return ps.idlePeers(63, 101, idle, throughput)
508+
return ps.idlePeers(63, 200, idle, throughput)
509509
}
510510

511511
// NodeDataIdlePeers retrieves a flat list of all the currently node-data-idle
@@ -519,7 +519,7 @@ func (ps *peerSet) NodeDataIdlePeers() ([]*peerConnection, int) {
519519
defer p.lock.RUnlock()
520520
return p.stateThroughput
521521
}
522-
return ps.idlePeers(63, 101, idle, throughput)
522+
return ps.idlePeers(63, 200, idle, throughput)
523523
}
524524

525525
// idlePeers retrieves a flat list of all currently idle peers satisfying the

eth/handler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
699699
}
700700
}
701701

702-
case p.version >= eth63 && msg.Code == GetNodeDataMsg:
702+
case supportsEth63(p.version) && msg.Code == GetNodeDataMsg:
703703
// Decode the retrieval message
704704
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
705705
if _, err := msgStream.List(); err != nil {
@@ -726,7 +726,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
726726
}
727727
return p.SendNodeData(data)
728728

729-
case p.version >= eth63 && msg.Code == NodeDataMsg:
729+
case supportsEth63(p.version) && msg.Code == NodeDataMsg:
730730
// A batch of node state data arrived to one of our previous requests
731731
var data [][]byte
732732
if err := msg.Decode(&data); err != nil {
@@ -737,7 +737,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
737737
log.Debug("Failed to deliver node state data", "err", err)
738738
}
739739

740-
case p.version >= eth63 && msg.Code == GetReceiptsMsg:
740+
case supportsEth63(p.version) && msg.Code == GetReceiptsMsg:
741741
// Decode the retrieval message
742742
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
743743
if _, err := msgStream.List(); err != nil {
@@ -773,7 +773,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
773773
}
774774
return p.SendReceiptsRLP(receipts)
775775

776-
case p.version >= eth63 && msg.Code == ReceiptsMsg:
776+
case supportsEth63(p.version) && msg.Code == ReceiptsMsg:
777777
// A batch of receipts arrived to one of our previous requests
778778
var receipts [][]*types.Receipt
779779
if err := msg.Decode(&receipts); err != nil {
@@ -847,7 +847,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
847847
}
848848
}
849849

850-
case msg.Code == NewPooledTransactionHashesMsg && p.version >= eth65:
850+
case msg.Code == NewPooledTransactionHashesMsg && supportsEth65(p.version):
851851
// New transaction announcement arrived, make sure we have
852852
// a valid and fresh chain to handle them
853853
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
@@ -863,7 +863,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
863863
}
864864
pm.txFetcher.Notify(p.id, hashes)
865865

866-
case msg.Code == GetPooledTransactionsMsg && p.version >= eth65:
866+
case msg.Code == GetPooledTransactionsMsg && supportsEth65(p.version):
867867
// Decode the retrieval message
868868
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
869869
if _, err := msgStream.List(); err != nil {
@@ -899,7 +899,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
899899
}
900900
return p.SendPooledTransactionsRLP(hashes, txs)
901901

902-
case msg.Code == TransactionMsg || (msg.Code == PooledTransactionsMsg && p.version >= eth65):
902+
case msg.Code == TransactionMsg || (msg.Code == PooledTransactionsMsg && supportsEth65(p.version)):
903903
// Transactions arrived, make sure we have a valid and fresh chain to handle them
904904
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
905905
break

eth/peer.go

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -783,23 +783,16 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
783783
)
784784
go func() {
785785
switch {
786-
case p.version == xdpos2:
787-
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
788-
ProtocolVersion: uint32(p.version),
789-
NetworkId: network,
790-
TD: td,
791-
CurrentBlock: head,
792-
GenesisBlock: genesis,
793-
})
794-
case p.version == eth63:
795-
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
786+
case supportsEth65(p.version):
787+
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
796788
ProtocolVersion: uint32(p.version),
797-
NetworkId: network,
789+
NetworkID: network,
798790
TD: td,
799-
CurrentBlock: head,
800-
GenesisBlock: genesis,
791+
Head: head,
792+
Genesis: genesis,
793+
ForkID: forkID,
801794
})
802-
case p.version >= eth64 || p.version >= xdpos22:
795+
case supportsEth64(p.version):
803796
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
804797
ProtocolVersion: uint32(p.version),
805798
NetworkID: network,
@@ -808,18 +801,24 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
808801
Genesis: genesis,
809802
ForkID: forkID,
810803
})
804+
case supportsEth63(p.version):
805+
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
806+
ProtocolVersion: uint32(p.version),
807+
NetworkId: network,
808+
TD: td,
809+
CurrentBlock: head,
810+
GenesisBlock: genesis,
811+
})
811812
default:
812813
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
813814
}
814815
}()
815816
go func() {
816817
switch {
817-
case p.version == xdpos2:
818-
errc <- p.readStatusLegacy(network, &status63, genesis)
819-
case p.version == eth63:
820-
errc <- p.readStatusLegacy(network, &status63, genesis)
821-
case p.version >= eth64 || p.version >= xdpos22: //include xdpos22 condition for completeness
818+
case supportsEth64(p.version):
822819
errc <- p.readStatus(network, &status, genesis, forkFilter)
820+
case supportsEth63(p.version):
821+
errc <- p.readStatusLegacy(network, &status63, genesis)
823822
default:
824823
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
825824
}
@@ -837,12 +836,10 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
837836
}
838837
}
839838
switch {
840-
case p.version == xdpos2:
841-
p.td, p.head = status63.TD, status63.CurrentBlock
842-
case p.version == eth63:
843-
p.td, p.head = status63.TD, status63.CurrentBlock
844-
case p.version >= eth64 || p.version >= xdpos22: //include xdpos22 for completeness
839+
case supportsEth64(p.version):
845840
p.td, p.head = status.TD, status.Head
841+
case supportsEth63(p.version):
842+
p.td, p.head = status63.TD, status63.CurrentBlock
846843
default:
847844
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
848845
}

eth/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func supportsEth63(version int) bool {
4242
switch {
4343
case version < 63:
4444
return false
45-
case version > 63:
45+
case version >= 63:
4646
return true
4747
default:
4848
return false

eth/sync.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ func (pm *ProtocolManager) syncer() {
155155
// Start and ensure cleanup of sync mechanisms
156156
pm.blockFetcher.Start()
157157
pm.txFetcher.Start()
158+
pm.bft.Start()
158159
defer pm.blockFetcher.Stop()
159160
defer pm.txFetcher.Stop()
161+
defer pm.bft.Stop()
160162
defer pm.downloader.Terminate()
161163

162164
// Wait for different events to fire synchronisation operations

0 commit comments

Comments
 (0)