Skip to content

Commit 414cf41

Browse files
authored
Merge pull request #566 from frstrtr/btc/g3b-mempool-bip35-ingest
btc: BIP 35 mempool pull on connect -> POPULATED G3b templates
2 parents 7e798ba + 7c6ed7b commit 414cf41

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/c2pool/main_btc.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,15 @@ int main(int argc, char* argv[])
533533
LOG_INFO << "[BTC] Connecting to bitcoind...";
534534
coin_node.start_p2p(NetService(bitcoind_host, bitcoind_port));
535535

536+
// Phase 10c: pull the peer mempool on connect (BIP 35) so TemplateBuilder
537+
// produces POPULATED blocks. Without this the new_tx subscription above only
538+
// sees txs announced via inv AFTER connect; txs already resident in the
539+
// bitcoind mempool at connect time (e.g. a seeded regtest mempool) are never
540+
// requested, leaving coinbase-only templates. Mirrors main_dgb. Peer must
541+
// advertise NODE_BLOOM (regtest: -peerbloomfilters=1) or the request is
542+
// skipped (logged) to avoid a disconnect; normal inv relay still applies.
543+
coin_node.enable_mempool_request();
544+
536545
// Drive initial header sync. Per BTC protocol, NodeP2P's verack handler
537546
// sends sendheaders/sendcmpct/feefilter but NOT getheaders — header sync
538547
// is the consumer's responsibility (LTC drives this from the broadcaster).

src/impl/btc/coin/node.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Node : public btc::interfaces::Node
2929

3030
std::unique_ptr<NodeRPC> m_rpc;
3131
std::unique_ptr<NodeP2P<config_t>> m_p2p;
32+
bool m_request_mempool_on_connect{false}; // BIP 35 pull on (re)connect
3233

3334
void init_p2p()
3435
{
@@ -79,10 +80,26 @@ class Node : public btc::interfaces::Node
7980
void start_p2p(const NetService& addr)
8081
{
8182
m_p2p = std::make_unique<NodeP2P<config_t>>(m_context, this, m_config);
83+
if (m_request_mempool_on_connect)
84+
m_p2p->enable_mempool_request();
8285
m_p2p->connect(addr);
8386
LOG_INFO << "Coin P2P broadcaster connecting to " << addr.to_string();
8487
}
8588

89+
/// Opt into the BIP 35 `mempool` request on (re)connect. Without this the
90+
/// embedded mempool only learns txs announced via `inv` AFTER we connect,
91+
/// so any tx already resident in the peer mempool at connect time is never
92+
/// pulled -> coinbase-only templates. Mirrors main_dgb. Idempotent; applies
93+
/// to the current peer immediately and to any peer start_p2p creates later.
94+
/// NOTE: the peer must advertise NODE_BLOOM (regtest: -peerbloomfilters=1)
95+
/// or NodeP2P skips the request to avoid a disconnect.
96+
void enable_mempool_request()
97+
{
98+
m_request_mempool_on_connect = true;
99+
if (m_p2p)
100+
m_p2p->enable_mempool_request();
101+
}
102+
86103
/// Submit a block via P2P directly (faster propagation than RPC).
87104
void submit_block_p2p(BlockType& block)
88105
{

0 commit comments

Comments
 (0)