[resharding] add hmyaccount and fnaccount

use configurable hmyaccount and fnaccount to create genesis block

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1207/head
Leo Chen 5 years ago
parent a8a9953a82
commit 5f6a8a12bf
  1. 22
      cmd/harmony/main.go
  2. 12
      core/resharding.go
  3. 40
      internal/configs/sharding/instance.go
  4. 8
      internal/configs/sharding/mainnet.go
  5. 11
      internal/configs/sharding/shardingconfig.go
  6. 8
      internal/configs/sharding/testnet.go
  7. 2
      internal/genesis/foundational.go
  8. 34
      internal/genesis/genesis.go
  9. 2
      internal/genesis/harmony.go
  10. 15
      internal/genesis/tn_harmony.go

@ -210,10 +210,15 @@ func passphraseForBls() {
func setupECDSAKeys() {
ks = hmykey.GetHmyKeyStore()
// TODO: lc try to enable multiple staking accounts per node
accountIndex, genesisAccount = setUpConsensusKeyAndReturnIndex(nodeconfig.GetDefaultConfig())
genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch))
pubKey := setUpConsensusKeyAndReturnIndex(nodeconfig.GetDefaultConfig())
index, genesisAccount := genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr())
if index < 0 {
fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr())
os.Exit(100)
}
genesisAccount.ShardID = uint32(accountIndex) % genesisShardingConfig.NumShards()
fmt.Printf("My Genesis Account: %v\n", *genesisAccount)
@ -224,18 +229,13 @@ func setupECDSAKeys() {
}
}
func setUpConsensusKeyAndReturnIndex(nodeConfig *nodeconfig.ConfigType) (int, *genesis.DeployAccount) {
func setUpConsensusKeyAndReturnIndex(nodeConfig *nodeconfig.ConfigType) *bls.PublicKey {
consensusPriKey, err := blsgen.LoadBlsKeyWithPassPhrase(*blsKeyFile, blsPassphrase)
if err != nil {
fmt.Printf("error when loading bls key, err :%v\n", err)
os.Exit(100)
}
pubKey := consensusPriKey.GetPublicKey()
index, acc := genesis.IsBlsPublicKeyIndex(pubKey.SerializeToHexStr())
if index < 0 {
fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr())
os.Exit(100)
}
// Consensus keys are the BLS12-381 keys used to sign consensus messages
nodeConfig.ConsensusPriKey, nodeConfig.ConsensusPubKey = consensusPriKey, consensusPriKey.GetPublicKey()
@ -243,7 +243,7 @@ func setUpConsensusKeyAndReturnIndex(nodeConfig *nodeconfig.ConfigType) (int, *g
fmt.Println("error to get consensus keys.")
os.Exit(100)
}
return index, acc
return pubKey
}
func createGlobalConfig() *nodeconfig.ConfigType {
@ -472,7 +472,7 @@ func main() {
*devnetHarmonySize = *devnetShardSize
}
devnetConfig, err := shardingconfig.NewInstance(
uint32(*devnetNumShards), *devnetShardSize, *devnetHarmonySize)
uint32(*devnetNumShards), *devnetShardSize, *devnetHarmonySize, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "invalid devnet sharding config: %s",
err)

@ -15,7 +15,6 @@ import (
common2 "github.com/harmony-one/harmony/internal/common"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/genesis"
"github.com/harmony-one/harmony/internal/utils"
)
@ -234,6 +233,9 @@ func GetInitShardState() types.ShardState {
genesisShardNum := int(initShardingConfig.NumShards())
genesisShardHarmonyNodes := initShardingConfig.NumHarmonyOperatedNodesPerShard()
genesisShardSize := initShardingConfig.NumNodesPerShard()
genesisHmyAccounts := initShardingConfig.HmyAccounts()
genesisFnAccounts := initShardingConfig.FnAccounts()
shardState := types.ShardState{}
for i := 0; i < genesisShardNum; i++ {
com := types.Committee{ShardID: uint32(i)}
@ -241,11 +243,11 @@ func GetInitShardState() types.ShardState {
index := i + j*genesisShardNum // The initial account to use for genesis nodes
pub := &bls.PublicKey{}
pub.DeserializeHexStr(genesis.HarmonyAccounts[index].BlsPublicKey)
pub.DeserializeHexStr(genesisHmyAccounts[index].BlsPublicKey)
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(pub)
// TODO: directly read address for bls too
curNodeID := types.NodeID{common2.ParseAddr(genesis.HarmonyAccounts[index].Address), pubKey}
curNodeID := types.NodeID{common2.ParseAddr(genesisHmyAccounts[index].Address), pubKey}
com.NodeList = append(com.NodeList, curNodeID)
}
@ -254,12 +256,12 @@ func GetInitShardState() types.ShardState {
index := i + (j-genesisShardHarmonyNodes)*genesisShardNum
pub := &bls.PublicKey{}
pub.DeserializeHexStr(genesis.FoundationalNodeAccounts[index].BlsPublicKey)
pub.DeserializeHexStr(genesisFnAccounts[index].BlsPublicKey)
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(pub)
// TODO: directly read address for bls too
curNodeID := types.NodeID{common2.ParseAddr(genesis.FoundationalNodeAccounts[index].Address), pubKey}
curNodeID := types.NodeID{common2.ParseAddr(genesisFnAccounts[index].Address), pubKey}
com.NodeList = append(com.NodeList, curNodeID)
}
shardState = append(shardState, com)

@ -1,17 +1,24 @@
package shardingconfig
import "github.com/harmony-one/harmony/internal/ctxerror"
import (
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/genesis"
)
type instance struct {
numShards uint32
numNodesPerShard int
numHarmonyOperatedNodesPerShard int
hmyAccounts []genesis.DeployAccount
fnAccounts []genesis.DeployAccount
}
// NewInstance creates and validates a new sharding configuration based
// upon given parameters.
func NewInstance(
numShards uint32, numNodesPerShard, numHarmonyOperatedNodesPerShard int,
hmyAccounts []genesis.DeployAccount,
fnAccounts []genesis.DeployAccount,
) (Instance, error) {
if numShards < 1 {
return nil, ctxerror.New("sharding config must have at least one shard",
@ -36,6 +43,8 @@ func NewInstance(
numShards: numShards,
numNodesPerShard: numNodesPerShard,
numHarmonyOperatedNodesPerShard: numHarmonyOperatedNodesPerShard,
hmyAccounts: hmyAccounts,
fnAccounts: fnAccounts,
}, nil
}
@ -44,9 +53,11 @@ func NewInstance(
// It is intended to be used for static initialization.
func MustNewInstance(
numShards uint32, numNodesPerShard, numHarmonyOperatedNodesPerShard int,
hmyAccounts []genesis.DeployAccount,
fnAccounts []genesis.DeployAccount,
) Instance {
sc, err := NewInstance(
numShards, numNodesPerShard, numHarmonyOperatedNodesPerShard)
numShards, numNodesPerShard, numHarmonyOperatedNodesPerShard, hmyAccounts, fnAccounts)
if err != nil {
panic(err)
}
@ -68,3 +79,28 @@ func (sc instance) NumNodesPerShard() int {
func (sc instance) NumHarmonyOperatedNodesPerShard() int {
return sc.numHarmonyOperatedNodesPerShard
}
// HmyAccounts returns the list of Harmony accounts
func (sc instance) HmyAccounts() []genesis.DeployAccount {
return sc.hmyAccounts
}
// FnAccounts returns the list of Foundational Node accounts
func (sc instance) FnAccounts() []genesis.DeployAccount {
return sc.fnAccounts
}
// FindAccount returns the deploy account based on the blskey
func (sc instance) FindAccount(blsPubKey string) (int, *genesis.DeployAccount) {
for i, item := range sc.hmyAccounts {
if item.BlsPublicKey == blsPubKey {
return i, &item
}
}
for i, item := range sc.fnAccounts {
if item.BlsPublicKey == blsPubKey {
return i + int(sc.numShards), &item
}
}
return -1, nil
}

@ -1,6 +1,10 @@
package shardingconfig
import "math/big"
import (
"math/big"
"github.com/harmony-one/harmony/internal/genesis"
)
// MainnetSchedule is the mainnet sharding configuration schedule.
var MainnetSchedule mainnetSchedule
@ -18,7 +22,7 @@ func (mainnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
}
}
var mainnetV0 = MustNewInstance(4, 150, 112)
var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts)
//var mainnetV2 = MustNewInstance(8, 200, 100)
//var mainnet6400 = MustNewInstance(16, 400, 50)

@ -4,6 +4,8 @@ package shardingconfig
import (
"math/big"
"github.com/harmony-one/harmony/internal/genesis"
)
// Schedule returns the sharding configuration instance for the given
@ -23,4 +25,13 @@ type Instance interface {
// NumHarmonyOperatedNodesPerShard returns number of nodes in each shard
// that are operated by Harmony.
NumHarmonyOperatedNodesPerShard() int
// HmyAccounts returns a list of Harmony accounts
HmyAccounts() []genesis.DeployAccount
// FnAccounts returns a list of Foundational node accounts
FnAccounts() []genesis.DeployAccount
// FindAccount returns the deploy account based on the blskey
FindAccount(blsPubKey string) (int, *genesis.DeployAccount)
}

@ -1,6 +1,10 @@
package shardingconfig
import "math/big"
import (
"math/big"
"github.com/harmony-one/harmony/internal/genesis"
)
// TestnetSchedule is the long-running public testnet sharding
// configuration schedule.
@ -15,4 +19,4 @@ func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
}
}
var testnetV0 = MustNewInstance(2, 150, 150)
var testnetV0 = MustNewInstance(2, 5, 5, genesis.TNHarmonyAccounts, genesis.FoundationalNodeAccounts)

@ -1,7 +1,7 @@
package genesis
// FoundationalNodeAccounts are the accounts for the foundational nodes at genesis.
var FoundationalNodeAccounts = [...]DeployAccount{
var FoundationalNodeAccounts = []DeployAccount{
{Index: "0", Address: "one1y0xcf40fg65n2ehm8fx5vda4thrkymhpg45ecj", BlsPublicKey: "9e70e8d76851f6e8dc648255acdd57bb5c49cdae7571aed43f86e9f140a6343caed2ffa860919d03e0912411fee4850a"},
{Index: "1", Address: "one18lp2w7ghhuajdpzl8zqeddza97u92wtkfcwpjk", BlsPublicKey: "fce3097d9fc234d34d6eaef3eecd0365d435d1118f69f2da1ed2a69ba725270771572e40347c222aca784cb973307b11"},
{Index: "2", Address: "one1tqa46jj9ut8zu20jm3kqv3f5fwkeq964t496mx", BlsPublicKey: "edb61007e99af30191098f2cd6f787e2f53fb595bf63fcb4d31a386e7070f7a4fdcefd3e896080a665dc19fecbafc306"},

@ -7,7 +7,6 @@ import (
"strings"
"github.com/ethereum/go-ethereum/crypto"
"github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/utils"
)
@ -35,39 +34,6 @@ func BeaconAccountPriKey() *ecdsa.PrivateKey {
return prikey
}
// FindAccount find the DeployAccount based on the account address, and the account index
// the account address could be from HarmonyAccounts or from FoundationalNodeAccounts
// the account index can be used to determin the shard of the account
func FindAccount(address string) (int, *DeployAccount) {
addr := common.ParseAddr(address)
for i, acc := range HarmonyAccounts {
if addr == common.ParseAddr(acc.Address) {
return i, &acc
}
}
for i, acc := range FoundationalNodeAccounts {
if addr == common.ParseAddr(acc.Address) {
return i + 8, &acc
}
}
return 0, nil
}
// IsBlsPublicKeyIndex returns index and DeployAccount.
func IsBlsPublicKeyIndex(blsPublicKey string) (int, *DeployAccount) {
for i, item := range HarmonyAccounts {
if item.BlsPublicKey == blsPublicKey {
return i, &item
}
}
for i, item := range FoundationalNodeAccounts {
if item.BlsPublicKey == blsPublicKey {
return i + 8, &item
}
}
return -1, nil
}
// GenesisBeaconAccountPriKey is the private key of genesis beacon account.
var GenesisBeaconAccountPriKey = BeaconAccountPriKey()

@ -1,7 +1,7 @@
package genesis
// HarmonyAccounts are the accounts for the initial genesis nodes hosted by Harmony.
var HarmonyAccounts = [...]DeployAccount{
var HarmonyAccounts = []DeployAccount{
{Index: " 0 ", Address: "one1gh043zc95e6mtutwy5a2zhvsxv7lnlklkj42ux", BlsPublicKey: "ca23704be46ce9c4704681ac9c08ddc644f1858a5c28ce236e1b5d9dee67c1f5a28075b5ef089adeffa8a372c1762007"},
{Index: " 1 ", Address: "one1u0kt4ng2x9c0zl0jv57rwj4rvw8fhem2vqksdv", BlsPublicKey: "c6c008ec354ac776fce5c24ce46d5a9897449b66d91d8bbe2ca0249f1e1fce1a5577cf6f91067b060ee20114ac726297"},
{Index: " 2 ", Address: "one1xdnm2fj6hyk7e49af2h9dmudkdlta9q354094e", BlsPublicKey: "f9a835dac43236ded1899257c904da922a9a86242ccced1f782eed8f9df6732c0d44f56280d2ca1689db878c2f14d285"},

@ -0,0 +1,15 @@
package genesis
// TNHarmonyAccounts are the accounts for the initial genesis nodes hosted by Harmony for testnet.
var TNHarmonyAccounts = []DeployAccount{
{Index: " 0 ", Address: "one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy", BlsPublicKey: "65f55eb3052f9e9f632b2923be594ba77c55543f5c58ee1454b9cfd658d25e06373b0f7d42a19c84768139ea294f6204"},
{Index: " 1 ", Address: "one1m6m0ll3q7ljdqgmth2t5j7dfe6stykucpj2nr5", BlsPublicKey: "40379eed79ed82bebfb4310894fd33b6a3f8413a78dc4d43b98d0adc9ef69f3285df05eaab9f2ce5f7227f8cb920e809"},
{Index: " 2 ", Address: "one12fuf7x9rgtdgqg7vgq0962c556m3p7afsxgvll", BlsPublicKey: "02c8ff0b88f313717bc3a627d2f8bb172ba3ad3bb9ba3ecb8eed4b7c878653d3d4faf769876c528b73f343967f74a917"},
{Index: " 3 ", Address: "one16qsd5ant9v94jrs89mruzx62h7ekcfxmduh2rx", BlsPublicKey: "ee2474f93cba9241562efc7475ac2721ab0899edf8f7f115a656c0c1f9ef8203add678064878d174bb478fa2e6630502"},
{Index: " 4 ", Address: "one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp", BlsPublicKey: "e751ec995defe4931273aaebcb2cd14bf37e629c554a57d3f334c37881a34a6188a93e76113c55ef3481da23b7d7ab09"},
{Index: " 5 ", Address: "one1est2gxcvavmtnzc7mhd73gzadm3xxcv5zczdtw", BlsPublicKey: "776f3b8704f4e1092a302a60e84f81e476c212d6f458092b696df420ea19ff84a6179e8e23d090b9297dc041600bc100"},
{Index: " 6 ", Address: "one1spshr72utf6rwxseaz339j09ed8p6f8ke370zj", BlsPublicKey: "2d61379e44a772e5757e27ee2b3874254f56073e6bd226eb8b160371cc3c18b8c4977bd3dcb71fd57dc62bf0e143fd08"},
{Index: " 7 ", Address: "one1a0x3d6xpmr6f8wsyaxd9v36pytvp48zckswvv9", BlsPublicKey: "c4e4708b6cf2a2ceeb59981677e9821eebafc5cf483fb5364a28fa604cc0ce69beeed40f3f03815c9e196fdaec5f1097"},
{Index: " 8 ", Address: "one1d2rngmem4x2c6zxsjjz29dlah0jzkr0k2n88wc", BlsPublicKey: "86dc2fdc2ceec18f6923b99fd86a68405c132e1005cf1df72dca75db0adfaeb53d201d66af37916d61f079f34f21fb96"},
{Index: " 9 ", Address: "one1658znfwf40epvy7e46cqrmzyy54h4n0qa73nep", BlsPublicKey: "49d15743b36334399f9985feb0753430a2b287b2d68b84495bbb15381854cbf01bca9d1d9f4c9c8f18509b2bfa6bd40f"},
}
Loading…
Cancel
Save