watchtower/lookout/justice_descriptor: anchor justice txn
This commit modifies the JusticeDescriptor to support creation of justice transactions spending from anchor commitments. Rather than the unencumbered p2wkh scripts from before, the tower will now use the to-remote-confirmed that includes the additional CSV delay of 1. This also requires setting the sequence number appropriately on the to-remote input.
This commit is contained in:
2 files changed
+105
-26
No files matched your search
@@ -48,6 +48,7 @@ type breachedInput struct {
|
||||
txOut *wire.TxOut
|
||||
outPoint wire.OutPoint
|
||||
witness [][]byte
|
||||
sequence uint32
|
||||
}
|
||||
|
||||
// commitToLocalInput extracts the information required to spend the commit
|
||||
@@ -104,20 +105,35 @@ func (p *JusticeDescriptor) commitToRemoteInput() (*breachedInput, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Since the to-remote witness script should just be a regular p2wkh
|
||||
// output, we'll parse it to retrieve the public key.
|
||||
toRemotePubKey, err := btcec.ParsePubKey(toRemoteScript, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Compute the witness script hash from the to-remote pubkey, which will
|
||||
// be used to locate the input on the breach commitment transaction.
|
||||
toRemoteScriptHash, err := input.CommitScriptUnencumbered(
|
||||
toRemotePubKey,
|
||||
var (
|
||||
toRemoteScriptHash []byte
|
||||
toRemoteSequence uint32
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if p.JusticeKit.BlobType.IsAnchorChannel() {
|
||||
toRemoteScriptHash, err = input.WitnessScriptHash(
|
||||
toRemoteScript,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
toRemoteSequence = 1
|
||||
} else {
|
||||
// Since the to-remote witness script should just be a regular p2wkh
|
||||
// output, we'll parse it to retrieve the public key.
|
||||
toRemotePubKey, err := btcec.ParsePubKey(toRemoteScript, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Compute the witness script hash from the to-remote pubkey, which will
|
||||
// be used to locate the input on the breach commitment transaction.
|
||||
toRemoteScriptHash, err = input.CommitScriptUnencumbered(
|
||||
toRemotePubKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Locate the to-remote output on the breaching commitment transaction.
|
||||
@@ -146,6 +162,7 @@ func (p *JusticeDescriptor) commitToRemoteInput() (*breachedInput, error) {
|
||||
txOut: toRemoteTxOut,
|
||||
outPoint: toRemoteOutPoint,
|
||||
witness: buildWitness(witnessStack, toRemoteScript),
|
||||
sequence: toRemoteSequence,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -164,6 +181,7 @@ func (p *JusticeDescriptor) assembleJusticeTxn(txWeight int64,
|
||||
totalAmt += btcutil.Amount(input.txOut.Value)
|
||||
justiceTxn.AddTxIn(&wire.TxIn{
|
||||
PreviousOutPoint: input.outPoint,
|
||||
Sequence: input.sequence,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -279,8 +297,13 @@ func (p *JusticeDescriptor) CreateJusticeTxn() (*wire.MsgTx, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
weightEstimate.AddWitnessInput(input.P2WKHWitnessSize)
|
||||
sweepInputs = append(sweepInputs, toRemoteInput)
|
||||
|
||||
if p.JusticeKit.BlobType.IsAnchorChannel() {
|
||||
weightEstimate.AddWitnessInput(input.ToRemoteConfirmedWitnessSize)
|
||||
} else {
|
||||
weightEstimate.AddWitnessInput(input.P2WKHWitnessSize)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(conner): sweep htlc outputs
|
||||
|
||||
Reference in new issue
Block a user