From a1d71afde8544f74cc8e5862ffa1a794a5cf5bc0 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 4 Jul 2024 20:36:16 +0800 Subject: [PATCH] lntest: allow specifying min relay feerate in itest --- lntest/fee_service.go | 24 ++++++++++++++++++------ lntest/harness.go | 6 ++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lntest/fee_service.go b/lntest/fee_service.go index cee9ae0ab..0514a387e 100644 --- a/lntest/fee_service.go +++ b/lntest/fee_service.go @@ -33,6 +33,9 @@ type WebFeeService interface { // target. SetFeeRate(feeRate chainfee.SatPerKWeight, conf uint32) + // SetMinRelayFeerate sets a min relay feerate. + SetMinRelayFeerate(fee chainfee.SatPerKVByte) + // Reset resets the fee rate map to the default value. Reset() } @@ -52,8 +55,9 @@ const ( type FeeService struct { *testing.T - feeRateMap map[uint32]uint32 - url string + feeRateMap map[uint32]uint32 + minRelayFeerate chainfee.SatPerKVByte + url string srv *http.Server wg sync.WaitGroup @@ -79,6 +83,7 @@ func NewFeeService(t *testing.T) *FeeService { f.feeRateMap = map[uint32]uint32{ feeServiceTarget: DefaultFeeRateSatPerKw, } + f.minRelayFeerate = chainfee.FeePerKwFloor.FeePerKVByte() listenAddr := fmt.Sprintf(":%v", port) mux := http.NewServeMux() @@ -113,10 +118,9 @@ func (f *FeeService) handleRequest(w http.ResponseWriter, _ *http.Request) { defer f.lock.Unlock() bytes, err := json.Marshal( - struct { - Fees map[uint32]uint32 `json:"fee_by_block_target"` - }{ - Fees: f.feeRateMap, + chainfee.WebAPIResponse{ + FeeByBlockTarget: f.feeRateMap, + MinRelayFeerate: f.minRelayFeerate, }, ) require.NoErrorf(f, err, "cannot serialize estimates") @@ -143,6 +147,14 @@ func (f *FeeService) SetFeeRate(fee chainfee.SatPerKWeight, conf uint32) { f.feeRateMap[conf] = uint32(fee.FeePerKVByte()) } +// SetMinRelayFeerate sets a min relay feerate. +func (f *FeeService) SetMinRelayFeerate(fee chainfee.SatPerKVByte) { + f.lock.Lock() + defer f.lock.Unlock() + + f.minRelayFeerate = fee +} + // Reset resets the fee rate map to the default value. func (f *FeeService) Reset() { f.lock.Lock() diff --git a/lntest/harness.go b/lntest/harness.go index eefdcfec1..9a11eaa88 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -860,6 +860,12 @@ func (h *HarnessTest) SetFeeEstimateWithConf( h.feeService.SetFeeRate(fee, conf) } +// SetMinRelayFeerate sets a min relay fee rate to be returned from fee +// estimator. +func (h *HarnessTest) SetMinRelayFeerate(fee chainfee.SatPerKVByte) { + h.feeService.SetMinRelayFeerate(fee) +} + // validateNodeState checks that the node doesn't have any uncleaned states // which will affect its following tests. func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error {