Add -staking={true,false} flag; default to false

If -staking=true, determine shard assignment from the BLS public key.
The formula is: ((serialized BLS public key bytes interpreted as
unsigned big-endian integer) % (number of shards)).

In particular:

Network		Pubkey last digit	Shard
---------------------------------------------
Mainnet		[048c]			0
Mainnet		[159d]			1
Mainnet		[26ae]			2
Mainnet		[37bf]			3
Devnet		[02468ace]		0
Devnet		[13579bdf]		1
pull/1939/head
Eugene Kim 5 years ago
parent 92c011a114
commit a30be8fdd8
  1. 18
      cmd/harmony/main.go

@ -87,6 +87,8 @@ var (
// blockPeriod indicates the how long the leader waits to propose a new block.
blockPeriod = flag.Int("block_period", 8, "how long in second the leader waits to propose a new block.")
leaderOverride = flag.Bool("leader_override", false, "true means override the default leader role and acts as validator")
// staking indicates whether the node is operating in staking mode.
stakingFlag = flag.Bool("staking", false, "whether the node should operate in staking mode")
// shardID indicates the shard ID of this node
shardID = flag.Int("shard_id", -1, "the shard ID of this node")
enableMemProfiling = flag.Bool("enableMemProfiling", false, "Enable memsize logging.")
@ -447,6 +449,22 @@ func main() {
if *nodeType == "validator" {
setupInitialAccount()
if *stakingFlag {
var blsPubKey shard.BlsPublicKey
pubKey := nodeconfig.GetDefaultConfig().ConsensusPubKey
if err := blsPubKey.FromLibBLSPublicKey(pubKey); err != nil {
_, _ = fmt.Fprint(os.Stderr,
"ERROR cannot convert libbls pubkey to internal form: %s",
err)
os.Exit(1)
}
// Use the number of shards as of staking epoch.
chainConfig := node.ChainConfigForNetworkType(nodeconfig.NetworkType(*networkType))
stakingEpochShardConfig := shard.Schedule.InstanceForEpoch(chainConfig.StakingEpoch)
numShardsBig := big.NewInt(int64(stakingEpochShardConfig.NumShards()))
shardIDBig := new(big.Int).Mod(blsPubKey.Big(), numShardsBig)
initialAccount.ShardID = uint32(shardIDBig.Uint64())
}
}
if *nodeType != "validator" && *shardID >= 0 {

Loading…
Cancel
Save