mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
enable bft and better protocol version check
This commit is contained in:
parent
ebb9a63107
commit
b5c7bd5cba
5 changed files with 38 additions and 39 deletions
|
|
@ -477,7 +477,7 @@ func (ps *peerSet) HeaderIdlePeers() ([]*peerConnection, int) {
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
return p.headerThroughput
|
return p.headerThroughput
|
||||||
}
|
}
|
||||||
return ps.idlePeers(62, 101, idle, throughput)
|
return ps.idlePeers(62, 200, idle, throughput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BodyIdlePeers retrieves a flat list of all the currently body-idle peers within
|
// BodyIdlePeers retrieves a flat list of all the currently body-idle peers within
|
||||||
|
|
@ -491,7 +491,7 @@ func (ps *peerSet) BodyIdlePeers() ([]*peerConnection, int) {
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
return p.blockThroughput
|
return p.blockThroughput
|
||||||
}
|
}
|
||||||
return ps.idlePeers(62, 101, idle, throughput)
|
return ps.idlePeers(62, 200, idle, throughput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReceiptIdlePeers retrieves a flat list of all the currently receipt-idle peers
|
// ReceiptIdlePeers retrieves a flat list of all the currently receipt-idle peers
|
||||||
|
|
@ -505,7 +505,7 @@ func (ps *peerSet) ReceiptIdlePeers() ([]*peerConnection, int) {
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
return p.receiptThroughput
|
return p.receiptThroughput
|
||||||
}
|
}
|
||||||
return ps.idlePeers(63, 101, idle, throughput)
|
return ps.idlePeers(63, 200, idle, throughput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeDataIdlePeers retrieves a flat list of all the currently node-data-idle
|
// NodeDataIdlePeers retrieves a flat list of all the currently node-data-idle
|
||||||
|
|
@ -519,7 +519,7 @@ func (ps *peerSet) NodeDataIdlePeers() ([]*peerConnection, int) {
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
return p.stateThroughput
|
return p.stateThroughput
|
||||||
}
|
}
|
||||||
return ps.idlePeers(63, 101, idle, throughput)
|
return ps.idlePeers(63, 200, idle, throughput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// idlePeers retrieves a flat list of all currently idle peers satisfying the
|
// idlePeers retrieves a flat list of all currently idle peers satisfying the
|
||||||
|
|
|
||||||
|
|
@ -699,7 +699,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case p.version >= eth63 && msg.Code == GetNodeDataMsg:
|
case supportsEth63(p.version) && msg.Code == GetNodeDataMsg:
|
||||||
// Decode the retrieval message
|
// Decode the retrieval message
|
||||||
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
|
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
|
||||||
if _, err := msgStream.List(); err != nil {
|
if _, err := msgStream.List(); err != nil {
|
||||||
|
|
@ -726,7 +726,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
}
|
}
|
||||||
return p.SendNodeData(data)
|
return p.SendNodeData(data)
|
||||||
|
|
||||||
case p.version >= eth63 && msg.Code == NodeDataMsg:
|
case supportsEth63(p.version) && msg.Code == NodeDataMsg:
|
||||||
// A batch of node state data arrived to one of our previous requests
|
// A batch of node state data arrived to one of our previous requests
|
||||||
var data [][]byte
|
var data [][]byte
|
||||||
if err := msg.Decode(&data); err != nil {
|
if err := msg.Decode(&data); err != nil {
|
||||||
|
|
@ -737,7 +737,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
log.Debug("Failed to deliver node state data", "err", err)
|
log.Debug("Failed to deliver node state data", "err", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case p.version >= eth63 && msg.Code == GetReceiptsMsg:
|
case supportsEth63(p.version) && msg.Code == GetReceiptsMsg:
|
||||||
// Decode the retrieval message
|
// Decode the retrieval message
|
||||||
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
|
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
|
||||||
if _, err := msgStream.List(); err != nil {
|
if _, err := msgStream.List(); err != nil {
|
||||||
|
|
@ -773,7 +773,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
}
|
}
|
||||||
return p.SendReceiptsRLP(receipts)
|
return p.SendReceiptsRLP(receipts)
|
||||||
|
|
||||||
case p.version >= eth63 && msg.Code == ReceiptsMsg:
|
case supportsEth63(p.version) && msg.Code == ReceiptsMsg:
|
||||||
// A batch of receipts arrived to one of our previous requests
|
// A batch of receipts arrived to one of our previous requests
|
||||||
var receipts [][]*types.Receipt
|
var receipts [][]*types.Receipt
|
||||||
if err := msg.Decode(&receipts); err != nil {
|
if err := msg.Decode(&receipts); err != nil {
|
||||||
|
|
@ -847,7 +847,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case msg.Code == NewPooledTransactionHashesMsg && p.version >= eth65:
|
case msg.Code == NewPooledTransactionHashesMsg && supportsEth65(p.version):
|
||||||
// New transaction announcement arrived, make sure we have
|
// New transaction announcement arrived, make sure we have
|
||||||
// a valid and fresh chain to handle them
|
// a valid and fresh chain to handle them
|
||||||
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
|
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
|
||||||
|
|
@ -863,7 +863,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
}
|
}
|
||||||
pm.txFetcher.Notify(p.id, hashes)
|
pm.txFetcher.Notify(p.id, hashes)
|
||||||
|
|
||||||
case msg.Code == GetPooledTransactionsMsg && p.version >= eth65:
|
case msg.Code == GetPooledTransactionsMsg && supportsEth65(p.version):
|
||||||
// Decode the retrieval message
|
// Decode the retrieval message
|
||||||
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
|
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
|
||||||
if _, err := msgStream.List(); err != nil {
|
if _, err := msgStream.List(); err != nil {
|
||||||
|
|
@ -899,7 +899,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
}
|
}
|
||||||
return p.SendPooledTransactionsRLP(hashes, txs)
|
return p.SendPooledTransactionsRLP(hashes, txs)
|
||||||
|
|
||||||
case msg.Code == TransactionMsg || (msg.Code == PooledTransactionsMsg && p.version >= eth65):
|
case msg.Code == TransactionMsg || (msg.Code == PooledTransactionsMsg && supportsEth65(p.version)):
|
||||||
// Transactions arrived, make sure we have a valid and fresh chain to handle them
|
// Transactions arrived, make sure we have a valid and fresh chain to handle them
|
||||||
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
|
if atomic.LoadUint32(&pm.acceptTxs) == 0 {
|
||||||
break
|
break
|
||||||
|
|
|
||||||
51
eth/peer.go
51
eth/peer.go
|
|
@ -783,23 +783,7 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
|
||||||
)
|
)
|
||||||
go func() {
|
go func() {
|
||||||
switch {
|
switch {
|
||||||
case p.version == xdpos2:
|
case supportsEth65(p.version):
|
||||||
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
|
|
||||||
ProtocolVersion: uint32(p.version),
|
|
||||||
NetworkId: network,
|
|
||||||
TD: td,
|
|
||||||
CurrentBlock: head,
|
|
||||||
GenesisBlock: genesis,
|
|
||||||
})
|
|
||||||
case p.version == eth63:
|
|
||||||
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
|
|
||||||
ProtocolVersion: uint32(p.version),
|
|
||||||
NetworkId: network,
|
|
||||||
TD: td,
|
|
||||||
CurrentBlock: head,
|
|
||||||
GenesisBlock: genesis,
|
|
||||||
})
|
|
||||||
case p.version >= eth64 || p.version >= xdpos22:
|
|
||||||
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
|
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
|
||||||
ProtocolVersion: uint32(p.version),
|
ProtocolVersion: uint32(p.version),
|
||||||
NetworkID: network,
|
NetworkID: network,
|
||||||
|
|
@ -808,18 +792,33 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
|
||||||
Genesis: genesis,
|
Genesis: genesis,
|
||||||
ForkID: forkID,
|
ForkID: forkID,
|
||||||
})
|
})
|
||||||
|
case supportsEth64(p.version):
|
||||||
|
errc <- p2p.Send(p.rw, StatusMsg, &statusData{
|
||||||
|
ProtocolVersion: uint32(p.version),
|
||||||
|
NetworkID: network,
|
||||||
|
TD: td,
|
||||||
|
Head: head,
|
||||||
|
Genesis: genesis,
|
||||||
|
ForkID: forkID,
|
||||||
|
})
|
||||||
|
case supportsEth63(p.version):
|
||||||
|
errc <- p2p.Send(p.rw, StatusMsg, &statusData63{
|
||||||
|
ProtocolVersion: uint32(p.version),
|
||||||
|
NetworkId: network,
|
||||||
|
TD: td,
|
||||||
|
CurrentBlock: head,
|
||||||
|
GenesisBlock: genesis,
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
|
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
switch {
|
switch {
|
||||||
case p.version == xdpos2:
|
case supportsEth64(p.version):
|
||||||
errc <- p.readStatusLegacy(network, &status63, genesis)
|
|
||||||
case p.version == eth63:
|
|
||||||
errc <- p.readStatusLegacy(network, &status63, genesis)
|
|
||||||
case p.version >= eth64 || p.version >= xdpos22: //include xdpos22 condition for completeness
|
|
||||||
errc <- p.readStatus(network, &status, genesis, forkFilter)
|
errc <- p.readStatus(network, &status, genesis, forkFilter)
|
||||||
|
case supportsEth63(p.version):
|
||||||
|
errc <- p.readStatusLegacy(network, &status63, genesis)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
|
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
|
||||||
}
|
}
|
||||||
|
|
@ -837,12 +836,10 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case p.version == xdpos2:
|
case supportsEth64(p.version):
|
||||||
p.td, p.head = status63.TD, status63.CurrentBlock
|
|
||||||
case p.version == eth63:
|
|
||||||
p.td, p.head = status63.TD, status63.CurrentBlock
|
|
||||||
case p.version >= eth64 || p.version >= xdpos22: //include xdpos22 for completeness
|
|
||||||
p.td, p.head = status.TD, status.Head
|
p.td, p.head = status.TD, status.Head
|
||||||
|
case supportsEth63(p.version):
|
||||||
|
p.td, p.head = status63.TD, status63.CurrentBlock
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
|
panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func supportsEth63(version int) bool {
|
||||||
switch {
|
switch {
|
||||||
case version < 63:
|
case version < 63:
|
||||||
return false
|
return false
|
||||||
case version > 63:
|
case version >= 63:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,10 @@ func (pm *ProtocolManager) syncer() {
|
||||||
// Start and ensure cleanup of sync mechanisms
|
// Start and ensure cleanup of sync mechanisms
|
||||||
pm.blockFetcher.Start()
|
pm.blockFetcher.Start()
|
||||||
pm.txFetcher.Start()
|
pm.txFetcher.Start()
|
||||||
|
pm.bft.Start()
|
||||||
defer pm.blockFetcher.Stop()
|
defer pm.blockFetcher.Stop()
|
||||||
defer pm.txFetcher.Stop()
|
defer pm.txFetcher.Stop()
|
||||||
|
defer pm.bft.Stop()
|
||||||
defer pm.downloader.Terminate()
|
defer pm.downloader.Terminate()
|
||||||
|
|
||||||
// Wait for different events to fire synchronisation operations
|
// Wait for different events to fire synchronisation operations
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue