From 82307820d57a62ded24a1bca1ab9a16579526b12 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 17 Jul 2019 23:54:30 -0700 Subject: [PATCH] [resharding] add resharding epoch Signed-off-by: Leo Chen --- cmd/harmony/main.go | 16 ++++++++++++++-- internal/configs/sharding/localnet.go | 17 +++++++++++------ internal/configs/sharding/mainnet.go | 4 ++-- internal/configs/sharding/shardingconfig.go | 3 +++ internal/configs/sharding/testnet.go | 3 ++- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 450746cc5..7b80897a6 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -185,7 +185,19 @@ func setupGenesisAccount() (isLeader bool) { genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch)) 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 { fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr()) os.Exit(100) @@ -433,7 +445,7 @@ func main() { } 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() } if *shardID >= 0 { diff --git a/internal/configs/sharding/localnet.go b/internal/configs/sharding/localnet.go index ae97a5a8a..7460ad2bb 100644 --- a/internal/configs/sharding/localnet.go +++ b/internal/configs/sharding/localnet.go @@ -12,19 +12,24 @@ var LocalnetSchedule localnetSchedule type localnetSchedule struct{} +const ( + localnetV1Epoch = 10 + localnetV2Epoch = 20 +) + func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { switch { - case epoch.Cmp(big.NewInt(20)) >= 0: + case epoch.Cmp(big.NewInt(localnetV2Epoch)) >= 0: return localnetV2 - case epoch.Cmp(big.NewInt(10)) >= 0: + case epoch.Cmp(big.NewInt(localnetV1Epoch)) >= 0: return localnetV1 default: // genesis 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 localnetV1 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccountsV1, genesis.LocalFnAccountsV1, reshardingEpoch) -var localnetV2 = MustNewInstance(2, 7, 4, genesis.LocalHarmonyAccountsV2, genesis.LocalFnAccountsV2, reshardingEpoch) +var localnetV0 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccounts, genesis.LocalFnAccounts, localnetReshardingEpoch) +var localnetV1 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccountsV1, genesis.LocalFnAccountsV1, localnetReshardingEpoch) +var localnetV2 = MustNewInstance(2, 10, 4, genesis.LocalHarmonyAccountsV2, genesis.LocalFnAccountsV2, localnetReshardingEpoch) diff --git a/internal/configs/sharding/mainnet.go b/internal/configs/sharding/mainnet.go index bf3fac2f1..189cf64f4 100644 --- a/internal/configs/sharding/mainnet.go +++ b/internal/configs/sharding/mainnet.go @@ -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 mainnet6400 = MustNewInstance(16, 400, 50) diff --git a/internal/configs/sharding/shardingconfig.go b/internal/configs/sharding/shardingconfig.go index b0cb73ecf..382e1f8d5 100644 --- a/internal/configs/sharding/shardingconfig.go +++ b/internal/configs/sharding/shardingconfig.go @@ -34,4 +34,7 @@ type Instance interface { // FindAccount returns the deploy account based on the blskey FindAccount(blsPubKey string) (bool, *genesis.DeployAccount) + + // ReshardingEpoch return list of Epoch while off-chain resharding happens + ReshardingEpoch() []*big.Int } diff --git a/internal/configs/sharding/testnet.go b/internal/configs/sharding/testnet.go index 532fea229..37573665f 100644 --- a/internal/configs/sharding/testnet.go +++ b/internal/configs/sharding/testnet.go @@ -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)