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:
Olaoluwa Osuntokun 2017-02-02 17:05:25 -08:00
parent aeb7cce7c3
commit f4b403679b
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
5 changed files with 17 additions and 17 deletions

@ -5,6 +5,7 @@ import (
"container/list"
"fmt"
"sync"
"sync/atomic"
"github.com/btcsuite/fastsha256"
"github.com/davecgh/go-spew/spew"
@ -344,8 +345,6 @@ type LightningChannel struct {
signer Signer
signDesc *SignDescriptor
bio BlockChainIO
channelEvents chainntnfs.ChainNotifier
sync.RWMutex
@ -454,13 +453,11 @@ type LightningChannel struct {
// settled channel state. Throughout state transitions, then channel will
// automatically persist pertinent state to the database in an efficient
// manner.
func NewLightningChannel(signer Signer, bio BlockChainIO,
events chainntnfs.ChainNotifier,
func NewLightningChannel(signer Signer, events chainntnfs.ChainNotifier,
state *channeldb.OpenChannel) (*LightningChannel, error) {
lc := &LightningChannel{
signer: signer,
bio: bio,
channelEvents: events,
currentHeight: state.NumUpdates,
remoteCommitChain: newCommitmentChain(state.NumUpdates),

@ -308,11 +308,11 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
notifier := &mockNotfier{}
channelAlice, err := NewLightningChannel(aliceSigner, nil, notifier, aliceChannelState)
channelAlice, err := NewLightningChannel(aliceSigner, notifier, aliceChannelState)
if err != nil {
return nil, nil, nil, err
}
channelBob, err := NewLightningChannel(bobSigner, nil, notifier, bobChannelState)
channelBob, err := NewLightningChannel(bobSigner, notifier, bobChannelState)
if err != nil {
return nil, nil, nil, err
}
@ -1052,11 +1052,11 @@ func TestStateUpdatePersistence(t *testing.T) {
t.Fatalf("unable to fetch channel: %v", err)
}
notifier := aliceChannel.channelEvents
aliceChannelNew, err := NewLightningChannel(aliceChannel.signer, nil, notifier, aliceChannels[0])
aliceChannelNew, err := NewLightningChannel(aliceChannel.signer, notifier, aliceChannels[0])
if err != nil {
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 {
t.Fatalf("unable to create new channel: %v", err)
}

@ -1230,7 +1230,7 @@ func (l *LightningWallet) handleChannelOpen(req *channelOpenMsg) {
// Finally, create and officially open the payment channel!
// 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)
if err != nil {
req.err <- err
@ -1285,7 +1285,7 @@ out:
// Finally, create and officially open the payment channel!
// 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)
if err != nil {
res.chanOpenErr <- err

11
peer.go

@ -226,7 +226,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
for _, dbChan := range chans {
chanID := dbChan.ChanID
lnChan, err := lnwallet.NewLightningChannel(p.server.lnwallet.Signer,
p.server.bio, p.server.chainNotifier, dbChan)
p.server.chainNotifier, dbChan)
if err != nil {
return err
}
@ -820,7 +820,7 @@ func (p *peer) handleLocalClose(req *closeLinkReq) {
switch req.CloseType {
// A type of CloseRegular indicates that the user has opted to close
// out this channel on-chian, so we execute the cooperative channel
// closre workflow.
// closure workflow.
case CloseRegular:
closingTxid, err = p.executeCooperativeClose(channel)
peerLog.Infof("Attempting cooperative close of "+
@ -828,7 +828,7 @@ func (p *peer) handleLocalClose(req *closeLinkReq) {
closingTxid)
// 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:
peerLog.Infof("ChannelPoint(%v) has been breached, wiping "+
"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
// 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)
out:
@ -1134,6 +1135,8 @@ out:
break out
case <-channel.ForceCloseSignal:
// TODO(roasbeef): path never taken now that server
// force closes's directly?
peerLog.Warnf("ChannelPoint(%v) has been force "+
"closed, disconnecting from peerID(%x)",
state.chanPoint, p.id)

@ -563,8 +563,8 @@ func (r *rpcServer) fetchActiveChannel(chanPoint wire.OutPoint) (*lnwallet.Light
// Otherwise, we create a fully populated channel state machine which
// uses the db channel as backing storage.
return lnwallet.NewLightningChannel(r.server.lnwallet.Signer,
r.server.bio, r.server.chainNotifier, dbChan)
return lnwallet.NewLightningChannel(r.server.lnwallet.Signer, nil,
dbChan)
}
// forceCloseChan executes a unilateral close of the target channel by