diff --git a/contractcourt/breacharbiter.go b/contractcourt/breacharbiter.go index 1735d0cec..b5f7583cc 100644 --- a/contractcourt/breacharbiter.go +++ b/contractcourt/breacharbiter.go @@ -1243,7 +1243,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint, } return &retributionInfo{ - commitHash: breachInfo.BreachTransaction.TxHash(), + commitHash: breachInfo.BreachTxHash, chainHash: breachInfo.ChainHash, chanPoint: *chanPoint, breachedOutputs: breachedOutputs, diff --git a/contractcourt/breacharbiter_test.go b/contractcourt/breacharbiter_test.go index 3cb16c084..4c8863ded 100644 --- a/contractcourt/breacharbiter_test.go +++ b/contractcourt/breacharbiter_test.go @@ -1051,7 +1051,7 @@ func TestBreachHandoffSuccess(t *testing.T) { processACK <- brarErr }, BreachRetribution: &lnwallet.BreachRetribution{ - BreachTransaction: bobClose.CloseTx, + BreachTxHash: bobClose.CloseTx.TxHash(), LocalOutputSignDesc: &input.SignDescriptor{ Output: &wire.TxOut{ PkScript: breachKeys[0], @@ -1085,7 +1085,7 @@ func TestBreachHandoffSuccess(t *testing.T) { processACK <- brarErr }, BreachRetribution: &lnwallet.BreachRetribution{ - BreachTransaction: bobClose.CloseTx, + BreachTxHash: bobClose.CloseTx.TxHash(), LocalOutputSignDesc: &input.SignDescriptor{ Output: &wire.TxOut{ PkScript: breachKeys[0], @@ -1137,7 +1137,7 @@ func TestBreachHandoffFail(t *testing.T) { processACK <- brarErr }, BreachRetribution: &lnwallet.BreachRetribution{ - BreachTransaction: bobClose.CloseTx, + BreachTxHash: bobClose.CloseTx.TxHash(), LocalOutputSignDesc: &input.SignDescriptor{ Output: &wire.TxOut{ PkScript: breachKeys[0], @@ -1179,7 +1179,7 @@ func TestBreachHandoffFail(t *testing.T) { processACK <- brarErr }, BreachRetribution: &lnwallet.BreachRetribution{ - BreachTransaction: bobClose.CloseTx, + BreachTxHash: bobClose.CloseTx.TxHash(), LocalOutputSignDesc: &input.SignDescriptor{ Output: &wire.TxOut{ PkScript: breachKeys[0], diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index c9b5e7ef9..f9d919023 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -812,7 +812,7 @@ func (c *chainWatcher) handlePossibleBreach(commitSpend *chainntnfs.SpendDetail, // own broadcasted state we are looking at. Therefore check that the // commit matches before assuming it was a breach. commitHash := commitSpend.SpendingTx.TxHash() - if retribution.BreachTransaction.TxHash() != commitHash { + if retribution.BreachTxHash != commitHash { return false, nil } diff --git a/lnwallet/channel.go b/lnwallet/channel.go index b9cde8dc8..b151b9efa 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2213,10 +2213,10 @@ type HtlcRetribution struct { // transaction. The BreachRetribution is then sent over the ContractBreach // channel in order to allow the subscriber of the channel to dispatch justice. type BreachRetribution struct { - // BreachTransaction is the transaction which breached the channel + // BreachTxHash is the transaction hash which breached the channel // contract by spending from the funding multi-sig with a revoked // commitment transaction. - BreachTransaction *wire.MsgTx + BreachTxHash chainhash.Hash // BreachHeight records the block height confirming the breach // transaction, used as a height hint when registering for @@ -2233,7 +2233,7 @@ type BreachRetribution struct { // LocalOutputSignDesc is a SignDescriptor which is capable of // generating the signature necessary to sweep the output within the - // BreachTransaction that pays directly us. + // breach transaction that pays directly us. // // NOTE: A nil value indicates that the local output is considered dust // according to the remote party's dust limit. @@ -2458,8 +2458,8 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, // BreachRetribution struct which houses all the data necessary to // swiftly bring justice to the cheating remote party. return &BreachRetribution{ + BreachTxHash: commitHash, ChainHash: chanState.ChainHash, - BreachTransaction: revokedSnapshot.CommitTx, BreachHeight: breachHeight, RevokedStateNum: stateNum, LocalOutpoint: ourOutpoint, diff --git a/watchtower/wtclient/backup_task.go b/watchtower/wtclient/backup_task.go index 6f9d2082a..5ac179c0a 100644 --- a/watchtower/wtclient/backup_task.go +++ b/watchtower/wtclient/backup_task.go @@ -346,7 +346,7 @@ func (t *backupTask) craftSessionPayload( } } - breachTxID := t.breachInfo.BreachTransaction.TxHash() + breachTxID := t.breachInfo.BreachTxHash // Compute the breach key as SHA256(txid). hint, key := blob.NewBreachHintAndKeyFromHash(&breachTxID) diff --git a/watchtower/wtclient/backup_task_internal_test.go b/watchtower/wtclient/backup_task_internal_test.go index 790283328..661f5e144 100644 --- a/watchtower/wtclient/backup_task_internal_test.go +++ b/watchtower/wtclient/backup_task_internal_test.go @@ -124,8 +124,8 @@ func genTaskTest( // the breach transaction, which we will continue to modify. breachTxn := wire.NewMsgTx(2) breachInfo := &lnwallet.BreachRetribution{ - RevokedStateNum: stateNum, - BreachTransaction: breachTxn, + RevokedStateNum: stateNum, + BreachTxHash: breachTxn.TxHash(), KeyRing: &lnwallet.CommitmentKeyRing{ RevocationKey: revPK, ToLocalKey: toLocalPK, @@ -607,7 +607,7 @@ func testBackupTask(t *testing.T, test backupTaskTest) { } // Verify that the breach hint matches the breach txid's prefix. - breachTxID := test.breachInfo.BreachTransaction.TxHash() + breachTxID := test.breachInfo.BreachTxHash expHint := blob.NewBreachHintFromHash(&breachTxID) if hint != expHint { t.Fatalf("breach hint mismatch, want: %x, got: %v", diff --git a/watchtower/wtclient/client_test.go b/watchtower/wtclient/client_test.go index 5f091223e..fcd256cd1 100644 --- a/watchtower/wtclient/client_test.go +++ b/watchtower/wtclient/client_test.go @@ -10,6 +10,7 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" @@ -300,7 +301,7 @@ func (c *mockChannel) createRemoteCommitTx(t *testing.T) { } retribution := &lnwallet.BreachRetribution{ - BreachTransaction: commitTxn, + BreachTxHash: commitTxn.TxHash(), RevokedStateNum: c.commitHeight, KeyRing: commitKeyRing, RemoteDelay: c.csvDelay, @@ -360,13 +361,15 @@ func (c *mockChannel) receivePayment(t *testing.T, amt lnwire.MilliSatoshi) { } // getState retrieves the channel's commitment and retribution at state i. -func (c *mockChannel) getState(i uint64) (*wire.MsgTx, *lnwallet.BreachRetribution) { +func (c *mockChannel) getState( + i uint64) (chainhash.Hash, *lnwallet.BreachRetribution) { + c.mu.Lock() defer c.mu.Unlock() retribution := c.retributions[i] - return retribution.BreachTransaction, retribution + return retribution.BreachTxHash, retribution } type testHarness struct { @@ -608,8 +611,7 @@ func (h *testHarness) advanceChannelN(id uint64, n int) []blob.BreachHint { var hints []blob.BreachHint for i := uint64(0); i < uint64(n); i++ { channel.advanceState(h.t) - commitTx, _ := h.channel(id).getState(i) - breachTxID := commitTx.TxHash() + breachTxID, _ := h.channel(id).getState(i) hints = append(hints, blob.NewBreachHintFromHash(&breachTxID)) } @@ -654,8 +656,7 @@ func (h *testHarness) sendPayments(id, from, to uint64, var hints []blob.BreachHint for i := from; i < to; i++ { h.channel(id).sendPayment(h.t, amt) - commitTx, _ := channel.getState(i) - breachTxID := commitTx.TxHash() + breachTxID, _ := channel.getState(i) hints = append(hints, blob.NewBreachHintFromHash(&breachTxID)) } @@ -675,8 +676,7 @@ func (h *testHarness) recvPayments(id, from, to uint64, var hints []blob.BreachHint for i := from; i < to; i++ { channel.receivePayment(h.t, amt) - commitTx, _ := channel.getState(i) - breachTxID := commitTx.TxHash() + breachTxID, _ := channel.getState(i) hints = append(hints, blob.NewBreachHintFromHash(&breachTxID)) }