-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incentives: cache top online accounts and use when building AbsentParticipationAccounts #6085
Open
cce
wants to merge
25
commits into
algorand:master
Choose a base branch
from
cce:track-incentive-candidates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
21db44d
periodically track top N online accounts in Ledger, and use when buil…
cce e968515
run make msgp
cce 8587b28
update votersTracker
cce 38d4b8d
CR fixes
cce 9740ddc
rename and simplify
cce b8b9673
add LastProposed/LastHeartbeat to BaseOnlineAccountData handling
cce 0b7fbad
fill out LastHeartbeat/LastProposed from #5965
cce b2f1130
fix remaining tests
cce 5242990
fix missing AccountData => OnlineAccountData transformation function …
cce 0baf81f
Merge remote-tracking branch 'upstream/master' into track-incentive-c…
cce be464cf
Update ledger/ledger.go
cce 97d0bcf
Update ledger/ledger.go
cce 55d5068
Merge remote-tracking branch 'upstream/master' into track-incentive-c…
cce 01b150a
update TestAbsenteeChecks
cce 0f954d1
Merge remote-tracking branch 'upstream/master' into track-incentive-c…
cce c24e809
also consider candidates for ExpiredParticipationAccounts
cce c252d95
update TestExpiredAccountGeneration
cce bb82a97
Fix TestAbsentTracking
cce 04c0a84
add TestLatestCompletedVotersUpTo
cce c41a49a
don't propose to suspend yourself, and update TestAbsenteeChallenges
cce e476730
Update TestExpiredAccountGeneration
cce 9115aae
update TestAbsenteeChecks for proposer change
cce 23b9996
update TestTotalWeightChanges and update comment on generateKnockOffl…
cce 9bc39aa
update TestEvalFunctionForExpiredAccounts
cce c558d59
update TestOnlineActModel*
cce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ type LedgerForCowBase interface { | |
CheckDup(config.ConsensusParams, basics.Round, basics.Round, basics.Round, transactions.Txid, ledgercore.Txlease) error | ||
LookupWithoutRewards(basics.Round, basics.Address) (ledgercore.AccountData, basics.Round, error) | ||
LookupAgreement(basics.Round, basics.Address) (basics.OnlineAccountData, error) | ||
GetKnockOfflineCandidates(basics.Round, config.ConsensusParams) (map[basics.Address]basics.OnlineAccountData, error) | ||
jannotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LookupAsset(basics.Round, basics.Address, basics.AssetIndex) (ledgercore.AssetResource, error) | ||
LookupApplication(basics.Round, basics.Address, basics.AppIndex) (ledgercore.AppResource, error) | ||
LookupKv(basics.Round, string) ([]byte, error) | ||
|
@@ -237,6 +238,10 @@ func (x *roundCowBase) lookupAgreement(addr basics.Address) (basics.OnlineAccoun | |
return ad, err | ||
} | ||
|
||
func (x *roundCowBase) knockOfflineCandidates() (map[basics.Address]basics.OnlineAccountData, error) { | ||
return x.l.GetKnockOfflineCandidates(x.rnd, x.proto) | ||
} | ||
|
||
// onlineStake returns the total online stake as of the start of the round. It | ||
// caches the result to prevent repeated calls to the ledger. | ||
func (x *roundCowBase) onlineStake() (basics.MicroAlgos, error) { | ||
|
@@ -1611,20 +1616,68 @@ func (eval *BlockEvaluator) generateKnockOfflineAccountsList() { | |
if !eval.generate { | ||
return | ||
} | ||
current := eval.Round() | ||
|
||
current := eval.Round() | ||
maxExpirations := eval.proto.MaxProposedExpiredOnlineAccounts | ||
maxSuspensions := eval.proto.Payouts.MaxMarkAbsent | ||
|
||
updates := &eval.block.ParticipationUpdates | ||
|
||
ch := activeChallenge(&eval.proto, uint64(eval.Round()), eval.state) | ||
ch := activeChallenge(&eval.proto, uint64(current), eval.state) | ||
|
||
// Make a set of candidate addresses to check for absentee status. | ||
type candidateData struct { | ||
VoteLastValid basics.Round | ||
VoteID crypto.OneTimeSignatureVerifier | ||
Status basics.Status | ||
LastProposed basics.Round | ||
LastHeartbeat basics.Round | ||
MicroAlgosWithRewards basics.MicroAlgos | ||
IncentiveEligible bool // currently unused below, but may be needed in the future | ||
} | ||
absentCandidates := make(map[basics.Address]candidateData) | ||
|
||
// First, ask the ledger for the top N online accounts, with their latest | ||
// online account data, current up to the previous round. | ||
if maxSuspensions > 0 { | ||
knockOfflineCandidates, err := eval.state.knockOfflineCandidates() | ||
cce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
// Log an error and keep going; generating lists of absent and expired | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this implies some nodes can "choose" not to search for absent/expired accounts. |
||
// accounts is not required by block validation rules. | ||
logging.Base().Warnf("error fetching knockOfflineCandidates: %v", err) | ||
knockOfflineCandidates = nil | ||
} | ||
for accountAddr, acctData := range knockOfflineCandidates { | ||
// acctData is from previous block: doesn't include any updates in mods | ||
absentCandidates[accountAddr] = candidateData{ | ||
VoteLastValid: acctData.VoteLastValid, | ||
VoteID: acctData.VoteID, | ||
Status: basics.Online, // from lookupOnlineAccountData, which only returns online accounts | ||
LastProposed: acctData.LastProposed, | ||
LastHeartbeat: acctData.LastHeartbeat, | ||
MicroAlgosWithRewards: acctData.MicroAlgosWithRewards, | ||
IncentiveEligible: acctData.IncentiveEligible, | ||
} | ||
} | ||
} | ||
|
||
// Then add any accounts modified in this block, with their state at the | ||
// end of the round. | ||
for _, accountAddr := range eval.state.modifiedAccounts() { | ||
acctData, found := eval.state.mods.Accts.GetData(accountAddr) | ||
if !found { | ||
continue | ||
} | ||
// This will overwrite data from the knockOfflineCandidates() list, if they were modified in the current block. | ||
absentCandidates[accountAddr] = candidateData{ | ||
VoteLastValid: acctData.VoteLastValid, | ||
VoteID: acctData.VoteID, | ||
Status: acctData.Status, | ||
jannotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LastProposed: acctData.LastProposed, | ||
LastHeartbeat: acctData.LastHeartbeat, | ||
MicroAlgosWithRewards: acctData.WithUpdatedRewards(eval.proto, eval.state.rewardsLevel()).MicroAlgos, | ||
IncentiveEligible: acctData.IncentiveEligible, | ||
} | ||
|
||
// Regardless of being online or suspended, if voting data exists, the | ||
// account can be expired to remove it. This means an offline account | ||
|
@@ -1637,17 +1690,24 @@ func (eval *BlockEvaluator) generateKnockOfflineAccountsList() { | |
updates.ExpiredParticipationAccounts, | ||
accountAddr, | ||
) | ||
continue // if marking expired, do not also suspend | ||
delete(absentCandidates, accountAddr) // if marking expired, do not also suspend | ||
} | ||
} | ||
} | ||
|
||
// Now, check these candidate accounts to see if they are expired or absent. | ||
for accountAddr, acctData := range absentCandidates { | ||
if acctData.MicroAlgosWithRewards.IsZero() { | ||
continue // should only happen in tests; prevents panic in isAbsent | ||
} | ||
|
||
if len(updates.AbsentParticipationAccounts) >= maxSuspensions { | ||
continue // no more room (don't break the loop, since we may have more expiries) | ||
} | ||
|
||
if acctData.Status == basics.Online { | ||
lastSeen := max(acctData.LastProposed, acctData.LastHeartbeat) | ||
if isAbsent(eval.state.prevTotals.Online.Money, acctData.MicroAlgos, lastSeen, current) || | ||
if isAbsent(eval.state.prevTotals.Online.Money, acctData.MicroAlgosWithRewards, lastSeen, current) || | ||
jannotti marked this conversation as resolved.
Show resolved
Hide resolved
gmalouf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
failsChallenge(ch, accountAddr, lastSeen) { | ||
updates.AbsentParticipationAccounts = append( | ||
updates.AbsentParticipationAccounts, | ||
|
@@ -1658,14 +1718,6 @@ func (eval *BlockEvaluator) generateKnockOfflineAccountsList() { | |
} | ||
} | ||
|
||
// delete me in Go 1.21 | ||
func max(a, b basics.Round) basics.Round { | ||
if a > b { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
// bitsMatch checks if the first n bits of two byte slices match. Written to | ||
// work on arbitrary slices, but we expect that n is small. Only user today | ||
// calls with n=5. | ||
|
@@ -1821,6 +1873,9 @@ func (eval *BlockEvaluator) validateAbsentOnlineAccounts() error { | |
if acctData.Status != basics.Online { | ||
return fmt.Errorf("proposed absent account %v was %v, not Online", accountAddr, acctData.Status) | ||
} | ||
if acctData.MicroAlgos.IsZero() { | ||
return fmt.Errorf("proposed absent account %v with zero algos", accountAddr) | ||
} | ||
jannotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
lastSeen := max(acctData.LastProposed, acctData.LastHeartbeat) | ||
if isAbsent(eval.state.prevTotals.Online.Money, acctData.MicroAlgos, lastSeen, eval.Round()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -638,10 +638,39 @@ func (l *Ledger) LookupAgreement(rnd basics.Round, addr basics.Address) (basics. | |
defer l.trackerMu.RUnlock() | ||
|
||
// Intentionally apply (pending) rewards up to rnd. | ||
data, err := l.acctsOnline.LookupOnlineAccountData(rnd, addr) | ||
data, err := l.acctsOnline.lookupOnlineAccountData(rnd, addr) | ||
return data, err | ||
} | ||
|
||
// GetKnockOfflineCandidates retrieves a list of online accounts who will be | ||
// checked to a recent proposal or heartbeat. Large accounts are the ones worth checking. | ||
func (l *Ledger) GetKnockOfflineCandidates(rnd basics.Round, proto config.ConsensusParams) (map[basics.Address]basics.OnlineAccountData, error) { | ||
l.trackerMu.RLock() | ||
defer l.trackerMu.RUnlock() | ||
|
||
// get state proof worker's most recent list for top N addresses | ||
if proto.StateProofInterval == 0 { | ||
return nil, nil | ||
} | ||
// get latest state proof voters information, up to rnd, without calling cond.Wait() | ||
_, voters := l.acctsOnline.voters.LatestCompletedVotersUpTo(rnd) | ||
if voters == nil { // no cached voters found < rnd | ||
return nil, nil | ||
} | ||
|
||
// fetch fresh data up to this round from online account cache. These accounts should all | ||
// be in cache, as long as proto.StateProofTopVoters < onlineAccountsCacheMaxSize. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a condition to call out in the consensus file. |
||
ret := make(map[basics.Address]basics.OnlineAccountData) | ||
for addr := range voters.AddrToPos { | ||
data, err := l.acctsOnline.lookupOnlineAccountData(rnd, addr) | ||
if err != nil { | ||
continue // skip missing / not online accounts | ||
} | ||
ret[addr] = data | ||
} | ||
return ret, nil | ||
} | ||
|
||
// LookupWithoutRewards is like Lookup but does not apply pending rewards up | ||
// to the requested round rnd. | ||
func (l *Ledger) LookupWithoutRewards(rnd basics.Round, addr basics.Address) (ledgercore.AccountData, basics.Round, error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a NIT: should we actually call this top online accounts or similar naming? It's very clear from comments that's what we are requesting, more a debate over if the name should be based on what it's sourced from vs the use-case we have for this atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a potentially stale list of top online accounts, if new accounts appeared online in the last 256 rounds (since the last state proof) they wouldn't appear. So the word "candidates" was intended to make it seem a little less definitive that this was the complete list of top online accounts for the round... but happy to pick any other name, I wasn't particularly happy with this name.
This is already being used in a method JJ called "generateKnockOfflineAccountsList" in #5757 which is where the "knockOffline" part came from.