|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | +#pragma once |
| 3 | +// =========================================================================== |
| 4 | +// dash reception wire (leg 1 of 4) -- interfaces::Node::new_tx -> maintainer. |
| 5 | +// |
| 6 | +// #672..#685 landed the node-held embedded coin-state bundle plus its async |
| 7 | +// CoinStateMaintainer, and proved that DRIVING the maintainer's on_*() methods |
| 8 | +// flips select_work() to the embedded arm. But nothing in a LIVE NodeImpl ever |
| 9 | +// subscribed the coin interface's reception events to that maintainer, so in a |
| 10 | +// running node the arm could never flip on its own -- the maintainer sat idle. |
| 11 | +// This is the first of the four reception legs |
| 12 | +// (on_mempool_tx / on_block_connected / on_new_tip / on_mn_list_update): the |
| 13 | +// mempool-relay leg, wired exactly as the dgb sibling (wire_mempool_ingest) |
| 14 | +// but routed through the maintainer's on_mempool_tx() so the readiness / |
| 15 | +// republish bookkeeping stays in one place. |
| 16 | +// |
| 17 | +// PAYLOAD-COMPLETE TODAY: interfaces::Node::new_tx carries a whole |
| 18 | +// coin::Transaction, and on_mempool_tx() never gates publication (an empty |
| 19 | +// mempool still yields a valid coinbase-only template), so this leg needs no |
| 20 | +// chain context. The other three legs are NOT wired here: on_block_connected |
| 21 | +// needs the connected block's HEIGHT (full_block carries none -- see bch's |
| 22 | +// block_connector deriving it from the chain tip), on_new_tip needs |
| 23 | +// bits/mtp/address-version params a bare best_block_hash does not carry, and |
| 24 | +// on_mn_list_update has no source event on interfaces::Node at all. Those are |
| 25 | +// their own slices; opening them touches the interface shape and is a design |
| 26 | +// decision surfaced to the integrator, not guessed here. |
| 27 | +// |
| 28 | +// LIFETIME: the handler captures `maint` by reference, so `maint` (and the |
| 29 | +// NodeCoinState it drives) MUST outlive `node`. The returned EventDisposable |
| 30 | +// lets a caller tear the subscription down explicitly; EventDisposable does |
| 31 | +// NOT auto-dispose on destruction, so if the handle is dropped the |
| 32 | +// subscription persists for the node's life. |
| 33 | +// |
| 34 | +// SCC (#143 / #22 / #39): pulls transaction.hpp (the tx serialization codec), |
| 35 | +// so include this header ONLY from a TU that already links the full dash codec |
| 36 | +// (main_dash + this leg's KAT), never a guard-weight TU -- identical to the |
| 37 | +// dgb mempool_ingest / embedded_tx_select btclibs-SCC trap. |
| 38 | +// =========================================================================== |
| 39 | +#include <memory> |
| 40 | + |
| 41 | +#include <core/events.hpp> |
| 42 | + |
| 43 | +#include "node_interface.hpp" // dash::interfaces::Node (new_tx feed) |
| 44 | +#include "coin_state_maintainer.hpp" // dash::coin::CoinStateMaintainer::on_mempool_tx |
| 45 | +#include "transaction.hpp" // dash::coin::Transaction -> MutableTransaction |
| 46 | + |
| 47 | +namespace c2pool::dash |
| 48 | +{ |
| 49 | + |
| 50 | +// Subscribe `maint` to `node.new_tx`: every relayed tx is folded into the |
| 51 | +// maintainer's mempool via on_mempool_tx (fee_known=false until a UTXO view |
| 52 | +// feeds it, matching the embedded shaper's conservative default -- a P2P-fed |
| 53 | +// mempool cannot desync coinbasevalue versus a daemon's GBT). The mempool leg |
| 54 | +// never gates publication, so a rejected tx (bad utxo ref / already-in) is a |
| 55 | +// no-op here, not a demotion. Returns the subscription handle so the caller |
| 56 | +// controls teardown. |
| 57 | +inline std::shared_ptr<EventDisposable> |
| 58 | +wire_mempool_ingest(::dash::interfaces::Node& node, |
| 59 | + ::dash::coin::CoinStateMaintainer& maint) |
| 60 | +{ |
| 61 | + return node.new_tx.subscribe( |
| 62 | + [&maint](const ::dash::coin::Transaction& tx) |
| 63 | + { |
| 64 | + maint.on_mempool_tx(::dash::coin::MutableTransaction(tx)); |
| 65 | + }); |
| 66 | +} |
| 67 | + |
| 68 | +} // namespace c2pool::dash |
0 commit comments