Skip to content

Commit

Permalink
lntest: allow specifying min relay feerate in itest
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Jul 4, 2024
1 parent b108b37 commit 6c41661
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lntest/fee_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -114,9 +119,12 @@ func (f *FeeService) handleRequest(w http.ResponseWriter, _ *http.Request) {

bytes, err := json.Marshal(
struct {
Fees map[uint32]uint32 `json:"fee_by_block_target"`
//nolint:lll
Fees map[uint32]uint32 `json:"fee_by_block_target"`
MinRelayFeerate chainfee.SatPerKVByte `json:"min_relay_feerate"`
}{
Fees: f.feeRateMap,
Fees: f.feeRateMap,
MinRelayFeerate: f.minRelayFeerate,
},
)
require.NoErrorf(f, err, "cannot serialize estimates")
Expand All @@ -143,6 +151,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()
Expand Down
6 changes: 6 additions & 0 deletions lntest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,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 {
Expand Down

0 comments on commit 6c41661

Please sign in to comment.