mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
htlcswitch: add InterceptableSwitchConfig
Preparation for adding more config options.
This commit is contained in:
parent
4fbd608b73
commit
4a3e90f4d0
@ -111,19 +111,32 @@ type fwdResolution struct {
|
|||||||
errChan chan error
|
errChan chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInterceptableSwitch returns an instance of InterceptableSwitch.
|
// InterceptableSwitchConfig contains the configuration of InterceptableSwitch.
|
||||||
func NewInterceptableSwitch(s *Switch, cltvRejectDelta uint32,
|
type InterceptableSwitchConfig struct {
|
||||||
requireInterceptor bool) *InterceptableSwitch {
|
// Switch is a reference to the actual switch implementation that
|
||||||
|
// packets get sent to on resume.
|
||||||
|
Switch *Switch
|
||||||
|
|
||||||
|
// CltvRejectDelta defines the number of blocks before the expiry of the
|
||||||
|
// htlc where we no longer intercept it and instead cancel it back.
|
||||||
|
CltvRejectDelta uint32
|
||||||
|
|
||||||
|
// RequireInterceptor indicates whether processing should block if no
|
||||||
|
// interceptor is connected.
|
||||||
|
RequireInterceptor bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInterceptableSwitch returns an instance of InterceptableSwitch.
|
||||||
|
func NewInterceptableSwitch(cfg *InterceptableSwitchConfig) *InterceptableSwitch {
|
||||||
return &InterceptableSwitch{
|
return &InterceptableSwitch{
|
||||||
htlcSwitch: s,
|
htlcSwitch: cfg.Switch,
|
||||||
intercepted: make(chan *interceptedPackets),
|
intercepted: make(chan *interceptedPackets),
|
||||||
onchainIntercepted: make(chan InterceptedForward),
|
onchainIntercepted: make(chan InterceptedForward),
|
||||||
interceptorRegistration: make(chan ForwardInterceptor),
|
interceptorRegistration: make(chan ForwardInterceptor),
|
||||||
holdForwards: make(map[channeldb.CircuitKey]InterceptedForward),
|
holdForwards: make(map[channeldb.CircuitKey]InterceptedForward),
|
||||||
resolutionChan: make(chan *fwdResolution),
|
resolutionChan: make(chan *fwdResolution),
|
||||||
requireInterceptor: requireInterceptor,
|
requireInterceptor: cfg.RequireInterceptor,
|
||||||
cltvRejectDelta: cltvRejectDelta,
|
cltvRejectDelta: cfg.CltvRejectDelta,
|
||||||
|
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
@ -3846,7 +3846,10 @@ func TestSwitchHoldForward(t *testing.T) {
|
|||||||
interceptedChan: make(chan InterceptedPacket),
|
interceptedChan: make(chan InterceptedPacket),
|
||||||
}
|
}
|
||||||
switchForwardInterceptor := NewInterceptableSwitch(
|
switchForwardInterceptor := NewInterceptableSwitch(
|
||||||
s, cltvRejectDelta, false,
|
&InterceptableSwitchConfig{
|
||||||
|
Switch: s,
|
||||||
|
CltvRejectDelta: cltvRejectDelta,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
require.NoError(t, switchForwardInterceptor.Start())
|
require.NoError(t, switchForwardInterceptor.Start())
|
||||||
|
|
||||||
@ -4037,7 +4040,13 @@ func TestSwitchHoldForward(t *testing.T) {
|
|||||||
require.NoError(t, switchForwardInterceptor.Stop())
|
require.NoError(t, switchForwardInterceptor.Stop())
|
||||||
|
|
||||||
// Test always-on interception.
|
// Test always-on interception.
|
||||||
switchForwardInterceptor = NewInterceptableSwitch(s, cltvRejectDelta, true)
|
switchForwardInterceptor = NewInterceptableSwitch(
|
||||||
|
&InterceptableSwitchConfig{
|
||||||
|
Switch: s,
|
||||||
|
CltvRejectDelta: cltvRejectDelta,
|
||||||
|
RequireInterceptor: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
require.NoError(t, switchForwardInterceptor.Start())
|
require.NoError(t, switchForwardInterceptor.Start())
|
||||||
|
|
||||||
// Forward a fresh packet. It is expected to be failed immediately,
|
// Forward a fresh packet. It is expected to be failed immediately,
|
||||||
@ -5329,7 +5338,11 @@ func testSwitchAliasInterceptFail(t *testing.T, zeroConf bool) {
|
|||||||
t: t,
|
t: t,
|
||||||
interceptedChan: make(chan InterceptedPacket),
|
interceptedChan: make(chan InterceptedPacket),
|
||||||
}
|
}
|
||||||
interceptSwitch := NewInterceptableSwitch(s, 0, false)
|
interceptSwitch := NewInterceptableSwitch(
|
||||||
|
&InterceptableSwitchConfig{
|
||||||
|
Switch: s,
|
||||||
|
},
|
||||||
|
)
|
||||||
require.NoError(t, interceptSwitch.Start())
|
require.NoError(t, interceptSwitch.Start())
|
||||||
interceptSwitch.SetInterceptor(forwardInterceptor.InterceptForwardHtlc)
|
interceptSwitch.SetInterceptor(forwardInterceptor.InterceptForwardHtlc)
|
||||||
|
|
||||||
|
@ -367,7 +367,9 @@ func createTestPeer(t *testing.T, notifier chainntnfs.ChainNotifier,
|
|||||||
Switch: mockSwitch,
|
Switch: mockSwitch,
|
||||||
ChanActiveTimeout: chanActiveTimeout,
|
ChanActiveTimeout: chanActiveTimeout,
|
||||||
InterceptSwitch: htlcswitch.NewInterceptableSwitch(
|
InterceptSwitch: htlcswitch.NewInterceptableSwitch(
|
||||||
nil, testCltvRejectDelta, false,
|
&htlcswitch.InterceptableSwitchConfig{
|
||||||
|
CltvRejectDelta: testCltvRejectDelta,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ChannelDB: dbAlice.ChannelStateDB(),
|
ChannelDB: dbAlice.ChannelStateDB(),
|
||||||
FeeEstimator: estimator,
|
FeeEstimator: estimator,
|
||||||
|
@ -667,8 +667,11 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.interceptableSwitch = htlcswitch.NewInterceptableSwitch(
|
s.interceptableSwitch = htlcswitch.NewInterceptableSwitch(
|
||||||
s.htlcSwitch, lncfg.DefaultFinalCltvRejectDelta,
|
&htlcswitch.InterceptableSwitchConfig{
|
||||||
s.cfg.RequireInterceptor,
|
Switch: s.htlcSwitch,
|
||||||
|
CltvRejectDelta: lncfg.DefaultFinalCltvRejectDelta,
|
||||||
|
RequireInterceptor: s.cfg.RequireInterceptor,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
s.witnessBeacon = newPreimageBeacon(
|
s.witnessBeacon = newPreimageBeacon(
|
||||||
|
Loading…
Reference in New Issue
Block a user