-
Notifications
You must be signed in to change notification settings - Fork 9
accounting: fill client fee ledger gaps #768
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1b6d0b9
ledger: account round and sweep fee flows
Roasbeef a79b80e
unroll: emit confirmed exit costs
Roasbeef a03ac26
tools: add accounting report command
Roasbeef 4b3da4a
docs: update fee ledger accounting map
Roasbeef 6338034
tools: open accounting DB read-only
Roasbeef b08f6bd
round: scope ledger outflow keys by round
Roasbeef 2667c03
ledger: refresh accounting comments
Roasbeef ec65c5f
ledger: require sweep fee idempotency keys
Roasbeef f081236
accounting: bound CoinGecko response and reject non-finite prices
Roasbeef 2665257
multi: fold boarding sweep ledger emission into one atomic message
Roasbeef b2f3d3e
unroll: defer terminal handoff until exit cost is delivered
Roasbeef ec8f9f3
db: renumber accounting migration to 000020
Roasbeef 4a6a5f6
wallet: doc consolidated boarding sweep ledger emission
Roasbeef 8537990
tools: support postgres and CSV in the accounting report
Roasbeef 2cb10c2
docs: add accounting report command guide
Roasbeef 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
db/sqlc/migrations/000020_accounting_wallet_sweeps.down.sql
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| DROP INDEX IF EXISTS idx_client_ledger_idempotent_round; | ||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_client_ledger_idempotent_round | ||
| ON ledger_entries(round_id, event_type, debit_account, credit_account) | ||
| WHERE round_id IS NOT NULL; | ||
|
|
||
| DELETE FROM ledger_event_types | ||
| WHERE event_type IN ('wallet_utxo_spent', 'wallet_sweep_transfer'); | ||
|
|
||
| DELETE FROM accounts | ||
| WHERE account_id = 'wallet_clearing'; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- Add the clearing account and event types needed to account for | ||
| -- wallet-level sweeps without double-counting internal return outputs. | ||
| INSERT INTO accounts (account_id, account_name, account_type) VALUES | ||
| ('wallet_clearing', 'Wallet Sweep Clearing', 'asset') | ||
| ON CONFLICT DO NOTHING; | ||
|
|
||
| INSERT INTO ledger_event_types (event_type) VALUES | ||
| ('wallet_utxo_spent'), | ||
| ('wallet_sweep_transfer') | ||
| ON CONFLICT DO NOTHING; | ||
|
|
||
| -- Round-scoped events without a specific key remain deduped by | ||
| -- (round_id, event_type, accounts). Events that carry an explicit | ||
| -- idempotency_key, such as per-recipient round sends, are instead | ||
| -- deduped by idx_client_ledger_idempotent_key so multiple sends in | ||
| -- the same round can coexist. | ||
| DROP INDEX IF EXISTS idx_client_ledger_idempotent_round; | ||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_client_ledger_idempotent_round | ||
| ON ledger_entries(round_id, event_type, debit_account, credit_account) | ||
| WHERE round_id IS NOT NULL | ||
| AND idempotency_key IS NULL; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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.
Using an
ORcondition in aLEFT JOIN(e.g.,le.debit_account = a.account_id OR le.credit_account = a.account_id) prevents SQLite from efficiently utilizing indexes ondebit_accountandcredit_account, resulting in full table scans. Sinceledger_entriescan grow very large in production, this query will become a performance bottleneck. Rewriting the query to use two correlated subqueries allows SQLite to perform highly efficient index lookups.