Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Relay Draft 2 (Orphanage Eviction Approach) #9

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c50859c
[rpc] allow submitpackage to be called outside of regtest
glozow Apr 11, 2023
d6a52d6
[validation] call AcceptSingleTransaction when only 1 package tx left
glozow Dec 15, 2022
3005f35
MOVEONLY: move package checks into helper functions
glozow Sep 16, 2022
feb39aa
scripted-diff: rename CheckPackage to IsPackageWellFormed
glozow Jan 19, 2023
298c09c
[packages] AncestorPackage sorts and builds ancestor subsets
glozow Sep 16, 2022
ee8d481
[fuzz] AncestorPackage
glozow Feb 16, 2023
c5e16ee
[test util] multi-input multi-output CreateValidMempoolTransaction
glozow Oct 3, 2022
08189a8
[validation] skip and pre-fill txns with irreversibly invalid ancestors
glozow Dec 14, 2022
1241c5e
[validation] skip last tx in AcceptPackage "submit individually" loop
glozow Dec 16, 2022
704ecd1
[validation] validate packages by submitting each tx's ancestor sub-p…
glozow Dec 15, 2022
161c61a
[policy] allow any ancestor package, not just child-with-unconfirmed-…
glozow Feb 17, 2023
70adade
[refactor] rename AcceptPackage to AcceptAncestorPackage
glozow Apr 17, 2023
8cf5291
-- Part 1: Orphan Resolution Module --
glozow Feb 20, 2023
9977fa6
[p2p] add tx package tracker
glozow May 1, 2022
2d002cc
[refactor] wrap TxOrphanage inside TxPackageTracker
glozow Oct 6, 2022
73656ff
[txorphange] GetTx by wtxid
glozow Jan 24, 2023
2947755
[txorphanage] EraseTx by wtxid
glozow Feb 20, 2023
14e2f3e
[txorphanage] return erased wtxids from EraseForBlock
glozow Feb 20, 2023
80d756d
[log] add category TXPACKAGES for orphanage and package relay
glozow Mar 6, 2023
f604dc3
[txorphanage] impose a maximum total size of orphans
glozow Mar 31, 2023
f030a4e
[txorphanage] track bytes provided per peer
glozow Apr 18, 2023
412876f
[txorphanage] when peers are overloaded, favor their orphans for evic…
glozow Apr 18, 2023
809e2c4
[txorphanage] handle AddTx(nullptr)
glozow Apr 18, 2023
2d5e167
[txpackagetracker] add orphan resolution tracker
glozow Jan 24, 2023
b41a471
[refactor] use txpackagetracker for orphan resolution
glozow Oct 6, 2022
31c556d
[txpackagetracker] delete unused OrphanageAddTx
glozow Apr 18, 2023
0d693fb
[txrequest] GetCandidatePeers and ResetRequestTimeout
glozow Mar 20, 2023
dffdc15
[txorphanage] support multiple announcers
glozow Apr 18, 2023
808fe20
[unit test] orphanage: multiple announcers, eviction
glozow Apr 18, 2023
427fe67
[p2p] use all orphan announcers as potential parent sources
glozow Oct 6, 2022
17a88be
[doc] no notfound handling for orphan resolution by parent txid
glozow Apr 19, 2023
ee88683
[functional test] orphan handling with multiple announcers and dosers
glozow Apr 19, 2023
e46daca
-- Part 2: Signal SENDPACKAGES --
glozow Feb 20, 2023
8909aec
[txpackagetracker] negotiation logic
glozow Feb 20, 2023
e2ce8cc
[unit test] txpackagetracker tests
glozow Feb 20, 2023
0544ec6
[p2p] signal support for package relay
glozow Oct 7, 2022
eda5593
[rpc] expose package relay on rpc
glozow Sep 6, 2022
cab6f5a
-- Part 3: Request Ancestor Package Info For Orphans --
glozow Feb 20, 2023
80d688b
[packages] hash multiple transactions
glozow Jan 9, 2023
be2e540
[validation/p2p] separate TxValidationResult and rejects filter for l…
glozow Sep 12, 2022
20ca067
[p2p] respond to getdata(ancpkginfo) requests with ancpkginfo
glozow Sep 6, 2022
d7cea47
[txpackagetracker] create ancpkginfo requests using orphan resolution…
glozow Jan 24, 2023
9e3f816
[unit test] txpackagetracker orphan tracking
glozow Feb 20, 2023
0850bc9
[p2p] Resolve orphans by requesting ancpkginfo and requesting txdata
glozow Oct 6, 2022
c71b4f4
-- Part 4: Download and Validate Packages --
glozow Feb 20, 2023
9eb814a
[p2p] respond to getpkgtxns with pkgtxns or notfound MSG_PKGTXNS
glozow Oct 3, 2022
165b930
[txpackagetracker] track packages to download
glozow Jan 5, 2023
f38d199
[txpackagetracker] handle pkgtxns/notfound, return validation work items
glozow Jan 9, 2023
68e8897
[unit test] PkgInfoAllowed, ReceivedAncPkgInfo, ReceivedPkgTxns
glozow Feb 20, 2023
df737db
[p2p] use ancpkginfo to make getpkgtxns requests
glozow Jan 6, 2023
3a67c66
[p2p] handle pkgtxns and validate packages
glozow Jan 9, 2023
9d2a7f7
[p2p] don't inv fee-bumping children to non-pkgrelay peers
glozow Apr 4, 2023
d172b7b
-- Part 5: Nice to Haves --
glozow Feb 20, 2023
3b461e8
[txpackagetracker] delay overloaded peers and expire orphans faster
glozow May 3, 2023
9d9e1de
[mempool] evict everything below min relay fee in TrimToSize()
glozow Jan 17, 2023
1d2b4cb
[test framework] return txhex from create_lots_of_big_transactions
glozow Jan 19, 2023
d7ed479
[test] raise wallet_abandonconflict -minrelaytxfee settings
glozow Jan 19, 2023
82a2cdd
[mempool] persist packages across restart
glozow Jan 19, 2023
7ee77ad
wip [test] orphanage DoSing
glozow May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ BITCOIN_CORE_H = \
node/minisketchwrapper.h \
node/psbt.h \
node/transaction.h \
node/txpackagetracker.h \
node/txreconciliation.h \
node/utxo_snapshot.h \
node/validation_cache_args.h \
Expand Down Expand Up @@ -412,6 +413,7 @@ libbitcoin_node_a_SOURCES = \
node/minisketchwrapper.cpp \
node/psbt.cpp \
node/transaction.cpp \
node/txpackagetracker.cpp \
node/txreconciliation.cpp \
node/utxo_snapshot.cpp \
node/validation_cache_args.cpp \
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ BITCOIN_TESTS =\
test/translation_tests.cpp \
test/txindex_tests.cpp \
test/txpackage_tests.cpp \
test/txpackagetracker_tests.cpp \
test/txreconciliation_tests.cpp \
test/txrequest_tests.cpp \
test/txvalidation_tests.cpp \
Expand Down Expand Up @@ -237,6 +238,7 @@ test_fuzz_fuzz_SOURCES = \
$(FUZZ_WALLET_SRC) \
test/fuzz/addition_overflow.cpp \
test/fuzz/addrman.cpp \
test/fuzz/ancestorpackage.cpp \
test/fuzz/asmap.cpp \
test/fuzz/asmap_direct.cpp \
test/fuzz/autofile.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/consensus/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum class TxValidationResult {
TX_CONFLICT,
TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/RBF/etc limits
TX_NO_MEMPOOL, //!< this node does not have a mempool so can't validate the transaction
TX_LOW_FEE, //!< fee was insufficient to meet some policy (minimum/RBF/etc)
};

/** A "reason" why a block was invalid, suitable for determining whether the
Expand Down
5 changes: 4 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <node/mempool_args.h>
#include <node/mempool_persist_args.h>
#include <node/miner.h>
#include <node/txpackagetracker.h>
#include <node/txreconciliation.h>
#include <node/validation_cache_args.h>
#include <policy/feerate.h>
Expand Down Expand Up @@ -489,6 +490,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-i2pacceptincoming", strprintf("Whether to accept inbound I2P connections (default: %i). Ignored if -i2psam is not set. Listening for inbound I2P connections is done through the SAM proxy, not by binding to a local address and port.", DEFAULT_I2P_ACCEPT_INCOMING), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-onlynet=<net>", "Make automatic outbound connections only to network <net> (" + Join(GetNetworkNames(), ", ") + "). Inbound and manual connections are not affected by this option. It can be specified multiple times to allow multiple networks.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-packagerelay", strprintf("[EXPERIMENTAL] Support relaying transaction packages (default: %u)", node::DEFAULT_ENABLE_PACKAGE_RELAY), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-txreconciliation", strprintf("Enable transaction reconciliations per BIP 330 (default: %d)", DEFAULT_TXRECONCILIATION_ENABLE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
Expand Down Expand Up @@ -1556,10 +1558,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}

ChainstateManager& chainman = *Assert(node.chainman);
const bool enable_package_relay{gArgs.GetBoolArg("-packagerelay", node::DEFAULT_ENABLE_PACKAGE_RELAY)};

assert(!node.peerman);
node.peerman = PeerManager::make(*node.connman, *node.addrman, node.banman.get(),
chainman, *node.mempool, ignores_incoming_txs);
chainman, *node.mempool, ignores_incoming_txs, enable_package_relay);
RegisterValidationInterface(node.peerman.get());

// ********************************************************* Step 8: start indexers
Expand Down
16 changes: 14 additions & 2 deletions src/kernel/mempool_persist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
}
uint64_t num;
file >> num;
LOCK2(cs_main, pool.cs);
while (num) {
--num;
CTransactionRef tx;
Expand All @@ -77,8 +78,12 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
pool.PrioritiseTransaction(tx->GetHash(), amountdelta);
}
if (nTime > TicksSinceEpoch<std::chrono::seconds>(now - pool.m_expiry)) {
LOCK(cs_main);
const auto& accepted = AcceptToMemoryPool(active_chainstate, tx, nTime, /*bypass_limits=*/false, /*test_accept=*/false);
// Use bypass_limits=true to skip feerate checks, and call TrimToSize() at the very
// end. This means the mempool may temporarily exceed its maximum capacity. However,
// this means fee-bumped transactions are persisted, and the resulting mempool
// minimum feerate is not dependent on the order in which transactions are loaded
// from disk.
const auto& accepted = AcceptToMemoryPool(active_chainstate, tx, nTime, /*bypass_limits=*/true, /*test_accept=*/false);
if (accepted.m_result_type == MempoolAcceptResult::ResultType::VALID) {
++count;
} else {
Expand All @@ -104,6 +109,13 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
for (const auto& i : mapDeltas) {
pool.PrioritiseTransaction(i.first, i.second);
}
const auto size_before_trim{pool.size()};
// Ensure the maximum memory limits are ultimately enforced and any transactions below
// minimum feerates are evicted, since bypass_limits was set to true during ATMP calls.
pool.TrimToSize(pool.m_max_size_bytes);
const auto num_evicted{size_before_trim - pool.size()};
count -= num_evicted;
failed += num_evicted;

std::set<uint256> unbroadcast_txids;
file >> unbroadcast_txids;
Expand Down
3 changes: 3 additions & 0 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::BLOCKSTORE, "blockstorage"},
{BCLog::TXRECONCILIATION, "txreconciliation"},
{BCLog::SCAN, "scan"},
{BCLog::TXPACKAGES, "txpackages"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
};
Expand Down Expand Up @@ -286,6 +287,8 @@ std::string LogCategoryToStr(BCLog::LogFlags category)
return "txreconciliation";
case BCLog::LogFlags::SCAN:
return "scan";
case BCLog::LogFlags::TXPACKAGES:
return "txpackages";
case BCLog::LogFlags::ALL:
return "all";
}
Expand Down
1 change: 1 addition & 0 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace BCLog {
BLOCKSTORE = (1 << 26),
TXRECONCILIATION = (1 << 27),
SCAN = (1 << 28),
TXPACKAGES = (1 << 29),
ALL = ~(uint32_t)0,
};
enum class Level {
Expand Down
Loading