multi: update to latest fee estimation interface
This commit is contained in:
21 files changed
+150
-204
No files matched your search
+3
-21
@@ -35,11 +35,6 @@ const (
|
||||
// TODO(roasbeef): must be < default delta
|
||||
expiryGraceDelta = 2
|
||||
|
||||
// minCommitFeePerKw is the smallest fee rate that we should propose
|
||||
// for a new fee update. We'll use this as a fee floor when proposing
|
||||
// and accepting updates.
|
||||
minCommitFeePerKw = 253
|
||||
|
||||
// DefaultMinLinkFeeUpdateTimeout represents the minimum interval in
|
||||
// which a link should propose to update its commitment fee rate.
|
||||
DefaultMinLinkFeeUpdateTimeout = 10 * time.Minute
|
||||
@@ -495,26 +490,13 @@ func (l *channelLink) EligibleToForward() bool {
|
||||
// this is the native rate used when computing the fee for commitment
|
||||
// transactions, and the second-level HTLC transactions.
|
||||
func (l *channelLink) sampleNetworkFee() (lnwallet.SatPerKWeight, error) {
|
||||
// We'll first query for the sat/vbyte recommended to be confirmed
|
||||
// within 3 blocks.
|
||||
feePerVSize, err := l.cfg.FeeEstimator.EstimateFeePerVSize(3)
|
||||
// We'll first query for the sat/kw recommended to be confirmed within 3
|
||||
// blocks.
|
||||
feePerKw, err := l.cfg.FeeEstimator.EstimateFeePerKW(3)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Once we have this fee rate, we'll convert to sat-per-kw.
|
||||
feePerKw := feePerVSize.FeePerKWeight()
|
||||
|
||||
// If the returned feePerKw is less than the current widely used
|
||||
// policy, then we'll use that instead as a floor.
|
||||
if feePerKw < minCommitFeePerKw {
|
||||
log.Debugf("Proposed fee rate of %v sat/kw is below min "+
|
||||
"of %v sat/kw, using fee floor", int64(feePerKw),
|
||||
int64(minCommitFeePerKw))
|
||||
|
||||
feePerKw = minCommitFeePerKw
|
||||
}
|
||||
|
||||
log.Debugf("ChannelLink(%v): sampled fee rate for 3 block conf: %v "+
|
||||
"sat/kw", l, int64(feePerKw))
|
||||
|
||||
|
||||
+14
-33
@@ -1726,14 +1726,11 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
||||
coreLink.cfg.HodlMask = hodl.MaskFromFlags(hodl.ExitSettle)
|
||||
coreLink.cfg.DebugHTLC = true
|
||||
|
||||
estimator := &lnwallet.StaticFeeEstimator{
|
||||
FeeRate: 24,
|
||||
}
|
||||
feeRate, err := estimator.EstimateFeePerVSize(1)
|
||||
estimator := &lnwallet.StaticFeeEstimator{FeePerKW: 6000}
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
feePerKw := feeRate.FeePerKWeight()
|
||||
htlcFee := lnwire.NewMSatFromSatoshis(
|
||||
feePerKw.FeeForWeight(lnwallet.HtlcWeight),
|
||||
)
|
||||
@@ -2140,14 +2137,11 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
||||
aliceMsgs = coreLink.cfg.Peer.(*mockPeer).sentMsgs
|
||||
)
|
||||
|
||||
estimator := &lnwallet.StaticFeeEstimator{
|
||||
FeeRate: 24,
|
||||
}
|
||||
feeRate, err := estimator.EstimateFeePerVSize(1)
|
||||
estimator := &lnwallet.StaticFeeEstimator{FeePerKW: 6000}
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
feePerKw := feeRate.FeePerKWeight()
|
||||
|
||||
var htlcID uint64
|
||||
addLinkHTLC := func(id uint64, amt lnwire.MilliSatoshi) [32]byte {
|
||||
@@ -2390,17 +2384,15 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) {
|
||||
|
||||
// Compute the static fees that will be used to determine the
|
||||
// correctness of Alice's bandwidth when forwarding HTLCs.
|
||||
estimator := &lnwallet.StaticFeeEstimator{
|
||||
FeeRate: 24,
|
||||
}
|
||||
feeRate, err := estimator.EstimateFeePerVSize(1)
|
||||
estimator := &lnwallet.StaticFeeEstimator{FeePerKW: 6000}
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
|
||||
defaultCommitFee := alice.channel.StateSnapshot().CommitFee
|
||||
htlcFee := lnwire.NewMSatFromSatoshis(
|
||||
feeRate.FeePerKWeight().FeeForWeight(lnwallet.HtlcWeight),
|
||||
feePerKw.FeeForWeight(lnwallet.HtlcWeight),
|
||||
)
|
||||
|
||||
// The starting bandwidth of the channel should be exactly the amount
|
||||
@@ -2666,17 +2658,15 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
||||
|
||||
// Compute the static fees that will be used to determine the
|
||||
// correctness of Alice's bandwidth when forwarding HTLCs.
|
||||
estimator := &lnwallet.StaticFeeEstimator{
|
||||
FeeRate: 24,
|
||||
}
|
||||
feeRate, err := estimator.EstimateFeePerVSize(1)
|
||||
estimator := &lnwallet.StaticFeeEstimator{FeePerKW: 6000}
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
|
||||
defaultCommitFee := alice.channel.StateSnapshot().CommitFee
|
||||
htlcFee := lnwire.NewMSatFromSatoshis(
|
||||
feeRate.FeePerKWeight().FeeForWeight(lnwallet.HtlcWeight),
|
||||
feePerKw.FeeForWeight(lnwallet.HtlcWeight),
|
||||
)
|
||||
|
||||
// The starting bandwidth of the channel should be exactly the amount
|
||||
@@ -2926,14 +2916,11 @@ func TestChannelLinkBandwidthChanReserve(t *testing.T) {
|
||||
aliceMsgs = coreLink.cfg.Peer.(*mockPeer).sentMsgs
|
||||
)
|
||||
|
||||
estimator := &lnwallet.StaticFeeEstimator{
|
||||
FeeRate: 24,
|
||||
}
|
||||
feeRate, err := estimator.EstimateFeePerVSize(1)
|
||||
estimator := &lnwallet.StaticFeeEstimator{FeePerKW: 6000}
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
feePerKw := feeRate.FeePerKWeight()
|
||||
htlcFee := lnwire.NewMSatFromSatoshis(
|
||||
feePerKw.FeeForWeight(lnwallet.HtlcWeight),
|
||||
)
|
||||
@@ -3460,15 +3447,9 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
|
||||
|
||||
startingFeeRate := channels.aliceToBob.CommitFeeRate()
|
||||
|
||||
// Convert starting fee rate to sat/vbyte. This is usually a
|
||||
// lossy conversion, but since the startingFeeRate is
|
||||
// 6000 sat/kw in this case, we won't lose precision.
|
||||
startingFeeRateSatPerVByte := lnwallet.SatPerVByte(
|
||||
startingFeeRate * 4 / 1000)
|
||||
|
||||
// Next, we'll send the first fee rate response to Alice.
|
||||
select {
|
||||
case n.feeEstimator.byteFeeIn <- startingFeeRateSatPerVByte:
|
||||
case n.feeEstimator.byteFeeIn <- startingFeeRate:
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatalf("alice didn't query for the new network fee")
|
||||
}
|
||||
@@ -3497,7 +3478,7 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
|
||||
// fee update.
|
||||
newFeeRate := startingFeeRate * 3
|
||||
select {
|
||||
case n.feeEstimator.byteFeeIn <- startingFeeRateSatPerVByte * 3:
|
||||
case n.feeEstimator.byteFeeIn <- newFeeRate:
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatalf("alice didn't query for the new network fee")
|
||||
}
|
||||
|
||||
+4
-2
@@ -58,12 +58,14 @@ func (m *mockPreimageCache) SubscribeUpdates() *contractcourt.WitnessSubscriptio
|
||||
}
|
||||
|
||||
type mockFeeEstimator struct {
|
||||
byteFeeIn chan lnwallet.SatPerVByte
|
||||
byteFeeIn chan lnwallet.SatPerKWeight
|
||||
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
func (m *mockFeeEstimator) EstimateFeePerVSize(numBlocks uint32) (lnwallet.SatPerVByte, error) {
|
||||
func (m *mockFeeEstimator) EstimateFeePerKW(
|
||||
numBlocks uint32) (lnwallet.SatPerKWeight, error) {
|
||||
|
||||
select {
|
||||
case feeRate := <-m.byteFeeIn:
|
||||
return feeRate, nil
|
||||
|
||||
@@ -271,14 +271,11 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
estimator := &lnwallet.StaticFeeEstimator{
|
||||
FeeRate: 24,
|
||||
}
|
||||
feePerVSize, err := estimator.EstimateFeePerVSize(1)
|
||||
estimator := &lnwallet.StaticFeeEstimator{FeePerKW: 6000}
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
feePerKw := feePerVSize.FeePerKWeight()
|
||||
commitFee := feePerKw.FeeForWeight(724)
|
||||
|
||||
const broadcastHeight = 1
|
||||
@@ -873,7 +870,7 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
carolDecoder := newMockIteratorDecoder()
|
||||
|
||||
feeEstimator := &mockFeeEstimator{
|
||||
byteFeeIn: make(chan lnwallet.SatPerVByte),
|
||||
byteFeeIn: make(chan lnwallet.SatPerKWeight),
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user