aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_assumeutxo.py
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-07-02 18:02:26 -0400
committerAva Chow <github@achow101.com>2024-07-02 18:02:26 -0400
commit173ab0ccf2164dd8cd3d486559dffda0d4a1a813 (patch)
treee9a080951b904449b68d32ae670f93e0c09d9736 /test/functional/feature_assumeutxo.py
parent3325a0afa45ee88c9e859f1002183f1bd61868da (diff)
parent2342b46c451658a418f8e28e50b2ad0e5abd284d (diff)
downloadbitcoin-173ab0ccf2164dd8cd3d486559dffda0d4a1a813.tar.xz
Merge bitcoin/bitcoin#29720: rpc: Avoid getchaintxstats invalid results
2342b46c451658a418f8e28e50b2ad0e5abd284d test: Add coverage for getchaintxstats in assumeutxo context (Fabian Jahr) faf2a6750b2da97a18c48a3acf9c9da2aebe86d0 rpc: Reorder getchaintxstats output (MarcoFalke) fa2dada0c9ab61266bcca86fcd28ced873976916 rpc: Avoid getchaintxstats invalid results (MarcoFalke) Pull request description: The `getchaintxstats` RPC reply during AU background download may return non-zero, but invalid, values for `window_tx_count` and `txrate`. For example, `txcount` may be zero for a to-be-downloaded block, but may be non-zero for an ancestor block which is already downloaded. Thus, the values returned may be negative (and cause intermediate integer sanitizer violations). Also, `txcount` may be accurate for the snapshot base block, or a descendant of it. However it may be zero for an ancestor block that still needs to be downloaded. Thus, the values returned may be positive, but wrong. Fix all issues by skipping the returned value if either `txcount` is unset (equal to zero). Also, skip `txcount` in the returned value, if it is unset (equal to zero). Fixes https://github.com/bitcoin/bitcoin/issues/29328 ACKs for top commit: fjahr: re-ACK 2342b46c451658a418f8e28e50b2ad0e5abd284d achow101: ACK 2342b46c451658a418f8e28e50b2ad0e5abd284d mzumsande: ACK 2342b46c451658a418f8e28e50b2ad0e5abd284d Tree-SHA512: 931cecc40ee5dc0f96be728db7eb297155f8343076cd29c8b8c050c99fd1d568b80f54c9459a34ca7a9489c2474c729796d00eeb1934d6a9f7b4d6a53e3ec430
Diffstat (limited to 'test/functional/feature_assumeutxo.py')
-rwxr-xr-xtest/functional/feature_assumeutxo.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py
index 0b434d1616..9ac8d27e9c 100755
--- a/test/functional/feature_assumeutxo.py
+++ b/test/functional/feature_assumeutxo.py
@@ -33,6 +33,7 @@ from dataclasses import dataclass
from test_framework.messages import tx_from_hex
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
+ assert_approx,
assert_equal,
assert_raises_rpc_error,
)
@@ -315,21 +316,35 @@ class AssumeutxoTest(BitcoinTestFramework):
the snapshot, and final values after the snapshot is validated."""
for height, block in blocks.items():
tx = n1.getblockheader(block.hash)["nTx"]
- chain_tx = n1.getchaintxstats(nblocks=1, blockhash=block.hash)["txcount"]
+ stats = n1.getchaintxstats(nblocks=1, blockhash=block.hash)
+ chain_tx = stats.get("txcount", None)
+ window_tx_count = stats.get("window_tx_count", None)
+ tx_rate = stats.get("txrate", None)
+ window_interval = stats.get("window_interval")
# Intermediate nTx of the starting block should be set, but nTx of
# later blocks should be 0 before they are downloaded.
+ # The window_tx_count of one block is equal to the blocks tx count.
+ # If the window tx count is unknown, the value is missing.
+ # The tx_rate is calculated from window_tx_count and window_interval
+ # when possible.
if final or height == START_HEIGHT:
assert_equal(tx, block.tx)
+ assert_equal(window_tx_count, tx)
+ if window_interval > 0:
+ assert_approx(tx_rate, window_tx_count / window_interval, vspan=0.1)
+ else:
+ assert_equal(tx_rate, None)
else:
assert_equal(tx, 0)
+ assert_equal(window_tx_count, None)
# Intermediate nChainTx of the starting block and snapshot block
- # should be set, but others should be 0 until they are downloaded.
+ # should be set, but others should be None until they are downloaded.
if final or height in (START_HEIGHT, SNAPSHOT_BASE_HEIGHT):
assert_equal(chain_tx, block.chain_tx)
else:
- assert_equal(chain_tx, 0)
+ assert_equal(chain_tx, None)
check_tx_counts(final=False)