Skip to content

Commit fd8f2e3

Browse files
authored
nmc(P0): embedded merge-mining foundation leaf — structure-only coin tree (#175)
Lay down src/impl/nmc/coin as the P0 structural foundation for embedded merge-mined Namecoin under a BTC parent (DOGE-under-LTC analog): header_chain.hpp (AuxPow header interface, parent-powhash path), block.hpp, transaction.{hpp,cpp}, coin_smoke.cpp TU, plus CMake wiring (nmc_coin lib). Fences (per integrator ACK msgid 5823428726...): - btc tree READ-ONLY: NMC consumes src/impl/btc public header types only. - AuxPow merkle-branch proof walk + block-validation = P0-DEFER stubs. - vector<AuxChain> stays nmc-local; no lift into bitcoin_family/src/core. - chain_id / auxpow_activation_height (cited ~19200) / genesis kept as -1 TO-CONFIRM sentinels, NOT compiled constants — pinning gated on VMID 219 nmc-testnet landing (chainparams + namecoind ground-truth). nmc_coin smoke target builds clean (cmake --build --target nmc_coin, exit 0). Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>
1 parent 6b7454a commit fd8f2e3

8 files changed

Lines changed: 854 additions & 0 deletions

File tree

src/impl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory(ltc)
22
add_subdirectory(btc)
33
add_subdirectory(dgb)
44
add_subdirectory(dash)
5+
add_subdirectory(nmc)

src/impl/nmc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# NMC (embedded merge-mined Namecoin) — P0 structural leaf.
2+
# Only the coin tree exists at P0. node/stratum/share layers come later.
3+
add_subdirectory(coin)

src/impl/nmc/coin/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# NMC coin tree — P0 structural leaf.
2+
# Mirror of src/impl/btc/coin/CMakeLists.txt (header-only interface files +
3+
# a translation unit that forces them to compile). STRUCTURE-only: no node /
4+
# rpc / p2p layers yet.
5+
6+
set(nmc_coin_interface
7+
transaction.hpp transaction.cpp
8+
block.hpp
9+
header_chain.hpp
10+
coin_smoke.cpp
11+
)
12+
13+
add_library(nmc_coin ${nmc_coin_interface})
14+
15+
target_link_libraries(nmc_coin core nlohmann_json::nlohmann_json)

src/impl/nmc/coin/block.hpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#pragma once
2+
3+
// NMC (Namecoin) block / header primitives.
4+
//
5+
// Mirror of src/impl/btc/coin/block.hpp. Namecoin is a Bitcoin (SHA256d) fork;
6+
// its plain block header layout is byte-identical to Bitcoin's. Re-homed into
7+
// namespace nmc::coin. No btc header is modified.
8+
//
9+
// P0-DEFER: Namecoin blocks are AUX-POW capable. The merge-mined parent-chain
10+
// proof (CAuxPow: parent coinbase tx + coinbase merkle branch + parent block
11+
// header) is NOT modelled here. The plain header below is the foundation leaf;
12+
// the AuxPow attachment is a later leaf — see header_chain.hpp AuxPowStub.
13+
14+
#include "transaction.hpp"
15+
16+
#include <core/uint256.hpp>
17+
#include <core/pack_types.hpp>
18+
#include <core/netaddress.hpp>
19+
20+
namespace nmc
21+
{
22+
23+
namespace coin
24+
{
25+
26+
struct SmallBlockHeaderType
27+
{
28+
uint64_t m_version {};
29+
uint256 m_previous_block{};
30+
uint32_t m_timestamp{};
31+
uint32_t m_bits{};
32+
uint32_t m_nonce{};
33+
34+
C2POOL_SERIALIZE_METHODS(SmallBlockHeaderType) { READWRITE(VarInt(obj.m_version), obj.m_previous_block, obj.m_timestamp, obj.m_bits, obj.m_nonce); }
35+
36+
SmallBlockHeaderType() {}
37+
38+
void SetNull()
39+
{
40+
m_version = 0;
41+
m_previous_block.SetNull();
42+
m_timestamp = 0;
43+
m_bits = 0;
44+
m_nonce = 0;
45+
}
46+
47+
bool IsNull() const
48+
{
49+
return (m_bits == 0);
50+
}
51+
};
52+
53+
struct BlockHeaderType : SmallBlockHeaderType
54+
{
55+
uint256 m_merkle_root;
56+
57+
// Full block header uses fixed 4-byte int32 version (not VarInt like SmallBlockHeaderType)
58+
template<typename Stream>
59+
void Serialize(Stream& s) const {
60+
uint32_t version32 = static_cast<uint32_t>(m_version);
61+
::Serialize(s, version32);
62+
::Serialize(s, m_previous_block);
63+
::Serialize(s, m_merkle_root);
64+
::Serialize(s, m_timestamp);
65+
::Serialize(s, m_bits);
66+
::Serialize(s, m_nonce);
67+
}
68+
template<typename Stream>
69+
void Unserialize(Stream& s) {
70+
uint32_t version32;
71+
::Unserialize(s, version32);
72+
m_version = version32;
73+
::Unserialize(s, m_previous_block);
74+
::Unserialize(s, m_merkle_root);
75+
::Unserialize(s, m_timestamp);
76+
::Unserialize(s, m_bits);
77+
::Unserialize(s, m_nonce);
78+
}
79+
80+
BlockHeaderType() : SmallBlockHeaderType() { }
81+
82+
void SetNull()
83+
{
84+
SmallBlockHeaderType::SetNull();
85+
m_merkle_root.SetNull();
86+
}
87+
88+
bool IsNull() const
89+
{
90+
return (m_bits == 0);
91+
}
92+
93+
};
94+
95+
struct BlockType : BlockHeaderType
96+
{
97+
std::vector<MutableTransaction> m_txs;
98+
99+
template <typename Stream>
100+
void Serialize(Stream& s) const {
101+
BlockHeaderType::Serialize(s);
102+
::Serialize(s, TX_WITH_WITNESS(m_txs));
103+
}
104+
105+
template <typename Stream>
106+
void Unserialize(Stream& s) {
107+
BlockHeaderType::Unserialize(s);
108+
::Unserialize(s, TX_WITH_WITNESS(m_txs));
109+
}
110+
111+
BlockType() : BlockHeaderType() { }
112+
113+
void SetNull()
114+
{
115+
BlockHeaderType::SetNull();
116+
m_txs.clear();
117+
}
118+
119+
bool IsNull() const
120+
{
121+
return BlockHeaderType::IsNull();
122+
}
123+
};
124+
125+
} // namespace coin
126+
127+
} // namespace nmc

src/impl/nmc/coin/coin_smoke.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// NMC coin P0 structural-leaf smoke translation unit.
2+
//
3+
// Header-only NMC coin types (block.hpp, header_chain.hpp) are otherwise never
4+
// instantiated in a .cpp, so they would not be compile-checked by the build.
5+
// This TU forces instantiation of the P0 structural leaf so CMake's nmc_coin
6+
// target actually compiles header_chain.hpp (and its AuxPow / HeaderChain
7+
// skeleton). It does NOT perform any validation — consistent with the P0 fence.
8+
9+
#include "header_chain.hpp"
10+
#include "block.hpp"
11+
12+
namespace nmc {
13+
namespace coin {
14+
15+
// Force template/inline instantiation of the structural leaf.
16+
void nmc_coin_p0_smoke()
17+
{
18+
NMCChainParams params = NMCChainParams::mainnet();
19+
HeaderChain chain(params);
20+
(void)chain.init();
21+
(void)chain.height();
22+
(void)chain.size();
23+
24+
BlockHeaderType header;
25+
header.SetNull();
26+
(void)block_hash(header);
27+
(void)pow_hash(header);
28+
29+
AuxPow auxpow;
30+
auxpow.SetNull();
31+
// P0-DEFER stub must report NOT_IMPLEMENTED_P0.
32+
(void)auxpow.check_proof(uint256{}, params.aux_chain_id);
33+
34+
AuxChain aux_slot;
35+
std::vector<AuxChain> aux_chains; // nmc-local list (fence #4)
36+
aux_chains.push_back(aux_slot);
37+
(void)aux_chains;
38+
}
39+
40+
} // namespace coin
41+
} // namespace nmc

0 commit comments

Comments
 (0)