[staking] Stumble out test case for validator information

pull/1827/head
Edgar Aroutiounian 5 years ago
parent 867fdb1f8d
commit 78c0cf030c
  1. 77
      core/blockchain.go
  2. 2
      internal/params/config.go
  3. 7
      shard/committee/assignment.go

@ -23,6 +23,7 @@ import (
"fmt"
"io"
"math/big"
"math/rand"
"sync"
"sync/atomic"
"time"
@ -42,6 +43,7 @@ import (
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
common2 "github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/utils"
@ -2438,26 +2440,75 @@ func (bc *BlockChain) CurrentValidatorAddresses() []common.Address {
return filtered
}
const (
a = "one1x4080kv34a4s3s886vs3rvvhm28pk3r0fnfh6n"
b = "one1pjq82a97vfxvmlm60htyc7kafhyjm59f7wgz22"
c = "one1yc06ghr2p8xnl2380kpfayweguuhxdtupkhqzw"
d = "one1wh4p0kuc7unxez2z8f82zfnhsg4ty6dupqyjt2"
e = "one16qsd5ant9v94jrs89mruzx62h7ekcfxmduh2rx"
f = "one1spshr72utf6rwxseaz339j09ed8p6f8ke370zj"
g = "one1v788ag7ukh6wjujvpempss6h9ugvfxmnsyklr5"
h = "one1hx3gy5e864eycmjtpcvsuz59m3lu7y89q0ddhl"
i = "one1mmvhupm7ejytype664mhs2m95vn9pfdjrqfadv"
)
// ValidatorCandidates returns the up to date validator candidates for next epoch
func (bc *BlockChain) ValidatorCandidates() []common.Address {
list, err := bc.ReadValidatorList()
if err != nil {
return make([]common.Address, 0)
// TODO Turn this into 400 length generated slice
return []common.Address{
common2.ParseAddr(a),
common2.ParseAddr(b),
common2.ParseAddr(c),
common2.ParseAddr(d),
common2.ParseAddr(e),
common2.ParseAddr(f),
common2.ParseAddr(g),
common2.ParseAddr(h),
}
return list
}
var (
sequence = rand.New(rand.NewSource(42))
)
// ValidatorInformation returns the information of validator
func (bc *BlockChain) ValidatorInformation(addr common.Address) (*staking.Validator, error) {
state, err := bc.StateAt(bc.CurrentBlock().Root())
if err != nil || state == nil {
return nil, err
}
wrapper := state.GetStakingInfo(addr)
if wrapper == nil {
return nil, fmt.Errorf("ValidatorInformation not found: %v", addr)
}
return &wrapper.Validator, nil
// EDGAR 0x355E77D991Af6B08C0e7d32111b197da8e1B446f
// EDGAR 0x0C807574BE624CcdFf7A7dD64c7ADd4dC92dd0a9
// EDGAR 0x261fa45c6A09cD3Faa277d829e91d9473973357C
// EDGAR 0x75eA17DB98F7266C89423A4EA12677822Ab269Bc
// EDGAR 0xD020dA766b2b0b590E072ec7c11b4AbFb36c24DB
// EDGAR 0x806171f95C5a74371a19e8a312c9e5Cb4E1D24f6
// EDGAR 0x678E7Ea3DCb5f4e9724C0e761843572f10c49B73
// EDGAR 0xB9A2825327D5724C6E4b0e190E0a85dc7FCf10e5
someValidator := &staking.Validator{}
someValidator.Address = addr
someValidator.Stake = big.NewInt(int64(sequence.Intn(100)))
switch B := common2.MustAddressToBech32(addr); true {
case B == a:
fmt.Println("Called here:", B, a)
return someValidator, nil
case B == b:
case B == c:
case B == d:
case B == e:
case B == f:
case B == g:
case B == h:
}
fmt.Println("EDGAR", addr.String())
return nil, nil
// state, err := bc.StateAt(bc.CurrentBlock().Root())
// if err != nil || state == nil {
// return nil, err
// }
// wrapper := state.GetStakingInfo(addr)
// if wrapper == nil {
// return nil, fmt.Errorf("ValidatorInformation not found: %v", addr)
// }
// return &wrapper.Validator, nil
}
// DelegatorsInformation returns up to date information of delegators of a given validator address

@ -36,7 +36,7 @@ var (
ChainID: TestnetChainID,
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(0),
StakingEpoch: EpochTBD,
StakingEpoch: big.NewInt(5),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
}

@ -1,6 +1,7 @@
package committee
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
@ -248,8 +249,6 @@ func (def partialStakingEnabled) Compute(
if !config.IsStaking(epoch) {
return preStakingEnabledCommittee(instance), nil
}
stakedSlots :=
(instance.NumNodesPerShard() - instance.NumHarmonyOperatedNodesPerShard()) *
int(instance.NumShards())
return eposStakedCommittee(instance, stakerReader, stakedSlots)
fmt.Println("Staking epoch happened", config.String())
return with400Stakers(instance, stakerReader)
}

Loading…
Cancel
Save