Skip to content

Commit 91d60dc

Browse files
authored
Merge pull request #93 from frstrtr/dgb/embedded-p2p-mempool
DGB Phase A: embedded P2P + mempool (#82)
2 parents c67fbc1 + f992d95 commit 91d60dc

15 files changed

Lines changed: 3125 additions & 23 deletions

src/impl/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(ltc)
2-
add_subdirectory(btc)
2+
add_subdirectory(btc)
3+
add_subdirectory(dgb)

src/impl/dgb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# follows the OBJECT-lib convention PR; held ~2-3 heartbeats, not raced here.
1919
if(COIN_DGB)
2020
message(STATUS "c2pool: DGB Scrypt-only coin module enabled (skeleton)")
21-
# add_subdirectory(coin)
21+
add_subdirectory(coin)
2222
# add_subdirectory(daemon)
2323
# add_subdirectory(test)
2424
endif()

src/impl/dgb/coin/CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
# dgb_coin -- DGB coin-layer library (Path A minimal-stub surface).
2-
# Mirrors src/impl/btc/coin/CMakeLists.txt, listing only the files that exist
3-
# at this milestone. NOT yet referenced by any add_subdirectory(): top-level
4-
# registration of src/impl/dgb follows the ci-steward OBJECT-lib convention
5-
# (see ../CMakeLists.txt); staged here so that wiring is a one-line flip.
1+
# dgb_coin -- DGB coin-layer library.
2+
# Mirrors src/impl/btc/coin/CMakeLists.txt. Phase A (#82) adds the embedded
3+
# P2P + mempool layer (non-MWEB, btc-shaped; Scrypt PoW lives in header_chain).
4+
# NOT yet referenced by any add_subdirectory(): top-level registration of
5+
# src/impl/dgb follows the ci-steward OBJECT-lib convention (see ../CMakeLists.txt);
6+
# staged here so that wiring is a one-line flip.
67

78
set(dgb_coin_impl
89
rpc_data.hpp
910
rpc.hpp
11+
p2p_connection.hpp p2p_connection.cpp
12+
p2p_node.cpp p2p_node.hpp
13+
p2p_messages.hpp
1014
node.hpp
1115
coin_node.hpp coin_node.cpp
1216
)
1317

1418
set(dgb_coin_interface
19+
txidcache.hpp
1520
node_interface.hpp
21+
block.hpp
22+
transaction.hpp transaction.cpp
23+
compact_blocks.hpp
1624
header_chain.hpp
25+
mempool.hpp
1726
template_builder.hpp
1827
)
1928

src/impl/dgb/coin/block.hpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#pragma once
2+
3+
// DGB block/header types. 1:1 mirror of src/impl/btc/coin/block.hpp (NON-MWEB).
4+
//
5+
// >>> MULTI-ALGO NOTE (project_v36_dgb_scrypt_only) <<<
6+
// The 80-byte header layout (version|prev|merkle|time|bits|nonce) is identical
7+
// across DGB`s 5 algos -- this serialization is algo-agnostic and correct as-is.
8+
// The block version field additionally ENCODES the mining algo in its bits;
9+
// DGB-Scrypt validation reads that algo selector in header_chain.hpp, NOT here.
10+
// Do not add per-algo branching to (de)serialization -- it is single-format.
11+
12+
#include "transaction.hpp"
13+
14+
#include <core/uint256.hpp>
15+
#include <core/pack_types.hpp>
16+
#include <core/netaddress.hpp>
17+
18+
namespace dgb
19+
{
20+
21+
namespace coin
22+
{
23+
24+
struct SmallBlockHeaderType
25+
{
26+
uint64_t m_version {};
27+
uint256 m_previous_block{};
28+
uint32_t m_timestamp{};
29+
uint32_t m_bits{};
30+
uint32_t m_nonce{};
31+
32+
C2POOL_SERIALIZE_METHODS(SmallBlockHeaderType) { READWRITE(VarInt(obj.m_version), obj.m_previous_block, obj.m_timestamp, obj.m_bits, obj.m_nonce); }
33+
34+
SmallBlockHeaderType() {}
35+
36+
void SetNull()
37+
{
38+
m_version = 0;
39+
m_previous_block.SetNull();
40+
m_timestamp = 0;
41+
m_bits = 0;
42+
m_nonce = 0;
43+
}
44+
45+
bool IsNull() const
46+
{
47+
return (m_bits == 0);
48+
}
49+
};
50+
51+
struct BlockHeaderType : SmallBlockHeaderType
52+
{
53+
uint256 m_merkle_root;
54+
55+
// Full block header uses fixed 4-byte int32 version (not VarInt like SmallBlockHeaderType)
56+
template<typename Stream>
57+
void Serialize(Stream& s) const {
58+
uint32_t version32 = static_cast<uint32_t>(m_version);
59+
::Serialize(s, version32);
60+
::Serialize(s, m_previous_block);
61+
::Serialize(s, m_merkle_root);
62+
::Serialize(s, m_timestamp);
63+
::Serialize(s, m_bits);
64+
::Serialize(s, m_nonce);
65+
}
66+
template<typename Stream>
67+
void Unserialize(Stream& s) {
68+
uint32_t version32;
69+
::Unserialize(s, version32);
70+
m_version = version32;
71+
::Unserialize(s, m_previous_block);
72+
::Unserialize(s, m_merkle_root);
73+
::Unserialize(s, m_timestamp);
74+
::Unserialize(s, m_bits);
75+
::Unserialize(s, m_nonce);
76+
}
77+
78+
BlockHeaderType() : SmallBlockHeaderType() { }
79+
80+
void SetNull()
81+
{
82+
SmallBlockHeaderType::SetNull();
83+
m_merkle_root.SetNull();
84+
}
85+
86+
bool IsNull() const
87+
{
88+
return (m_bits == 0);
89+
}
90+
91+
};
92+
93+
struct BlockType : BlockHeaderType
94+
{
95+
std::vector<MutableTransaction> m_txs;
96+
97+
template <typename Stream>
98+
void Serialize(Stream& s) const {
99+
BlockHeaderType::Serialize(s);
100+
::Serialize(s, TX_WITH_WITNESS(m_txs));
101+
}
102+
103+
template <typename Stream>
104+
void Unserialize(Stream& s) {
105+
BlockHeaderType::Unserialize(s);
106+
::Unserialize(s, TX_WITH_WITNESS(m_txs));
107+
}
108+
109+
BlockType() : BlockHeaderType() { }
110+
111+
void SetNull()
112+
{
113+
BlockHeaderType::SetNull();
114+
m_txs.clear();
115+
}
116+
117+
bool IsNull() const
118+
{
119+
return BlockHeaderType::IsNull();
120+
}
121+
};
122+
123+
} // namespace coin
124+
125+
} // namespace dgb

0 commit comments

Comments
 (0)