mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-08-20 05:28:47 -06:00
Hardcode default consensus ID for faster startup
This commit is contained in:
parent
8aa9e54dc4
commit
b4ea125a8a
@ -55,7 +55,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
|||||||
: m_pool(pool)
|
: m_pool(pool)
|
||||||
, m_networkType(type)
|
, m_networkType(type)
|
||||||
, m_chainTip(nullptr)
|
, m_chainTip(nullptr)
|
||||||
, m_poolName(pool_name ? pool_name : "mainnet test 2")
|
, m_poolName(pool_name ? pool_name : "default")
|
||||||
, m_targetBlockTime(10)
|
, m_targetBlockTime(10)
|
||||||
, m_minDifficulty(MIN_DIFFICULTY, 0)
|
, m_minDifficulty(MIN_DIFFICULTY, 0)
|
||||||
, m_chainWindowSize(2160)
|
, m_chainWindowSize(2160)
|
||||||
@ -78,6 +78,24 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
|||||||
|
|
||||||
LOGINFO(1, "generating consensus ID");
|
LOGINFO(1, "generating consensus ID");
|
||||||
|
|
||||||
|
char buf[log::Stream::BUF_SIZE + 1];
|
||||||
|
log::Stream s(buf);
|
||||||
|
|
||||||
|
s << m_networkType << '\0'
|
||||||
|
<< m_poolName << '\0'
|
||||||
|
<< m_poolPassword << '\0'
|
||||||
|
<< m_targetBlockTime << '\0'
|
||||||
|
<< m_minDifficulty << '\0'
|
||||||
|
<< m_chainWindowSize << '\0'
|
||||||
|
<< m_unclePenalty << '\0';
|
||||||
|
|
||||||
|
constexpr char default_config[] = "mainnet\0" "default\0" "\0" "10\0" "100000\0" "2160\0" "20\0";
|
||||||
|
|
||||||
|
if (memcmp(buf, default_config, sizeof(default_config) - 1) == 0) {
|
||||||
|
// Hardcoded default consensus ID
|
||||||
|
m_consensusId.assign({ 34,175,126,231,181,11,104,146,227,153,218,107,44,108,68,39,178,81,4,212,169,4,142,0,177,110,157,240,68,7,249,24 });
|
||||||
|
}
|
||||||
|
else {
|
||||||
const randomx_flags flags = randomx_get_flags();
|
const randomx_flags flags = randomx_get_flags();
|
||||||
randomx_cache* cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
|
randomx_cache* cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
@ -89,20 +107,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
randomx_init_cache(cache, buf, s.m_pos);
|
||||||
char consensus_str[log::Stream::BUF_SIZE + 1];
|
|
||||||
log::Stream s(consensus_str);
|
|
||||||
|
|
||||||
s << m_networkType << '\0'
|
|
||||||
<< m_poolName << '\0'
|
|
||||||
<< m_poolPassword << '\0'
|
|
||||||
<< m_targetBlockTime << '\0'
|
|
||||||
<< m_minDifficulty << '\0'
|
|
||||||
<< m_chainWindowSize << '\0'
|
|
||||||
<< m_unclePenalty << '\0';
|
|
||||||
|
|
||||||
randomx_init_cache(cache, consensus_str, s.m_pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intentionally not a power of 2
|
// Intentionally not a power of 2
|
||||||
constexpr size_t scratchpad_size = 1009;
|
constexpr size_t scratchpad_size = 1009;
|
||||||
@ -123,18 +128,16 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
|||||||
|
|
||||||
hash id;
|
hash id;
|
||||||
keccak(reinterpret_cast<uint8_t*>(scratchpad), static_cast<int>(scratchpad_size * sizeof(rx_vec_i128)), id.h, HASH_SIZE);
|
keccak(reinterpret_cast<uint8_t*>(scratchpad), static_cast<int>(scratchpad_size * sizeof(rx_vec_i128)), id.h, HASH_SIZE);
|
||||||
|
|
||||||
randomx_release_cache(cache);
|
randomx_release_cache(cache);
|
||||||
|
|
||||||
m_consensusId.assign(id.h, id.h + HASH_SIZE);
|
m_consensusId.assign(id.h, id.h + HASH_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
char buf[HASH_SIZE * 2 + 1];
|
s.m_pos = 0;
|
||||||
log::Stream s(buf);
|
s << log::hex_buf(m_consensusId.data(), m_consensusId.size()) << '\0';
|
||||||
s << id << '\0';
|
|
||||||
|
|
||||||
// Hide most consensus ID bytes, we only want it on screen to show that we're on the right sidechain
|
// Hide most consensus ID bytes, we only want it on screen to show that we're on the right sidechain
|
||||||
memset(buf + 8, '*', HASH_SIZE * 2 - 16);
|
memset(buf + 8, '*', HASH_SIZE * 2 - 16);
|
||||||
LOGINFO(1, "consensus ID = " << log::LightCyan() << buf);
|
LOGINFO(1, "consensus ID = " << log::LightCyan() << static_cast<char*>(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
SideChain::~SideChain()
|
SideChain::~SideChain()
|
||||||
|
Loading…
Reference in New Issue
Block a user