0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-15 11:36:00 -05:00

Merge bitcoin/bitcoin#30395: rpc: Use untranslated error strings in loadtxoutset

fa5b8920be rpc: Use untranslated error strings in loadtxoutset (MarcoFalke)
fa45865778 refactor: Use named arguments to get path arg in loadtxoutset (MarcoFalke)

Pull request description:

  Motivation:
  * Some are not translated at all, anyway. See https://github.com/bitcoin/bitcoin/pull/30267#discussion_r1663631973
  * 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 https://github.com/bitcoin/bitcoin/pull/30267#discussion_r1663611194

  Also, while touching this:
  * Remove the trailing `\n`. See https://github.com/bitcoin/bitcoin/pull/30267#discussion_r1663647981
  * Add back the path. See https://github.com/bitcoin/bitcoin/pull/30267#discussion_r1663666751
  * Use named args to get the path.

ACKs for top commit:
  fjahr:
    re-ACK fa5b8920be
  tdb3:
    ACK fa5b8920be
  ryanofsky:
    Code review ACK fa5b8920be

Tree-SHA512: 46504dc5fd55a6274ef885dbe071aa9efb25bca247cd68cd86fb2ff066d70d295e0522e1fe42e63f1fdf7e4c89bd696220edaf06e33b804aba746492eafd852e
This commit is contained in:
Ryan Ofsky 2024-07-09 14:28:29 -04:00
commit c06b3764fe
No known key found for this signature in database
GPG key ID: 46800E30FC748A66
2 changed files with 12 additions and 12 deletions

View file

@ -2814,7 +2814,7 @@ static RPCHelpMan loadtxoutset()
{ {
NodeContext& node = EnsureAnyNodeContext(request.context); NodeContext& node = EnsureAnyNodeContext(request.context);
ChainstateManager& chainman = EnsureChainman(node); ChainstateManager& chainman = EnsureChainman(node);
fs::path path{AbsPathForConfigVal(EnsureArgsman(node), fs::u8path(request.params[0].get_str()))}; const fs::path path{AbsPathForConfigVal(EnsureArgsman(node), fs::u8path(self.Arg<std::string>("path")))};
FILE* file{fsbridge::fopen(path, "rb")}; FILE* file{fsbridge::fopen(path, "rb")};
AutoFile afile{file}; AutoFile afile{file};
@ -2833,7 +2833,7 @@ static RPCHelpMan loadtxoutset()
auto activation_result{chainman.ActivateSnapshot(afile, metadata, false)}; auto activation_result{chainman.ActivateSnapshot(afile, metadata, false)};
if (!activation_result) { if (!activation_result) {
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf(_("Unable to load UTXO snapshot: %s\n"), util::ErrorString(activation_result)).original); throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Unable to load UTXO snapshot: %s. (%s)", util::ErrorString(activation_result).original, path.utf8string()));
} }
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);

View file

@ -5657,7 +5657,7 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
int base_blockheight = metadata.m_base_blockheight; int base_blockheight = metadata.m_base_blockheight;
if (this->SnapshotBlockhash()) { if (this->SnapshotBlockhash()) {
return util::Error{_("Can't activate a snapshot-based chainstate more than once")}; return util::Error{Untranslated("Can't activate a snapshot-based chainstate more than once")};
} }
{ {
@ -5666,7 +5666,7 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) { if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) {
auto available_heights = GetParams().GetAvailableSnapshotHeights(); auto available_heights = GetParams().GetAvailableSnapshotHeights();
std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); }); std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); });
return util::Error{strprintf(_("assumeutxo block hash in snapshot metadata not recognized (hash: %s, height: %s). The following snapshot heights are available: %s."), return util::Error{strprintf(Untranslated("assumeutxo block hash in snapshot metadata not recognized (hash: %s, height: %s). The following snapshot heights are available: %s"),
base_blockhash.ToString(), base_blockhash.ToString(),
base_blockheight, base_blockheight,
heights_formatted)}; heights_formatted)};
@ -5674,18 +5674,18 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
CBlockIndex* snapshot_start_block = m_blockman.LookupBlockIndex(base_blockhash); CBlockIndex* snapshot_start_block = m_blockman.LookupBlockIndex(base_blockhash);
if (!snapshot_start_block) { if (!snapshot_start_block) {
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."), 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"),
base_blockhash.ToString())}; base_blockhash.ToString())};
} }
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK; bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
if (start_block_invalid) { if (start_block_invalid) {
return util::Error{strprintf(_("The base block header (%s) is part of an invalid chain."), base_blockhash.ToString())}; return util::Error{strprintf(Untranslated("The base block header (%s) is part of an invalid chain"), base_blockhash.ToString())};
} }
auto mempool{m_active_chainstate->GetMempool()}; auto mempool{m_active_chainstate->GetMempool()};
if (mempool && mempool->size() > 0) { if (mempool && mempool->size() > 0) {
return util::Error{_("Can't activate a snapshot when mempool not empty.")}; return util::Error{Untranslated("Can't activate a snapshot when mempool not empty")};
} }
} }
@ -5734,7 +5734,7 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
static_cast<size_t>(current_coinstip_cache_size * SNAPSHOT_CACHE_PERC)); static_cast<size_t>(current_coinstip_cache_size * SNAPSHOT_CACHE_PERC));
} }
auto cleanup_bad_snapshot = [&](const char* reason) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { auto cleanup_bad_snapshot = [&](bilingual_str&& reason) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
this->MaybeRebalanceCaches(); this->MaybeRebalanceCaches();
// PopulateAndValidateSnapshot can return (in error) before the leveldb datadir // PopulateAndValidateSnapshot can return (in error) before the leveldb datadir
@ -5750,12 +5750,12 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
"Manually remove it before restarting.\n"), fs::PathToString(*snapshot_datadir))); "Manually remove it before restarting.\n"), fs::PathToString(*snapshot_datadir)));
} }
} }
return util::Error{_(reason)}; return util::Error{std::move(reason)};
}; };
if (!this->PopulateAndValidateSnapshot(*snapshot_chainstate, coins_file, metadata)) { if (!this->PopulateAndValidateSnapshot(*snapshot_chainstate, coins_file, metadata)) {
LOCK(::cs_main); LOCK(::cs_main);
return cleanup_bad_snapshot("population failed"); return cleanup_bad_snapshot(Untranslated("population failed"));
} }
LOCK(::cs_main); // cs_main required for rest of snapshot activation. LOCK(::cs_main); // cs_main required for rest of snapshot activation.
@ -5764,13 +5764,13 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
// work chain than the active chainstate; a user could have loaded a snapshot // work chain than the active chainstate; a user could have loaded a snapshot
// very late in the IBD process, and we wouldn't want to load a useless chainstate. // very late in the IBD process, and we wouldn't want to load a useless chainstate.
if (!CBlockIndexWorkComparator()(ActiveTip(), snapshot_chainstate->m_chain.Tip())) { if (!CBlockIndexWorkComparator()(ActiveTip(), snapshot_chainstate->m_chain.Tip())) {
return cleanup_bad_snapshot("work does not exceed active chainstate"); return cleanup_bad_snapshot(Untranslated("work does not exceed active chainstate"));
} }
// If not in-memory, persist the base blockhash for use during subsequent // If not in-memory, persist the base blockhash for use during subsequent
// initialization. // initialization.
if (!in_memory) { if (!in_memory) {
if (!node::WriteSnapshotBaseBlockhash(*snapshot_chainstate)) { if (!node::WriteSnapshotBaseBlockhash(*snapshot_chainstate)) {
return cleanup_bad_snapshot("could not write base blockhash"); return cleanup_bad_snapshot(Untranslated("could not write base blockhash"));
} }
} }