mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 18:00:46 +00:00
Merge pull request #292 from XinFinOrg/add-standbynodes-api
add standbynodes in GetMasternodesByNumber similar way to subnet
This commit is contained in:
commit
176a3d0756
4 changed files with 46 additions and 16 deletions
|
|
@ -62,13 +62,15 @@ type SignerTypes struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MasternodesStatus struct {
|
type MasternodesStatus struct {
|
||||||
Number uint64
|
Number uint64
|
||||||
Round types.Round
|
Round types.Round
|
||||||
MasternodesLen int
|
MasternodesLen int
|
||||||
Masternodes []common.Address
|
Masternodes []common.Address
|
||||||
PenaltyLen int
|
PenaltyLen int
|
||||||
Penalty []common.Address
|
Penalty []common.Address
|
||||||
Error error
|
StandbynodesLen int
|
||||||
|
Standbynodes []common.Address
|
||||||
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageStatus map[string]map[string]SignerTypes
|
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)
|
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(),
|
||||||
Round: round,
|
Round: round,
|
||||||
MasternodesLen: len(masterNodes),
|
MasternodesLen: len(masterNodes),
|
||||||
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,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())
|
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,
|
||||||
Masternodes: masternodes,
|
Standbynodes: standbynodes,
|
||||||
|
Masternodes: masternodes,
|
||||||
EpochSwitchBlockInfo: &types.BlockInfo{
|
EpochSwitchBlockInfo: &types.BlockInfo{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Number: h.Number,
|
Number: h.Number,
|
||||||
|
|
|
||||||
|
|
@ -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