Repository navigation
Roll back burns and buyers with the index, and pay rewards only on settled mints - #51
Merged
Merged
Conversation
…ttled mints A Core re-parse or reorg now also takes back the chain-derived rows the first rollback missed: token burns after the fork (with the launches' burned supply and the burn count restated), buyers whose every buy was after it, and the community rollup, which is marked stale so the next tick rebuilds it instead of waiting hours. The burn scan's cursors are Core's tx_index and event_index, which a re-parse hands out again from the fork, so they cannot be rewound to a block. The rollback leaves a marker instead; the next scan re-reads by block from there, resets both cursors to what the node now has, and clears the marker with them. Announcement keys keep it from reposting. Telegram announcements and reward records stay, since they record things that happened off the chain. reward-batch.mjs now counts only mints six confirmations deep (tip - 5 or older), so a reorg cannot change who a frozen batch paid.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #47. Rule: what comes from the chain is rolled back; what records something that happened off it is not.
rollbackIndexTo now also:
token_burnsafter the block, restateslaunches.burned_quantityfor the launches those burns touched (same sum asreconcileBurnedSupply, only the surviving burns), and restatesburn_totals(its count is kept by an insert-only trigger);behavior_buyersrows whose every buy was after the block (the asset refold adds back the ones still true);behavior_totals.buyersis then recomputed by the rollup that already runs after a rollback;community_rollup_staleinchain_state, read byhasCommunityRollup) so the next tick rebuilds it from the remaining mints instead of waiting up to six hours. Using a marker instead of deleting the row means the public endpoint never shows zeros in between.Burn cursors. The burn scan reads from two cursors of its own: Core
tx_indexfor receives andevent_indexfor destructions. A re-parse hands those numbers out again from the fork, so the cursors can't be rewound to a block number. The rollback setstelegram_burn_rescan_from_blockto block + 1 instead, and a later rollback can only move it lower. On its next run the scan reads both feeds newest-first until it reaches a row below that block, then sets both cursors to the node's newest values, which can be lower than the old ones.advanceBurnCursordoes that write without the usual monotonic guard and clears the marker in the same batch, and only if the marker still names the block it re-read from. Burns that come back are not announced twice, because announcements are deduplicated by key inannounced.Left alone on purpose:
announced,announcement_workand the reward tables. There is now a comment inrollbackIndexTosaying why.Reward safety.
scripts/reward-batch.mjshad no confirmation buffer: it took the first N conforming mints, including mints in the tip block. Its query now lives inscripts/lib/reward-eligibility.mjsand only counts mints atblock_index <= tip - 5(six confirmations, wheretipis Counterparty's parsed height or--height). If mint #N is not that deep yet the script refuses to run. The manifest recordssettled_through_block, anddocs/reward-distributions.mdstep 1 says the same.reward_accountsis a display rollup that is already rebuilt after a rollback, so it is unchanged.Tests (
tests/api-indexer-safety.test.ts, real migrations on node:sqlite):announceduntouched, the community rollup going stale;Gates run locally:
npm run check(111 files, 1425 tests, both typechecks, lint, numeric, i18n),next build,wrangler deploy --dry-run.