lnwallet: remove BlockChainIO as a dependency to LightningChannel
This commit removes the BlockChainIO interface as a dependency to the LightningChannel struct as the interface is no longer used within the operation of the LightningChannel.
This commit is contained in:
5 files changed
+17
-17
No files matched your search
+2
-5
@@ -5,6 +5,7 @@ import (
|
|||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/btcsuite/fastsha256"
|
"github.com/btcsuite/fastsha256"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
@@ -344,8 +345,6 @@ type LightningChannel struct {
|
|||||||
signer Signer
|
signer Signer
|
||||||
signDesc *SignDescriptor
|
signDesc *SignDescriptor
|
||||||
|
|
||||||
bio BlockChainIO
|
|
||||||
|
|
||||||
channelEvents chainntnfs.ChainNotifier
|
channelEvents chainntnfs.ChainNotifier
|
||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
@@ -454,13 +453,11 @@ type LightningChannel struct {
|
|||||||
// settled channel state. Throughout state transitions, then channel will
|
// settled channel state. Throughout state transitions, then channel will
|
||||||
// automatically persist pertinent state to the database in an efficient
|
// automatically persist pertinent state to the database in an efficient
|
||||||
// manner.
|
// manner.
|
||||||
func NewLightningChannel(signer Signer, bio BlockChainIO,
|
func NewLightningChannel(signer Signer, events chainntnfs.ChainNotifier,
|
||||||
events chainntnfs.ChainNotifier,
|
|
||||||
state *channeldb.OpenChannel) (*LightningChannel, error) {
|
state *channeldb.OpenChannel) (*LightningChannel, error) {
|
||||||
|
|
||||||
lc := &LightningChannel{
|
lc := &LightningChannel{
|
||||||
signer: signer,
|
signer: signer,
|
||||||
bio: bio,
|
|
||||||
channelEvents: events,
|
channelEvents: events,
|
||||||
currentHeight: state.NumUpdates,
|
currentHeight: state.NumUpdates,
|
||||||
remoteCommitChain: newCommitmentChain(state.NumUpdates),
|
remoteCommitChain: newCommitmentChain(state.NumUpdates),
|
||||||
|
|||||||
@@ -308,11 +308,11 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
|
|||||||
|
|
||||||
notifier := &mockNotfier{}
|
notifier := &mockNotfier{}
|
||||||
|
|
||||||
channelAlice, err := NewLightningChannel(aliceSigner, nil, notifier, aliceChannelState)
|
channelAlice, err := NewLightningChannel(aliceSigner, notifier, aliceChannelState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
channelBob, err := NewLightningChannel(bobSigner, nil, notifier, bobChannelState)
|
channelBob, err := NewLightningChannel(bobSigner, notifier, bobChannelState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -1052,11 +1052,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
t.Fatalf("unable to fetch channel: %v", err)
|
t.Fatalf("unable to fetch channel: %v", err)
|
||||||
}
|
}
|
||||||
notifier := aliceChannel.channelEvents
|
notifier := aliceChannel.channelEvents
|
||||||
aliceChannelNew, err := NewLightningChannel(aliceChannel.signer, nil, notifier, aliceChannels[0])
|
aliceChannelNew, err := NewLightningChannel(aliceChannel.signer, notifier, aliceChannels[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new channel: %v", err)
|
t.Fatalf("unable to create new channel: %v", err)
|
||||||
}
|
}
|
||||||
bobChannelNew, err := NewLightningChannel(bobChannel.signer, nil, notifier, bobChannels[0])
|
bobChannelNew, err := NewLightningChannel(bobChannel.signer, notifier, bobChannels[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new channel: %v", err)
|
t.Fatalf("unable to create new channel: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1230,7 +1230,7 @@ func (l *LightningWallet) handleChannelOpen(req *channelOpenMsg) {
|
|||||||
|
|
||||||
// Finally, create and officially open the payment channel!
|
// Finally, create and officially open the payment channel!
|
||||||
// TODO(roasbeef): CreationTime once tx is 'open'
|
// TODO(roasbeef): CreationTime once tx is 'open'
|
||||||
channel, err := NewLightningChannel(l.Signer, l.ChainIO, l.chainNotifier,
|
channel, err := NewLightningChannel(l.Signer, l.chainNotifier,
|
||||||
res.partialState)
|
res.partialState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
req.err <- err
|
req.err <- err
|
||||||
@@ -1285,7 +1285,7 @@ out:
|
|||||||
|
|
||||||
// Finally, create and officially open the payment channel!
|
// Finally, create and officially open the payment channel!
|
||||||
// TODO(roasbeef): CreationTime once tx is 'open'
|
// TODO(roasbeef): CreationTime once tx is 'open'
|
||||||
channel, err := NewLightningChannel(l.Signer, l.ChainIO, l.chainNotifier,
|
channel, err := NewLightningChannel(l.Signer, l.chainNotifier,
|
||||||
res.partialState)
|
res.partialState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.chanOpenErr <- err
|
res.chanOpenErr <- err
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
for _, dbChan := range chans {
|
for _, dbChan := range chans {
|
||||||
chanID := dbChan.ChanID
|
chanID := dbChan.ChanID
|
||||||
lnChan, err := lnwallet.NewLightningChannel(p.server.lnwallet.Signer,
|
lnChan, err := lnwallet.NewLightningChannel(p.server.lnwallet.Signer,
|
||||||
p.server.bio, p.server.chainNotifier, dbChan)
|
p.server.chainNotifier, dbChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -820,7 +820,7 @@ func (p *peer) handleLocalClose(req *closeLinkReq) {
|
|||||||
switch req.CloseType {
|
switch req.CloseType {
|
||||||
// A type of CloseRegular indicates that the user has opted to close
|
// A type of CloseRegular indicates that the user has opted to close
|
||||||
// out this channel on-chian, so we execute the cooperative channel
|
// out this channel on-chian, so we execute the cooperative channel
|
||||||
// closre workflow.
|
// closure workflow.
|
||||||
case CloseRegular:
|
case CloseRegular:
|
||||||
closingTxid, err = p.executeCooperativeClose(channel)
|
closingTxid, err = p.executeCooperativeClose(channel)
|
||||||
peerLog.Infof("Attempting cooperative close of "+
|
peerLog.Infof("Attempting cooperative close of "+
|
||||||
@@ -828,7 +828,7 @@ func (p *peer) handleLocalClose(req *closeLinkReq) {
|
|||||||
closingTxid)
|
closingTxid)
|
||||||
|
|
||||||
// A type of CloseBreach indicates that the counterparty has breached
|
// A type of CloseBreach indicates that the counterparty has breached
|
||||||
// the cahnnel therefore we need to clean up our local state.
|
// the channel therefore we need to clean up our local state.
|
||||||
case CloseBreach:
|
case CloseBreach:
|
||||||
peerLog.Infof("ChannelPoint(%v) has been breached, wiping "+
|
peerLog.Infof("ChannelPoint(%v) has been breached, wiping "+
|
||||||
"channel", req.chanPoint)
|
"channel", req.chanPoint)
|
||||||
@@ -1116,7 +1116,8 @@ func (p *peer) htlcManager(channel *lnwallet.LightningChannel,
|
|||||||
|
|
||||||
// TODO(roasbeef): check to see if able to settle any currently pending
|
// TODO(roasbeef): check to see if able to settle any currently pending
|
||||||
// HTLCs
|
// HTLCs
|
||||||
// * also need signals when new invoices are added by the invoiceRegistry
|
// * also need signals when new invoices are added by the
|
||||||
|
// invoiceRegistry
|
||||||
|
|
||||||
batchTimer := time.Tick(10 * time.Millisecond)
|
batchTimer := time.Tick(10 * time.Millisecond)
|
||||||
out:
|
out:
|
||||||
@@ -1134,6 +1135,8 @@ out:
|
|||||||
|
|
||||||
break out
|
break out
|
||||||
case <-channel.ForceCloseSignal:
|
case <-channel.ForceCloseSignal:
|
||||||
|
// TODO(roasbeef): path never taken now that server
|
||||||
|
// force closes's directly?
|
||||||
peerLog.Warnf("ChannelPoint(%v) has been force "+
|
peerLog.Warnf("ChannelPoint(%v) has been force "+
|
||||||
"closed, disconnecting from peerID(%x)",
|
"closed, disconnecting from peerID(%x)",
|
||||||
state.chanPoint, p.id)
|
state.chanPoint, p.id)
|
||||||
|
|||||||
+2
-2
@@ -563,8 +563,8 @@ func (r *rpcServer) fetchActiveChannel(chanPoint wire.OutPoint) (*lnwallet.Light
|
|||||||
|
|
||||||
// Otherwise, we create a fully populated channel state machine which
|
// Otherwise, we create a fully populated channel state machine which
|
||||||
// uses the db channel as backing storage.
|
// uses the db channel as backing storage.
|
||||||
return lnwallet.NewLightningChannel(r.server.lnwallet.Signer,
|
return lnwallet.NewLightningChannel(r.server.lnwallet.Signer, nil,
|
||||||
r.server.bio, r.server.chainNotifier, dbChan)
|
dbChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// forceCloseChan executes a unilateral close of the target channel by
|
// forceCloseChan executes a unilateral close of the target channel by
|
||||||
|
|||||||
Reference in new issue
Block a user