Merge pull request #1482 from cfromknecht/uniform-fee-update-timeout

htlcswitch/link: correct bias in fee update backoff
This commit is contained in:
Olaoluwa Osuntokun 2018-07-03 22:27:22 -05:00 committed by GitHub
commit 0a045f8651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 19 deletions

@ -995,12 +995,7 @@ out:
func (l *channelLink) randomFeeUpdateTimeout() time.Duration { func (l *channelLink) randomFeeUpdateTimeout() time.Duration {
lower := int64(l.cfg.MinFeeUpdateTimeout) lower := int64(l.cfg.MinFeeUpdateTimeout)
upper := int64(l.cfg.MaxFeeUpdateTimeout) upper := int64(l.cfg.MaxFeeUpdateTimeout)
rand := prand.Int63n(upper) return time.Duration(prand.Int63n(upper-lower) + lower)
if rand < lower {
rand = lower
}
return time.Duration(rand)
} }
// handleDownStreamPkt processes an HTLC packet sent from the downstream HTLC // handleDownStreamPkt processes an HTLC packet sent from the downstream HTLC

@ -1497,7 +1497,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
// to not trigger commit updates automatically during tests. // to not trigger commit updates automatically during tests.
BatchSize: 10000, BatchSize: 10000,
MinFeeUpdateTimeout: 30 * time.Minute, MinFeeUpdateTimeout: 30 * time.Minute,
MaxFeeUpdateTimeout: 30 * time.Minute, MaxFeeUpdateTimeout: 40 * time.Minute,
} }
const startingHeight = 100 const startingHeight = 100
@ -3878,7 +3878,7 @@ func restartLink(aliceChannel *lnwallet.LightningChannel, aliceSwitch *Switch,
// to not trigger commit updates automatically during tests. // to not trigger commit updates automatically during tests.
BatchSize: 10000, BatchSize: 10000,
MinFeeUpdateTimeout: 30 * time.Minute, MinFeeUpdateTimeout: 30 * time.Minute,
MaxFeeUpdateTimeout: 30 * time.Minute, MaxFeeUpdateTimeout: 40 * time.Minute,
// Set any hodl flags requested for the new link. // Set any hodl flags requested for the new link.
HodlMask: hodl.MaskFromFlags(hodlFlags...), HodlMask: hodl.MaskFromFlags(hodlFlags...),
DebugHTLC: len(hodlFlags) > 0, DebugHTLC: len(hodlFlags) > 0,

@ -878,9 +878,10 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
} }
const ( const (
batchTimeout = 50 * time.Millisecond batchTimeout = 50 * time.Millisecond
fwdPkgTimeout = 5 * time.Second fwdPkgTimeout = 5 * time.Second
feeUpdateTimeout = 30 * time.Minute minFeeUpdateTimeout = 30 * time.Minute
maxFeeUpdateTimeout = 40 * time.Minute
) )
pCache := &mockPreimageCache{ pCache := &mockPreimageCache{
@ -919,8 +920,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
BatchSize: 10, BatchSize: 10,
BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C}, BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C},
FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C}, FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C},
MinFeeUpdateTimeout: feeUpdateTimeout, MinFeeUpdateTimeout: minFeeUpdateTimeout,
MaxFeeUpdateTimeout: feeUpdateTimeout, MaxFeeUpdateTimeout: maxFeeUpdateTimeout,
OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {}, OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {},
}, },
aliceChannel, aliceChannel,
@ -962,8 +963,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
BatchSize: 10, BatchSize: 10,
BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C}, BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C},
FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C}, FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C},
MinFeeUpdateTimeout: feeUpdateTimeout, MinFeeUpdateTimeout: minFeeUpdateTimeout,
MaxFeeUpdateTimeout: feeUpdateTimeout, MaxFeeUpdateTimeout: maxFeeUpdateTimeout,
OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {}, OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {},
}, },
firstBobChannel, firstBobChannel,
@ -1005,8 +1006,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
BatchSize: 10, BatchSize: 10,
BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C}, BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C},
FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C}, FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C},
MinFeeUpdateTimeout: feeUpdateTimeout, MinFeeUpdateTimeout: minFeeUpdateTimeout,
MaxFeeUpdateTimeout: feeUpdateTimeout, MaxFeeUpdateTimeout: maxFeeUpdateTimeout,
OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {}, OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {},
}, },
secondBobChannel, secondBobChannel,
@ -1048,8 +1049,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
BatchSize: 10, BatchSize: 10,
BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C}, BatchTicker: &mockTicker{time.NewTicker(batchTimeout).C},
FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C}, FwdPkgGCTicker: &mockTicker{time.NewTicker(fwdPkgTimeout).C},
MinFeeUpdateTimeout: feeUpdateTimeout, MinFeeUpdateTimeout: minFeeUpdateTimeout,
MaxFeeUpdateTimeout: feeUpdateTimeout, MaxFeeUpdateTimeout: maxFeeUpdateTimeout,
OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {}, OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {},
}, },
carolChannel, carolChannel,