Skip to content
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

ledger: Exclude stake at R-320 that is expired by R #5403

Merged
merged 1 commit into from May 19, 2023

Conversation

algorandskiy
Copy link
Contributor

Summary

This adds a DB method to calculate the total expired stake registered at rnd that is expired by voteRnd.

It adds a consensus check to the ledger implementation of the Circulation(rnd) call that agreement makes, which in turn calls onlineAccounts.onlineTotals. If ExcludeExpiredCirculation is set, it subtracts expired stake at rnd+320 from the total online stake at rnd.

Details:

  • when the next round is going to be round R, a proposal/vote will come in for round R (or some other trigger we could add)
  • query the DB's onlineaccounts table looking for accounts online at R that are expired in any round before R+320 (this using the "updated as of rnd" and "expired by rnd" indexes)
  • sum up the expired online stake for these accounts
  • subtract expired stake from total online stake and put in cache to use for all votes seen for R

Test Plan

New unit tests added

This adds a DB method to calculate the total expired stake registered at rnd that is expired by voteRnd.

It adds a consensus check to the ledger implementation of the Circulation(rnd) call that agreement makes, which in turn calls onlineAccounts.onlineTotals. If ExcludeExpiredCirculation is set, it subtracts expired stake at rnd+320 from the total online stake at rnd.

Details:
* when the next round is going to be round R, a proposal/vote will come in for round R (or some other trigger we could add)
* query the DB's onlineaccounts table looking for accounts online at R that are expired in any round before R+320 (this using the "updated as of rnd" and "expired by rnd" indexes)
* sum up the expired online stake for these accounts
* subtract expired stake from total online stake and put in cache to use for all votes seen for R

Co-authored-by: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com>
@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #5403 (ed14cbb) into master (5e1f8a2) will decrease coverage by 1.00%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##           master    #5403      +/-   ##
==========================================
- Coverage   55.42%   54.43%   -1.00%     
==========================================
  Files         452      452              
  Lines       63689    63812     +123     
==========================================
- Hits        35302    34733     -569     
- Misses      25972    26603     +631     
- Partials     2415     2476      +61     
Impacted Files Coverage Δ
agreement/abstractions.go 50.00% <ø> (ø)
data/ledger.go 30.96% <0.00%> (-0.21%) ⬇️
ledger/acctupdates.go 70.63% <ø> (-0.25%) ⬇️
ledger/store/trackerdb/sqlitedriver/accountsV2.go 14.53% <0.00%> (-0.95%) ⬇️
ledger/store/trackerdb/sqlitedriver/schema.go 50.71% <0.00%> (-0.32%) ⬇️
ledger/store/trackerdb/sqlitedriver/trackerdbV2.go 0.00% <0.00%> (ø)
ledger/testing/testGenesis.go 0.00% <0.00%> (ø)
ledger/acctonline.go 78.89% <76.59%> (-1.24%) ⬇️
agreement/selector.go 73.33% <100.00%> (ø)
config/consensus.go 85.85% <100.00%> (+0.03%) ⬆️
... and 1 more

... and 65 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +43 to +51
type simpleLedgerOption func(*simpleLedgerCfg)

func simpleLedgerOnDisk() simpleLedgerOption {
return func(cfg *simpleLedgerCfg) { cfg.onDisk = true }
}

func simpleLedgerNotArchival() simpleLedgerOption {
return func(cfg *simpleLedgerCfg) { cfg.notArchival = true }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat 👍

Copy link
Contributor

@bbroder-algo bbroder-algo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch removes expired voting stake totals from the total online stake for the agreement implementation. It adds a table scan and a sort of the onlineaccounts table to the calculation, and includes a lock-held synchronization check to guard against asynchronous DB advancement.

@bbroder-algo bbroder-algo merged commit b684243 into master May 19, 2023
29 checks passed
@winder winder deleted the feature/online-circulation-on-demand branch May 19, 2023 19:27
tzaffi pushed a commit to tzaffi/go-algorand that referenced this pull request May 22, 2023
wip

netdeploy: Copy ledger directory for kv tracker database (algorand#5392)

assembler: Error if extra args are present in pragmas (algorand#5400)

ledger: Exclude stake at R-320 that is expired by R (algorand#5403)

Co-authored-by: cce <51567+cce@users.noreply.github.com>

algod: Don't return a top level array from algod (algorand#5404)

revert

go get github.com/algorand/msgp@v1.1.53

go get github.com/getkin/kin-openapi@v0.107.0

go mod tidy -compat=1.17

go get github.com/algorand/msgp@v1.1.50

go mod tidy -compat=1.17

go get github.com/algorand/msgp@v1.1.50

revert to master

github.com/getkin/kin-openapi v0.117.0

github.com/getkin/kin-openapi v0.117.0

github.com/getkin/kin-openapi v0.117.0

go get golang.org/x/mod/modfile

tidy #0

go get github.com/algorand/msgp@v1.1.53

go mod tidy

tidy up after every go get

simplify

revert

tidier

tg

tg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants