Fix unit test crashes for Carrot v1 block format

This commit is contained in:
Matt Hess
2025-12-23 23:33:32 +00:00
parent 506f670114
commit fbb73f9658
3 changed files with 51 additions and 46 deletions
+9 -14
View File
@@ -136,14 +136,6 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name, cons
constexpr char mini_config[] = "mainnet\0" "salvium_mini\0" "\0" "10\0" "10000\0" "2160\0" "20\0";
constexpr char nano_config[] = "mainnet\0" "salvium_nano\0" "\0" "30\0" "10000\0" "2160\0" "10\0";
// Debug: print buffer contents
fprintf(stderr, "DEBUG consensus: s.m_pos=%zu, sizeof(default_config)-1=%zu\n", s.m_pos, sizeof(default_config) - 1);
fprintf(stderr, "DEBUG buf hex: ");
for (size_t i = 0; i < s.m_pos && i < 60; ++i) {
fprintf(stderr, "%02x ", static_cast<unsigned char>(buf[i]));
}
fprintf(stderr, "\n");
// Hardcoded default consensus ID
if ((s.m_pos == sizeof(default_config) - 1) && (memcmp(buf, default_config, sizeof(default_config) - 1) == 0)) {
m_consensusId.assign(default_consensus_id, default_consensus_id + HASH_SIZE);
@@ -157,7 +149,6 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name, cons
m_consensusId.assign(nano_consensus_id, nano_consensus_id + HASH_SIZE);
}
else {
fprintf(stderr, "DEBUG: No config match, falling through to RandomX\n");
#ifdef WITH_RANDOMX
const randomx_flags flags = randomx_get_flags();
randomx_cache* cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
@@ -199,6 +190,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name, cons
#endif
}
s.m_pos = 0;
s << log::hex_buf(m_consensusId.data(), m_consensusId.size()) << '\0';
@@ -274,18 +266,18 @@ bool SideChain::fill_sidechain_data(PoolBlock& block, std::vector<MinerShare>& s
if (!m_adoptedGenesisId.empty()) {
const uint64_t elapsed = seconds_since_epoch() - m_adoptedGenesisTime;
const uint64_t timeout = 90;
if (elapsed < timeout) {
// Log every 15 seconds so user knows we're working
if ((elapsed % 15) < 2) {
LOGINFO(3, "Waiting for peer's genesis block " << m_adoptedGenesisId
LOGINFO(3, "Waiting for peer's genesis block " << m_adoptedGenesisId
<< " (" << elapsed << "s / " << timeout << "s)");
}
return false;
}
// Timeout - give up on peer's genesis and create our own
LOGWARN(3, "Timeout waiting for peer's genesis block after " << elapsed
LOGWARN(3, "Timeout waiting for peer's genesis block after " << elapsed
<< "s, creating own genesis");
m_adoptedGenesisId = {};
m_adoptedGenesisTimestamp = 0;
@@ -295,7 +287,7 @@ bool SideChain::fill_sidechain_data(PoolBlock& block, std::vector<MinerShare>& s
// Don't create genesis block until initial peer sync has been attempted
// This prevents nodes from creating independent chains when starting simultaneously
if (!m_precalcFinished.load()) {
if (!m_precalcFinished.load() && m_pool) {
const P2PServer* p2p = m_pool->p2p_server();
if (p2p && (p2p->peer_list_size() > 0 || p2p->num_connections() > 0)) {
LOGINFO(5, "Waiting for initial peer sync before creating genesis block");
@@ -522,6 +514,7 @@ bool SideChain::get_shares(const PoolBlock* tip, std::vector<MinerShare>& shares
cur = it->second;
} while (true);
if (bottom_height) {
*bottom_height = cur->m_sidechainHeight;
}
@@ -1382,6 +1375,8 @@ bool SideChain::split_reward(uint64_t reward, const std::vector<MinerShare>& sha
{
const size_t num_shares = shares.size();
for (size_t i = 0; i < shares.size(); ++i) {
}
const difficulty_type total_weight = std::accumulate(shares.begin(), shares.end(), difficulty_type(), [](const difficulty_type& a, const MinerShare& b) { return a + b.m_weight; });
if (total_weight.empty()) {