Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/pocx/mining/block_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ std::unique_ptr<CBlock> PoCXBlockBuilder::BuildBlock(
uint32_t compression,
node::NodeContext* context
) {
LogPrintf("PoCX: [BlockBuilder] Building block for account %s (quality=%llu, compression=%u)\n",
account_id.c_str(), quality, compression);

// Parse account ID
auto plot_id = pocx::algorithms::ParseAccountID(account_id.c_str());

// Render a 20-byte hash160 as its bech32 P2WPKH address for user-facing logs.
// Falls back to the raw input if the account_id failed to parse (logged below).
auto to_bech32 = [](const std::array<uint8_t, 20>& h) {
uint160 u; std::copy(h.begin(), h.end(), u.begin());
return EncodeDestination(WitnessV0KeyHash{u});
};
const std::string plot_address = plot_id ? to_bech32(*plot_id) : account_id;

LogPrintf("PoCX: [BlockBuilder] Building block for account %s (quality=%llu, compression=%u)\n",
plot_address, quality, compression);

if (!plot_id) {
LogPrintf("PoCX: [BlockBuilder] Invalid account ID format\n");
return nullptr;
Expand All @@ -95,8 +104,8 @@ std::unique_ptr<CBlock> PoCXBlockBuilder::BuildBlock(
effective_signer_account = HexStr(signer);

LogPrintf("PoCX: [BlockBuilder] Plot: %s, Effective signer: %s at height %d\n",
account_id.c_str(),
effective_signer_account.c_str(),
plot_address,
to_bech32(signer),
current_height);
}

Expand Down
19 changes: 13 additions & 6 deletions src/pocx/mining/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <chain.h>
#include <coins.h>
#include <interfaces/wallet.h>
#include <key_io.h>
#include <logging.h>
#include <node/context.h>
#include <sync.h>
Expand Down Expand Up @@ -455,13 +456,19 @@ bool PoCXScheduler::ForgeBlock(bool defensive) {
// Resolve effective signer (respect assignments) before handing off to
// the wallet-side signer. Keeps the ChainstateManager access in node lib.
std::string effective_signer = account_id;
if (context && context->chainman) {
std::string effective_signer_address = account_id; // bech32 P2WPKH for user-facing log
{
auto plot_id = pocx::algorithms::ParseAccountID(account_id.c_str());
if (plot_id) {
LOCK(cs_main);
const CCoinsViewCache& view = context->chainman->ActiveChainstate().CoinsTip();
auto signer = pocx::assignments::GetEffectiveSigner(*plot_id, block->nHeight, view);
effective_signer = HexStr(signer);
std::array<uint8_t, 20> signer = *plot_id;
if (context && context->chainman) {
LOCK(cs_main);
const CCoinsViewCache& view = context->chainman->ActiveChainstate().CoinsTip();
signer = pocx::assignments::GetEffectiveSigner(*plot_id, block->nHeight, view);
effective_signer = HexStr(signer);
}
uint160 u; std::copy(signer.begin(), signer.end(), u.begin());
effective_signer_address = EncodeDestination(WitnessV0KeyHash{u});
}
}

Expand All @@ -471,7 +478,7 @@ bool PoCXScheduler::ForgeBlock(bool defensive) {
if (context->wallet_loader) {
auto wallets = context->wallet_loader->getWallets();
LogPrintf("PoCX: [Scheduler] Trying %zu wallet(s) for effective signer %s\n",
wallets.size(), effective_signer.c_str());
wallets.size(), effective_signer_address);
for (auto& wallet : wallets) {
if (wallet->haveAccountKey(effective_signer) &&
wallet->signPoCXBlock(effective_signer, *block)) {
Expand Down
5 changes: 3 additions & 2 deletions src/pocx/mining/wallet_signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ bool SignPoCXBlock(
CTxDestination dest = WitnessV0KeyHash(pkhash);
CScript script = GetScriptForDestination(dest);

LogPrintf("PoCX: Account ID: %s -> CKeyID: %s\n", account_id.c_str(), ckeyid.ToString().c_str());
const std::string account_address = EncodeDestination(dest);
LogPrintf("PoCX: Signing for account %s\n", account_address);

CWallet* cwallet = wallet->wallet();
if (!cwallet) {
Expand Down Expand Up @@ -147,7 +148,7 @@ bool SignPoCXBlock(
}
}

LogPrintf("PoCX: No ScriptPubKeyMan found that can sign for account %s\n", account_id.c_str());
LogPrintf("PoCX: No ScriptPubKeyMan found that can sign for account %s\n", account_address);
return false;
}

Expand Down
16 changes: 13 additions & 3 deletions src/pocx/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#ifdef ENABLE_WALLET
#include <interfaces/wallet.h>
#include <key_io.h>
#include <pocx/algorithms/time_bending.h>
#include <pocx/algorithms/encoding.h>
#include <pocx/consensus/proof.h>
Expand Down Expand Up @@ -208,6 +209,14 @@ static RPCHelpMan submit_nonce()
bool has_key = false;
std::string effective_signer_account = account_id;

// Render a 20-byte hash160 as its bech32 P2WPKH address for user-facing messages.
auto to_bech32 = [](const std::array<uint8_t, 20>& h) {
uint160 u; std::copy(h.begin(), h.end(), u.begin());
return EncodeDestination(WitnessV0KeyHash{u});
};
const std::string plot_address = to_bech32(*account_id_parsed);
std::string effective_signer_address = plot_address;

// Check for assignments to get the effective signer
{
LOCK(cs_main);
Expand All @@ -217,10 +226,11 @@ static RPCHelpMan submit_nonce()
// Get effective signer considering assignments
std::array<uint8_t, 20> effective_signer = pocx::assignments::GetEffectiveSigner(*account_id_parsed, height, view);
effective_signer_account = HexStr(effective_signer);
effective_signer_address = to_bech32(effective_signer);

if (effective_signer_account != account_id) {
LogPrintf("PoCX: Plot %s has assignment, checking key for effective signer: %s\n",
account_id.c_str(), effective_signer_account.c_str());
plot_address, effective_signer_address);
}
}

Expand All @@ -244,11 +254,11 @@ static RPCHelpMan submit_nonce()
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED,
strprintf("Wallet holding key for effective signer %s is locked - "
"unlock with walletpassphrase first",
effective_signer_account));
effective_signer_address));
}
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
strprintf("No private key available for effective signer %s (plot: %s)",
effective_signer_account, account_id));
effective_signer_address, plot_address));
}
}

Expand Down
Loading