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 2022-04-11 01:58:55 +08:00
parent 37b11c4503
commit 953767961e
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
7 changed files with 23 additions and 23 deletions

View File

@ -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,

View File

@ -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],

View File

@ -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
}

View File

@ -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,

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).
hint, key := blob.NewBreachHintAndKeyFromHash(&breachTxID)

View File

@ -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",

View File

@ -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))
}