Skip to content

Commit 80bdd4b

Browse files
committed
Merge bitcoin/bitcoin#30167: doc, rpc: Release notes and follow-ups for #29612
efc1b5b test: Add coverage for txid coins count check when loading snapshot (Fabian Jahr) 6b60848 assumeutxo: Add network magic ctor param to SnapshotMetadata (Fabian Jahr) 1f1f998 assumeutxo: Deserialize trailing byte instead of Txid (Fabian Jahr) 359967e doc: Add release notes for #29612 (Fabian Jahr) Pull request description: This adds release notes for #29612 and addresses post-merge review comments. ACKs for top commit: maflcko: utACK efc1b5b theStack: utACK efc1b5b Tree-SHA512: 3b270202e4f7b2576090ef1d970fd54a6840d96fc3621dddd28e888fb8696a97ff69af2e000bcee3b364316ca3f6e2a9b2f1694c6184f0e704dc487823127ce4
2 parents f7c0ddf + efc1b5b commit 80bdd4b

File tree

10 files changed

+34
-15
lines changed

10 files changed

+34
-15
lines changed

doc/release-notes-29612.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
RPC
2+
---
3+
4+
- The `dumptxoutset` RPC now returns the UTXO set dump in a new and
5+
improved format. At the same time the `loadtxoutset` RPC now
6+
expects this new format in dumps it tries to load. Dumps with the
7+
old format are no longer supported and need to be recreated using
8+
the new format in order to be usable.

src/kernel/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ std::vector<int> CChainParams::GetAvailableSnapshotHeights() const
554554
return heights;
555555
}
556556

557-
std::optional<ChainType> GetNetworkForMagic(MessageStartChars& message)
557+
std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& message)
558558
{
559559
const auto mainnet_msg = CChainParams::Main()->MessageStart();
560560
const auto testnet_msg = CChainParams::TestNet()->MessageStart();

src/kernel/chainparams.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,6 @@ class CChainParams
184184
ChainTxData chainTxData;
185185
};
186186

187-
std::optional<ChainType> GetNetworkForMagic(MessageStartChars& pchMessageStart);
187+
std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& pchMessageStart);
188188

189189
#endif // BITCOIN_KERNEL_CHAINPARAMS_H

src/node/utxo_snapshot.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sync.h>
1414
#include <uint256.h>
1515
#include <util/chaintype.h>
16+
#include <util/check.h>
1617
#include <util/fs.h>
1718

1819
#include <cstdint>
@@ -31,6 +32,7 @@ class SnapshotMetadata
3132
{
3233
const uint16_t m_version{1};
3334
const std::set<uint16_t> m_supported_versions{1};
35+
const MessageStartChars m_network_magic;
3436
public:
3537
//! The hash of the block that reflects the tip of the chain for the
3638
//! UTXO set contained in this snapshot.
@@ -42,11 +44,15 @@ class SnapshotMetadata
4244
//! during snapshot load to estimate progress of UTXO set reconstruction.
4345
uint64_t m_coins_count = 0;
4446

45-
SnapshotMetadata() { }
4647
SnapshotMetadata(
48+
const MessageStartChars network_magic) :
49+
m_network_magic(network_magic) { }
50+
SnapshotMetadata(
51+
const MessageStartChars network_magic,
4752
const uint256& base_blockhash,
4853
const int base_blockheight,
4954
uint64_t coins_count) :
55+
m_network_magic(network_magic),
5056
m_base_blockhash(base_blockhash),
5157
m_base_blockheight(base_blockheight),
5258
m_coins_count(coins_count) { }
@@ -55,7 +61,7 @@ class SnapshotMetadata
5561
inline void Serialize(Stream& s) const {
5662
s << SNAPSHOT_MAGIC_BYTES;
5763
s << m_version;
58-
s << Params().MessageStart();
64+
s << m_network_magic;
5965
s << m_base_blockheight;
6066
s << m_base_blockhash;
6167
s << m_coins_count;
@@ -80,11 +86,13 @@ class SnapshotMetadata
8086
// Read the network magic (pchMessageStart)
8187
MessageStartChars message;
8288
s >> message;
83-
if (!std::equal(message.begin(), message.end(), Params().MessageStart().data())) {
84-
auto metadata_network = GetNetworkForMagic(message);
89+
if (!std::equal(message.begin(), message.end(), m_network_magic.data())) {
90+
auto metadata_network{GetNetworkForMagic(message)};
8591
if (metadata_network) {
8692
std::string network_string{ChainTypeToString(metadata_network.value())};
87-
throw std::ios_base::failure(strprintf("The network of the snapshot (%s) does not match the network of this node (%s).", network_string, Params().GetChainTypeString()));
93+
auto node_network{GetNetworkForMagic(m_network_magic)};
94+
std::string node_network_string{ChainTypeToString(node_network.value())};
95+
throw std::ios_base::failure(strprintf("The network of the snapshot (%s) does not match the network of this node (%s).", network_string, node_network_string));
8896
} else {
8997
throw std::ios_base::failure("This snapshot has been created for an unrecognized network. This could be a custom signet, a new testnet or possibly caused by data corruption.");
9098
}

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ UniValue CreateUTXOSnapshot(
26972697
tip->nHeight, tip->GetBlockHash().ToString(),
26982698
fs::PathToString(path), fs::PathToString(temppath)));
26992699

2700-
SnapshotMetadata metadata{tip->GetBlockHash(), tip->nHeight, maybe_stats->coins_count};
2700+
SnapshotMetadata metadata{chainstate.m_chainman.GetParams().MessageStart(), tip->GetBlockHash(), tip->nHeight, maybe_stats->coins_count};
27012701

27022702
afile << metadata;
27032703

@@ -2809,7 +2809,7 @@ static RPCHelpMan loadtxoutset()
28092809
"Couldn't open file " + path.utf8string() + " for reading.");
28102810
}
28112811

2812-
SnapshotMetadata metadata;
2812+
SnapshotMetadata metadata{chainman.GetParams().MessageStart()};
28132813
try {
28142814
afile >> metadata;
28152815
} catch (const std::ios_base::failure& e) {

src/test/fuzz/deserialize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ FUZZ_TARGET_DESERIALIZE(blocktransactionsrequest_deserialize, {
316316
DeserializeFromFuzzingInput(buffer, btr);
317317
})
318318
FUZZ_TARGET_DESERIALIZE(snapshotmetadata_deserialize, {
319-
SnapshotMetadata snapshot_metadata;
319+
auto msg_start = Params().MessageStart();
320+
SnapshotMetadata snapshot_metadata{msg_start};
320321
DeserializeFromFuzzingInput(buffer, snapshot_metadata);
321322
})
322323
FUZZ_TARGET_DESERIALIZE(uint160_deserialize, {

src/test/fuzz/utxo_snapshot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ FUZZ_TARGET(utxo_snapshot, .init = initialize_chain)
4747

4848
const auto ActivateFuzzedSnapshot{[&] {
4949
AutoFile infile{fsbridge::fopen(snapshot_path, "rb")};
50-
SnapshotMetadata metadata;
50+
auto msg_start = Params().MessageStart();
51+
SnapshotMetadata metadata{msg_start};
5152
try {
5253
infile >> metadata;
5354
} catch (const std::ios_base::failure&) {

src/test/util/chainstate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CreateAndActivateUTXOSnapshot(
5656
//
5757
FILE* infile{fsbridge::fopen(snapshot_path, "rb")};
5858
AutoFile auto_infile{infile};
59-
node::SnapshotMetadata metadata;
59+
node::SnapshotMetadata metadata{node.chainman->GetParams().MessageStart()};
6060
auto_infile >> metadata;
6161

6262
malleation(auto_infile, metadata);

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5811,8 +5811,8 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
58115811

58125812
bool out_of_coins{false};
58135813
try {
5814-
Txid txid;
5815-
coins_file >> txid;
5814+
std::byte left_over_byte;
5815+
coins_file >> left_over_byte;
58165816
} catch (const std::ios_base::failure&) {
58175817
// We expect an exception since we should be out of coins.
58185818
out_of_coins = true;

test/functional/feature_assumeutxo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def expected_error(log_msg="", rpc_details=""):
130130
cases = [
131131
# (content, offset, wrong_hash, custom_message)
132132
[b"\xff" * 32, 0, "7d52155c9a9fdc4525b637ef6170568e5dad6fabd0b1fdbb9432010b8453095b", None], # wrong outpoint hash
133-
[(2).to_bytes(1, "little"), 32, None, "[snapshot] bad snapshot data after deserializing 1 coins"], # wrong outpoint hash
133+
[(2).to_bytes(1, "little"), 32, None, "[snapshot] bad snapshot data after deserializing 1 coins"], # wrong txid coins count
134+
[b"\xfd\xff\xff", 32, None, "[snapshot] mismatch in coins count in snapshot metadata and actual snapshot data"], # txid coins count exceeds coins left
134135
[b"\x01", 33, "9f4d897031ab8547665b4153317ae2fdbf0130c7840b66427ebc48b881cb80ad", None], # wrong outpoint index
135136
[b"\x81", 34, "3da966ba9826fb6d2604260e01607b55ba44e1a5de298606b08704bc62570ea8", None], # wrong coin code VARINT
136137
[b"\x80", 34, "091e893b3ccb4334378709578025356c8bcb0a623f37c7c4e493133c988648e5", None], # another wrong coin code

0 commit comments

Comments
 (0)