Repository navigation
Consolidate UTXOs, start-up wait for the asset rebuild, GUI asset fixes, CompressAmount range - #295
Merged
Merged
Conversation
The dialog took its coins from listCoins(), which includes locked coins, and selected them like any other, so a coin the user had locked was spent. Coins are now taken by one rule in the list and in the run: within the input amounts, confirmed, not locked. Unconfirmed coins are left for a later run. The coin a batch made was listed again at once, and when it fell within the input amounts the next batch spent it. Two batches of 500 inputs chained that way are more than the mempool takes as one family, and the wallet keeps a transaction the mempool refused. Also: - a batch spends the coins selected for it and no others (m_allow_other_inputs was left on); - a coin too large for what is left of a batch is passed over for a smaller one, where the selection used to stop at it within an address; - the coins are counted from the wallet for each batch, not kept in a counter, and the progress goes by coins: the estimate of the batches to come went by the coins-per-batch limit alone, and the amount limit is often the one that binds; - a selection worth 0.001 AVN or less ends the run; it was skipped with nothing changed, so the loop went round until it was cancelled; - a run that ends normally is reported with an information box, not a warning; - the dialog does not run on a wallet without private keys. From reading: it would have committed transactions without signatures. A test drives the dialog on a regtest wallet: 520 small coins go into a transaction of 500 inputs and one of 20, and block rewards go 16 to a batch under an amount limit. Each transaction is accepted by the mempool, pays one output to the address, costs 1000 per 1000 bytes, which is the least a 4.x node relays, and is taken by a block. Before the change the test failed on the locked coin, which was spent; everything else it checks passed then too.
The rebuild runs in the initload thread under cs_main. AppInitMain did not
wait for it: with a chain tip already loaded it went straight on to start
the node, and needed cs_main on the way. Which thread took the lock first
decided what happened:
- AppInitMain first: "Done loading", the network threads and the GUI window
came up while the rebuild had only begun, on an asset database half
rebuilt.
- the rebuild first: AppInitMain waited for the lock, past its last check
for a shutdown request. When the rebuild was interrupted it got the lock
and finished the start-up as if nothing had happened.
A shutdown request during the rebuild (q on the splash screen) therefore
left a GUI running on a database that was not rebuilt. Seen on Linux with
the GUI and a copy of mainnet: the window was up, the request was not acted
on, and the process had to be killed. On Windows the same key press was
reported to crash the wallet with a heap corruption.
AppInitMain now waits until the initload thread is done with the asset
database and returns false if a shutdown was requested meanwhile. On the
same data the GUI stops within a second of the request ("Shutdown done"),
the next start says an earlier rebuild did not finish, rebuilds, and reports
"Done loading" only after it.
AssetAmountField::setUnit() stored the decimals and did nothing with them: every asset was shown and entered with eight. The spin box now formats an amount with the decimals of the asset and takes no amount finer than that. The value stays in base units of 0.00000001 as before. 4.x did this through its own unit formatting.
…restricted asset Locks. Eight places in the asset pages took cs_wallet or cs_main and then opened a message box in the same scope: the freeze and tag handlers with their confirmation, error and success boxes, the two Check buttons, and the "sent" boxes of Create, Manage and Transfer Assets. With cs_wallet held the wallet cannot take in a block, with cs_main the node cannot connect one, until the user answers. The wallet functions called there take cs_wallet themselves, so those locks are gone; the two Check handlers hold cs_main for the lookup only. Change of a restricted asset. A transfer of part of a restricted asset sent the rest to a new address of the wallet, which has none of the tags the verifier string asks for, and the node refused the transaction (bad-txns-null-verifier-address-failed-verification). The change now goes back to an address the asset is being spent from that passes the verifier, which is what 4.x did. A change address named by the caller that fails is refused with a message that says why. Checked on regtest: 100 of 1000 $RST sent to a tagged address, 900 back to the tagged holder, in the mempool; before the change the same call was rejected. Custom change address. On Transfer Assets it was passed on for the asset change only when coins were selected too. On all three pages a change address that is not a key hash address is refused when it is entered: it is given an asset output.
…allet, two warnings Transaction list. An asset output was decomposed like a payment in coins and read "Sent to" or "Received with" 0.00 AVN. The record now knows four more kinds of row, as 4.x had: an asset issued, reissued, sent and received, with the amount of the asset and its name in the amount column. An asset output that stays in the wallet of a transaction the wallet made is not a payment and has no debit row; a transfer between the wallet's own addresses has no row at all. The fee of a transaction is put on its first payment in coins, and a plain asset transfer has none, so it gets a fee row. The type filter has an Assets entry. The amount role of an asset row stays 0: sorting, the amount filter and the balloon work in coins. Asset lists. Transfer Assets filled its list of assets on the first visit and never again; 4.x refreshed it on every new transaction. It and Create Assets now follow the asset model, which changes when the wallet's asset balances do, and keep what is selected. Warnings. Create Assets, Manage Assets and the two restricted asset actions ask before sending while the node is in initial block download, as Send and Transfer Assets do. The PSBT dialog asks before signing with NONE or SINGLE. A test issues an asset with one decimal, sends 100.5 of it to a foreign address and reads the rows of the table model: "Asset issued 1000", the owner token, "Asset sent to -100.5", one fee row, no row for the 899.5 of change. The warnings and the list refresh are compiled and not run.
CompressAmount() turns an amount that does not end in a zero into about nine times the amount. With Bitcoin's MAX_MONEY that fits 64 bits with room to spare; Avian's is a thousand times larger, and from 20,496,382,304.12172403 coins up the compressed form wraps around, so the amount read back from the coins database would be another one. No output of a valid chain can hold that much. The subsidy starts at 2500 and halves every 2,100,000 blocks, the founder payment is taken from it, and the sum over all of it is under 10.5 billion. So the database format is left alone: there is no unused value to mark a wide amount with, and a new format would mean rewriting every chainstate for a case that cannot occur. What changes is that the limit has a name, MAX_COMPRESSIBLE_AMOUNT, and a test: the amount at the limit survives, the next one does not, and the coins the subsidy schedule issues on each network stay under it. A change to the schedule that broke this would fail the test. The integer fuzz target asserted the property up to MAX_MONEY, failed, and was excluded from the CI run. It asserts it up to the limit now and is back in the run: a million runs of it under ASan and UBSan found nothing. The coins simulation in coins_tests draws its amounts up to the limit instead of a round ten billion.
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-ups for 5.0.7: the Consolidate UTXOs dialog, a start-up race with the asset database rebuild, the open findings from the comparison of the 5.x GUI with 4.2.1, and the range of
CompressAmount. Six commits, one per subject.Consolidate UTXOs
Checked by driving the dialog on a regtest wallet. It built valid transactions before this change; what it got wrong:
A transaction pays 1 sat/byte, the minimum a 4.x node relays, to one output.
Start-up waits for the asset database rebuild
-reindexassetsand the balance rebuild run in theinitloadthread, undercs_main.AppInitMaindid not wait for them: whichever thread took the lock first decided whether the window, the RPC server and the network came up on a half-built asset database. Quitting during the rebuild (qon the splash screen) then hung or crashed the GUI.Start-up now waits for the rebuild and stops if a shutdown was requested meanwhile. The next start reports that an earlier rebuild did not finish and runs it again.
GUI findings from the 4.2.1 comparison
cs_walletwhile a message box was open, and the two Check handlers of the restricted page heldcs_main. The wallet, or the node, stood still until the box was answered.bad-txns-null-verifier-address-failed-verification). Alsotransferand the other asset RPCs.NONEandSINGLENot in this PR:
wallet/asset_tx.cppsign unconditionally.CompressAmount
CompressAmount()turns an amount that does not end in a zero into about nine times the amount. With Avian'sMAX_MONEYthat no longer fits 64 bits: from 20,496,382,304.12172403 AVN up, the amount read back from the coins database is another one.No output of a valid chain can hold that much: the subsidy schedule issues under 10.5 billion in all. The database format is therefore left alone. There is no unused value to mark a wide amount with, and a new format would mean rewriting every chainstate for a case that cannot occur.
What changes: the limit has a name,
MAX_COMPRESSIBLE_AMOUNT, and a unit test holds the schedule of each network to it. Theintegerfuzz target, which asserted the property up toMAX_MONEYand was excluded from CI for failing, asserts it up to the limit and runs again.How it was checked
Built and run in WSL (clang 18, Qt 6.4). Nothing was run on Windows or macOS.
Unit tests: 167 of 168 suites pass;
script_assets_testsis skipped locally for want of its data directory.Qt tests (
test_avian-qt, offscreen):consolidateDialogTests: 520 coins of 0.04 AVN become transactions of 500 and 20 inputs; block rewards go 16 to a batch with a locked one left alone. Each transaction is in the mempool, has one output, pays 1 sat/byte and is mined. The locked coin check fails without the fix.assetAmountFieldTests: what the field shows and what it refuses for 0, 2 and 8 decimals.assetHistoryTests: issue and transfer of an asset with one decimal give the rows above.Start-up, on a copy of mainnet: SIGTERM sent during the rebuild. Before, the GUI's window and network threads had come up during the rebuild and the process did not exit. Now GUI and daemon log "Shutdown done" within a second; the next start logs that an earlier rebuild did not finish, rebuilds, and reaches "Done loading" only after it.
Restricted change, regtest:
transferof 100 out of a coin of 1000 of a restricted asset. Before: refused. Now: 100 to the buyer, 900 back to the tagged holder, in the mempool. A named change address without the tag is refused with the new message.Fuzz:
integer, 1,027,642 runs under ASan and UBSan, clean.Functional:
mining_sv2.py, the one functional test CI runs, passes.Compiled, not run: the sync warning, the
NONE/SINGLEquestion and the list refresh. Nothing was looked at on screen. A manual pass before release: consolidate with a locked coin in the wallet; quit on the splash screen during-reindexassets; type an amount for an asset with fewer than eight decimals; send part of a restricted asset coin; look at the transaction list after an issue and a transfer; sign a PSBT withSINGLE.