Fix: don't use outdated merge mining data

And warn the user in the log
This commit is contained in:
SChernykh
2025-06-02 13:55:06 +02:00
parent a01ea2d9d8
commit b06fcc7516
4 changed files with 26 additions and 3 deletions

View File

@@ -63,7 +63,7 @@ jobs:
cd external/src/libzmq
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS='-Os -flto=auto ${{ matrix.config.flags }}' -DCMAKE_CXX_FLAGS='-Os -flto=auto ${{ matrix.config.flags }}' -DWITH_LIBSODIUM=OFF -DWITH_LIBBSD=OFF -DBUILD_TESTS=OFF -DWITH_DOCS=OFF -DENABLE_DRAFTS=OFF -DBUILD_SHARED=OFF
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM="3.5" -DCMAKE_C_FLAGS='-Os -flto=auto ${{ matrix.config.flags }}' -DCMAKE_CXX_FLAGS='-Os -flto=auto ${{ matrix.config.flags }}' -DWITH_LIBSODIUM=OFF -DWITH_LIBBSD=OFF -DBUILD_TESTS=OFF -DWITH_DOCS=OFF -DENABLE_DRAFTS=OFF -DBUILD_SHARED=OFF
make -j$(nproc)
- name: Build p2pool
@@ -71,7 +71,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_BINARY=ON -DARCH_ID=${{ matrix.config.arch }}
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM="3.5" -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_BINARY=ON -DARCH_ID=${{ matrix.config.arch }}
make -j$(nproc) p2pool
- name: Run RandomX tests
@@ -88,7 +88,7 @@ jobs:
cd tests
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_LIBS=ON -DARCH_ID=${{ matrix.config.arch }}
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM="3.5" -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_LIBS=ON -DARCH_ID=${{ matrix.config.arch }}
make -j$(nproc) p2pool_tests
- name: Run tests

View File

@@ -28,10 +28,17 @@ class IMergeMiningClient
public:
struct ChainParameters
{
ChainParameters() : last_updated(0) {}
enum {
EXPIRE_TIME = 1800,
};
hash aux_id;
hash aux_hash;
std::vector<uint8_t> aux_blob;
difficulty_type aux_diff;
uint64_t last_updated;
};
public:

View File

@@ -281,6 +281,7 @@ bool MergeMiningClientJSON_RPC::parse_merge_mining_get_aux_block(const char* dat
m_chainParams.aux_hash = h;
m_chainParams.aux_diff.lo = result["aux_diff"].GetUint64();
m_chainParams.aux_diff.hi = 0;
m_chainParams.last_updated = seconds_since_epoch();
changed = true;
@@ -334,12 +335,19 @@ void MergeMiningClientJSON_RPC::print_status() const
bool MergeMiningClientJSON_RPC::get_params(ChainParameters& out_params) const
{
const uint64_t t = seconds_since_epoch();
ReadLock lock(m_lock);
if (m_chainParams.aux_id.empty() || m_chainParams.aux_diff.empty()) {
return false;
}
if (t >= m_chainParams.last_updated + ChainParameters::EXPIRE_TIME) {
LOGWARN(4, m_host << ':' << m_port << " merge mining data is outdated (" << (t - m_chainParams.last_updated) << " seconds old)");
return false;
}
out_params = m_chainParams;
return true;
}

View File

@@ -132,12 +132,19 @@ MergeMiningClientTari::~MergeMiningClientTari()
bool MergeMiningClientTari::get_params(ChainParameters& out_params) const
{
const uint64_t t = seconds_since_epoch();
ReadLock lock(m_chainParamsLock);
if (m_chainParams.aux_id.empty() || m_chainParams.aux_diff.empty()) {
return false;
}
if (t >= m_chainParams.last_updated + ChainParameters::EXPIRE_TIME) {
LOGWARN(4, m_hostStr << " merge mining data is outdated (" << (t - m_chainParams.last_updated) << " seconds old)");
return false;
}
out_params = m_chainParams;
return true;
}
@@ -659,6 +666,7 @@ void MergeMiningClientTari::run()
std::copy(mm_hash.begin(), mm_hash.end(), m_chainParams.aux_hash.h);
m_chainParams.aux_diff = static_cast<difficulty_type>(response.miner_data().target_difficulty());
m_chainParams.last_updated = seconds_since_epoch();
m_tariBlock = response.block();