mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +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
|
|
@ -62,13 +62,15 @@ type SignerTypes struct {
|
|||
}
|
||||
|
||||
type MasternodesStatus struct {
|
||||
Number uint64
|
||||
Round types.Round
|
||||
MasternodesLen int
|
||||
Masternodes []common.Address
|
||||
PenaltyLen int
|
||||
Penalty []common.Address
|
||||
Error error
|
||||
Number uint64
|
||||
Round types.Round
|
||||
MasternodesLen int
|
||||
Masternodes []common.Address
|
||||
PenaltyLen int
|
||||
Penalty []common.Address
|
||||
StandbynodesLen int
|
||||
Standbynodes []common.Address
|
||||
Error error
|
||||
}
|
||||
|
||||
type MessageStatus map[string]map[string]SignerTypes
|
||||
|
|
@ -144,14 +146,17 @@ func (api *API) GetMasternodesByNumber(number *rpc.BlockNumber) MasternodesStatu
|
|||
|
||||
masterNodes := api.XDPoS.EngineV2.GetMasternodes(api.chain, header)
|
||||
penalties := api.XDPoS.EngineV2.GetPenalties(api.chain, header)
|
||||
standbynodes := api.XDPoS.EngineV2.GetStandbynodes(api.chain, header)
|
||||
|
||||
info := MasternodesStatus{
|
||||
Number: header.Number.Uint64(),
|
||||
Round: round,
|
||||
MasternodesLen: len(masterNodes),
|
||||
Masternodes: masterNodes,
|
||||
PenaltyLen: len(penalties),
|
||||
Penalty: penalties,
|
||||
Number: header.Number.Uint64(),
|
||||
Round: round,
|
||||
MasternodesLen: len(masterNodes),
|
||||
Masternodes: masterNodes,
|
||||
PenaltyLen: len(penalties),
|
||||
Penalty: penalties,
|
||||
StandbynodesLen: len(standbynodes),
|
||||
Standbynodes: standbynodes,
|
||||
}
|
||||
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 {
|
||||
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, header, header.Hash())
|
||||
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 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.
|
||||
func (x *XDPoS_v2) calcMasternodes(chain consensus.ChainReader, blockNum *big.Int, parentHash common.Hash) ([]common.Address, []common.Address, error) {
|
||||
// using new max masterndoes
|
||||
|
|
|
|||
|
|
@ -56,10 +56,25 @@ func (x *XDPoS_v2) getEpochSwitchInfo(chain consensus.ChainReader, header *types
|
|||
log.Error("[getEpochSwitchInfo] get extra field", "err", err, "number", h.Number.Uint64())
|
||||
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)
|
||||
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{
|
||||
Penalties: penalties,
|
||||
Masternodes: masternodes,
|
||||
Penalties: penalties,
|
||||
Standbynodes: standbynodes,
|
||||
Masternodes: masternodes,
|
||||
EpochSwitchBlockInfo: &types.BlockInfo{
|
||||
Hash: hash,
|
||||
Number: h.Number,
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ func (e *ExtraFields_v2) EncodeToBytes() ([]byte, error) {
|
|||
|
||||
type EpochSwitchInfo struct {
|
||||
Penalties []common.Address
|
||||
Standbynodes []common.Address
|
||||
Masternodes []common.Address
|
||||
EpochSwitchBlockInfo *BlockInfo
|
||||
EpochSwitchParentBlockInfo *BlockInfo
|
||||
|
|
|
|||
Loading…
Reference in a new issue