Merge pull request #1903 from rlan35/staking_last_push

Add shard assignment in validator RPC; fix main.go for staking validator setup
pull/1907/head
Rongjian Lan 5 years ago committed by GitHub
commit ea3a66eb66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      cmd/harmony/main.go
  2. 6
      cmd/staking/root.go
  3. 9
      hmy/api_backend.go
  4. 1
      internal/hmyapi/backend.go
  5. 20
      internal/hmyapi/blockchain.go
  6. 2
      internal/hmyapi/types.go
  7. 2
      shard/committee/assignment.go

@ -209,6 +209,7 @@ func setupInitialAccount() (isLeader bool) {
}
if initialAccount == nil {
initialAccount = &genesis.DeployAccount{}
initialAccount.ShardID = uint32(*shardID)
initialAccount.BlsPublicKey = pubKey.SerializeToHexStr()
blsAddressBytes := pubKey.GetAddress()
@ -463,7 +464,7 @@ func main() {
setupInitialAccount()
}
if *shardID >= 0 {
if *nodeType != "validator" && *shardID >= 0 {
utils.Logger().Info().
Uint32("original", initialAccount.ShardID).
Int("override", *shardID).

@ -121,13 +121,13 @@ func (s *staker) run(cmd *cobra.Command, args []string) error {
return staking.DirectiveDelegate, staking.Delegate{
dAddr,
dAddr2,
big.NewInt(1000),
big.NewInt(0).Mul(big.NewInt(denominations.One), big.NewInt(10)),
}
} else if cmdType == "undelegate" {
return staking.DirectiveUndelegate, staking.Undelegate{
dAddr,
dAddr2,
big.NewInt(1000),
big.NewInt(0).Mul(big.NewInt(denominations.One), big.NewInt(10)),
}
}
return staking.DirectiveCollectRewards, staking.CollectRewards{
@ -182,7 +182,7 @@ func (s *staker) run(cmd *cobra.Command, args []string) error {
param := []interface{}{hexSignature}
local := "http://localhost:9500"
dev := "https://api.s0.pga.hmny.io/" //"http://34.221.51.210:9500" // "https://api.s0.pga.hmny.io/"
dev := "https://api.s0.pga.hmny.io/" // "http://34.209.25.152:9500"
net := local
if !localTest {
net = dev

@ -362,3 +362,12 @@ func (b *APIBackend) GetValidatorSelfDelegation(addr common.Address) *big.Int {
}
return wrapper.Delegations[0].Amount
}
// GetShardState ...
func (b *APIBackend) GetShardState() (shard.State, error) {
state, err := b.hmy.BlockChain().ReadShardState(b.hmy.BlockChain().CurrentHeader().Epoch())
if err != nil {
return nil, err
}
return state, nil
}

@ -80,6 +80,7 @@ type Backend interface {
GetDelegationsByValidator(validator common.Address) []*staking.Delegation
GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation)
GetValidatorSelfDelegation(addr common.Address) *big.Int
GetShardState() (shard.State, error)
}
// GetAPIs returns all the APIs.

@ -518,6 +518,26 @@ func (s *PublicBlockChainAPI) GetValidatorInformation(ctx context.Context, addre
rpcValidator.TotalEffectiveStake = stats.TotalEffectiveStake.String()
}
shardState, err := s.b.GetShardState()
if err == nil {
blsKeyToShardID := make(map[shard.BlsPublicKey]uint32)
for _, committee := range shardState {
for _, slot := range committee.Slots {
blsKeyToShardID[slot.BlsPublicKey] = committee.ShardID
}
}
shardIDs := make([]int, len(rpcValidator.SlotPubKeys))
for i, slotKey := range rpcValidator.SlotPubKeys {
shardID, ok := blsKeyToShardID[slotKey]
if !ok {
shardIDs[i] = int(shardID)
}
}
rpcValidator.SlotShardIDs = shardIDs
}
return rpcValidator, nil
}

@ -68,6 +68,7 @@ type HeaderInformation struct {
type RPCValidator struct {
Address common.Address `json:"address"`
SlotPubKeys []shard.BlsPublicKey `json:"slot_pub_keys"`
SlotShardIDs []int `json:"slot_shard_ids"`
UnbondingHeight *big.Int `json:"unbonding_height"`
MinSelfDelegation *big.Int `json:"min_self_delegation"`
MaxTotalDelegation *big.Int `json:"max_total_delegation"`
@ -157,6 +158,7 @@ func newRPCValidator(validator *types2.Validator) *RPCValidator {
return &RPCValidator{
validator.Address,
validator.SlotPubKeys,
nil,
validator.UnbondingHeight,
validator.MinSelfDelegation,
validator.MaxTotalDelegation,

@ -68,6 +68,7 @@ func preStakingEnabledCommittee(s shardingconfig.Instance) shard.State {
hmyAccounts := s.HmyAccounts()
fnAccounts := s.FnAccounts()
shardState := shard.State{}
// Shard state needs to be sorted by shard ID
for i := 0; i < shardNum; i++ {
com := shard.Committee{ShardID: uint32(i)}
for j := 0; j < shardHarmonyNodes; j++ {
@ -133,6 +134,7 @@ func eposStakedCommittee(
superComm := make(shard.State, shardCount)
hAccounts := s.HmyAccounts()
// Shard state needs to be sorted by shard ID
for i := 0; i < shardCount; i++ {
superComm[i] = shard.Committee{uint32(i), shard.SlotList{}}
}

Loading…
Cancel
Save