Commit graph

42 commits

Author SHA1 Message Date
MarcoFalke
fa2dada0c9
rpc: Avoid getchaintxstats invalid results 2024-07-02 08:46:02 +02:00
Ava Chow
56ea8ed3d3
Merge bitcoin/bitcoin#29428: test: Assumeutxo: snapshots with less work should not be loaded
df6dc2aaae test: Assumeutxo: snapshots with less work should not be loaded (Hernan Marino)

Pull request description:

  This PR adds a test which checks that snapshots with less accumulated work than the node's active chain, should not be loaded and return with an error. Although in a different context of discussion the missing test was detect in a thread in https://github.com/bitcoin/bitcoin/pull/29394 (see https://github.com/bitcoin/bitcoin/pull/29394#discussion_r1484122214)

ACKs for top commit:
  maflcko:
    utACK df6dc2aaae
  kevkevinpal:
    utACK [df6dc2a](df6dc2aaae)
  achow101:
    ACK df6dc2aaae
  alfonsoromanz:
    Re ACK df6dc2aaae. Make is successful and the test passes.

Tree-SHA512: 07a394b4b288cc8ad3f66ed4e70dcda468db18113e9442eb7215cf491768432d55efaaa5b79d633094917e05475a30f0c5e4f64f8f2da293ba306891b4485560
2024-06-04 19:13:03 -04:00
Fabian Jahr
efc1b5be8a
test: Add coverage for txid coins count check when loading snapshot 2024-05-24 18:44:05 +02:00
Ava Chow
413844f1c2
Merge bitcoin/bitcoin#29612: rpc: Optimize serialization and enhance metadata of dumptxoutset output
542e13b293 rpc: Enhance metadata of the dumptxoutset output (Fabian Jahr)
4d8e5edbaa assumeutxo: Add documentation on dumptxoutset serialization format (Fabian Jahr)
c14ed7f384 assumeutxo: Add test for changed coin size value (Fabian Jahr)
de95953d87 rpc: Optimize serialization disk space of dumptxoutset (Fabian Jahr)

Pull request description:

  The second attempt at implementing the `dumptxoutset` space optimization as suggested in #25675. Closes #25675.

  This builds on the work done in #26045, addresses open feedback, adds some further improvements (most importantly usage of compact size), documentation, and an additional test.

  The [original snapshot at height 830,000](https://github.com/bitcoin/bitcoin/pull/29551) came in at 10.82 GB. With this change, the same snapshot is 8.94 GB, a reduction of 17.4%.

  This also enhances the metadata of the output file and adds the following data to allow for better error handling and make future upgrades easier:
  - A newly introduced utxo set magic
  - A version number
  - The network magic
  - The block height

ACKs for top commit:
  achow101:
    ACK 542e13b293
  TheCharlatan:
    Re-ACK 542e13b293
  theStack:
    ACK 542e13b293

Tree-SHA512: 0825d30e5c3c364062db3c6cbca4e3c680e6e6d3e259fa70c0c2b2a7020f24a47406a623582040988d5c7745b08649c31110df4c10656aa25f3f27eb35843d99
2024-05-23 12:31:23 -04:00
Hernan Marino
df6dc2aaae test: Assumeutxo: snapshots with less work should not be loaded 2024-05-22 21:06:06 -03:00
Fabian Jahr
542e13b293
rpc: Enhance metadata of the dumptxoutset output
The following data is added:
- A newly introduced utxo set magic
- A version number
- The network magic
- The block height
2024-05-21 13:57:09 +02:00
Fabian Jahr
c14ed7f384
assumeutxo: Add test for changed coin size value 2024-05-21 13:38:09 +02:00
Fabian Jahr
de95953d87
rpc: Optimize serialization disk space of dumptxoutset
Co-authored-by: Aurèle Oulès <aurele@oules.com>
Co-authored-by: TheCharlatan <seb.kung@gmail.com>
2024-05-21 13:38:07 +02:00
Ava Chow
921c61e9a5
Merge bitcoin/bitcoin#29973: test: Assumeutxo: ensure failure when importing a snapshot twice
b259b0e8d3 [Test] Assumeutxo: ensure failure when importing a snapshot twice (Alfonso Roman Zubeldia)

Pull request description:

  I am getting familiar with the `assume_utxo` tests and I found that the scenario of trying to activate a snapshot twice is not covered. This test is to ensure failure when loading a snapshot if there is already a snapshot-based chainstate.

ACKs for top commit:
  fjahr:
    Code review ACK b259b0e8d3
  kevkevinpal:
    tACK [b259b0e](b259b0e8d3)
  achow101:
    ACK b259b0e8d3
  rkrux:
    tACK [b259b0e](b259b0e8d3)

Tree-SHA512: 3510861390d0e40cdad6861b728df04827a1b63e642f3d956aee66ed2770b1cb7e3aa3eb00c62eb9da0544703c943cc5296936c9ebfcac18c719741c354421bb
2024-05-09 11:55:15 -04:00
merge-script
43a66c55ec
Merge bitcoin/bitcoin#30053: test: added test coverage to loadtxoutset could not open file
ee67bba76c test: added test coverage to loadtxoutset (kevkevin)

Pull request description:

  The functional test coverage did not cover the rpc error of "Couldn't open file..." for loadtxoutset and this test adds coverage for it

  This adds coverage to this line
  https://github.com/bitcoin/bitcoin/blob/master/src/rpc/blockchain.cpp#L2777

ACKs for top commit:
  maflcko:
    ACK ee67bba76c
  davidgumberg:
    LGTM ACK ee67bba76c
  rkrux:
    ACK [ee67bba](ee67bba76c)
  alfonsoromanz:
    ACK ee67bba76c. Code looks good to me. I also ran `test/functional/feature_assumeutxo.py` to make sure all tests passes, including this one.
  tdb3:
    ACK for ee67bba76c

Tree-SHA512: 210a7eb928f625d2a8d9acb63ee83cb4aaec9c267e5a0c52ad219c2935466e2cdc68667e30ad29566e6060981587e5bec42805d296f6e60f9b3b13f3330575f2
2024-05-08 16:15:00 +08:00
kevkevin
ee67bba76c
test: added test coverage to loadtxoutset
The functional test coverage did not cover the rpc error of Couldn't
open file for loadtxoutset and this test adds coverage for it
2024-05-06 17:11:22 -05:00
Alfonso Roman Zubeldia
b259b0e8d3 [Test] Assumeutxo: ensure failure when importing a snapshot twice 2024-04-26 10:50:00 -03:00
jrakibi
ec1f1abfef test:Validate UTXO snapshot with coin_height > base_height & amount > money_supply
You can use this tool to decode the utxo snapshot https://github.com/jrakibi/utxo-live
Here’s an overview of how it’s done:
The serialization forma for a UTXO in the snapshot is as follows:
1. Transaction ID (txid) - 32 bytes
2. Output Index (outnum)- 4 bytes
3. VARINT (code) - A varible-length integer encoding the height and whether the transaction is a coinbase. The format of this VARINT is (height << 1) | coinbase_flag.
4. VARINT (amount_v) - A variable-length integer that represents a compressed format of the output amount (in satoshis).

For the test cases mentioned:
* b"\x84\x58" - This value corresponds to a VARINT representing the height and coinbase flag. Once we decode this code, we can extract the height and coinbase using height = code_decoded >> 1 and coinbase = code_decoded & 0x01. In our case, with code_decoded = 728, it results in height = 364 and coinbase = 0.
* b"\xCA\xD2\x8F\x5A" - This byte sequence represents a compressed amount value. The decompression function takes this value and translates it into a full amount in satoshis. In our case, the decompression of this amount translates to a number larger than the maximum allowed value of coins (21 million BTC)

test:Validate UTXO snapshot with coin_height > base_height & amount > money_supply

test:Validate UTXO snapshot with coin_height > base_height & amount > money_supply
2024-04-22 23:37:31 +01:00
Martin Zumsande
b7ba60f81a test: add coverage for -reindex and assumeutxo
Co-authored-by: Fabian Jahr <fjahr@protonmail.com>
2024-03-28 13:22:42 -04:00
TheCharlatan
ddc7872c08
node: Make translations of fatal errors consistent
The extra `bilingual_str` argument of the fatal error notifications and
`node::AbortNode()` is often unused and when used usually contains the
same string as the message argument. It also seems to be confusing,
since it is not consistently used for errors requiring user action. For
example some assumeutxo fatal errors require the user to do something,
but are not translated.

So simplify the fatal error and abort node interfaces by only passing a
translated string. This slightly changes the fatal errors displayed to
the user.

Also de-duplicate the abort error log since it is repeated in noui.cpp.
2024-03-21 16:40:22 +01:00
Ryan Ofsky
ef174e9ed2 test: assumeutxo snapshot block CheckBlockIndex crash test
Add a test for a CheckBlockIndex crash that would happen before previous
"assumeutxo: Get rid of faked nTx and nChainTx values" commit.

The crash was an assert failure in the (pindex->nChainTx == pindex->nTx +
prev_chain_tx) check that would previously happen if the snapshot block was
submitted after loading the snapshot and downloading a few blocks after the
snapshot. In that case ReceivedBlockTransactions() previously would overwrite
the nChainTx value of the submitted snapshot block with a fake value based on
the previous block, so the (pindex->nChainTx == pindex->nTx + prev_chain_tx)
check would later fail on the first block after the snapshot. This test was
originally posted by Martin Zumsande <mzumsande@gmail.com> in
https://github.com/bitcoin/bitcoin/pull/29370#issuecomment-1974096225

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
2024-03-18 11:28:40 -05:00
Ryan Ofsky
0391458d76 test: assumeutxo stale block CheckBlockIndex crash test
Add a test for a CheckBlockIndex crash that would happen before previous
"assumeutxo: Get rid of faked nTx and nChainTx values" commit.

The crash was an assert failure in the (pindex->nChainTx == pindex->nTx +
prev_chain_tx) check that would previously happen if a snapshot was loaded, and
a block was submitted which forked from the chain before the snapshot block and
after the last downloaded background chain block. This block would not be
marked assumed-valid because it would not be an ancestor of the snapshot, and
it would have nTx set, nChainTx unset, and prev->nChainTx set with a fake
value, so the assert would fail. After the fix, prev->nChainTx is unset instead
of being set to a fake value, so the assert succeeds. This test was originally
posted by maflcko in
https://github.com/bitcoin/bitcoin/issues/29261#issuecomment-1918947945

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2024-03-18 11:28:40 -05:00
Ryan Ofsky
ef29c8b662 assumeutxo: Get rid of faked nTx and nChainTx values
The `PopulateAndValidateSnapshot` function introduced in
f6e2da5fb7 from #19806 has been setting fake
`nTx` and `nChainTx` values that can show up in RPC results (see #29328) and
make `CBlockIndex` state hard to reason about, because it is difficult to know
whether the values are real or fake.

Revert to previous behavior of setting `nTx` and `nChainTx` to 0 when the
values are unknown, instead of faking them.

This commit fixes at least two assert failures in the (pindex->nChainTx ==
pindex->nTx + prev_chain_tx) check that would happen previously. Tests for
these failures are added separately in the next two commits.

Compatibility note: This change could result in -checkblockindex failures if a
snapshot was loaded by a previous version of Bitcoin Core and not fully
validated, because fake nTx values will have been saved to the block index. It
would be pretty easy to avoid these failures by adding some compatibility code
to `LoadBlockIndex` and changing `nTx` values from 1 to 0 when they are fake
(when `(pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_TRANSACTIONS`), but a
little simpler not to worry about being compatible in this case.
2024-03-18 11:28:40 -05:00
Ryan Ofsky
f252e687ec assumeutxo test: Add RPC test for fake nTx and nChainTx values
The fake values will be removed in an upcoming commit, so it is useful to have
test coverage confirming the change in behavior.
2024-03-18 11:28:40 -05:00
Fabian Jahr
1ec6684b08
test: Add test for loadtxoutset when headers are not synced 2024-02-26 18:26:26 +01:00
Fabian Jahr
2bc1ecfaa9
test: Remove unnecessary sync_blocks in assumeutxo tests
The nodes are not connected at this point and no blocks have been mined, so it does not seem do anything
2024-02-26 17:04:46 +01:00
Hernan Marino
8d20602e55 test, assumeutxo: Add test to ensure failure when mempool not empty 2024-02-09 00:30:17 -03:00
MarcoFalke
fa5cd66f0a
test: Assumeutxo with more than just coinbase transactions 2024-01-31 12:39:51 +01:00
Sebastian Falbesoner
931575418e test: assumeutxo: spend coin from snapshot chainstate after loading
Check that an UTXO that is only available in the snapshot chainstate
is also visible to the mempool by submitting a spending transaction.
2024-01-10 01:18:27 +01:00
fanquake
22025d06e5
Merge bitcoin/bitcoin#28605: Fix typos
43de4d3630 doc: fix typos (Sjors Provoost)

Pull request description:

  This PR fixes typos found by lint-spelling.py using codespell 2.2.6.

  Our CI linter job uses codespell 2.2.5 and found fewer typos that I did locally. In any case it's happy now.

ACKs for top commit:
  pablomartin4btc:
    re ACK 43de4d3630

Tree-SHA512: c032fe86cb49c924a468385653b31f309a9db68c478d70335bba3e65a1ff3826abe80284fe00a090ab5a509e1edbf17e476f6922fb15d055e50f1103dad2ccb0
2023-11-16 10:35:49 +00:00
pablomartin4btc
7de7685372 test, assumeutxo: Use assert_debug_log for error details
This is a follow-up on the invalid hash dump fix PR #28698.

https://github.com/bitcoin/bitcoin/pull/28698#pullrequestreview-1698178157
2023-11-09 18:54:27 -03:00
Sjors Provoost
43de4d3630
doc: fix typos
As found by lint-spelling.py using codespell 2.2.6.
2023-11-07 10:21:51 +09:00
pablomartin4btc
811067ca1c test: add coverage for snapshot chainstate not matching AssumeUTXO parameters
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
2023-10-25 11:14:43 -03:00
Fabian Jahr
351370a1d2
coinstats: Fix hash_serialized2 calculation
The legacy serialization was vulnerable to maleation and is fixed by
adopting the same serialization procedure as was already in use for
MuHash.

This also includes necessary test fixes where the hash_serialized2 was
hardcoded as well as correction of the regtest chainparams.

Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
2023-10-20 22:53:05 +02:00
Fabian Jahr
d3223685b1
test: De-dublicate/optimize assumeutxo test for further extensions 2023-10-20 14:39:23 +02:00
Fabian Jahr
0a576d62fe
test: check au file with changed outpoint index 2023-10-20 14:39:21 +02:00
Ryan Ofsky
655dc716aa
Merge bitcoin/bitcoin#28666: test: assumeutxo file with unknown block hash
621db2f004 test: assumeutxo file with unknown block hash (Fabian Jahr)

Pull request description:

  Takes care of one of the open Todos in the assumeutxo functional test. Since an unknown block could be any hash, I simply chose one placeholder, it could also be a random string though.

ACKs for top commit:
  maflcko:
    lgtm ACK 621db2f004
  pablomartin4btc:
    cr ACK 621db2f004
  theStack:
    ACK 621db2f004
  ryanofsky:
    Code review ACK 621db2f004

Tree-SHA512: ee0438ce619f7348c6f88e39b0ea7ddddb8832956d9034ecc795c6033d5d905c09d11b7d0d5afc38231b2fd091ea7c1bd0a0be99d9c32c4e6357a25d76294142
2023-10-18 08:18:48 -04:00
Fabian Jahr
621db2f004
test: assumeutxo file with unknown block hash 2023-10-17 17:12:29 +02:00
MarcoFalke
fa68571566
test: Add assumeutxo test for wrong hash 2023-10-17 13:24:07 +02:00
Sebastian Falbesoner
9620cb4493 assumeutxo: fail early if snapshot block hash doesn't match AssumeUTXO parameters 2023-10-16 17:20:59 +02:00
MarcoFalke
fafde92f84
test: Check snapshot file with wrong number of coins
Also, fix a bug in an assert_debug_log call.
2023-10-12 11:14:56 +02:00
Sebastian Falbesoner
2e31250027 test: check that loading snapshot not matching AssumeUTXO parameters fails 2023-10-10 09:43:10 +02:00
Fabian Jahr
4e915e926b
test: Improvements of feature_assumeutxo
- Remove usage of the internal wait_until_helper function
- Use framework self.no_op instead of new no_sync function

co-authored-by: Andrew Chow <github@achow101.com>
2023-10-06 18:39:02 +02:00
Ryan Ofsky
a9ef702a87 assumeutxo: change getchainstates RPC to return a list of chainstates
Current getchainstates RPC returns "normal" and "snapshot" fields which are not
ideal because it requires new "normal" and "snapshot" terms to be defined, and
the definitions are not really consistent with internal code. (In the RPC
interface, the "snapshot" chainstate becomes the "normal" chainstate after it
is validated, while in internal code there is no "normal chainstate" and the
"snapshot chainstate" is still called that temporarily after it is validated).

The current getchainstatees RPC is also awkward to use if you to want
information about the most-work chainstate because you have to look at the
"snapshot" field if it exists, and otherwise fall back to the "normal" field.

Fix these issues by having getchainstates just return a flat list of
chainstates ordered by work, and adding new chainstate "validated" field
alongside the existing "snapshot_blockhash" so it is explicit if a chainstate
was originally loaded from a snapshot, and whether the snapshot has been
validated.
2023-10-05 09:41:43 -04:00
James O'Beirne
7e40032260 tests: assumeutxo: accept final height from either chainstate 2023-10-04 11:32:36 -04:00
James O'Beirne
5bd2010f02 test: assumeutxo: avoid race in functional test 2023-10-04 11:05:27 -04:00
James O'Beirne
42cae39356 test: add feature_assumeutxo functional test
Most ideas for test improvements (TODOs) provided by Russ Yanofsky.
2023-09-30 06:41:23 -04:00