Skip to content

Commit c06b376

Browse files
committed
Merge bitcoin/bitcoin#30395: rpc: Use untranslated error strings in loadtxoutset
fa5b892 rpc: Use untranslated error strings in loadtxoutset (MarcoFalke) fa45865 refactor: Use named arguments to get path arg in loadtxoutset (MarcoFalke) Pull request description: Motivation: * Some are not translated at all, anyway. See bitcoin/bitcoin#30267 (comment) * For others translation is not yet needed, because they are not called by the GUI (yet) * For others translations will never be needed, because they are RPC code. See bitcoin/bitcoin#30267 (comment) Also, while touching this: * Remove the trailing `\n`. See bitcoin/bitcoin#30267 (comment) * Add back the path. See bitcoin/bitcoin#30267 (comment) * Use named args to get the path. ACKs for top commit: fjahr: re-ACK fa5b892 tdb3: ACK fa5b892 ryanofsky: Code review ACK fa5b892 Tree-SHA512: 46504dc5fd55a6274ef885dbe071aa9efb25bca247cd68cd86fb2ff066d70d295e0522e1fe42e63f1fdf7e4c89bd696220edaf06e33b804aba746492eafd852e
2 parents 79b8472 + fa5b892 commit c06b376

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,7 @@ static RPCHelpMan loadtxoutset()
28142814
{
28152815
NodeContext& node = EnsureAnyNodeContext(request.context);
28162816
ChainstateManager& chainman = EnsureChainman(node);
2817-
fs::path path{AbsPathForConfigVal(EnsureArgsman(node), fs::u8path(request.params[0].get_str()))};
2817+
const fs::path path{AbsPathForConfigVal(EnsureArgsman(node), fs::u8path(self.Arg<std::string>("path")))};
28182818

28192819
FILE* file{fsbridge::fopen(path, "rb")};
28202820
AutoFile afile{file};
@@ -2833,7 +2833,7 @@ static RPCHelpMan loadtxoutset()
28332833

28342834
auto activation_result{chainman.ActivateSnapshot(afile, metadata, false)};
28352835
if (!activation_result) {
2836-
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf(_("Unable to load UTXO snapshot: %s\n"), util::ErrorString(activation_result)).original);
2836+
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Unable to load UTXO snapshot: %s. (%s)", util::ErrorString(activation_result).original, path.utf8string()));
28372837
}
28382838

28392839
UniValue result(UniValue::VOBJ);

src/validation.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,7 +5657,7 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
56575657
int base_blockheight = metadata.m_base_blockheight;
56585658

56595659
if (this->SnapshotBlockhash()) {
5660-
return util::Error{_("Can't activate a snapshot-based chainstate more than once")};
5660+
return util::Error{Untranslated("Can't activate a snapshot-based chainstate more than once")};
56615661
}
56625662

56635663
{
@@ -5666,26 +5666,26 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
56665666
if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) {
56675667
auto available_heights = GetParams().GetAvailableSnapshotHeights();
56685668
std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); });
5669-
return util::Error{strprintf(_("assumeutxo block hash in snapshot metadata not recognized (hash: %s, height: %s). The following snapshot heights are available: %s."),
5669+
return util::Error{strprintf(Untranslated("assumeutxo block hash in snapshot metadata not recognized (hash: %s, height: %s). The following snapshot heights are available: %s"),
56705670
base_blockhash.ToString(),
56715671
base_blockheight,
56725672
heights_formatted)};
56735673
}
56745674

56755675
CBlockIndex* snapshot_start_block = m_blockman.LookupBlockIndex(base_blockhash);
56765676
if (!snapshot_start_block) {
5677-
return util::Error{strprintf(_("The base block header (%s) must appear in the headers chain. Make sure all headers are syncing, and call loadtxoutset again."),
5677+
return util::Error{strprintf(Untranslated("The base block header (%s) must appear in the headers chain. Make sure all headers are syncing, and call loadtxoutset again"),
56785678
base_blockhash.ToString())};
56795679
}
56805680

56815681
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
56825682
if (start_block_invalid) {
5683-
return util::Error{strprintf(_("The base block header (%s) is part of an invalid chain."), base_blockhash.ToString())};
5683+
return util::Error{strprintf(Untranslated("The base block header (%s) is part of an invalid chain"), base_blockhash.ToString())};
56845684
}
56855685

56865686
auto mempool{m_active_chainstate->GetMempool()};
56875687
if (mempool && mempool->size() > 0) {
5688-
return util::Error{_("Can't activate a snapshot when mempool not empty.")};
5688+
return util::Error{Untranslated("Can't activate a snapshot when mempool not empty")};
56895689
}
56905690
}
56915691

@@ -5734,7 +5734,7 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
57345734
static_cast<size_t>(current_coinstip_cache_size * SNAPSHOT_CACHE_PERC));
57355735
}
57365736

5737-
auto cleanup_bad_snapshot = [&](const char* reason) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
5737+
auto cleanup_bad_snapshot = [&](bilingual_str&& reason) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
57385738
this->MaybeRebalanceCaches();
57395739

57405740
// PopulateAndValidateSnapshot can return (in error) before the leveldb datadir
@@ -5750,12 +5750,12 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
57505750
"Manually remove it before restarting.\n"), fs::PathToString(*snapshot_datadir)));
57515751
}
57525752
}
5753-
return util::Error{_(reason)};
5753+
return util::Error{std::move(reason)};
57545754
};
57555755

57565756
if (!this->PopulateAndValidateSnapshot(*snapshot_chainstate, coins_file, metadata)) {
57575757
LOCK(::cs_main);
5758-
return cleanup_bad_snapshot("population failed");
5758+
return cleanup_bad_snapshot(Untranslated("population failed"));
57595759
}
57605760

57615761
LOCK(::cs_main); // cs_main required for rest of snapshot activation.
@@ -5764,13 +5764,13 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
57645764
// work chain than the active chainstate; a user could have loaded a snapshot
57655765
// very late in the IBD process, and we wouldn't want to load a useless chainstate.
57665766
if (!CBlockIndexWorkComparator()(ActiveTip(), snapshot_chainstate->m_chain.Tip())) {
5767-
return cleanup_bad_snapshot("work does not exceed active chainstate");
5767+
return cleanup_bad_snapshot(Untranslated("work does not exceed active chainstate"));
57685768
}
57695769
// If not in-memory, persist the base blockhash for use during subsequent
57705770
// initialization.
57715771
if (!in_memory) {
57725772
if (!node::WriteSnapshotBaseBlockhash(*snapshot_chainstate)) {
5773-
return cleanup_bad_snapshot("could not write base blockhash");
5773+
return cleanup_bad_snapshot(Untranslated("could not write base blockhash"));
57745774
}
57755775
}
57765776

0 commit comments

Comments
 (0)