More clear up and fixes

pull/1866/head
Rongjian Lan 5 years ago
parent bad9c62922
commit 1049bd5f24
  1. 3
      consensus/consensus_service.go
  2. 16
      core/blockchain.go
  3. 9
      internal/hmyapi/blockchain.go
  4. 2
      internal/hmyapi/types.go
  5. 3
      node/node_newblock.go
  6. 6
      node/worker/worker.go
  7. 8
      shard/committee/assignment.go
  8. 11
      staking/types/validator.go
  9. 2
      staking/types/validator_test.go

@ -228,9 +228,6 @@ func (consensus *Consensus) ToggleConsensusCheck() {
// IsValidatorInCommittee returns whether the given validator BLS address is part of my committee
func (consensus *Consensus) IsValidatorInCommittee(pubKey *bls.PublicKey) bool {
utils.Logger().Print("XXXXXXXX")
utils.Logger().Print(consensus.Decider.JSON())
return consensus.Decider.IndexOf(pubKey) != -1
}

@ -1177,15 +1177,13 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
}
// Do bookkeeping for new staking txns
if bc.chainConfig.IsStaking(block.Epoch()) {
for _, tx := range block.StakingTransactions() {
err = bc.UpdateStakingMetaData(tx, root)
// keep offchain database consistency with onchain we need revert
// but it should not happend unless local database corrupted
if err != nil {
utils.Logger().Debug().Msgf("oops, UpdateStakingMetaData failed, err: %+v", err)
return NonStatTy, err
}
for _, tx := range block.StakingTransactions() {
err = bc.UpdateStakingMetaData(tx, root)
// keep offchain database consistency with onchain we need revert
// but it should not happend unless local database corrupted
if err != nil {
utils.Logger().Debug().Msgf("oops, UpdateStakingMetaData failed, err: %+v", err)
return NonStatTy, err
}
}

@ -302,8 +302,13 @@ func (s *PublicBlockChainAPI) GetLeader(ctx context.Context) string {
// GetStake returns validator stake.
func (s *PublicBlockChainAPI) GetStake(ctx context.Context, address string) hexutil.Uint64 {
validator := s.b.GetValidatorInformation(internal_common.ParseAddr(address))
return hexutil.Uint64(validator.Stake.Uint64())
delegations := s.b.GetDelegationsByValidator(internal_common.ParseAddr(address))
totalStake := big.NewInt(0)
for _, delegation := range delegations {
totalStake.Add(totalStake, delegation.Amount)
}
// TODO: return more than uint64
return hexutil.Uint64(totalStake.Uint64())
}
// GetValidatorStakingAddress stacking address returns validator stacking address.

@ -156,7 +156,7 @@ func newRPCValidator(validator *types2.Validator) *RPCValidator {
return &RPCValidator{
validator.Address,
validator.SlotPubKeys,
validator.Stake,
big.NewInt(0), // TODO: add using the delegations
validator.UnbondingHeight,
validator.MinSelfDelegation,
validator.MaxTotalDelegation,

@ -123,9 +123,6 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
node.Consensus.ShardID, node.Blockchain(),
)
utils.Logger().Print("TESTTEST")
utils.Logger().Print(shardState.JSON())
if err != nil {
return nil, err
}

@ -303,17 +303,11 @@ func (w *Worker) SuperCommitteeForNextEpoch(
// WARN When we first enable staking, this condition may not be robust by itself.
if w.config.IsStaking(w.current.header.Epoch()) {
utils.Logger().Print("CURRRRRRRRRR")
utils.Logger().Print(beacon.CurrentHeader().Number())
utils.Logger().Print(beacon.CurrentHeader().Epoch())
utils.Logger().Print(w.current.header.Epoch())
switch beacon.CurrentHeader().Epoch().Cmp(w.current.header.Epoch()) {
case 1:
utils.Logger().Print("TTTTTTTT")
nextCommittee, oops = committee.WithStakingEnabled.ReadFromDB(
beacon.CurrentHeader().Epoch(), beacon,
)
utils.Logger().Print(nextCommittee)
}
} else {
if shard.Schedule.IsLastBlock(w.current.header.Number().Uint64()) {

@ -7,7 +7,7 @@ import (
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/block"
common2 "github.com/harmony-one/harmony/internal/common"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/utils"
@ -126,11 +126,15 @@ func eposStakedCommittee(
for i := range candidates {
// TODO Should be using .ValidatorStakingWithDelegation, not implemented yet
validator, err := stakerReader.ReadValidatorData(candidates[i])
validatorStake := big.NewInt(0)
for _, delegation := range validator.Delegations {
validatorStake.Add(validatorStake, delegation.Amount)
}
if err != nil {
return nil, err
}
essentials[validator.Address] = effective.SlotOrder{
validator.Stake,
validatorStake,
validator.SlotPubKeys,
}
}

@ -57,9 +57,6 @@ type Validator struct {
Address common.Address `json:"address" yaml:"address"`
// The BLS public key of the validator for consensus
SlotPubKeys []shard.BlsPublicKey `json:"slot_pub_keys" yaml:"slot_pub_keys"`
// TODO Need to remove this .Stake Field
// The stake put by the validator itself
Stake *big.Int `json:"stake" yaml:"stake"`
// if unbonding, height at which this validator has begun unbonding
UnbondingHeight *big.Int `json:"unbonding_height" yaml:"unbonding_height"`
// validator's self declared minimum self delegation
@ -218,9 +215,6 @@ func (v *Validator) GetAddress() common.Address { return v.Address }
// GetName returns the name of validator in the description
func (v *Validator) GetName() string { return v.Description.Name }
// GetStake returns the total staking amount
func (v *Validator) GetStake() *big.Int { return v.Stake }
// GetCommissionRate returns the commission rate of the validator
func (v *Validator) GetCommissionRate() numeric.Dec { return v.Commission.Rate }
@ -239,7 +233,7 @@ func CreateValidatorFromNewMsg(val *CreateValidator, blockNum *big.Int) (*Valida
// TODO: a new validator should have a minimum of 1 token as self delegation, and that should be added as a delegation entry here.
v := Validator{
val.ValidatorAddress, pubKeys,
val.Amount, new(big.Int), val.MinSelfDelegation, val.MaxTotalDelegation, false,
new(big.Int), val.MinSelfDelegation, val.MaxTotalDelegation, false,
commission, desc, blockNum,
}
return &v, nil
@ -304,14 +298,13 @@ func (v *Validator) String() string {
return fmt.Sprintf(`Validator
Address: %s
SlotPubKeys: %s
Stake: %s
Unbonding Height: %v
Minimum Self Delegation: %v
Maximum Total Delegation: %v
Description: %v
Commission: %v`,
common2.MustAddressToBech32(v.Address), printSlotPubKeys(v.SlotPubKeys),
v.Stake, v.UnbondingHeight,
v.UnbondingHeight,
v.MinSelfDelegation, v.MaxTotalDelegation, v.Description, v.Commission,
)
}

@ -12,7 +12,7 @@ func CreateNewValidator() Validator {
c := Commission{cr, big.NewInt(300)}
d := Description{Name: "SuperHero", Identity: "YouWillNotKnow", Website: "under_construction", Details: "N/A"}
v := Validator{Address: common.Address{}, SlotPubKeys: nil,
Stake: big.NewInt(500), UnbondingHeight: big.NewInt(20), MinSelfDelegation: big.NewInt(7),
UnbondingHeight: big.NewInt(20), MinSelfDelegation: big.NewInt(7),
Active: false, Commission: c, Description: d}
return v
}

Loading…
Cancel
Save