Skip to content

Commit 8498833

Browse files
authored
Merge pull request #115 from frstrtr/dgb/pool-layer-port
dgb: Phase B pool wire-message layer (messages, share_messages) — Scrypt-only
2 parents fc436c0 + 8da2172 commit 8498833

5 files changed

Lines changed: 1315 additions & 0 deletions

File tree

src/impl/dgb/messages.hpp

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#pragma once
2+
// V36 DGB-Scrypt pool wire-message layer — namespace-only divergence from
3+
// src/impl/ltc/messages.hpp; message format byte-parity with p2pool-merged-v36.
4+
5+
#include "coin/block.hpp"
6+
#include "coin/transaction.hpp"
7+
8+
#include <string>
9+
10+
#include <core/message.hpp>
11+
#include <core/message_macro.hpp>
12+
#include <sharechain/share.hpp>
13+
14+
namespace dgb
15+
{
16+
17+
// message_version
18+
BEGIN_MESSAGE(version)
19+
MESSAGE_FIELDS
20+
(
21+
(uint32_t, m_version),
22+
(uint64_t, m_services),
23+
(addr_t , m_addr_to),
24+
(addr_t, m_addr_from),
25+
(uint64_t, m_nonce),
26+
(std::string, m_subversion),
27+
(uint32_t, m_mode), //# always 1 for legacy compatibility
28+
(uint256, m_best_share)
29+
)
30+
{
31+
READWRITE(obj.m_version, obj.m_services, obj.m_addr_to, obj.m_addr_from, obj.m_nonce, obj.m_subversion, obj.m_mode, obj.m_best_share);
32+
}
33+
END_MESSAGE()
34+
35+
// message_ping
36+
BEGIN_MESSAGE(ping)
37+
WITHOUT_MESSAGE_FIELDS() { }
38+
END_MESSAGE()
39+
40+
// message_addrme
41+
BEGIN_MESSAGE(addrme)
42+
MESSAGE_FIELDS
43+
(
44+
(uint16_t, m_port)
45+
)
46+
{
47+
READWRITE(obj.m_port);
48+
}
49+
END_MESSAGE()
50+
51+
// message_getaddrs
52+
BEGIN_MESSAGE(getaddrs)
53+
MESSAGE_FIELDS
54+
(
55+
(uint32_t, m_count)
56+
)
57+
{
58+
READWRITE(obj.m_count);
59+
}
60+
END_MESSAGE()
61+
62+
// message_addrs
63+
BEGIN_MESSAGE(addrs)
64+
MESSAGE_FIELDS
65+
(
66+
(std::vector<addr_record_t>, m_addrs)
67+
)
68+
{
69+
READWRITE(obj.m_addrs);
70+
}
71+
END_MESSAGE()
72+
73+
// message_shares
74+
BEGIN_MESSAGE(shares)
75+
MESSAGE_FIELDS
76+
(
77+
(std::vector<chain::RawShare>, m_shares)
78+
)
79+
{
80+
READWRITE(obj.m_shares);
81+
}
82+
END_MESSAGE()
83+
84+
// message_sharereq
85+
BEGIN_MESSAGE(sharereq)
86+
MESSAGE_FIELDS
87+
(
88+
(uint256, m_id),
89+
(std::vector<uint256>, m_hashes),
90+
(uint64_t, m_parents),
91+
(std::vector<uint256>, m_stops)
92+
)
93+
{
94+
READWRITE(obj.m_id, obj.m_hashes, VarInt(obj.m_parents), obj.m_stops);
95+
}
96+
END_MESSAGE()
97+
98+
enum ShareReplyResult
99+
{
100+
good = 0,
101+
too_long = 1,
102+
unk2 = 2,
103+
unk3 = 3,
104+
unk4 = 4,
105+
unk5 = 5,
106+
unk6 = 6
107+
};
108+
109+
// message_sharereply
110+
BEGIN_MESSAGE(sharereply)
111+
MESSAGE_FIELDS
112+
(
113+
(uint256, m_id),
114+
(ShareReplyResult, m_result),
115+
(std::vector<chain::RawShare>, m_shares)
116+
)
117+
{
118+
READWRITE(obj.m_id, Using<EnumType<CompactFormat>>(obj.m_result), obj.m_shares);
119+
}
120+
END_MESSAGE()
121+
122+
// message_bestblock
123+
BEGIN_MESSAGE(bestblock)
124+
MESSAGE_FIELDS
125+
(
126+
(coin::BlockHeaderType, m_header)
127+
)
128+
{
129+
READWRITE(obj.m_header);
130+
}
131+
END_MESSAGE()
132+
133+
// message_have_tx
134+
BEGIN_MESSAGE(have_tx)
135+
MESSAGE_FIELDS
136+
(
137+
(std::vector<uint256>, m_tx_hashes)
138+
)
139+
{
140+
READWRITE(obj.m_tx_hashes);
141+
}
142+
END_MESSAGE()
143+
144+
// message_losing_tx
145+
BEGIN_MESSAGE(losing_tx)
146+
MESSAGE_FIELDS
147+
(
148+
(std::vector<uint256>, m_tx_hashes)
149+
)
150+
{
151+
READWRITE(obj.m_tx_hashes);
152+
}
153+
END_MESSAGE()
154+
155+
// message_forget_tx
156+
BEGIN_MESSAGE(forget_tx)
157+
MESSAGE_FIELDS
158+
(
159+
(std::vector<uint256>, m_tx_hashes)
160+
)
161+
{
162+
READWRITE(obj.m_tx_hashes);
163+
}
164+
END_MESSAGE()
165+
166+
// message_remember_tx
167+
BEGIN_MESSAGE(remember_tx)
168+
MESSAGE_FIELDS
169+
(
170+
(std::vector<uint256>, m_tx_hashes),
171+
(std::vector<coin::MutableTransaction>, m_txs)
172+
)
173+
{
174+
READWRITE(obj.m_tx_hashes, coin::TX_WITH_WITNESS(obj.m_txs));
175+
}
176+
END_MESSAGE()
177+
178+
using Handler = MessageHandler<
179+
message_ping,
180+
message_addrme,
181+
message_getaddrs,
182+
message_addrs,
183+
message_shares,
184+
message_sharereq,
185+
message_sharereply,
186+
message_bestblock,
187+
message_have_tx,
188+
message_losing_tx,
189+
message_forget_tx,
190+
message_remember_tx
191+
>;
192+
193+
} // namespace dgb

src/impl/dgb/peer.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include "coin/transaction.hpp"
4+
5+
#include <chrono>
6+
#include <set>
7+
#include <optional>
8+
#include <core/uint256.hpp>
9+
10+
namespace dgb
11+
{
12+
13+
struct Peer
14+
{
15+
std::optional<uint32_t> m_other_version;
16+
std::string m_other_subversion;
17+
uint64_t m_other_services;
18+
uint64_t m_nonce;
19+
std::chrono::steady_clock::time_point m_connected_at{std::chrono::steady_clock::now()};
20+
21+
std::set<uint256> m_remote_txs; // hashes
22+
// int32_t remote_remembered_txs_size = 0;
23+
24+
std::map<uint256, coin::Transaction> m_remembered_txs;
25+
// int32_t remembered_txs_size = 0;
26+
// const int32_t max_remembered_txs_size = 25000000;
27+
};
28+
29+
}; // namespace dgb

0 commit comments

Comments
 (0)