diff --git a/consensus/XDPoS/api.go b/consensus/XDPoS/api.go index 3db252bb15..6edb6ae448 100644 --- a/consensus/XDPoS/api.go +++ b/consensus/XDPoS/api.go @@ -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 diff --git a/consensus/XDPoS/engines/engine_v2/engine.go b/consensus/XDPoS/engines/engine_v2/engine.go index dd2094ac3b..3699cea8ec 100644 --- a/consensus/XDPoS/engines/engine_v2/engine.go +++ b/consensus/XDPoS/engines/engine_v2/engine.go @@ -1019,3 +1019,7 @@ func (x *XDPoS_v2) periodicJob() { } }() } + +func (x *XDPoS_v2) GetLatestCommittedBlockInfo() *types.BlockInfo { + return x.highestCommitBlock +} diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 12a5e8173a..95ba4567c1 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -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}, } diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 69338e59a5..cccac82fed 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -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({