|
|
@ -86,8 +86,11 @@ func (ss *ShardingState) cuckooResharding(percent float64) { |
|
|
|
// assignLeaders will first add new nodes into shards, then use cuckoo rule to reshard to get new shard state
|
|
|
|
// assignLeaders will first add new nodes into shards, then use cuckoo rule to reshard to get new shard state
|
|
|
|
func (ss *ShardingState) assignLeaders() { |
|
|
|
func (ss *ShardingState) assignLeaders() { |
|
|
|
for i := 0; i < ss.numShards; i++ { |
|
|
|
for i := 0; i < ss.numShards; i++ { |
|
|
|
Shuffle(ss.shardState[i].NodeList) |
|
|
|
// At genesis epoch, the shards are empty.
|
|
|
|
ss.shardState[i].Leader = ss.shardState[i].NodeList[0] |
|
|
|
if len(ss.shardState[i].NodeList) > 0 { |
|
|
|
|
|
|
|
Shuffle(ss.shardState[i].NodeList) |
|
|
|
|
|
|
|
ss.shardState[i].Leader = ss.shardState[i].NodeList[0] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -143,6 +146,7 @@ func CalculateNewShardState(bc *BlockChain, epoch uint64, stakeInfo *map[common. |
|
|
|
ss := GetShardingStateFromBlockChain(bc, epoch-1) |
|
|
|
ss := GetShardingStateFromBlockChain(bc, epoch-1) |
|
|
|
newNodeList := ss.UpdateShardingState(stakeInfo) |
|
|
|
newNodeList := ss.UpdateShardingState(stakeInfo) |
|
|
|
percent := ss.calculateKickoutRate(newNodeList) |
|
|
|
percent := ss.calculateKickoutRate(newNodeList) |
|
|
|
|
|
|
|
utils.GetLogInstance().Info("Kickout Percentage", "percentage", percent) |
|
|
|
ss.Reshard(newNodeList, percent) |
|
|
|
ss.Reshard(newNodeList, percent) |
|
|
|
return ss.shardState |
|
|
|
return ss.shardState |
|
|
|
} |
|
|
|
} |
|
|
@ -201,7 +205,7 @@ func GetInitShardState() types.ShardState { |
|
|
|
if i == 0 { |
|
|
|
if i == 0 { |
|
|
|
for j := 0; j < GenesisShardSize; j++ { |
|
|
|
for j := 0; j < GenesisShardSize; j++ { |
|
|
|
priKey := bls.SecretKey{} |
|
|
|
priKey := bls.SecretKey{} |
|
|
|
priKey.SetHexString(contract.InitialBeaconChainAccounts[i].Private) |
|
|
|
priKey.SetHexString(contract.InitialBeaconChainAccounts[j].Private) |
|
|
|
addrBytes := priKey.GetPublicKey().GetAddress() |
|
|
|
addrBytes := priKey.GetPublicKey().GetAddress() |
|
|
|
address := hex.EncodeToString(addrBytes[:]) |
|
|
|
address := hex.EncodeToString(addrBytes[:]) |
|
|
|
com.NodeList = append(com.NodeList, types.NodeID(address)) |
|
|
|
com.NodeList = append(com.NodeList, types.NodeID(address)) |
|
|
|