Skip to content

Commit f7ca03a

Browse files
karalabefjl
authored andcommitted
eth, les, light: expose chain config in les node info too (#15732)
1 parent c15d76a commit f7ca03a

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

‎eth/handler.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,20 +744,20 @@ func (self *ProtocolManager) txBroadcastLoop() {
744744
}
745745
}
746746

747-
// EthNodeInfo represents a short summary of the Ethereum sub-protocol metadata known
748-
// about the host peer.
749-
type EthNodeInfo struct {
750-
Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3)
747+
// NodeInfo represents a short summary of the Ethereum sub-protocol metadata
748+
// known about the host peer.
749+
type NodeInfo struct {
750+
Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
751751
Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain
752752
Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block
753753
Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules
754754
Head common.Hash `json:"head"` // SHA3 hash of the host's best owned block
755755
}
756756

757757
// NodeInfo retrieves some protocol metadata about the running host node.
758-
func (self *ProtocolManager) NodeInfo() *EthNodeInfo {
758+
func (self *ProtocolManager) NodeInfo() *NodeInfo {
759759
currentBlock := self.blockchain.CurrentBlock()
760-
return &EthNodeInfo{
760+
return &NodeInfo{
761761
Network: self.networkId,
762762
Difficulty: self.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64()),
763763
Genesis: self.blockchain.Genesis().Hash(),

‎ethstats/ethstats.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ func (s *Service) login(conn *websocket.Conn) error {
374374

375375
var network, protocol string
376376
if info := infos.Protocols["eth"]; info != nil {
377-
network = fmt.Sprintf("%d", info.(*eth.EthNodeInfo).Network)
377+
network = fmt.Sprintf("%d", info.(*eth.NodeInfo).Network)
378378
protocol = fmt.Sprintf("eth/%d", eth.ProtocolVersions[0])
379379
} else {
380-
network = fmt.Sprintf("%d", infos.Protocols["les"].(*eth.EthNodeInfo).Network)
380+
network = fmt.Sprintf("%d", infos.Protocols["les"].(*les.NodeInfo).Network)
381381
protocol = fmt.Sprintf("les/%d", les.ClientProtocolVersions[0])
382382
}
383383
auth := &authMsg{

‎les/handler.go‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/ethereum/go-ethereum/core"
3333
"github.com/ethereum/go-ethereum/core/state"
3434
"github.com/ethereum/go-ethereum/core/types"
35-
"github.com/ethereum/go-ethereum/eth"
3635
"github.com/ethereum/go-ethereum/eth/downloader"
3736
"github.com/ethereum/go-ethereum/ethdb"
3837
"github.com/ethereum/go-ethereum/event"
@@ -73,6 +72,7 @@ func errResp(code errCode, format string, v ...interface{}) error {
7372
}
7473

7574
type BlockChain interface {
75+
Config() *params.ChainConfig
7676
HasHeader(hash common.Hash, number uint64) bool
7777
GetHeader(hash common.Hash, number uint64) *types.Header
7878
GetHeaderByHash(hash common.Hash) *types.Header
@@ -1123,12 +1123,23 @@ func (pm *ProtocolManager) txStatus(hashes []common.Hash) []txStatus {
11231123
return stats
11241124
}
11251125

1126+
// NodeInfo represents a short summary of the Ethereum sub-protocol metadata
1127+
// known about the host peer.
1128+
type NodeInfo struct {
1129+
Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
1130+
Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain
1131+
Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block
1132+
Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules
1133+
Head common.Hash `json:"head"` // SHA3 hash of the host's best owned block
1134+
}
1135+
11261136
// NodeInfo retrieves some protocol metadata about the running host node.
1127-
func (self *ProtocolManager) NodeInfo() *eth.EthNodeInfo {
1128-
return &eth.EthNodeInfo{
1137+
func (self *ProtocolManager) NodeInfo() *NodeInfo {
1138+
return &NodeInfo{
11291139
Network: self.networkId,
11301140
Difficulty: self.blockchain.GetTdByHash(self.blockchain.LastBlockHash()),
11311141
Genesis: self.blockchain.Genesis().Hash(),
1142+
Config: self.blockchain.Config(),
11321143
Head: self.blockchain.LastBlockHash(),
11331144
}
11341145
}

‎light/lightchain.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ func (self *LightChain) GetHeaderByNumberOdr(ctx context.Context, number uint64)
457457
return GetHeaderByNumber(ctx, self.odr, number)
458458
}
459459

460+
// Config retrieves the header chain's chain configuration.
461+
func (self *LightChain) Config() *params.ChainConfig { return self.hc.Config() }
462+
460463
func (self *LightChain) SyncCht(ctx context.Context) bool {
461464
if self.odr.ChtIndexer() == nil {
462465
return false

0 commit comments

Comments
 (0)