Skip to content

Commit

Permalink
Apply validation sharding on stats collecting (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbidenaio authored and sidenaio committed Sep 16, 2021
1 parent d247c25 commit 52c374a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
8 changes: 4 additions & 4 deletions blockchain/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func rewardValidIdentities(appState *appstate.AppState, config *config.Consensus
totalReward := big.NewInt(0).Add(config.BlockReward, config.FinalCommitteeReward)
currentEpochDuration := epochDurations[len(epochDurations)-1]
totalReward = totalReward.Mul(totalReward, big.NewInt(int64(currentEpochDuration)))
//TODO : update collector
//collector.SetValidationResults(statsCollector, validationResults)
collector.SetValidationResults(statsCollector, validationResults)
collector.SetTotalReward(statsCollector, totalReward)

log.Info("Total validation reward", "reward", ConvertToFloat(totalReward).String())
Expand Down Expand Up @@ -165,7 +164,8 @@ func addFlipReward(appState *appstate.AppState, config *config.ConsensusConf, va
}
}
for i := uint32(1); i <= appState.State.ShardsNum(); i++ {
validationResult, ok := validationResults[common.ShardId(i)]
shardId := common.ShardId(i)
validationResult, ok := validationResults[shardId]
if !ok {
continue
}
Expand All @@ -186,7 +186,7 @@ func addFlipReward(appState *appstate.AppState, config *config.ConsensusConf, va
collector.CompleteBalanceUpdate(statsCollector, appState)
collector.AddMintedCoins(statsCollector, reward)
collector.AddMintedCoins(statsCollector, stake)
collector.AddReportedFlipsReward(statsCollector, rewardDest, reporter.Address, flipIdx, reward, stake)
collector.AddReportedFlipsReward(statsCollector, rewardDest, reporter.Address, shardId, flipIdx, reward, stake)
collector.AfterAddStake(statsCollector, reporter.Address, stake, appState)
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/ceremony/ceremony.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ func (vc *ValidationCeremony) GetShortFlipsToSolve(address common.Address, shard
vc.mutex.Lock()
defer vc.mutex.Unlock()


shard, ok := vc.shardCandidates[shardId]
if !ok {
return nil
Expand Down Expand Up @@ -893,8 +892,10 @@ func applyOnState(cfg *config.ConsensusConf, appState *appstate.AppState, statsC
if cfg.FixDelegation && value.state.NewbieOrBetter() && (value.prevState == state.Suspended || value.prevState == state.Zombie || value.prevState == state.Candidate) && value.delegatee != nil {
transitiveDelegatee := appState.State.Delegatee(*value.delegatee)
if transitiveDelegatee != nil {
value.delegatee = nil
appState.State.RemoveDelegatee(addr)
delegatee := *value.delegatee
value.delegatee = nil
appState.State.RemoveDelegatee(addr)
collector.AddRemovedTransitiveDelegation(statsCollector, addr, delegatee)
}
}

Expand Down Expand Up @@ -924,8 +925,7 @@ func (vc *ValidationCeremony) ApplyNewEpoch(height uint64, appState *appstate.Ap
vc.applyEpochMutex.Lock()
defer vc.applyEpochMutex.Unlock()
defer func() {
//TODO : modify collector to save stats by shards
//collector.SetValidation(statsCollector, vc.validationStats)
collector.SetValidation(statsCollector, vc.validationStats)
}()

if applyingCache, ok := vc.epochApplyingCache[height]; ok {
Expand Down
27 changes: 20 additions & 7 deletions stats/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type StatsCollector interface {
SetValidation(validation *statsTypes.ValidationStats)
SetMinScoreForInvite(score float32)

SetValidationResults(authors *types.ValidationResults)
SetValidationResults(validationResults map[common.ShardId]*types.ValidationResults)

SetTotalReward(amount *big.Int)
SetTotalValidationReward(amount *big.Int, share *big.Int)
Expand All @@ -26,7 +26,7 @@ type StatsCollector interface {
SetTotalZeroWalletFund(amount *big.Int)
AddValidationReward(balanceDest, stakeDest common.Address, age uint16, balance, stake *big.Int)
AddFlipsReward(balanceDest, stakeDest common.Address, balance, stake *big.Int, flipsToReward []*types.FlipToReward)
AddReportedFlipsReward(balanceDest, stakeDest common.Address, flipIdx int, balance, stake *big.Int)
AddReportedFlipsReward(balanceDest, stakeDest common.Address, shardId common.ShardId, flipIdx int, balance, stake *big.Int)
AddInvitationsReward(balanceDest, stakeDest common.Address, balance, stake *big.Int, age uint16, txHash *common.Hash,
epochHeight uint32, isSavedInviteWinner bool)
AddFoundationPayout(addr common.Address, balance *big.Int)
Expand Down Expand Up @@ -116,6 +116,8 @@ type StatsCollector interface {
AddTxReceipt(txReceipt *types.TxReceipt, appState *appstate.AppState)

RemoveMemPoolTx(tx *types.Transaction)

AddRemovedTransitiveDelegation(delegator, delegatee common.Address)
}

type GetBalanceFunc func(address common.Address) *big.Int
Expand Down Expand Up @@ -157,11 +159,11 @@ func SetMinScoreForInvite(c StatsCollector, score float32) {
c.SetMinScoreForInvite(score)
}

func (c *collectorStub) SetValidationResults(validationResults *types.ValidationResults) {
func (c *collectorStub) SetValidationResults(validationResults map[common.ShardId]*types.ValidationResults) {
// do nothing
}

func SetValidationResults(c StatsCollector, validationResults *types.ValidationResults) {
func SetValidationResults(c StatsCollector, validationResults map[common.ShardId]*types.ValidationResults) {
if c == nil {
return
}
Expand Down Expand Up @@ -256,15 +258,15 @@ func AddFlipsReward(c StatsCollector, balanceDest, stakeDest common.Address, bal
c.AddFlipsReward(balanceDest, stakeDest, balance, stake, flipsToReward)
}

func (c *collectorStub) AddReportedFlipsReward(balanceDest, stakeDest common.Address, flipIdx int, balance, stake *big.Int) {
func (c *collectorStub) AddReportedFlipsReward(balanceDest, stakeDest common.Address, shardId common.ShardId, flipIdx int, balance, stake *big.Int) {
// do nothing
}

func AddReportedFlipsReward(c StatsCollector, balanceDest, stakeDest common.Address, flipIdx int, balance, stake *big.Int) {
func AddReportedFlipsReward(c StatsCollector, balanceDest, stakeDest common.Address, shardId common.ShardId, flipIdx int, balance, stake *big.Int) {
if c == nil {
return
}
c.AddReportedFlipsReward(balanceDest, stakeDest, flipIdx, balance, stake)
c.AddReportedFlipsReward(balanceDest, stakeDest, shardId, flipIdx, balance, stake)
}

func (c *collectorStub) AddInvitationsReward(balanceDest, stakeDest common.Address, balance, stake *big.Int, age uint16,
Expand Down Expand Up @@ -1007,3 +1009,14 @@ func AddTxReceipt(c StatsCollector, txReceipt *types.TxReceipt, appState *appsta
}
c.AddTxReceipt(txReceipt, appState)
}

func (c *collectorStub) AddRemovedTransitiveDelegation(delegator, delegatee common.Address) {
// do nothing
}

func AddRemovedTransitiveDelegation(c StatsCollector, delegator, delegatee common.Address) {
if c == nil {
return
}
c.AddRemovedTransitiveDelegation(delegator, delegatee)
}

0 comments on commit 52c374a

Please sign in to comment.