multi: merge DetermineFeePerKw and Estimate

This commit moves `DetermineFeePerKw` into the `Estimate` method on
`FeePreference`. A few callsites previously calling `DetermineFeePerKw`
without the max fee rate is now also temporarily fixed by forcing them
to use `Estimate` with the default sweeper max fee rate.
This commit is contained in:
yyforyongyu
2023-11-03 18:48:09 +08:00
parent 18b06b7303
commit 6ff6c86155
8 changed files with 228 additions and 179 deletions

View File

@@ -1,6 +1,8 @@
package chainfee
import "github.com/stretchr/testify/mock"
import (
"github.com/stretchr/testify/mock"
)
type mockFeeSource struct {
mock.Mock
@@ -15,3 +17,50 @@ func (m *mockFeeSource) GetFeeMap() (map[uint32]uint32, error) {
return args.Get(0).(map[uint32]uint32), args.Error(1)
}
// MockEstimator implements the `Estimator` interface and is used by
// other packages for mock testing.
type MockEstimator struct {
mock.Mock
}
// Compile time assertion that MockEstimator implements Estimator.
var _ Estimator = (*MockEstimator)(nil)
// EstimateFeePerKW takes in a target for the number of blocks until an initial
// confirmation and returns the estimated fee expressed in sat/kw.
func (m *MockEstimator) EstimateFeePerKW(
numBlocks uint32) (SatPerKWeight, error) {
args := m.Called(numBlocks)
if args.Get(0) == nil {
return 0, args.Error(1)
}
return args.Get(0).(SatPerKWeight), args.Error(1)
}
// Start signals the Estimator to start any processes or goroutines it needs to
// perform its duty.
func (m *MockEstimator) Start() error {
args := m.Called()
return args.Error(0)
}
// Stop stops any spawned goroutines and cleans up the resources used by the
// fee estimator.
func (m *MockEstimator) Stop() error {
args := m.Called()
return args.Error(0)
}
// RelayFeePerKW returns the minimum fee rate required for transactions to be
// relayed. This is also the basis for calculation of the dust limit.
func (m *MockEstimator) RelayFeePerKW() SatPerKWeight {
args := m.Called()
return args.Get(0).(SatPerKWeight)
}