Added merge mining extra
Some checks are pending
C/C++ CI / build-alpine-static (map[arch:aarch64 branch:latest-stable flags:-ffunction-sections -Wno-error=inline -mfix-cortex-a53-835769 -mfix-cortex-a53-843419]) (push) Waiting to run
C/C++ CI / build-macos-aarch64 (push) Waiting to run
C/C++ CI / build-alpine-static (map[arch:riscv64 branch:edge flags:-ffunction-sections -Wno-error=inline]) (push) Waiting to run
C/C++ CI / build-alpine-static (map[arch:x86_64 branch:latest-stable flags:-ffunction-sections -Wno-error=inline]) (push) Waiting to run
C/C++ CI / build-ubuntu (map[c:gcc-11 cpp:g++-11 flags: os:ubuntu-20.04]) (push) Waiting to run
C/C++ CI / build-ubuntu (map[c:gcc-12 cpp:g++-12 flags: os:ubuntu-22.04]) (push) Waiting to run
C/C++ CI / build-ubuntu (map[c:gcc-8 cpp:g++-8 flags: os:ubuntu-20.04]) (push) Waiting to run
C/C++ CI / build-ubuntu-static-libs (map[flags:-fuse-linker-plugin -ffunction-sections -Wno-error=inline]) (push) Waiting to run
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-20.04]) (push) Waiting to run
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-22.04]) (push) Waiting to run
C/C++ CI / build-windows-msys2 (map[c:clang cxx:clang++ flags:-fuse-ld=lld -Wno-unused-command-line-argument -Wno-nan-infinity-disabled]) (push) Waiting to run
C/C++ CI / build-windows-msys2 (map[c:gcc cxx:g++ flags:-ffunction-sections -Wno-error=maybe-uninitialized -Wno-error=attributes]) (push) Waiting to run
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF upnp:OFF vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Waiting to run
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Waiting to run
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Waiting to run
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2019 rx:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Waiting to run
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2022 rx:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Waiting to run
C/C++ CI / build-macos (push) Waiting to run
C/C++ CI / build-freebsd (map[architecture:x86-64 host:ubuntu-latest name:freebsd version:13.3]) (push) Waiting to run
C/C++ CI / build-openbsd (map[architecture:x86-64 host:ubuntu-latest name:openbsd version:7.4]) (push) Waiting to run
clang-tidy / clang-tidy (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run
cppcheck / cppcheck-ubuntu (push) Waiting to run
cppcheck / cppcheck-windows (push) Waiting to run
Microsoft C++ Code Analysis / Analyze (push) Waiting to run
source-snapshot / source-snapshot (push) Waiting to run
Sync test (old) / sync-test-ubuntu-tsan (push) Waiting to run
Sync test (old) / sync-test-ubuntu-msan (push) Waiting to run
Sync test (old) / sync-test-ubuntu-ubsan (push) Waiting to run
Sync test (old) / sync-test-ubuntu-asan (push) Waiting to run
Sync test (old) / sync-test-macos (map[flags:-Og -ftrapv -target arm64-apple-macos-11 os:macos-14]) (push) Waiting to run
Sync test (old) / sync-test-macos (map[flags:-Og -ftrapv os:macos-13]) (push) Waiting to run
Sync test (old) / sync-test-windows-debug-asan (push) Waiting to run
Sync test (old) / sync-test-windows-leaks (push) Waiting to run
Sync test / sync-test-ubuntu-tsan (push) Waiting to run
Sync test / sync-test-ubuntu-msan (push) Waiting to run
Sync test / sync-test-ubuntu-ubsan (push) Waiting to run
Sync test / sync-test-ubuntu-asan (push) Waiting to run
Sync test / sync-test-macos (map[flags:-Og -ftrapv -target arm64-apple-macos-11 os:macos-14]) (push) Waiting to run
Sync test / sync-test-macos (map[flags:-Og -ftrapv os:macos-13]) (push) Waiting to run
Sync test / sync-test-windows-debug-asan (push) Waiting to run
Sync test / sync-test-windows-leaks (push) Waiting to run

For future merge mining needs
This commit is contained in:
SChernykh 2024-06-16 21:21:27 +02:00
parent 180766f9aa
commit 5b3c1d749c
3 changed files with 54 additions and 1 deletions

View file

@ -50,6 +50,7 @@ PoolBlock::PoolBlock()
, m_cumulativeDifficulty{} , m_cumulativeDifficulty{}
, m_merkleProof{} , m_merkleProof{}
, m_merkleProofPath(0) , m_merkleProofPath(0)
, m_mergeMiningExtra{}
, m_sidechainExtraBuf{} , m_sidechainExtraBuf{}
, m_sidechainId{} , m_sidechainId{}
, m_depth(0) , m_depth(0)
@ -105,6 +106,7 @@ PoolBlock& PoolBlock::operator=(const PoolBlock& b)
m_cumulativeDifficulty = b.m_cumulativeDifficulty; m_cumulativeDifficulty = b.m_cumulativeDifficulty;
m_merkleProof = b.m_merkleProof; m_merkleProof = b.m_merkleProof;
m_merkleProofPath = b.m_merkleProofPath; m_merkleProofPath = b.m_merkleProofPath;
m_mergeMiningExtra = b.m_mergeMiningExtra;
memcpy(m_sidechainExtraBuf, b.m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf)); memcpy(m_sidechainExtraBuf, b.m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf));
m_sidechainId = b.m_sidechainId; m_sidechainId = b.m_sidechainId;
m_depth = b.m_depth; m_depth = b.m_depth;
@ -273,6 +275,15 @@ std::vector<uint8_t> PoolBlock::serialize_sidechain_data() const
const hash& h = m_merkleProof[i]; const hash& h = m_merkleProof[i];
data.insert(data.end(), h.h, h.h + HASH_SIZE); data.insert(data.end(), h.h, h.h + HASH_SIZE);
} }
writeVarint(m_mergeMiningExtra.size(), data);
for (const auto& mm_extra_data : m_mergeMiningExtra) {
data.insert(data.end(), mm_extra_data.first.h, mm_extra_data.first.h + HASH_SIZE);
writeVarint(mm_extra_data.second.size(), data);
data.insert(data.end(), mm_extra_data.second.begin(), mm_extra_data.second.end());
}
} }
const uint8_t* p = reinterpret_cast<const uint8_t*>(m_sidechainExtraBuf); const uint8_t* p = reinterpret_cast<const uint8_t*>(m_sidechainExtraBuf);

View file

@ -59,6 +59,10 @@ static constexpr difficulty_type MAX_CUMULATIVE_DIFFICULTY{ 13019633956666736640
// 1000 years at 1 block/second. It should be enough for any normal use. // 1000 years at 1 block/second. It should be enough for any normal use.
static constexpr uint64_t MAX_SIDECHAIN_HEIGHT = 31556952000ULL; static constexpr uint64_t MAX_SIDECHAIN_HEIGHT = 31556952000ULL;
// Limited by the format of the Merkle tree parameters in tx_extra
static constexpr uint64_t MERGE_MINING_MAX_CHAINS = 256;
static constexpr uint64_t LOG2_MERGE_MINING_MAX_CHAINS = 8;
// TBD // TBD
static constexpr uint64_t MERGE_MINING_FORK_TIME = std::numeric_limits<uint64_t>::max(); static constexpr uint64_t MERGE_MINING_FORK_TIME = std::numeric_limits<uint64_t>::max();
@ -141,6 +145,11 @@ struct PoolBlock
std::vector<hash> m_merkleProof; std::vector<hash> m_merkleProof;
uint32_t m_merkleProofPath; uint32_t m_merkleProofPath;
// Merge mining extra data
// Format: vector of (chain ID, chain data) pairs
// Chain data format is arbitrary and depends on the merge mined chain's requirements
std::vector<std::pair<hash, std::vector<uint8_t>>> m_mergeMiningExtra;
// Arbitrary extra data // Arbitrary extra data
uint32_t m_sidechainExtraBuf[4]; uint32_t m_sidechainExtraBuf[4];

View file

@ -361,12 +361,13 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
} }
m_merkleProof.clear(); m_merkleProof.clear();
m_mergeMiningExtra.clear();
if (merge_mining_enabled()) { if (merge_mining_enabled()) {
uint8_t merkle_proof_size; uint8_t merkle_proof_size;
READ_BYTE(merkle_proof_size); READ_BYTE(merkle_proof_size);
if (merkle_proof_size > 8) { if (merkle_proof_size > LOG2_MERGE_MINING_MAX_CHAINS) {
return __LINE__; return __LINE__;
} }
@ -377,6 +378,38 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
READ_BUF(h.h, HASH_SIZE); READ_BUF(h.h, HASH_SIZE);
m_merkleProof.emplace_back(h); m_merkleProof.emplace_back(h);
} }
uint64_t mm_extra_data_count;
READ_VARINT(mm_extra_data_count);
if (mm_extra_data_count) {
// Sanity check
if (mm_extra_data_count > MERGE_MINING_MAX_CHAINS) return __LINE__;
if (static_cast<uint64_t>(data_end - data) < mm_extra_data_count * (HASH_SIZE + 1)) return __LINE__;
m_mergeMiningExtra.reserve(mm_extra_data_count);
for (uint64_t i = 0; i < mm_extra_data_count; ++i) {
hash chain_id;
READ_BUF(chain_id.h, HASH_SIZE);
// IDs must be ordered to avoid duplicates
if (i && !(m_mergeMiningExtra[i - 1].first < chain_id)) return __LINE__;
uint64_t n;
READ_VARINT(n);
// Sanity check
if (static_cast<uint64_t>(data_end - data) < n) return __LINE__;
std::vector<uint8_t> t;
t.resize(n);
READ_BUF(t.data(), n);
m_mergeMiningExtra.emplace_back(chain_id, std::move(t));
}
}
} }
READ_BUF(m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf)); READ_BUF(m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf));