Merge branch 'develop' of https://github.com/maticnetwork/bor into upstream_merge

This commit is contained in:
Pratik Patil 2024-05-28 22:24:54 +05:30
commit f25b6efad2
No known key found for this signature in database
GPG key ID: AFDCA496554874B3
8 changed files with 64 additions and 1 deletions

View file

@ -474,3 +474,7 @@ func (b *EthAPIBackend) GetWhitelistedMilestone() (bool, uint64, common.Hash) {
func (b *EthAPIBackend) PurgeWhitelistedMilestone() {
b.eth.Downloader().ChainValidator.PurgeWhitelistedMilestone()
}
func (b *EthAPIBackend) PeerStats() interface{} {
return b.eth.handler.GetPeerStats()
}

View file

@ -512,7 +512,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
}
defer func(start time.Time) {
log.Debug("Synchronisation terminated", "elapsed", common.PrettyDuration(time.Since(start)))
log.Debug("Synchronisation terminated", "elapsed", common.PrettyDuration(time.Since(start)), "err", err)
}(time.Now())
// Look up the sync boundaries: the common ancestor and the target block

View file

@ -732,3 +732,40 @@ func (h *handler) enableSyncedFeatures() {
h.chain.TrieDB().SetBufferSize(pathdb.DefaultBufferSize)
}
}
// PeerStats represents a short summary of the information known about a connected
// peer. Specifically, it contains details about the head hash and total difficulty
// of a peer which makes it a bit different from the PeerInfo.
type PeerStats struct {
Enode string `json:"enode"` // Node URL
ID string `json:"id"` // Unique node identifier
Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
Hash string `json:"hash"` // Head hash of the peer
Number uint64 `json:"number"` // Head number of the peer
Td uint64 `json:"td"` // Total difficulty of the peer
}
// PeerStats returns the current head height and td of all the connected peers
// along with few additional identifiers.
func (h *handler) GetPeerStats() []*PeerStats {
info := make([]*PeerStats, 0, len(h.peers.peers))
for _, peer := range h.peers.peers {
hash, td := peer.Head()
block := h.chain.GetBlockByHash(hash)
number := uint64(0)
if block != nil {
number = block.NumberU64()
}
info = append(info, &PeerStats{
Enode: peer.Node().URLv4(),
ID: peer.ID(),
Name: peer.Name(),
Hash: hash.String(),
Number: number,
Td: td.Uint64(),
})
}
return info
}

View file

@ -2623,6 +2623,12 @@ func (api *DebugAPI) GetTraceStack() string {
}
}
// PeerStats returns the current head height and td of all the connected peers
// along with few additional identifiers.
func (api *DebugAPI) PeerStats() interface{} {
return api.b.PeerStats()
}
// NetAPI offers network related RPC methods
type NetAPI struct {
net *p2p.Server

View file

@ -643,6 +643,10 @@ func (b testBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) even
panic("implement me")
}
func (b testBackend) PeerStats() interface{} {
panic("implement me")
}
func (b testBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) {
receipt, err := b.GetBorBlockReceipt(ctx, hash)
if err != nil || receipt == nil {

View file

@ -112,6 +112,9 @@ type Backend interface {
PurgeWhitelistedCheckpoint()
GetWhitelistedMilestone() (bool, uint64, common.Hash)
PurgeWhitelistedMilestone()
// Networking related APIs
PeerStats() interface{}
}
func GetAPIs(apiBackend Backend) []rpc.API {

View file

@ -412,3 +412,7 @@ func (b *backendMock) GetWhitelistedMilestone() (bool, uint64, common.Hash) {
func (b *backendMock) PurgeWhitelistedCheckpoint() {}
func (b *backendMock) PurgeWhitelistedMilestone() {}
func (b backendMock) PeerStats() interface{} {
return nil
}

View file

@ -565,6 +565,11 @@ web3._extend({
call: 'debug_getTrieFlushInterval',
params: 0
}),
new web3._extend.Method({
name: 'peerStats',
call: 'debug_peerStats',
params: 0
}),
],
properties: []
});