multi: use mutex-guarded ShortChanID() on OpenChannel
This commit is contained in:
parent
19b5eaa4dc
commit
f963f91a3c
@ -1437,7 +1437,7 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
|
|||||||
RemoteChanCfg: bobCfg,
|
RemoteChanCfg: bobCfg,
|
||||||
IdentityPub: aliceKeyPub,
|
IdentityPub: aliceKeyPub,
|
||||||
FundingOutpoint: *prevOut,
|
FundingOutpoint: *prevOut,
|
||||||
ShortChanID: shortChanID,
|
ShortChannelID: shortChanID,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
@ -1455,7 +1455,7 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
|
|||||||
RemoteChanCfg: aliceCfg,
|
RemoteChanCfg: aliceCfg,
|
||||||
IdentityPub: bobKeyPub,
|
IdentityPub: bobKeyPub,
|
||||||
FundingOutpoint: *prevOut,
|
FundingOutpoint: *prevOut,
|
||||||
ShortChanID: shortChanID,
|
ShortChannelID: shortChanID,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: false,
|
IsInitiator: false,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
|
@ -186,7 +186,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
ChanType: SingleFunder,
|
ChanType: SingleFunder,
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
FundingOutpoint: *testOutpoint,
|
FundingOutpoint: *testOutpoint,
|
||||||
ShortChanID: chanID,
|
ShortChannelID: chanID,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
IdentityPub: pubKey,
|
IdentityPub: pubKey,
|
||||||
@ -514,7 +514,7 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
}
|
}
|
||||||
channel.RemoteNextRevocation = newPriv.PubKey()
|
channel.RemoteNextRevocation = newPriv.PubKey()
|
||||||
|
|
||||||
fwdPkg := NewFwdPkg(channel.ShortChanID, oldRemoteCommit.CommitHeight,
|
fwdPkg := NewFwdPkg(channel.ShortChanID(), oldRemoteCommit.CommitHeight,
|
||||||
diskCommitDiff.LogUpdates, nil)
|
diskCommitDiff.LogUpdates, nil)
|
||||||
|
|
||||||
err = channel.AdvanceCommitChainTail(fwdPkg)
|
err = channel.AdvanceCommitChainTail(fwdPkg)
|
||||||
@ -563,7 +563,7 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
t.Fatalf("unable to add to commit chain: %v", err)
|
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)
|
err = channel.AdvanceCommitChainTail(fwdPkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -688,9 +688,9 @@ func TestFetchPendingChannels(t *testing.T) {
|
|||||||
t.Fatalf("channel marked open should no longer be pending")
|
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, "+
|
t.Fatalf("channel opening height not updated: expected %v, "+
|
||||||
"got %v", spew.Sdump(pendingChannels[0].ShortChanID),
|
"got %v", spew.Sdump(pendingChannels[0].ShortChanID()),
|
||||||
chanOpenLoc)
|
chanOpenLoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,9 +700,9 @@ func TestFetchPendingChannels(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch channels: %v", err)
|
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, "+
|
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)
|
chanOpenLoc)
|
||||||
}
|
}
|
||||||
if openChans[0].FundingBroadcastHeight != broadcastHeight {
|
if openChans[0].FundingBroadcastHeight != broadcastHeight {
|
||||||
|
@ -201,7 +201,7 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel,
|
|||||||
// all interfaces and methods the arbitrator needs to do its job.
|
// all interfaces and methods the arbitrator needs to do its job.
|
||||||
arbCfg := ChannelArbitratorConfig{
|
arbCfg := ChannelArbitratorConfig{
|
||||||
ChanPoint: chanPoint,
|
ChanPoint: chanPoint,
|
||||||
ShortChanID: channel.ShortChanID,
|
ShortChanID: channel.ShortChanID(),
|
||||||
BlockEpochs: blockEpoch,
|
BlockEpochs: blockEpoch,
|
||||||
ForceCloseChan: func() (*lnwallet.LocalForceCloseSummary, error) {
|
ForceCloseChan: func() (*lnwallet.LocalForceCloseSummary, error) {
|
||||||
// With the channels fetched, attempt to locate
|
// With the channels fetched, attempt to locate
|
||||||
|
@ -180,7 +180,7 @@ func (c *chainWatcher) Start() error {
|
|||||||
// As a height hint, we'll try to use the opening height, but if the
|
// 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
|
// channel isn't yet open, then we'll use the height it was broadcast
|
||||||
// at.
|
// at.
|
||||||
heightHint := chanState.ShortChanID.BlockHeight
|
heightHint := c.cfg.chanState.ShortChanID().BlockHeight
|
||||||
if heightHint == 0 {
|
if heightHint == 0 {
|
||||||
heightHint = chanState.FundingBroadcastHeight
|
heightHint = chanState.FundingBroadcastHeight
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ func (c *chainWatcher) dispatchCooperativeClose(commitSpend *chainntnfs.SpendDet
|
|||||||
CloseHeight: uint32(commitSpend.SpendingHeight),
|
CloseHeight: uint32(commitSpend.SpendingHeight),
|
||||||
SettledBalance: localAmt,
|
SettledBalance: localAmt,
|
||||||
CloseType: channeldb.CooperativeClose,
|
CloseType: channeldb.CooperativeClose,
|
||||||
ShortChanID: c.cfg.chanState.ShortChanID,
|
ShortChanID: c.cfg.chanState.ShortChanID(),
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
}
|
}
|
||||||
err := c.cfg.chanState.CloseChannel(closeSummary)
|
err := c.cfg.chanState.CloseChannel(closeSummary)
|
||||||
@ -564,7 +564,7 @@ func (c *chainWatcher) dispatchLocalForceClose(
|
|||||||
Capacity: chanSnapshot.Capacity,
|
Capacity: chanSnapshot.Capacity,
|
||||||
CloseType: channeldb.LocalForceClose,
|
CloseType: channeldb.LocalForceClose,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
ShortChanID: c.cfg.chanState.ShortChanID,
|
ShortChanID: c.cfg.chanState.ShortChanID(),
|
||||||
CloseHeight: uint32(commitSpend.SpendingHeight),
|
CloseHeight: uint32(commitSpend.SpendingHeight),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,7 +739,7 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail
|
|||||||
SettledBalance: settledBalance,
|
SettledBalance: settledBalance,
|
||||||
CloseType: channeldb.BreachClose,
|
CloseType: channeldb.BreachClose,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
ShortChanID: c.cfg.chanState.ShortChanID,
|
ShortChanID: c.cfg.chanState.ShortChanID(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.cfg.chanState.CloseChannel(&closeSummary); err != nil {
|
if err := c.cfg.chanState.CloseChannel(&closeSummary); err != nil {
|
||||||
|
@ -364,7 +364,7 @@ func (cm *circuitMap) trimAllOpenCircuits() error {
|
|||||||
// First, skip any channels that have not been assigned their
|
// First, skip any channels that have not been assigned their
|
||||||
// final channel identifier, otherwise we would try to trim
|
// final channel identifier, otherwise we would try to trim
|
||||||
// htlcs belonging to the all-zero, sourceHop ID.
|
// htlcs belonging to the all-zero, sourceHop ID.
|
||||||
chanID := activeChannel.ShortChanID
|
chanID := activeChannel.ShortChanID()
|
||||||
if chanID == sourceHop {
|
if chanID == sourceHop {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1560,7 +1560,7 @@ func (s *Switch) reforwardResponses() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, activeChannel := range activeChannels {
|
for _, activeChannel := range activeChannels {
|
||||||
shortChanID := activeChannel.ShortChanID
|
shortChanID := activeChannel.ShortChanID()
|
||||||
fwdPkgs, err := s.loadChannelFwdPkgs(shortChanID)
|
fwdPkgs, err := s.loadChannelFwdPkgs(shortChanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -324,7 +324,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
RevocationStore: shachain.NewRevocationStore(),
|
RevocationStore: shachain.NewRevocationStore(),
|
||||||
LocalCommitment: aliceCommit,
|
LocalCommitment: aliceCommit,
|
||||||
RemoteCommitment: aliceCommit,
|
RemoteCommitment: aliceCommit,
|
||||||
ShortChanID: chanID,
|
ShortChannelID: chanID,
|
||||||
Db: dbAlice,
|
Db: dbAlice,
|
||||||
Packager: channeldb.NewChannelPackager(chanID),
|
Packager: channeldb.NewChannelPackager(chanID),
|
||||||
FundingTxn: testTx,
|
FundingTxn: testTx,
|
||||||
@ -343,7 +343,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
RevocationStore: shachain.NewRevocationStore(),
|
RevocationStore: shachain.NewRevocationStore(),
|
||||||
LocalCommitment: bobCommit,
|
LocalCommitment: bobCommit,
|
||||||
RemoteCommitment: bobCommit,
|
RemoteCommitment: bobCommit,
|
||||||
ShortChanID: chanID,
|
ShortChannelID: chanID,
|
||||||
Db: dbBob,
|
Db: dbBob,
|
||||||
Packager: channeldb.NewChannelPackager(chanID),
|
Packager: channeldb.NewChannelPackager(chanID),
|
||||||
}
|
}
|
||||||
|
@ -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
|
// Now that we have gathered the set of HTLCs to forward, separated by
|
||||||
// type, construct a forwarding package using the height that the remote
|
// 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)
|
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||||
lc.channelState.ShortChanID)
|
lc.ShortChanID())
|
||||||
}
|
}
|
||||||
|
|
||||||
if htlc.RHash != sha256.Sum256(preimage[:]) {
|
if htlc.RHash != sha256.Sum256(preimage[:]) {
|
||||||
@ -4391,7 +4391,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||||
lc.channelState.ShortChanID)
|
lc.ShortChanID())
|
||||||
}
|
}
|
||||||
|
|
||||||
if htlc.RHash != sha256.Sum256(preimage[:]) {
|
if htlc.RHash != sha256.Sum256(preimage[:]) {
|
||||||
@ -4445,7 +4445,7 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||||
lc.channelState.ShortChanID)
|
lc.ShortChanID())
|
||||||
}
|
}
|
||||||
|
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
@ -4485,7 +4485,7 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
|||||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||||
lc.channelState.ShortChanID)
|
lc.ShortChanID())
|
||||||
}
|
}
|
||||||
|
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
@ -4518,7 +4518,7 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||||
lc.channelState.ShortChanID)
|
lc.ShortChanID())
|
||||||
}
|
}
|
||||||
|
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
@ -4546,7 +4546,7 @@ func (lc *LightningChannel) ChannelPoint() *wire.OutPoint {
|
|||||||
// ID encodes the exact location in the main chain that the original
|
// ID encodes the exact location in the main chain that the original
|
||||||
// funding output can be found.
|
// funding output can be found.
|
||||||
func (lc *LightningChannel) ShortChanID() lnwire.ShortChannelID {
|
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
|
// genHtlcScript generates the proper P2WSH public key scripts for the HTLC
|
||||||
|
@ -270,7 +270,7 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error)
|
|||||||
RemoteChanCfg: bobCfg,
|
RemoteChanCfg: bobCfg,
|
||||||
IdentityPub: aliceKeys[0].PubKey(),
|
IdentityPub: aliceKeys[0].PubKey(),
|
||||||
FundingOutpoint: *prevOut,
|
FundingOutpoint: *prevOut,
|
||||||
ShortChanID: shortChanID,
|
ShortChannelID: shortChanID,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
@ -288,7 +288,7 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error)
|
|||||||
RemoteChanCfg: aliceCfg,
|
RemoteChanCfg: aliceCfg,
|
||||||
IdentityPub: bobKeys[0].PubKey(),
|
IdentityPub: bobKeys[0].PubKey(),
|
||||||
FundingOutpoint: *prevOut,
|
FundingOutpoint: *prevOut,
|
||||||
ShortChanID: shortChanID,
|
ShortChannelID: shortChanID,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: false,
|
IsInitiator: false,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
|
@ -371,7 +371,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
|||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
ChainHash: *tc.netParams.GenesisHash,
|
ChainHash: *tc.netParams.GenesisHash,
|
||||||
FundingOutpoint: tc.fundingOutpoint,
|
FundingOutpoint: tc.fundingOutpoint,
|
||||||
ShortChanID: tc.shortChanID,
|
ShortChannelID: tc.shortChanID,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
IdentityPub: identityKey,
|
IdentityPub: identityKey,
|
||||||
LocalChanCfg: channeldb.ChannelConfig{
|
LocalChanCfg: channeldb.ChannelConfig{
|
||||||
|
2
pilot.go
2
pilot.go
@ -171,7 +171,7 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error)
|
|||||||
initialChanState := make([]autopilot.Channel, len(activeChannels))
|
initialChanState := make([]autopilot.Channel, len(activeChannels))
|
||||||
for i, channel := range activeChannels {
|
for i, channel := range activeChannels {
|
||||||
initialChanState[i] = autopilot.Channel{
|
initialChanState[i] = autopilot.Channel{
|
||||||
ChanID: channel.ShortChanID,
|
ChanID: channel.ShortChanID(),
|
||||||
Capacity: channel.Capacity,
|
Capacity: channel.Capacity,
|
||||||
Node: autopilot.NewNodeID(channel.IdentityPub),
|
Node: autopilot.NewNodeID(channel.IdentityPub),
|
||||||
}
|
}
|
||||||
|
@ -2306,7 +2306,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the policies for each end of the channel.
|
// Fetch the policies for each end of the channel.
|
||||||
chanID := channel.ShortChanID.ToUint64()
|
chanID := channel.ShortChanID().ToUint64()
|
||||||
_, p1, p2, err := graph.FetchChannelEdgesByID(chanID)
|
_, p1, p2, err := graph.FetchChannelEdgesByID(chanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rpcsLog.Errorf("Unable to fetch the routing "+
|
rpcsLog.Errorf("Unable to fetch the routing "+
|
||||||
|
@ -242,7 +242,7 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
|
|||||||
RemoteChanCfg: bobCfg,
|
RemoteChanCfg: bobCfg,
|
||||||
IdentityPub: aliceKeyPub,
|
IdentityPub: aliceKeyPub,
|
||||||
FundingOutpoint: *prevOut,
|
FundingOutpoint: *prevOut,
|
||||||
ShortChanID: shortChanID,
|
ShortChannelID: shortChanID,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
|
Loading…
Reference in New Issue
Block a user