@@ -206,4 +206,49 @@ BOOST_AUTO_TEST_CASE(client_tests)
206206 tester.m_mining_control ->Shutdown ();
207207}
208208
209+ // Test fee-based rate limiting timer (-sv2interval flag).
210+ // Uses is_test=false to exercise actual timer logic.
211+ BOOST_AUTO_TEST_CASE (fee_timer_blocking_test)
212+ {
213+ // Use real wall-clock time instead of mock time
214+ SetMockTime (std::chrono::seconds{0 });
215+
216+ Sv2TemplateProviderOptions opts;
217+ opts.is_test = false ;
218+ opts.fee_check_interval = std::chrono::seconds{2 };
219+ TPTester tester{opts};
220+
221+ tester.handshake ();
222+ tester.SendSetupConnection ();
223+ tester.SendCoinbaseOutputConstraints ();
224+ tester.ReceiveTemplatePair ();
225+
226+ const size_t expected_new_template = SV2_HEADER_ENCRYPTED_SIZE + TPTester::SV2_NEW_TEMPLATE_MSG_SIZE + Poly1305::TAGLEN;
227+
228+ uint64_t seq = tester.m_mining_control ->GetTemplateSeq ();
229+
230+ // Trigger a fee increase immediately after template; timer should block it
231+ BOOST_TEST_MESSAGE (" Trigger fee increase while timer is blocking" );
232+ std::vector<CTransactionRef> blocked_fee_txs{MakeDummyTx ()};
233+ tester.m_mining_control ->TriggerFeeIncrease (blocked_fee_txs);
234+
235+ bool got_template = tester.m_mining_control ->WaitForTemplateSeq (seq + 1 , std::chrono::milliseconds{2500 });
236+ BOOST_REQUIRE_MESSAGE (!got_template, " Fee increase should be blocked when timer hasn't fired" );
237+ BOOST_REQUIRE_EQUAL (tester.GetBlockTemplateCount (), 1 );
238+
239+ // After fee_check_interval (2s), the timer should allow fee checks
240+ BOOST_TEST_MESSAGE (" Trigger fee increase after timer fires" );
241+ std::vector<CTransactionRef> allowed_fee_txs{MakeDummyTx ()};
242+ tester.m_mining_control ->TriggerFeeIncrease (allowed_fee_txs);
243+
244+ got_template = tester.m_mining_control ->WaitForTemplateSeq (seq + 1 , std::chrono::milliseconds{3000 });
245+ BOOST_REQUIRE_MESSAGE (got_template, " Fee increase should be allowed after timer fires" );
246+
247+ size_t bytes_nt = tester.PeerReceiveBytes ();
248+ BOOST_REQUIRE_EQUAL (bytes_nt, expected_new_template);
249+ BOOST_REQUIRE_EQUAL (tester.GetBlockTemplateCount (), 2 );
250+
251+ tester.m_mining_control ->Shutdown ();
252+ }
253+
209254BOOST_AUTO_TEST_SUITE_END ()
0 commit comments