multi: use txid instead of tx in BreachRetribution

This commit replaces the field `BreachTransaction` with `BreachTxHash`
as there's no need to pass that large raw transaction.
This commit is contained in:
yyforyongyu committed 2022-04-20 01:18:14 +08:00
1 parent 37b11c4503
commit 953767961e
7 files changed
+23 -23

No files matched your search

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