htlcswitch: add error return value to NewInterceptableSwitch
Prepares for parameter validation.
This commit is contained in:
4 files changed
+33
-20
No files matched your search
@@ -146,7 +146,9 @@ type InterceptableSwitchConfig struct {
|
||||
}
|
||||
|
||||
// NewInterceptableSwitch returns an instance of InterceptableSwitch.
|
||||
func NewInterceptableSwitch(cfg *InterceptableSwitchConfig) *InterceptableSwitch {
|
||||
func NewInterceptableSwitch(cfg *InterceptableSwitchConfig) (
|
||||
*InterceptableSwitch, error) {
|
||||
|
||||
return &InterceptableSwitch{
|
||||
htlcSwitch: cfg.Switch,
|
||||
intercepted: make(chan *interceptedPackets),
|
||||
@@ -159,7 +161,7 @@ func NewInterceptableSwitch(cfg *InterceptableSwitchConfig) *InterceptableSwitch
|
||||
notifier: cfg.Notifier,
|
||||
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SetInterceptor sets the ForwardInterceptor to be used. A nil argument
|
||||
|
||||
@@ -3885,13 +3885,14 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
}
|
||||
notifier.EpochChan <- &chainntnfs.BlockEpoch{Height: testStartingHeight}
|
||||
|
||||
switchForwardInterceptor := NewInterceptableSwitch(
|
||||
switchForwardInterceptor, err := NewInterceptableSwitch(
|
||||
&InterceptableSwitchConfig{
|
||||
Switch: c.s,
|
||||
CltvRejectDelta: c.cltvRejectDelta,
|
||||
Notifier: notifier,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, switchForwardInterceptor.Start())
|
||||
|
||||
switchForwardInterceptor.SetInterceptor(c.forwardInterceptor.InterceptForwardHtlc)
|
||||
@@ -3901,7 +3902,7 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
packet := c.createTestPacket()
|
||||
packet.incomingTimeout = testStartingHeight + c.cltvRejectDelta - 1
|
||||
|
||||
err := switchForwardInterceptor.ForwardPackets(linkQuit, false, packet)
|
||||
err = switchForwardInterceptor.ForwardPackets(linkQuit, false, packet)
|
||||
require.NoError(t, err, "can't forward htlc packet")
|
||||
assertOutgoingLinkReceive(t, c.bobChannelLink, false)
|
||||
assertOutgoingLinkReceiveIntercepted(t, c.aliceChannelLink)
|
||||
@@ -4086,7 +4087,7 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
}
|
||||
notifier.EpochChan <- &chainntnfs.BlockEpoch{Height: testStartingHeight}
|
||||
|
||||
switchForwardInterceptor = NewInterceptableSwitch(
|
||||
switchForwardInterceptor, err = NewInterceptableSwitch(
|
||||
&InterceptableSwitchConfig{
|
||||
Switch: c.s,
|
||||
CltvRejectDelta: c.cltvRejectDelta,
|
||||
@@ -4094,6 +4095,7 @@ func TestSwitchHoldForward(t *testing.T) {
|
||||
Notifier: notifier,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, switchForwardInterceptor.Start())
|
||||
|
||||
// Forward a fresh packet. It is expected to be failed immediately,
|
||||
@@ -5391,12 +5393,13 @@ func testSwitchAliasInterceptFail(t *testing.T, zeroConf bool) {
|
||||
}
|
||||
notifier.EpochChan <- &chainntnfs.BlockEpoch{Height: testStartingHeight}
|
||||
|
||||
interceptSwitch := NewInterceptableSwitch(
|
||||
interceptSwitch, err := NewInterceptableSwitch(
|
||||
&InterceptableSwitchConfig{
|
||||
Switch: s,
|
||||
Notifier: notifier,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, interceptSwitch.Start())
|
||||
interceptSwitch.SetInterceptor(forwardInterceptor.InterceptForwardHtlc)
|
||||
|
||||
|
||||
+18
-13
@@ -366,6 +366,16 @@ func createTestPeer(t *testing.T, notifier chainntnfs.ChainNotifier,
|
||||
Height: 1,
|
||||
}
|
||||
|
||||
interceptableSwitch, err := htlcswitch.NewInterceptableSwitch(
|
||||
&htlcswitch.InterceptableSwitchConfig{
|
||||
CltvRejectDelta: testCltvRejectDelta,
|
||||
Notifier: interceptableSwitchNotifier,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Addr: cfgAddr,
|
||||
PubKeyBytes: pubKey,
|
||||
@@ -373,19 +383,14 @@ func createTestPeer(t *testing.T, notifier chainntnfs.ChainNotifier,
|
||||
ChainIO: chainIO,
|
||||
Switch: mockSwitch,
|
||||
ChanActiveTimeout: chanActiveTimeout,
|
||||
InterceptSwitch: htlcswitch.NewInterceptableSwitch(
|
||||
&htlcswitch.InterceptableSwitchConfig{
|
||||
CltvRejectDelta: testCltvRejectDelta,
|
||||
Notifier: interceptableSwitchNotifier,
|
||||
},
|
||||
),
|
||||
ChannelDB: dbAlice.ChannelStateDB(),
|
||||
FeeEstimator: estimator,
|
||||
Wallet: wallet,
|
||||
ChainNotifier: notifier,
|
||||
ChanStatusMgr: chanStatusMgr,
|
||||
Features: lnwire.NewFeatureVector(nil, lnwire.Features),
|
||||
DisconnectPeer: func(b *btcec.PublicKey) error { return nil },
|
||||
InterceptSwitch: interceptableSwitch,
|
||||
ChannelDB: dbAlice.ChannelStateDB(),
|
||||
FeeEstimator: estimator,
|
||||
Wallet: wallet,
|
||||
ChainNotifier: notifier,
|
||||
ChanStatusMgr: chanStatusMgr,
|
||||
Features: lnwire.NewFeatureVector(nil, lnwire.Features),
|
||||
DisconnectPeer: func(b *btcec.PublicKey) error { return nil },
|
||||
}
|
||||
|
||||
alicePeer := NewBrontide(*cfg)
|
||||
|
||||
@@ -666,7 +666,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.interceptableSwitch = htlcswitch.NewInterceptableSwitch(
|
||||
s.interceptableSwitch, err = htlcswitch.NewInterceptableSwitch(
|
||||
&htlcswitch.InterceptableSwitchConfig{
|
||||
Switch: s.htlcSwitch,
|
||||
CltvRejectDelta: lncfg.DefaultFinalCltvRejectDelta,
|
||||
@@ -674,6 +674,9 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
Notifier: s.cc.ChainNotifier,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.witnessBeacon = newPreimageBeacon(
|
||||
dbs.ChanStateDB.NewWitnessCache(),
|
||||
|
||||
Reference in new issue
Block a user