mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
Add API to get latest committed blockInfo, also send it via 'block' message type to stats server (#113)
This commit is contained in:
parent
765d962d8b
commit
4eea723717
4 changed files with 31 additions and 0 deletions
|
|
@ -91,6 +91,11 @@ func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) {
|
|||
return api.XDPoS.GetAuthorisedSignersFromSnapshot(api.chain, header)
|
||||
}
|
||||
|
||||
// Get the latest v2 committed block information. Note: This only applies to v2 engine. it doesn't make sense for v1
|
||||
func (api *API) GetLatestCommittedBlockHeader() *types.BlockInfo {
|
||||
return api.XDPoS.EngineV2.GetLatestCommittedBlockInfo()
|
||||
}
|
||||
|
||||
func (api *API) NetworkInformation() NetworkInformation {
|
||||
info := NetworkInformation{}
|
||||
info.NetworkId = api.chain.Config().ChainId
|
||||
|
|
|
|||
|
|
@ -1019,3 +1019,7 @@ func (x *XDPoS_v2) periodicJob() {
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (x *XDPoS_v2) GetLatestCommittedBlockInfo() *types.BlockInfo {
|
||||
return x.highestCommitBlock
|
||||
}
|
||||
|
|
|
|||
|
|
@ -511,6 +511,13 @@ type blockStats struct {
|
|||
Uncles uncleStats `json:"uncles"`
|
||||
}
|
||||
|
||||
// blockStats is the information to report about individual blocks.
|
||||
type latestCommittedBlockStats struct {
|
||||
Number *big.Int `json:"number"`
|
||||
Hash common.Hash `json:"hash"`
|
||||
Round uint64 `json:"round"`
|
||||
}
|
||||
|
||||
// txStats is the information to report about individual transactions.
|
||||
type txStats struct {
|
||||
Hash common.Hash `json:"hash"`
|
||||
|
|
@ -539,6 +546,17 @@ func (s *Service) reportBlock(conn *websocket.Conn, block *types.Block) error {
|
|||
"id": s.node,
|
||||
"block": details,
|
||||
}
|
||||
|
||||
// Get the latest committed block information
|
||||
if (s.engine.(*XDPoS.XDPoS).EngineV2 != nil) && (s.engine.(*XDPoS.XDPoS).EngineV2.GetLatestCommittedBlockInfo() != nil) {
|
||||
latestCommittedBlockInfo := s.engine.(*XDPoS.XDPoS).EngineV2.GetLatestCommittedBlockInfo()
|
||||
stats["latestCommittedBlockInfo"] = &latestCommittedBlockStats{
|
||||
Number: latestCommittedBlockInfo.Number,
|
||||
Round: uint64(latestCommittedBlockInfo.Round),
|
||||
Hash: latestCommittedBlockInfo.Hash,
|
||||
}
|
||||
}
|
||||
|
||||
report := map[string][]interface{}{
|
||||
"emit": {"block", stats},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,6 +138,10 @@ web3._extend({
|
|||
call: 'XDPoS_getSignersAtHash',
|
||||
params: 1
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'getLatestCommittedBlockInfo',
|
||||
call: 'XDPoS_getLatestCommittedBlockHeader'
|
||||
}),
|
||||
],
|
||||
properties: [
|
||||
new web3._extend.Property({
|
||||
|
|
|
|||
Loading…
Reference in a new issue