|
|
@ -19,8 +19,8 @@ import ( |
|
|
|
type ValidatorListProvider interface { |
|
|
|
type ValidatorListProvider interface { |
|
|
|
Compute( |
|
|
|
Compute( |
|
|
|
epoch *big.Int, reader DataProvider, |
|
|
|
epoch *big.Int, reader DataProvider, |
|
|
|
) (shard.State, error) |
|
|
|
) (*shard.State, error) |
|
|
|
ReadFromDB(epoch *big.Int, reader DataProvider) (shard.State, error) |
|
|
|
ReadFromDB(epoch *big.Int, reader DataProvider) (*shard.State, error) |
|
|
|
GetCommitteePublicKeys(committee *shard.Committee) []*bls.PublicKey |
|
|
|
GetCommitteePublicKeys(committee *shard.Committee) []*bls.PublicKey |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -41,7 +41,7 @@ type ChainReader interface { |
|
|
|
// ReadShardState retrieves sharding state given the epoch number.
|
|
|
|
// ReadShardState retrieves sharding state given the epoch number.
|
|
|
|
// This api reads the shard state cached or saved on the chaindb.
|
|
|
|
// This api reads the shard state cached or saved on the chaindb.
|
|
|
|
// Thus, only should be used to read the shard state of the current chain.
|
|
|
|
// Thus, only should be used to read the shard state of the current chain.
|
|
|
|
ReadShardState(epoch *big.Int) (shard.State, error) |
|
|
|
ReadShardState(epoch *big.Int) (*shard.State, error) |
|
|
|
// GetHeader retrieves a block header from the database by hash and number.
|
|
|
|
// GetHeader retrieves a block header from the database by hash and number.
|
|
|
|
GetHeaderByHash(common.Hash) *block.Header |
|
|
|
GetHeaderByHash(common.Hash) *block.Header |
|
|
|
// Config retrieves the blockchain's chain configuration.
|
|
|
|
// Config retrieves the blockchain's chain configuration.
|
|
|
@ -61,13 +61,13 @@ var ( |
|
|
|
WithStakingEnabled Reader = partialStakingEnabled{} |
|
|
|
WithStakingEnabled Reader = partialStakingEnabled{} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func preStakingEnabledCommittee(s shardingconfig.Instance) shard.State { |
|
|
|
func preStakingEnabledCommittee(s shardingconfig.Instance) *shard.State { |
|
|
|
shardNum := int(s.NumShards()) |
|
|
|
shardNum := int(s.NumShards()) |
|
|
|
shardHarmonyNodes := s.NumHarmonyOperatedNodesPerShard() |
|
|
|
shardHarmonyNodes := s.NumHarmonyOperatedNodesPerShard() |
|
|
|
shardSize := s.NumNodesPerShard() |
|
|
|
shardSize := s.NumNodesPerShard() |
|
|
|
hmyAccounts := s.HmyAccounts() |
|
|
|
hmyAccounts := s.HmyAccounts() |
|
|
|
fnAccounts := s.FnAccounts() |
|
|
|
fnAccounts := s.FnAccounts() |
|
|
|
shardState := shard.State{} |
|
|
|
shardState := &shard.State{} |
|
|
|
// Shard state needs to be sorted by shard ID
|
|
|
|
// Shard state needs to be sorted by shard ID
|
|
|
|
for i := 0; i < shardNum; i++ { |
|
|
|
for i := 0; i < shardNum; i++ { |
|
|
|
com := shard.Committee{ShardID: uint32(i)} |
|
|
|
com := shard.Committee{ShardID: uint32(i)} |
|
|
@ -100,14 +100,14 @@ func preStakingEnabledCommittee(s shardingconfig.Instance) shard.State { |
|
|
|
} |
|
|
|
} |
|
|
|
com.Slots = append(com.Slots, curNodeID) |
|
|
|
com.Slots = append(com.Slots, curNodeID) |
|
|
|
} |
|
|
|
} |
|
|
|
shardState = append(shardState, com) |
|
|
|
shardState.Shards = append(shardState.Shards, com) |
|
|
|
} |
|
|
|
} |
|
|
|
return shardState |
|
|
|
return shardState |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func eposStakedCommittee( |
|
|
|
func eposStakedCommittee( |
|
|
|
s shardingconfig.Instance, stakerReader DataProvider, stakedSlotsCount int, |
|
|
|
s shardingconfig.Instance, stakerReader DataProvider, stakedSlotsCount int, |
|
|
|
) (shard.State, error) { |
|
|
|
) (*shard.State, error) { |
|
|
|
// TODO Nervous about this because overtime the list will become quite large
|
|
|
|
// TODO Nervous about this because overtime the list will become quite large
|
|
|
|
candidates := stakerReader.ValidatorCandidates() |
|
|
|
candidates := stakerReader.ValidatorCandidates() |
|
|
|
essentials := map[common.Address]effective.SlotOrder{} |
|
|
|
essentials := map[common.Address]effective.SlotOrder{} |
|
|
@ -134,21 +134,23 @@ func eposStakedCommittee( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shardCount := int(s.NumShards()) |
|
|
|
shardCount := int(s.NumShards()) |
|
|
|
superComm := make(shard.State, shardCount) |
|
|
|
|
|
|
|
|
|
|
|
shardState := &shard.State{} |
|
|
|
|
|
|
|
shardState.Shards = make([]shard.Committee, shardCount) |
|
|
|
hAccounts := s.HmyAccounts() |
|
|
|
hAccounts := s.HmyAccounts() |
|
|
|
|
|
|
|
|
|
|
|
// Shard state needs to be sorted by shard ID
|
|
|
|
// Shard state needs to be sorted by shard ID
|
|
|
|
for i := 0; i < shardCount; i++ { |
|
|
|
for i := 0; i < shardCount; i++ { |
|
|
|
superComm[i] = shard.Committee{uint32(i), shard.SlotList{}} |
|
|
|
shardState.Shards[i] = shard.Committee{uint32(i), shard.SlotList{}} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i := range hAccounts { |
|
|
|
for i := range hAccounts { |
|
|
|
spot := i % shardCount |
|
|
|
shardID := i % shardCount |
|
|
|
pub := &bls.PublicKey{} |
|
|
|
pub := &bls.PublicKey{} |
|
|
|
pub.DeserializeHexStr(hAccounts[i].BlsPublicKey) |
|
|
|
pub.DeserializeHexStr(hAccounts[i].BlsPublicKey) |
|
|
|
pubKey := shard.BlsPublicKey{} |
|
|
|
pubKey := shard.BlsPublicKey{} |
|
|
|
pubKey.FromLibBLSPublicKey(pub) |
|
|
|
pubKey.FromLibBLSPublicKey(pub) |
|
|
|
superComm[spot].Slots = append(superComm[spot].Slots, shard.Slot{ |
|
|
|
shardState.Shards[shardID].Slots = append(shardState.Shards[shardID].Slots, shard.Slot{ |
|
|
|
common2.ParseAddr(hAccounts[i].Address), |
|
|
|
common2.ParseAddr(hAccounts[i].Address), |
|
|
|
pubKey, |
|
|
|
pubKey, |
|
|
|
nil, |
|
|
|
nil, |
|
|
@ -158,7 +160,7 @@ func eposStakedCommittee( |
|
|
|
if stakedSlotsCount == 0 { |
|
|
|
if stakedSlotsCount == 0 { |
|
|
|
utils.Logger().Info().Int("slots-for-epos", stakedSlotsCount). |
|
|
|
utils.Logger().Info().Int("slots-for-epos", stakedSlotsCount). |
|
|
|
Msg("committe composed only of harmony node") |
|
|
|
Msg("committe composed only of harmony node") |
|
|
|
return superComm, nil |
|
|
|
return shardState, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
staked := effective.Apply(essentials, stakedSlotsCount) |
|
|
|
staked := effective.Apply(essentials, stakedSlotsCount) |
|
|
@ -170,9 +172,9 @@ func eposStakedCommittee( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < stakedSlotsCount; i++ { |
|
|
|
for i := 0; i < stakedSlotsCount; i++ { |
|
|
|
bucket := int(new(big.Int).Mod(staked[i].BlsPublicKey.Big(), shardBig).Int64()) |
|
|
|
shardID := int(new(big.Int).Mod(staked[i].BlsPublicKey.Big(), shardBig).Int64()) |
|
|
|
slot := staked[i] |
|
|
|
slot := staked[i] |
|
|
|
superComm[bucket].Slots = append(superComm[bucket].Slots, shard.Slot{ |
|
|
|
shardState.Shards[shardID].Slots = append(shardState.Shards[shardID].Slots, shard.Slot{ |
|
|
|
slot.Address, |
|
|
|
slot.Address, |
|
|
|
staked[i].BlsPublicKey, |
|
|
|
staked[i].BlsPublicKey, |
|
|
|
&slot.Dec, |
|
|
|
&slot.Dec, |
|
|
@ -180,10 +182,10 @@ func eposStakedCommittee( |
|
|
|
} |
|
|
|
} |
|
|
|
if c := len(candidates); c != 0 { |
|
|
|
if c := len(candidates); c != 0 { |
|
|
|
utils.Logger().Info().Int("staked-candidates", c). |
|
|
|
utils.Logger().Info().Int("staked-candidates", c). |
|
|
|
RawJSON("staked-super-committee", []byte(superComm.JSON())). |
|
|
|
RawJSON("staked-super-committee", []byte(shardState.JSON())). |
|
|
|
Msg("EPoS based super-committe") |
|
|
|
Msg("EPoS based super-committe") |
|
|
|
} |
|
|
|
} |
|
|
|
return superComm, nil |
|
|
|
return shardState, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetCommitteePublicKeys returns the public keys of a shard
|
|
|
|
// GetCommitteePublicKeys returns the public keys of a shard
|
|
|
@ -201,14 +203,14 @@ func (def partialStakingEnabled) GetCommitteePublicKeys(committee *shard.Committ |
|
|
|
|
|
|
|
|
|
|
|
func (def partialStakingEnabled) ReadFromDB( |
|
|
|
func (def partialStakingEnabled) ReadFromDB( |
|
|
|
epoch *big.Int, reader DataProvider, |
|
|
|
epoch *big.Int, reader DataProvider, |
|
|
|
) (newSuperComm shard.State, err error) { |
|
|
|
) (newSuperComm *shard.State, err error) { |
|
|
|
return reader.ReadShardState(epoch) |
|
|
|
return reader.ReadShardState(epoch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ReadFromComputation is single entry point for reading the State of the network
|
|
|
|
// ReadFromComputation is single entry point for reading the State of the network
|
|
|
|
func (def partialStakingEnabled) Compute( |
|
|
|
func (def partialStakingEnabled) Compute( |
|
|
|
epoch *big.Int, stakerReader DataProvider, |
|
|
|
epoch *big.Int, stakerReader DataProvider, |
|
|
|
) (newSuperComm shard.State, err error) { |
|
|
|
) (newSuperComm *shard.State, err error) { |
|
|
|
preStaking := true |
|
|
|
preStaking := true |
|
|
|
if stakerReader != nil { |
|
|
|
if stakerReader != nil { |
|
|
|
config := stakerReader.Config() |
|
|
|
config := stakerReader.Config() |
|
|
|