multi: use mutex-guarded ShortChanID() on OpenChannel

This commit is contained in:
Conner Fromknecht 2018-05-01 16:27:20 -07:00
parent 19b5eaa4dc
commit f963f91a3c
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF
13 changed files with 31 additions and 31 deletions

View File

@ -1437,7 +1437,7 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
RemoteChanCfg: bobCfg,
IdentityPub: aliceKeyPub,
FundingOutpoint: *prevOut,
ShortChanID: shortChanID,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunder,
IsInitiator: true,
Capacity: channelCapacity,
@ -1455,7 +1455,7 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
RemoteChanCfg: aliceCfg,
IdentityPub: bobKeyPub,
FundingOutpoint: *prevOut,
ShortChanID: shortChanID,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunder,
IsInitiator: false,
Capacity: channelCapacity,

View File

@ -186,7 +186,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
ChanType: SingleFunder,
ChainHash: key,
FundingOutpoint: *testOutpoint,
ShortChanID: chanID,
ShortChannelID: chanID,
IsInitiator: true,
IsPending: true,
IdentityPub: pubKey,
@ -514,7 +514,7 @@ func TestChannelStateTransition(t *testing.T) {
}
channel.RemoteNextRevocation = newPriv.PubKey()
fwdPkg := NewFwdPkg(channel.ShortChanID, oldRemoteCommit.CommitHeight,
fwdPkg := NewFwdPkg(channel.ShortChanID(), oldRemoteCommit.CommitHeight,
diskCommitDiff.LogUpdates, nil)
err = channel.AdvanceCommitChainTail(fwdPkg)
@ -563,7 +563,7 @@ func TestChannelStateTransition(t *testing.T) {
t.Fatalf("unable to add to commit chain: %v", err)
}
fwdPkg = NewFwdPkg(channel.ShortChanID, oldRemoteCommit.CommitHeight, nil, nil)
fwdPkg = NewFwdPkg(channel.ShortChanID(), oldRemoteCommit.CommitHeight, nil, nil)
err = channel.AdvanceCommitChainTail(fwdPkg)
if err != nil {
@ -688,9 +688,9 @@ func TestFetchPendingChannels(t *testing.T) {
t.Fatalf("channel marked open should no longer be pending")
}
if pendingChannels[0].ShortChanID != chanOpenLoc {
if pendingChannels[0].ShortChanID() != chanOpenLoc {
t.Fatalf("channel opening height not updated: expected %v, "+
"got %v", spew.Sdump(pendingChannels[0].ShortChanID),
"got %v", spew.Sdump(pendingChannels[0].ShortChanID()),
chanOpenLoc)
}
@ -700,9 +700,9 @@ func TestFetchPendingChannels(t *testing.T) {
if err != nil {
t.Fatalf("unable to fetch channels: %v", err)
}
if openChans[0].ShortChanID != chanOpenLoc {
if openChans[0].ShortChanID() != chanOpenLoc {
t.Fatalf("channel opening heights don't match: expected %v, "+
"got %v", spew.Sdump(openChans[0].ShortChanID),
"got %v", spew.Sdump(openChans[0].ShortChanID()),
chanOpenLoc)
}
if openChans[0].FundingBroadcastHeight != broadcastHeight {

View File

@ -201,7 +201,7 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel,
// all interfaces and methods the arbitrator needs to do its job.
arbCfg := ChannelArbitratorConfig{
ChanPoint: chanPoint,
ShortChanID: channel.ShortChanID,
ShortChanID: channel.ShortChanID(),
BlockEpochs: blockEpoch,
ForceCloseChan: func() (*lnwallet.LocalForceCloseSummary, error) {
// With the channels fetched, attempt to locate

View File

@ -180,7 +180,7 @@ func (c *chainWatcher) Start() error {
// As a height hint, we'll try to use the opening height, but if the
// channel isn't yet open, then we'll use the height it was broadcast
// at.
heightHint := chanState.ShortChanID.BlockHeight
heightHint := c.cfg.chanState.ShortChanID().BlockHeight
if heightHint == 0 {
heightHint = chanState.FundingBroadcastHeight
}
@ -472,7 +472,7 @@ func (c *chainWatcher) dispatchCooperativeClose(commitSpend *chainntnfs.SpendDet
CloseHeight: uint32(commitSpend.SpendingHeight),
SettledBalance: localAmt,
CloseType: channeldb.CooperativeClose,
ShortChanID: c.cfg.chanState.ShortChanID,
ShortChanID: c.cfg.chanState.ShortChanID(),
IsPending: true,
}
err := c.cfg.chanState.CloseChannel(closeSummary)
@ -564,7 +564,7 @@ func (c *chainWatcher) dispatchLocalForceClose(
Capacity: chanSnapshot.Capacity,
CloseType: channeldb.LocalForceClose,
IsPending: true,
ShortChanID: c.cfg.chanState.ShortChanID,
ShortChanID: c.cfg.chanState.ShortChanID(),
CloseHeight: uint32(commitSpend.SpendingHeight),
}
@ -739,7 +739,7 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail
SettledBalance: settledBalance,
CloseType: channeldb.BreachClose,
IsPending: true,
ShortChanID: c.cfg.chanState.ShortChanID,
ShortChanID: c.cfg.chanState.ShortChanID(),
}
if err := c.cfg.chanState.CloseChannel(&closeSummary); err != nil {

View File

@ -364,7 +364,7 @@ func (cm *circuitMap) trimAllOpenCircuits() error {
// First, skip any channels that have not been assigned their
// final channel identifier, otherwise we would try to trim
// htlcs belonging to the all-zero, sourceHop ID.
chanID := activeChannel.ShortChanID
chanID := activeChannel.ShortChanID()
if chanID == sourceHop {
continue
}

View File

@ -1560,7 +1560,7 @@ func (s *Switch) reforwardResponses() error {
}
for _, activeChannel := range activeChannels {
shortChanID := activeChannel.ShortChanID
shortChanID := activeChannel.ShortChanID()
fwdPkgs, err := s.loadChannelFwdPkgs(shortChanID)
if err != nil {
return err

View File

@ -324,7 +324,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: aliceCommit,
RemoteCommitment: aliceCommit,
ShortChanID: chanID,
ShortChannelID: chanID,
Db: dbAlice,
Packager: channeldb.NewChannelPackager(chanID),
FundingTxn: testTx,
@ -343,7 +343,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: bobCommit,
RemoteCommitment: bobCommit,
ShortChanID: chanID,
ShortChannelID: chanID,
Db: dbBob,
Packager: channeldb.NewChannelPackager(chanID),
}

View File

@ -4178,7 +4178,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
}
}
source := lc.channelState.ShortChanID
source := lc.ShortChanID()
// Now that we have gathered the set of HTLCs to forward, separated by
// type, construct a forwarding package using the height that the remote
@ -4356,7 +4356,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
if htlc == nil {
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
lc.channelState.ShortChanID)
lc.ShortChanID())
}
if htlc.RHash != sha256.Sum256(preimage[:]) {
@ -4391,7 +4391,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
if htlc == nil {
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
lc.channelState.ShortChanID)
lc.ShortChanID())
}
if htlc.RHash != sha256.Sum256(preimage[:]) {
@ -4445,7 +4445,7 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
if htlc == nil {
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
lc.channelState.ShortChanID)
lc.ShortChanID())
}
pd := &PaymentDescriptor{
@ -4485,7 +4485,7 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
if htlc == nil {
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
lc.channelState.ShortChanID)
lc.ShortChanID())
}
pd := &PaymentDescriptor{
@ -4518,7 +4518,7 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
if htlc == nil {
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
lc.channelState.ShortChanID)
lc.ShortChanID())
}
pd := &PaymentDescriptor{
@ -4546,7 +4546,7 @@ func (lc *LightningChannel) ChannelPoint() *wire.OutPoint {
// ID encodes the exact location in the main chain that the original
// funding output can be found.
func (lc *LightningChannel) ShortChanID() lnwire.ShortChannelID {
return lc.channelState.ShortChanID
return lc.channelState.ShortChanID()
}
// genHtlcScript generates the proper P2WSH public key scripts for the HTLC

View File

@ -270,7 +270,7 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error)
RemoteChanCfg: bobCfg,
IdentityPub: aliceKeys[0].PubKey(),
FundingOutpoint: *prevOut,
ShortChanID: shortChanID,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunder,
IsInitiator: true,
Capacity: channelCapacity,
@ -288,7 +288,7 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error)
RemoteChanCfg: aliceCfg,
IdentityPub: bobKeys[0].PubKey(),
FundingOutpoint: *prevOut,
ShortChanID: shortChanID,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunder,
IsInitiator: false,
Capacity: channelCapacity,

View File

@ -371,7 +371,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
ChanType: channeldb.SingleFunder,
ChainHash: *tc.netParams.GenesisHash,
FundingOutpoint: tc.fundingOutpoint,
ShortChanID: tc.shortChanID,
ShortChannelID: tc.shortChanID,
IsInitiator: true,
IdentityPub: identityKey,
LocalChanCfg: channeldb.ChannelConfig{

View File

@ -171,7 +171,7 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error)
initialChanState := make([]autopilot.Channel, len(activeChannels))
for i, channel := range activeChannels {
initialChanState[i] = autopilot.Channel{
ChanID: channel.ShortChanID,
ChanID: channel.ShortChanID(),
Capacity: channel.Capacity,
Node: autopilot.NewNodeID(channel.IdentityPub),
}

View File

@ -2306,7 +2306,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
}
// Fetch the policies for each end of the channel.
chanID := channel.ShortChanID.ToUint64()
chanID := channel.ShortChanID().ToUint64()
_, p1, p2, err := graph.FetchChannelEdgesByID(chanID)
if err != nil {
rpcsLog.Errorf("Unable to fetch the routing "+

View File

@ -242,7 +242,7 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
RemoteChanCfg: bobCfg,
IdentityPub: aliceKeyPub,
FundingOutpoint: *prevOut,
ShortChanID: shortChanID,
ShortChannelID: shortChanID,
ChanType: channeldb.SingleFunder,
IsInitiator: true,
Capacity: channelCapacity,