[rpc] Add active status back to Validator information

[validator] Fix typo for ValidatorRPCEnhanced
[Makefile] Change make exe to build non-static by default
pull/3068/head
Janet Liang 5 years ago committed by Leo Chen
parent 819500aa70
commit 00676ced70
  1. 2
      Makefile
  2. 5
      hmy/api_backend.go
  3. 2
      internal/hmyapi/apiv1/backend.go
  4. 16
      internal/hmyapi/apiv1/blockchain.go
  5. 2
      internal/hmyapi/apiv2/backend.go
  6. 16
      internal/hmyapi/apiv2/blockchain.go
  7. 2
      internal/hmyapi/backend.go
  8. 13
      staking/effective/eligible.go
  9. 5
      staking/types/validator.go

@ -16,7 +16,7 @@ libs:
make -C $(TOP)/bls BLS_SWAP_G=1 -j8 make -C $(TOP)/bls BLS_SWAP_G=1 -j8
exe: exe:
./scripts/go_executable_build.sh ./scripts/go_executable_build.sh -S
race: race:
./scripts/go_executable_build.sh -r ./scripts/go_executable_build.sh -r

@ -387,7 +387,7 @@ var (
// GetValidatorInformation returns the information of validator // GetValidatorInformation returns the information of validator
func (b *APIBackend) GetValidatorInformation( func (b *APIBackend) GetValidatorInformation(
addr common.Address, block *types.Block, addr common.Address, block *types.Block,
) (*staking.ValidatorRPCEnchanced, error) { ) (*staking.ValidatorRPCEnhanced, error) {
bc := b.hmy.BlockChain() bc := b.hmy.BlockChain()
wrapper, err := bc.ReadValidatorInformationAt(addr, block.Root()) wrapper, err := bc.ReadValidatorInformationAt(addr, block.Root())
if err != nil { if err != nil {
@ -399,7 +399,7 @@ func (b *APIBackend) GetValidatorInformation(
// At the last block of epoch, block epoch is e while val.LastEpochInCommittee // At the last block of epoch, block epoch is e while val.LastEpochInCommittee
// is already updated to e+1. So need the >= check rather than == // is already updated to e+1. So need the >= check rather than ==
inCommittee := wrapper.LastEpochInCommittee.Cmp(now) >= 0 inCommittee := wrapper.LastEpochInCommittee.Cmp(now) >= 0
defaultReply := &staking.ValidatorRPCEnchanced{ defaultReply := &staking.ValidatorRPCEnhanced{
CurrentlyInCommittee: inCommittee, CurrentlyInCommittee: inCommittee,
Wrapper: *wrapper, Wrapper: *wrapper,
Performance: nil, Performance: nil,
@ -410,6 +410,7 @@ func (b *APIBackend) GetValidatorInformation(
).String(), ).String(),
EPoSWinningStake: nil, EPoSWinningStake: nil,
BootedStatus: nil, BootedStatus: nil,
ActiveStatus: wrapper.Validator.Status.String(),
Lifetime: &staking.AccumulatedOverLifetime{ Lifetime: &staking.AccumulatedOverLifetime{
wrapper.BlockReward, wrapper.BlockReward,
wrapper.Counters, wrapper.Counters,

@ -74,7 +74,7 @@ type Backend interface {
SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error
GetElectedValidatorAddresses() []common.Address GetElectedValidatorAddresses() []common.Address
GetAllValidatorAddresses() []common.Address GetAllValidatorAddresses() []common.Address
GetValidatorInformation(addr common.Address, block *types.Block) (*staking.ValidatorRPCEnchanced, error) GetValidatorInformation(addr common.Address, block *types.Block) (*staking.ValidatorRPCEnhanced, error)
GetDelegationsByValidator(validator common.Address) []*staking.Delegation GetDelegationsByValidator(validator common.Address) []*staking.Delegation
GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation) GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation)
GetDelegationsByDelegatorByBlock(delegator common.Address, block *types.Block) ([]common.Address, []*staking.Delegation) GetDelegationsByDelegatorByBlock(delegator common.Address, block *types.Block) ([]common.Address, []*staking.Delegation)

@ -627,7 +627,7 @@ func (s *PublicBlockChainAPI) GetElectedValidatorAddresses() ([]string, error) {
// GetValidatorInformation returns information about a validator. // GetValidatorInformation returns information about a validator.
func (s *PublicBlockChainAPI) GetValidatorInformation( func (s *PublicBlockChainAPI) GetValidatorInformation(
ctx context.Context, address string, ctx context.Context, address string,
) (*staking.ValidatorRPCEnchanced, error) { ) (*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }
@ -643,7 +643,7 @@ func (s *PublicBlockChainAPI) GetValidatorInformation(
// GetValidatorInformationByBlockNumber returns information about a validator. // GetValidatorInformationByBlockNumber returns information about a validator.
func (s *PublicBlockChainAPI) GetValidatorInformationByBlockNumber( func (s *PublicBlockChainAPI) GetValidatorInformationByBlockNumber(
ctx context.Context, address string, blockNr rpc.BlockNumber, ctx context.Context, address string, blockNr rpc.BlockNumber,
) (*staking.ValidatorRPCEnchanced, error) { ) (*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }
@ -661,13 +661,13 @@ func (s *PublicBlockChainAPI) GetValidatorInformationByBlockNumber(
func (s *PublicBlockChainAPI) getAllValidatorInformation( func (s *PublicBlockChainAPI) getAllValidatorInformation(
ctx context.Context, page int, blockNr rpc.BlockNumber, ctx context.Context, page int, blockNr rpc.BlockNumber,
) ([]*staking.ValidatorRPCEnchanced, error) { ) ([]*staking.ValidatorRPCEnhanced, error) {
if page < -1 { if page < -1 {
return nil, errors.Errorf("page given %d cannot be less than -1", page) return nil, errors.Errorf("page given %d cannot be less than -1", page)
} }
addresses := s.b.GetAllValidatorAddresses() addresses := s.b.GetAllValidatorAddresses()
if page != -1 && len(addresses) <= page*validatorsPageSize { if page != -1 && len(addresses) <= page*validatorsPageSize {
return make([]*staking.ValidatorRPCEnchanced, 0), nil return make([]*staking.ValidatorRPCEnhanced, 0), nil
} }
validatorsNum := len(addresses) validatorsNum := len(addresses)
start := 0 start := 0
@ -678,7 +678,7 @@ func (s *PublicBlockChainAPI) getAllValidatorInformation(
validatorsNum = len(addresses) - start validatorsNum = len(addresses) - start
} }
} }
validators := make([]*staking.ValidatorRPCEnchanced, validatorsNum) validators := make([]*staking.ValidatorRPCEnhanced, validatorsNum)
block, err := s.b.BlockByNumber(ctx, rpc.BlockNumber(blockNr)) block, err := s.b.BlockByNumber(ctx, rpc.BlockNumber(blockNr))
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "could not retrieve the block information for block number: %d", blockNr) return nil, errors.Wrapf(err, "could not retrieve the block information for block number: %d", blockNr)
@ -697,7 +697,7 @@ func (s *PublicBlockChainAPI) getAllValidatorInformation(
// If page is -1, return all instead of `validatorsPageSize` elements. // If page is -1, return all instead of `validatorsPageSize` elements.
func (s *PublicBlockChainAPI) GetAllValidatorInformation( func (s *PublicBlockChainAPI) GetAllValidatorInformation(
ctx context.Context, page int, ctx context.Context, page int,
) ([]*staking.ValidatorRPCEnchanced, error) { ) ([]*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }
@ -717,14 +717,14 @@ func (s *PublicBlockChainAPI) GetAllValidatorInformation(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return res.([]*staking.ValidatorRPCEnchanced), nil return res.([]*staking.ValidatorRPCEnhanced), nil
} }
// GetAllValidatorInformationByBlockNumber returns information about all validators. // GetAllValidatorInformationByBlockNumber returns information about all validators.
// If page is -1, return all instead of `validatorsPageSize` elements. // If page is -1, return all instead of `validatorsPageSize` elements.
func (s *PublicBlockChainAPI) GetAllValidatorInformationByBlockNumber( func (s *PublicBlockChainAPI) GetAllValidatorInformationByBlockNumber(
ctx context.Context, page int, blockNr rpc.BlockNumber, ctx context.Context, page int, blockNr rpc.BlockNumber,
) ([]*staking.ValidatorRPCEnchanced, error) { ) ([]*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }

@ -70,7 +70,7 @@ type Backend interface {
SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error
GetElectedValidatorAddresses() []common.Address GetElectedValidatorAddresses() []common.Address
GetAllValidatorAddresses() []common.Address GetAllValidatorAddresses() []common.Address
GetValidatorInformation(addr common.Address, block *types.Block) (*staking.ValidatorRPCEnchanced, error) GetValidatorInformation(addr common.Address, block *types.Block) (*staking.ValidatorRPCEnhanced, error)
GetDelegationsByValidator(validator common.Address) []*staking.Delegation GetDelegationsByValidator(validator common.Address) []*staking.Delegation
GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation) GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation)
GetDelegationsByDelegatorByBlock(delegator common.Address, block *types.Block) ([]common.Address, []*staking.Delegation) GetDelegationsByDelegatorByBlock(delegator common.Address, block *types.Block) ([]common.Address, []*staking.Delegation)

@ -578,7 +578,7 @@ func (s *PublicBlockChainAPI) GetElectedValidatorAddresses() ([]string, error) {
// GetValidatorInformation .. // GetValidatorInformation ..
func (s *PublicBlockChainAPI) GetValidatorInformation( func (s *PublicBlockChainAPI) GetValidatorInformation(
ctx context.Context, address string, ctx context.Context, address string,
) (*staking.ValidatorRPCEnchanced, error) { ) (*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }
@ -594,7 +594,7 @@ func (s *PublicBlockChainAPI) GetValidatorInformation(
// GetValidatorInformationByBlockNumber .. // GetValidatorInformationByBlockNumber ..
func (s *PublicBlockChainAPI) GetValidatorInformationByBlockNumber( func (s *PublicBlockChainAPI) GetValidatorInformationByBlockNumber(
ctx context.Context, address string, blockNr uint64, ctx context.Context, address string, blockNr uint64,
) (*staking.ValidatorRPCEnchanced, error) { ) (*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }
@ -612,13 +612,13 @@ func (s *PublicBlockChainAPI) GetValidatorInformationByBlockNumber(
func (s *PublicBlockChainAPI) getAllValidatorInformation( func (s *PublicBlockChainAPI) getAllValidatorInformation(
ctx context.Context, page int, blockNr rpc.BlockNumber, ctx context.Context, page int, blockNr rpc.BlockNumber,
) ([]*staking.ValidatorRPCEnchanced, error) { ) ([]*staking.ValidatorRPCEnhanced, error) {
if page < -1 { if page < -1 {
return nil, errors.Errorf("page given %d cannot be less than -1", page) return nil, errors.Errorf("page given %d cannot be less than -1", page)
} }
addresses := s.b.GetAllValidatorAddresses() addresses := s.b.GetAllValidatorAddresses()
if page != -1 && len(addresses) <= page*validatorsPageSize { if page != -1 && len(addresses) <= page*validatorsPageSize {
return make([]*staking.ValidatorRPCEnchanced, 0), nil return make([]*staking.ValidatorRPCEnhanced, 0), nil
} }
validatorsNum := len(addresses) validatorsNum := len(addresses)
start := 0 start := 0
@ -629,7 +629,7 @@ func (s *PublicBlockChainAPI) getAllValidatorInformation(
validatorsNum = len(addresses) - start validatorsNum = len(addresses) - start
} }
} }
validators := make([]*staking.ValidatorRPCEnchanced, validatorsNum) validators := make([]*staking.ValidatorRPCEnhanced, validatorsNum)
block, err := s.b.BlockByNumber(ctx, rpc.BlockNumber(blockNr)) block, err := s.b.BlockByNumber(ctx, rpc.BlockNumber(blockNr))
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "could not retrieve the block information for block number: %d", blockNr) return nil, errors.Wrapf(err, "could not retrieve the block information for block number: %d", blockNr)
@ -648,7 +648,7 @@ func (s *PublicBlockChainAPI) getAllValidatorInformation(
// If page is -1, return all else return the pagination. // If page is -1, return all else return the pagination.
func (s *PublicBlockChainAPI) GetAllValidatorInformation( func (s *PublicBlockChainAPI) GetAllValidatorInformation(
ctx context.Context, page int, ctx context.Context, page int,
) ([]*staking.ValidatorRPCEnchanced, error) { ) ([]*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }
@ -669,7 +669,7 @@ func (s *PublicBlockChainAPI) GetAllValidatorInformation(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return res.([]*staking.ValidatorRPCEnchanced), nil return res.([]*staking.ValidatorRPCEnhanced), nil
} }
@ -677,7 +677,7 @@ func (s *PublicBlockChainAPI) GetAllValidatorInformation(
// If page is -1, return all else return the pagination. // If page is -1, return all else return the pagination.
func (s *PublicBlockChainAPI) GetAllValidatorInformationByBlockNumber( func (s *PublicBlockChainAPI) GetAllValidatorInformationByBlockNumber(
ctx context.Context, page int, blockNr uint64, ctx context.Context, page int, blockNr uint64,
) ([]*staking.ValidatorRPCEnchanced, error) { ) ([]*staking.ValidatorRPCEnhanced, error) {
if err := s.isBeaconShard(); err != nil { if err := s.isBeaconShard(); err != nil {
return nil, err return nil, err
} }

@ -64,7 +64,7 @@ type Backend interface {
SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error
GetElectedValidatorAddresses() []common.Address GetElectedValidatorAddresses() []common.Address
GetAllValidatorAddresses() []common.Address GetAllValidatorAddresses() []common.Address
GetValidatorInformation(addr common.Address, block *types.Block) (*staking.ValidatorRPCEnchanced, error) GetValidatorInformation(addr common.Address, block *types.Block) (*staking.ValidatorRPCEnhanced, error)
GetDelegationsByValidator(validator common.Address) []*staking.Delegation GetDelegationsByValidator(validator common.Address) []*staking.Delegation
GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation) GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation)
GetDelegationsByDelegatorByBlock(delegator common.Address, block *types.Block) ([]common.Address, []*staking.Delegation) GetDelegationsByDelegatorByBlock(delegator common.Address, block *types.Block) ([]common.Address, []*staking.Delegation)

@ -21,6 +21,19 @@ const (
Banned Banned
) )
func (e Eligibility) String() string {
switch e {
case Active:
return "active"
case Inactive:
return "inactive"
case Banned:
return doubleSigningBanned
default:
return "unknown"
}
}
// Candidacy is a more semantically meaningful // Candidacy is a more semantically meaningful
// value that is derived from core protocol logic but // value that is derived from core protocol logic but
// meant more for the presentation of user, like at RPC // meant more for the presentation of user, like at RPC

@ -138,8 +138,8 @@ type CurrentEpochPerformance struct {
CurrentSigningPercentage Computed `json:"current-epoch-signing-percent"` CurrentSigningPercentage Computed `json:"current-epoch-signing-percent"`
} }
// ValidatorRPCEnchanced contains extra information for RPC consumer // ValidatorRPCEnhanced contains extra information for RPC consumer
type ValidatorRPCEnchanced struct { type ValidatorRPCEnhanced struct {
Wrapper ValidatorWrapper `json:"validator"` Wrapper ValidatorWrapper `json:"validator"`
Performance *CurrentEpochPerformance `json:"current-epoch-performance"` Performance *CurrentEpochPerformance `json:"current-epoch-performance"`
ComputedMetrics *ValidatorStats `json:"metrics"` ComputedMetrics *ValidatorStats `json:"metrics"`
@ -148,6 +148,7 @@ type ValidatorRPCEnchanced struct {
EPoSStatus string `json:"epos-status"` EPoSStatus string `json:"epos-status"`
EPoSWinningStake *numeric.Dec `json:"epos-winning-stake"` EPoSWinningStake *numeric.Dec `json:"epos-winning-stake"`
BootedStatus *string `json:"booted-status"` BootedStatus *string `json:"booted-status"`
ActiveStatus string `json:"active-status"`
Lifetime *AccumulatedOverLifetime `json:"lifetime"` Lifetime *AccumulatedOverLifetime `json:"lifetime"`
} }

Loading…
Cancel
Save