diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 6f58ba35f..3423e628e 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.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). diff --git a/cmd/staking/root.go b/cmd/staking/root.go index 3b53a1631..ad6f8ff74 100644 --- a/cmd/staking/root.go +++ b/cmd/staking/root.go @@ -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 diff --git a/hmy/api_backend.go b/hmy/api_backend.go index 4e4c3d802..d889bb218 100644 --- a/hmy/api_backend.go +++ b/hmy/api_backend.go @@ -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 +} diff --git a/internal/hmyapi/backend.go b/internal/hmyapi/backend.go index 020846c37..1b8259ed2 100644 --- a/internal/hmyapi/backend.go +++ b/internal/hmyapi/backend.go @@ -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. diff --git a/internal/hmyapi/blockchain.go b/internal/hmyapi/blockchain.go index 7ad2c5896..e636b7e62 100644 --- a/internal/hmyapi/blockchain.go +++ b/internal/hmyapi/blockchain.go @@ -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 } diff --git a/internal/hmyapi/types.go b/internal/hmyapi/types.go index 92986ea7b..52fe723e7 100644 --- a/internal/hmyapi/types.go +++ b/internal/hmyapi/types.go @@ -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, diff --git a/shard/committee/assignment.go b/shard/committee/assignment.go index 3d13c83d4..cc401d9d0 100644 --- a/shard/committee/assignment.go +++ b/shard/committee/assignment.go @@ -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{}} }