1- From 3cf380db8f763f4522ef1bda21b3c5f200dced75 Mon Sep 17 00:00:00 2001
1+ From 9fc9638e54a3550f9842e0a5a8d5dce6551ed7ed Mon Sep 17 00:00:00 2001
22From: Lawrence Nahum <
[email protected] >
3- Date: Fri, 29 Oct 2021 17:39:28 +0200
3+ Date: Sat, 19 Nov 2022 16:27:16 +0100
44Subject: [PATCH] add support to save fee estimates without shutting down the
55 node
66
77---
8- src/policy/fees.cpp | 18 ++++- --
8+ src/policy/fees.cpp | 16 ++++--
99 src/policy/fees.h | 3 ++
10- src/rpc/misc .cpp | 27 ++++++++++
10+ src/rpc/mempool .cpp | 29 ++++++++++
1111 src/test/fuzz/rpc.cpp | 1 +
1212 .../feature_fee_estimates_persist.py | 54 +++++++++++++++++++
1313 test/functional/test_runner.py | 1 +
14- 6 files changed, 98 insertions(+), 6 deletions(-)
14+ 6 files changed, 99 insertions(+), 5 deletions(-)
1515 create mode 100755 test/functional/feature_fee_estimates_persist.py
1616
1717diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp
18- index 2ae5798eb..8a5ac99fb 100644
18+ index 2b940be07..7edd5807f 100644
1919--- a/src/policy/fees.cpp
2020+++ b/src/policy/fees.cpp
21- @@ -883,12 +883 ,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation
21+ @@ -903,11 +903 ,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation
2222
2323 void CBlockPolicyEstimator::Flush() {
2424 FlushUnconfirmed();
2525-
26- - fs::path est_filepath = gArgs.GetDataDirNet() / FEE_ESTIMATES_FILENAME;
27- - CAutoFile est_file(fsbridge::fopen(est_filepath, "wb"), SER_DISK, CLIENT_VERSION);
26+ - AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
2827- if (est_file.IsNull() || !Write(est_file)) {
29- - LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", est_filepath.string( ));
28+ - LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath ));
3029- }
3130+ Write();
3231 }
3332
34- bool CBlockPolicyEstimator::Write(CAutoFile & fileout) const
35- @@ -916 ,6 +911,17 @@ bool CBlockPolicyEstimator::Write(CAutoFile & fileout) const
33+ bool CBlockPolicyEstimator::Write(AutoFile & fileout) const
34+ @@ -935 ,6 +931,16 @@ bool CBlockPolicyEstimator::Write(AutoFile & fileout) const
3635 return true;
3736 }
3837
3938+ bool CBlockPolicyEstimator::Write() const
4039+ {
41- + fs::path est_filepath = gArgs.GetDataDirNet() / FEE_ESTIMATES_FILENAME;
42- + CAutoFile est_file(fsbridge::fopen(est_filepath, "wb"), SER_DISK, CLIENT_VERSION);
40+ + AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
4341+ if (est_file.IsNull() || !Write(est_file)) {
44- + LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", est_filepath.string( ));
42+ + LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath ));
4543+ return false;
4644+ }
4745+ return true;
4846+ }
4947+
50- bool CBlockPolicyEstimator::Read(CAutoFile & filein)
48+ bool CBlockPolicyEstimator::Read(AutoFile & filein)
5149 {
5250 try {
5351diff --git a/src/policy/fees.h b/src/policy/fees.h
54- index c444d71a3..9d178d0a6 100644
52+ index e4628bf85..f4ac5c00e 100644
5553--- a/src/policy/fees.h
5654+++ b/src/policy/fees.h
57- @@ -213 ,6 +213 ,9 @@ public:
58- /** Write estimation data to a file */
59- bool Write(CAutoFile& fileout) const ;
55+ @@ -223 ,6 +223 ,9 @@ public:
56+ bool Write(AutoFile& fileout) const
57+ EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator) ;
6058
6159+ /** Write estimation data to the default file */
62- + bool Write() const;
60+ + bool Write() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator) ;
6361+
6462 /** Read estimation data from a file */
65- bool Read(CAutoFile& filein);
63+ bool Read(AutoFile& filein)
64+ EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
65+ diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
66+ index 5c1770704..20083a974 100644
67+ --- a/src/rpc/mempool.cpp
68+ +++ b/src/rpc/mempool.cpp
69+ @@ -22,6 +22,9 @@
70+ #include <util/moneystr.h>
71+ #include <util/time.h>
6672
67- diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
68- index 5178ce60e..0050b82a6 100644
69- --- a/src/rpc/misc.cpp
70- +++ b/src/rpc/misc.cpp
71- @@ -14,6 +14,7 @@
72- #include <key_io.h>
73- #include <node/context.h>
74- #include <outputtype.h>
7573+ #include <policy/fees.h>
76- #include <rpc/blockchain.h>
77- #include <rpc/server.h>
78- #include <rpc/util.h>
79- @@ -328,6 +329,31 @@ static RPCHelpMan verifymessage()
74+ +
75+ +
76+ using kernel::DumpMempool;
77+
78+ using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
79+ @@ -705,6 +708,31 @@ static RPCHelpMan getmempoolinfo()
8080 };
8181 }
8282
@@ -105,22 +105,22 @@ index 5178ce60e..0050b82a6 100644
105105+ };
106106+ }
107107+
108- static RPCHelpMan signmessagewithprivkey ()
108+ static RPCHelpMan savemempool ()
109109 {
110- return RPCHelpMan{"signmessagewithprivkey ",
111- @@ -759 ,6 +785 ,7 @@ static const CRPCCommand commands[] =
112- { "util", &deriveaddresses, },
113- { "util", &getdescriptorinfo, },
114- { "util", &verifymessage, },
115- + { "util ", &savefeeestimates, },
116- { "util", &signmessagewithprivkey, },
117- { "util", &getindexinfo, },
118-
110+ return RPCHelpMan{"savemempool ",
111+ @@ -898 ,6 +926 ,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
112+ {"blockchain", &getmempoolinfo },
113+ {"blockchain", &getrawmempool },
114+ {"blockchain", &savemempool },
115+ + {"blockchain ", &savefeeestimates},
116+ {"hidden", &submitpackage },
117+ };
118+ for (const auto& c : commands) {
119119diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp
120- index 9195cc487..df41004fa 100644
120+ index 26913a41d..977ae63a9 100644
121121--- a/src/test/fuzz/rpc.cpp
122122+++ b/src/test/fuzz/rpc.cpp
123- @@ -76 ,6 +76 ,7 @@ const std::vector<std::string> RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{
123+ @@ -80 ,6 +80 ,7 @@ const std::vector<std::string> RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{
124124 "importwallet", // avoid reading from disk
125125 "loadwallet", // avoid reading from disk
126126 "prioritisetransaction", // avoid signed integer overflow in CTxMemPool::PrioritiseTransaction(uint256 const&, long const&) (https://github.com/bitcoin/bitcoin/issues/20626)
@@ -189,10 +189,10 @@ index 000000000..c6d82345b
189189+ if __name__ == "__main__":
190190+ FeeEstimatesPersistTest().main()
191191diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
192- index 725706947..a2f50b537 100755
192+ index d78c1c634..bf9dbe12a 100755
193193--- a/test/functional/test_runner.py
194194+++ b/test/functional/test_runner.py
195- @@ -134 ,6 +134 ,7 @@ BASE_SCRIPTS = [
195+ @@ -136 ,6 +136 ,7 @@ BASE_SCRIPTS = [
196196 # vv Tests less than 30s vv
197197 'wallet_keypool_topup.py --legacy-wallet',
198198 'wallet_keypool_topup.py --descriptors',
@@ -201,5 +201,5 @@ index 725706947..a2f50b537 100755
201201 'interface_zmq.py',
202202 'rpc_invalid_address_message.py',
203203- -
204- 2.20.1
204+ 2.30.2
205205
0 commit comments