fix one critical bug and mostly code quality/cleanup items for portability, minor cleanup for compile on mac, fixed null check, Remove redundant TX_VERSION check

This commit is contained in:
Matt Hess
2025-12-17 22:53:56 +00:00
parent ff53f68c10
commit 9266f28d22
5 changed files with 8 additions and 25 deletions

View File

@@ -51,6 +51,7 @@ BlockTemplate::BlockTemplate(SideChain* sidechain, RandomX_Hasher_Base* hasher)
, m_numTransactionHashes(0)
, m_prevId{}
, m_height(0)
, m_majorVersion(0)
, m_difficulty{}
, m_auxDifficulty{}
, m_seedHash{}
@@ -59,6 +60,7 @@ BlockTemplate::BlockTemplate(SideChain* sidechain, RandomX_Hasher_Base* hasher)
, m_poolBlockTemplate(new PoolBlock())
, m_finalReward(0)
, m_minerTxKeccakState{}
, m_minerTxPrefixSize(0)
, m_minerTxKeccakStateInputLength(0)
, m_sidechainHashKeccakState{}
, m_sidechainHashInputLength(0)
@@ -733,7 +735,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
std::vector<uint8_t> v;
v.reserve(HASH_SIZE + 16);
v.assign(c.data.h, c.data.h + HASH_SIZE * 2);
v.assign(c.data.h, c.data.h + HASH_SIZE);
writeVarint(c.difficulty.lo, v);
writeVarint(c.difficulty.hi, v);
@@ -1845,20 +1847,6 @@ bool BlockTemplate::submit_sidechain_block(uint32_t template_id, uint32_t nonce,
return false;
}
hash BlockTemplate::calc_tx_merkle_root(uint32_t extra_nonce) const
{
const hash miner_hash = calc_miner_tx_hash(extra_nonce);
const uint8_t* protocol_hash_ptr = m_transactionHashes.data() + HASH_SIZE;
uint8_t combined[HASH_SIZE * 2];
memcpy(combined, miner_hash.h, HASH_SIZE);
memcpy(combined + HASH_SIZE, protocol_hash_ptr, HASH_SIZE);
hash result;
keccak(combined, HASH_SIZE * 2, result.h);
return result;
}
void BlockTemplate::init_merge_mining_merkle_proof()
{
const uint32_t n_aux_chains = static_cast<uint32_t>(m_poolBlockTemplate->m_auxChains.size() + 1);

View File

@@ -78,7 +78,6 @@ private:
int create_miner_tx(const MinerData& data, const std::vector<MinerShare>& shares, uint64_t max_reward_amounts_weight, bool dry_run, uint64_t full_block_reward);
hash calc_sidechain_hash(uint32_t sidechain_extra_nonce) const;
hash calc_miner_tx_hash(uint32_t extra_nonce) const;
hash calc_tx_merkle_root(uint32_t extra_nonce) const;
void calc_merkle_tree_main_branch();
hash m_protocolTxHash;

View File

@@ -40,6 +40,7 @@ PoolBlock::PoolBlock()
, m_prevId{}
, m_nonce(0)
, m_txinGenHeight(0)
, m_amountBurnt(0)
, m_txkeyPub{}
, m_extraNonceSize(0)
, m_extraNonce(0)

View File

@@ -75,10 +75,10 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
const int nonce_offset = static_cast<int>(data - data_begin);
READ_BUF(&m_nonce, NONCE_SIZE);
// Accept both old (4) and new (60) TX_VERSION during transition
// Verify TX_VERSION (currently 4)
uint8_t tx_version;
READ_BYTE(tx_version);
if (tx_version != 4 && tx_version != TX_VERSION) return __LINE__;
if (tx_version != TX_VERSION) return __LINE__;
uint64_t unlock_height;
READ_VARINT(unlock_height);

View File

@@ -958,7 +958,8 @@ bool SideChain::get_outputs_blob(PoolBlock* block, uint64_t total_reward, std::v
const PoolBlock::TxOutput& output = block->m_outputAmounts[i];
writeVarint(output.m_reward, blob);
blob.emplace_back(TXOUT_TO_CARROT_V1);
blob.insert(blob.end(), block->m_ephPublicKeys[i].h, block->m_ephPublicKeys[i].h + HASH_SIZE);
const hash eph_key = block->m_ephPublicKeys[i];
blob.insert(blob.end(), eph_key.h, eph_key.h + HASH_SIZE);
// Carrot v1 format
blob.push_back(4);
blob.push_back('S');
@@ -3458,12 +3459,6 @@ bool SideChain::validate_loaded_checkpoints()
PoolBlock* block = const_cast<PoolBlock*>(found);
if (!block) {
// Block not yet synced but reachable - can't validate yet
LOGWARN(3, "Checkpoint at height " << cp.height << " not yet synced, deferring validation - mining blocked");
return false; // NOT safe to mine yet
}
if (block->m_sidechainId != cp.id) {
LOGWARN(0, "CHECKPOINT MISMATCH at height " << cp.height <<
": cached=" << cp.id <<