mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +00:00
add standbynodes in GetMasternodesByNumber similar way to subnet
This commit is contained in:
parent
2c1aba814e
commit
a959bea092
4 changed files with 46 additions and 16 deletions
|
|
@ -68,6 +68,8 @@ type MasternodesStatus struct {
|
||||||
Masternodes []common.Address
|
Masternodes []common.Address
|
||||||
PenaltyLen int
|
PenaltyLen int
|
||||||
Penalty []common.Address
|
Penalty []common.Address
|
||||||
|
StandbynodesLen int
|
||||||
|
Standbynodes []common.Address
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,6 +146,7 @@ func (api *API) GetMasternodesByNumber(number *rpc.BlockNumber) MasternodesStatu
|
||||||
|
|
||||||
masterNodes := api.XDPoS.EngineV2.GetMasternodes(api.chain, header)
|
masterNodes := api.XDPoS.EngineV2.GetMasternodes(api.chain, header)
|
||||||
penalties := api.XDPoS.EngineV2.GetPenalties(api.chain, header)
|
penalties := api.XDPoS.EngineV2.GetPenalties(api.chain, header)
|
||||||
|
standbynodes := api.XDPoS.EngineV2.GetStandbynodes(api.chain, header)
|
||||||
|
|
||||||
info := MasternodesStatus{
|
info := MasternodesStatus{
|
||||||
Number: header.Number.Uint64(),
|
Number: header.Number.Uint64(),
|
||||||
|
|
@ -152,6 +155,8 @@ func (api *API) GetMasternodesByNumber(number *rpc.BlockNumber) MasternodesStatu
|
||||||
Masternodes: masterNodes,
|
Masternodes: masterNodes,
|
||||||
PenaltyLen: len(penalties),
|
PenaltyLen: len(penalties),
|
||||||
Penalty: penalties,
|
Penalty: penalties,
|
||||||
|
StandbynodesLen: len(standbynodes),
|
||||||
|
Standbynodes: standbynodes,
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -987,12 +987,21 @@ func (x *XDPoS_v2) GetMasternodes(chain consensus.ChainReader, header *types.Hea
|
||||||
func (x *XDPoS_v2) GetPenalties(chain consensus.ChainReader, header *types.Header) []common.Address {
|
func (x *XDPoS_v2) GetPenalties(chain consensus.ChainReader, header *types.Header) []common.Address {
|
||||||
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
|
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[GetMasternodes] Adaptor v2 getEpochSwitchInfo has error", "err", err)
|
log.Error("[GetPenalties] Adaptor v2 getEpochSwitchInfo has error", "err", err)
|
||||||
return []common.Address{}
|
return []common.Address{}
|
||||||
}
|
}
|
||||||
return epochSwitchInfo.Penalties
|
return epochSwitchInfo.Penalties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *XDPoS_v2) GetStandbynodes(chain consensus.ChainReader, header *types.Header) []common.Address {
|
||||||
|
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[GetStandbynodes] Adaptor v2 getEpochSwitchInfo has error", "err", err)
|
||||||
|
return []common.Address{}
|
||||||
|
}
|
||||||
|
return epochSwitchInfo.Standbynodes
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate masternodes for a block number and parent hash. In V2, truncating candidates[:MaxMasternodes] is done in this function.
|
// Calculate masternodes for a block number and parent hash. In V2, truncating candidates[:MaxMasternodes] is done in this function.
|
||||||
func (x *XDPoS_v2) calcMasternodes(chain consensus.ChainReader, blockNum *big.Int, parentHash common.Hash) ([]common.Address, []common.Address, error) {
|
func (x *XDPoS_v2) calcMasternodes(chain consensus.ChainReader, blockNum *big.Int, parentHash common.Hash) ([]common.Address, []common.Address, error) {
|
||||||
// using new max masterndoes
|
// using new max masterndoes
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,24 @@ func (x *XDPoS_v2) getEpochSwitchInfo(chain consensus.ChainReader, header *types
|
||||||
log.Error("[getEpochSwitchInfo] get extra field", "err", err, "number", h.Number.Uint64())
|
log.Error("[getEpochSwitchInfo] get extra field", "err", err, "number", h.Number.Uint64())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snap, err := x.getSnapshot(chain, header.Number.Uint64(), false)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[getEpochSwitchInfo] Adaptor v2 getSnapshot has error", "err", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
penalties := common.ExtractAddressFromBytes(h.Penalties)
|
penalties := common.ExtractAddressFromBytes(h.Penalties)
|
||||||
|
candidates := snap.NextEpochMasterNodes
|
||||||
|
standbynodes := []common.Address{}
|
||||||
|
if len(masternodes) != len(candidates) {
|
||||||
|
standbynodes = candidates
|
||||||
|
standbynodes = common.RemoveItemFromArray(standbynodes, masternodes)
|
||||||
|
standbynodes = common.RemoveItemFromArray(standbynodes, penalties)
|
||||||
|
}
|
||||||
|
|
||||||
epochSwitchInfo := &types.EpochSwitchInfo{
|
epochSwitchInfo := &types.EpochSwitchInfo{
|
||||||
Penalties: penalties,
|
Penalties: penalties,
|
||||||
|
Standbynodes: standbynodes,
|
||||||
Masternodes: masternodes,
|
Masternodes: masternodes,
|
||||||
EpochSwitchBlockInfo: &types.BlockInfo{
|
EpochSwitchBlockInfo: &types.BlockInfo{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ func (e *ExtraFields_v2) EncodeToBytes() ([]byte, error) {
|
||||||
|
|
||||||
type EpochSwitchInfo struct {
|
type EpochSwitchInfo struct {
|
||||||
Penalties []common.Address
|
Penalties []common.Address
|
||||||
|
Standbynodes []common.Address
|
||||||
Masternodes []common.Address
|
Masternodes []common.Address
|
||||||
EpochSwitchBlockInfo *BlockInfo
|
EpochSwitchBlockInfo *BlockInfo
|
||||||
EpochSwitchParentBlockInfo *BlockInfo
|
EpochSwitchParentBlockInfo *BlockInfo
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue