[resharding] add resharding epoch

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1224/head
Leo Chen 5 years ago
parent 297896a51b
commit 82307820d5
  1. 16
      cmd/harmony/main.go
  2. 17
      internal/configs/sharding/localnet.go
  3. 4
      internal/configs/sharding/mainnet.go
  4. 3
      internal/configs/sharding/shardingconfig.go
  5. 3
      internal/configs/sharding/testnet.go

@ -185,7 +185,19 @@ func setupGenesisAccount() (isLeader bool) {
genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch)) genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch))
pubKey := setUpConsensusKey(nodeconfig.GetDefaultConfig()) pubKey := setUpConsensusKey(nodeconfig.GetDefaultConfig())
isLeader, genesisAccount = genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr()) reshardingEpoch := genesisShardingConfig.ReshardingEpoch()
if reshardingEpoch != nil && len(reshardingEpoch) > 0 {
for _, epoch := range reshardingEpoch {
config := core.ShardingSchedule.InstanceForEpoch(epoch)
isLeader, genesisAccount = config.FindAccount(pubKey.SerializeToHexStr())
if genesisAccount != nil {
break
}
}
} else {
isLeader, genesisAccount = genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr())
}
if genesisAccount == nil { if genesisAccount == nil {
fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr()) fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr())
os.Exit(100) os.Exit(100)
@ -433,7 +445,7 @@ func main() {
} }
isLeader := false isLeader := false
if !*isExplorer && !*isNewNode { // Explorer node doesn't need the following setup if !*isExplorer { // Explorer node doesn't need the following setup
isLeader = setupGenesisAccount() isLeader = setupGenesisAccount()
} }
if *shardID >= 0 { if *shardID >= 0 {

@ -12,19 +12,24 @@ var LocalnetSchedule localnetSchedule
type localnetSchedule struct{} type localnetSchedule struct{}
const (
localnetV1Epoch = 10
localnetV2Epoch = 20
)
func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
switch { switch {
case epoch.Cmp(big.NewInt(20)) >= 0: case epoch.Cmp(big.NewInt(localnetV2Epoch)) >= 0:
return localnetV2 return localnetV2
case epoch.Cmp(big.NewInt(10)) >= 0: case epoch.Cmp(big.NewInt(localnetV1Epoch)) >= 0:
return localnetV1 return localnetV1
default: // genesis default: // genesis
return localnetV0 return localnetV0
} }
} }
var reshardingEpoch = []*big.Int{big.NewInt(10), big.NewInt(20)} var localnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(localnetV1Epoch), big.NewInt(localnetV2Epoch)}
var localnetV0 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccounts, genesis.LocalFnAccounts, reshardingEpoch) var localnetV0 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccounts, genesis.LocalFnAccounts, localnetReshardingEpoch)
var localnetV1 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccountsV1, genesis.LocalFnAccountsV1, reshardingEpoch) var localnetV1 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccountsV1, genesis.LocalFnAccountsV1, localnetReshardingEpoch)
var localnetV2 = MustNewInstance(2, 7, 4, genesis.LocalHarmonyAccountsV2, genesis.LocalFnAccountsV2, reshardingEpoch) var localnetV2 = MustNewInstance(2, 10, 4, genesis.LocalHarmonyAccountsV2, genesis.LocalFnAccountsV2, localnetReshardingEpoch)

@ -22,7 +22,7 @@ func (mainnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
} }
} }
var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts, nil) var mainnetReshardingEpoch = make([]*big.Int, 0)
var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts, mainnetReshardingEpoch)
//var mainnetV2 = MustNewInstance(8, 200, 100) //var mainnetV2 = MustNewInstance(8, 200, 100)
//var mainnet6400 = MustNewInstance(16, 400, 50) //var mainnet6400 = MustNewInstance(16, 400, 50)

@ -34,4 +34,7 @@ type Instance interface {
// FindAccount returns the deploy account based on the blskey // FindAccount returns the deploy account based on the blskey
FindAccount(blsPubKey string) (bool, *genesis.DeployAccount) FindAccount(blsPubKey string) (bool, *genesis.DeployAccount)
// ReshardingEpoch return list of Epoch while off-chain resharding happens
ReshardingEpoch() []*big.Int
} }

@ -19,4 +19,5 @@ func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
} }
} }
var testnetV0 = MustNewInstance(2, 150, 150, genesis.TNHarmonyAccounts, genesis.FoundationalNodeAccounts, nil) var testnetReshardingEpoch = make([]*big.Int, 0)
var testnetV0 = MustNewInstance(2, 150, 150, genesis.TNHarmonyAccounts, genesis.FoundationalNodeAccounts, testnetReshardingEpoch)

Loading…
Cancel
Save