From f963f91a3c50e7ae781d519d93948016024b34fc Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 1 May 2018 16:27:20 -0700 Subject: [PATCH] multi: use mutex-guarded ShortChanID() on OpenChannel --- breacharbiter_test.go | 4 ++-- channeldb/channel_test.go | 14 +++++++------- contractcourt/chain_arbitrator.go | 2 +- contractcourt/chain_watcher.go | 8 ++++---- htlcswitch/circuit_map.go | 2 +- htlcswitch/switch.go | 2 +- htlcswitch/test_utils.go | 4 ++-- lnwallet/channel.go | 14 +++++++------- lnwallet/test_utils.go | 4 ++-- lnwallet/transactions_test.go | 2 +- pilot.go | 2 +- rpcserver.go | 2 +- test_utils.go | 2 +- 13 files changed, 31 insertions(+), 31 deletions(-) diff --git a/breacharbiter_test.go b/breacharbiter_test.go index 216bf36c..b9c00a09 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -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, diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index 537d24bf..f7f331af 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -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 { diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index d84a9b83..1f7e90b8 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -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 diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index 897f7b6f..606ce980 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -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 { diff --git a/htlcswitch/circuit_map.go b/htlcswitch/circuit_map.go index 1fa0a042..0e56d43e 100644 --- a/htlcswitch/circuit_map.go +++ b/htlcswitch/circuit_map.go @@ -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 } diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 229aa25b..515b2254 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -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 diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index cf09a9f5..5ff5a1d1 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -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), } diff --git a/lnwallet/channel.go b/lnwallet/channel.go index b048d270..1ddb2657 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -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 diff --git a/lnwallet/test_utils.go b/lnwallet/test_utils.go index 27ee491f..34d9baf1 100644 --- a/lnwallet/test_utils.go +++ b/lnwallet/test_utils.go @@ -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, diff --git a/lnwallet/transactions_test.go b/lnwallet/transactions_test.go index 3ab47f2d..ed1c2a67 100644 --- a/lnwallet/transactions_test.go +++ b/lnwallet/transactions_test.go @@ -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{ diff --git a/pilot.go b/pilot.go index cb598915..91cb1285 100644 --- a/pilot.go +++ b/pilot.go @@ -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), } diff --git a/rpcserver.go b/rpcserver.go index 2db34de9..f22f091f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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 "+ diff --git a/test_utils.go b/test_utils.go index bd5ee4b2..0baf779d 100644 --- a/test_utils.go +++ b/test_utils.go @@ -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,