Skip to content

Commit e8ea6ad

Browse files
committed
init: don't create a CBlockPolicyEstimator if we don't relay transactions
Signed-off-by: Antoine Poinsot <[email protected]>
1 parent 86ff2cf commit e8ea6ad

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/init.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1384,13 +1384,20 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
13841384
// is not yet setup and may end up being set up twice if we
13851385
// need to reindex later.
13861386

1387+
// see Step 2: parameter interactions for more information about these
1388+
fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
1389+
fDiscover = args.GetBoolArg("-discover", true);
1390+
g_relay_txes = !args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
1391+
13871392
assert(!node.banman);
13881393
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
13891394
assert(!node.connman);
13901395
node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));
13911396

13921397
assert(!node.fee_estimator);
1393-
node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
1398+
// Don't initialize fee estimation with old data if we don't relay transactions,
1399+
// as they would never get updated.
1400+
if (g_relay_txes) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
13941401

13951402
assert(!node.mempool);
13961403
int check_ratio = std::min<int>(std::max<int>(args.GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
@@ -1476,11 +1483,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
14761483
}
14771484
}
14781485

1479-
// see Step 2: parameter interactions for more information about these
1480-
fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
1481-
fDiscover = args.GetBoolArg("-discover", true);
1482-
g_relay_txes = !args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
1483-
14841486
for (const std::string& strAddr : args.GetArgs("-externalip")) {
14851487
CService addrLocal;
14861488
if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())

test/functional/feature_fee_estimation.py

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
assert_equal,
1414
assert_greater_than,
1515
assert_greater_than_or_equal,
16+
assert_raises_rpc_error,
1617
satoshi_round,
1718
)
1819

@@ -262,6 +263,11 @@ def run_test(self):
262263
self.log.info("Final estimates after emptying mempools")
263264
check_estimates(self.nodes[1], self.fees_per_kb)
264265

266+
self.log.info("Testing that fee estimation is disabled in blocksonly.")
267+
self.restart_node(0, ["-blocksonly"])
268+
assert_raises_rpc_error(-32603, "Fee estimation disabled",
269+
self.nodes[0].estimatesmartfee, 2)
270+
265271

266272
if __name__ == '__main__':
267273
EstimateFeeTest().main()

0 commit comments

Comments
 (0)