mirror of
https://github.com/ACINQ/eclair.git
synced 2024-11-20 10:39:19 +01:00
renamed ClaimHtlcDelayedTx to ClaimDelayedOutputTx
This commit is contained in:
parent
22789d9395
commit
bcc5cb8f7b
@ -801,7 +801,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
|
||||
commitTx = tx,
|
||||
htlcSuccessTxs = claimTxs.collect { case c: HtlcSuccessTx => c.tx },
|
||||
htlcTimeoutTxs = claimTxs.collect { case c: HtlcTimeoutTx => c.tx },
|
||||
claimHtlcDelayedTx = claimTxs.collect { case c: ClaimHtlcDelayedTx => c.tx })
|
||||
claimHtlcDelayedTx = claimTxs.collect { case c: ClaimDelayedOutputTx => c.tx })
|
||||
|
||||
val nextData = d match {
|
||||
case closing: DATA_CLOSING => closing.copy(localCommitPublished = Some(localCommitPublished))
|
||||
|
@ -130,7 +130,7 @@ object Helpers {
|
||||
val delayedTxes = htlcTxes.map {
|
||||
case txinfo: TransactionWithInputInfo =>
|
||||
// TODO: we should use the current fee rate, not the initial fee rate that we get from localParams
|
||||
val claimDelayed = Transactions.makeClaimHtlcDelayed(txinfo.tx, localRevocationPubkey, localParams.toSelfDelay, localDelayedPrivkey.toPoint, localParams.defaultFinalScriptPubKey, commitments.localParams.feeratePerKw)
|
||||
val claimDelayed = Transactions.makeClaimDelayedOutputTx(txinfo.tx, localRevocationPubkey, localParams.toSelfDelay, localDelayedPrivkey.toPoint, localParams.defaultFinalScriptPubKey, commitments.localParams.feeratePerKw)
|
||||
val sig = Transactions.sign(claimDelayed, localDelayedPrivkey)
|
||||
Transactions.addSigs(claimDelayed, sig)
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ object Scripts {
|
||||
else tx.txIn.map(_.sequence).map(sequenceToBlockHeight).max
|
||||
}
|
||||
|
||||
def toLocal(revocationPubkey: BinaryData, toSelfDelay: Int, localDelayedPubkey: BinaryData) = {
|
||||
def toLocalDelayed(revocationPubkey: BinaryData, toSelfDelay: Int, localDelayedPubkey: BinaryData) = {
|
||||
// @formatter:off
|
||||
OP_IF ::
|
||||
OP_PUSHDATA(revocationPubkey) ::
|
||||
@ -211,6 +211,19 @@ object Scripts {
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
/**
|
||||
* This witness script spends a [[toLocalDelayed]] output using a local sig after a delay
|
||||
*/
|
||||
def witnessToLocalDelayedAfterDelay(localSig: BinaryData, toLocalDelayedScript: BinaryData) =
|
||||
ScriptWitness(localSig :: BinaryData.empty :: toLocalDelayedScript :: Nil)
|
||||
|
||||
/**
|
||||
* This witness script spends (steals) a [[toLocalDelayed]] output using a revocation key as a punishment
|
||||
* for having published a revoked transaction
|
||||
*/
|
||||
def witnessToLocalDelayedWithRevocationSig(revocationSig: BinaryData, toLocalScript: BinaryData) =
|
||||
ScriptWitness(revocationSig :: BinaryData("01") :: toLocalScript :: Nil)
|
||||
|
||||
def toRemote(remoteKey: BinaryData) = remoteKey
|
||||
|
||||
def htlcOffered(localPubkey: BinaryData, remotePubkey: BinaryData, paymentHash: BinaryData) = {
|
||||
@ -226,14 +239,6 @@ object Scripts {
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This witness script spends (steals) a toLocal output using a revocation key as a punishment
|
||||
* for having published a revoked transaction
|
||||
*/
|
||||
def witnessToLocalFromRevokedCommitTx(revocationSig: BinaryData, toLocalScript: BinaryData) =
|
||||
ScriptWitness(revocationSig :: BinaryData("01") :: toLocalScript :: Nil)
|
||||
|
||||
/**
|
||||
* This is the witness script of the 2nd-stage HTLC Success transaction (consumes htlcOffered script from commit tx)
|
||||
*/
|
||||
@ -273,18 +278,4 @@ object Scripts {
|
||||
def witnessClaimHtlcTimeoutFromCommitTx(localSig: BinaryData, htlcReceivedScript: BinaryData) =
|
||||
ScriptWitness(localSig :: BinaryData.empty :: htlcReceivedScript :: Nil)
|
||||
|
||||
def htlcSuccessOrTimeout(revocationPubkey: BinaryData, toSelfDelay: Long, localDelayedPubkey: BinaryData) = {
|
||||
// @formatter:off
|
||||
OP_IF ::
|
||||
OP_PUSHDATA(revocationPubkey) ::
|
||||
OP_ELSE ::
|
||||
OP_PUSHDATA(Script.encodeNumber(toSelfDelay)) :: OP_CHECKSEQUENCEVERIFY :: OP_DROP ::
|
||||
OP_PUSHDATA(localDelayedPubkey) ::
|
||||
OP_ENDIF ::
|
||||
OP_CHECKSIG :: Nil
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
def witnessHtlcDelayed(localSig: BinaryData, htlcDelayedScript: BinaryData) =
|
||||
ScriptWitness(localSig :: BinaryData.empty :: htlcDelayedScript :: Nil)
|
||||
}
|
@ -26,7 +26,7 @@ object Transactions {
|
||||
case class HtlcTimeoutTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class ClaimHtlcSuccessTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class ClaimHtlcTimeoutTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class ClaimHtlcDelayedTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class ClaimDelayedOutputTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class MainPunishmentTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class HtlcPunishmentTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
case class ClosingTx(input: InputInfo, tx: Transaction) extends TransactionWithInputInfo
|
||||
@ -34,10 +34,11 @@ object Transactions {
|
||||
|
||||
/**
|
||||
* When *local* *current* [[CommitTx]] is published:
|
||||
* - [[ClaimDelayedOutputTx]] spends to-local output of [[CommitTx]] after a delay
|
||||
* - [[HtlcSuccessTx]] spends htlc-received outputs of [[CommitTx]] for which we have the preimage
|
||||
* - [[ClaimHtlcDelayedTx]] spends [[HtlcSuccessTx]] after a delay
|
||||
* - [[ClaimDelayedOutputTx]] spends [[HtlcSuccessTx]] after a delay
|
||||
* - [[HtlcTimeoutTx]] spends htlc-sent outputs of [[CommitTx]] after a timeout
|
||||
* - [[ClaimHtlcDelayedTx]] spends [[HtlcTimeoutTx]] after a delay
|
||||
* - [[ClaimDelayedOutputTx]] spends [[HtlcTimeoutTx]] after a delay
|
||||
*
|
||||
* When *remote* *current* [[CommitTx]] is published:
|
||||
* - [[ClaimHtlcSuccessTx]] spends htlc-received outputs of [[CommitTx]] for which we have the preimage
|
||||
@ -138,7 +139,7 @@ object Transactions {
|
||||
case (local, remote) if !localIsFunder && remote.compare(commitFee) <= 0 => ??? //TODO: can't pay fees!
|
||||
case (local, remote) if !localIsFunder && remote.compare(commitFee) > 0 => (millisatoshi2satoshi(local), remote - commitFee)
|
||||
}
|
||||
val toLocalDelayedOutput_opt = if (toLocalAmount.compare(localDustLimit) > 0) Some(TxOut(toLocalAmount, pay2wsh(toLocal(localRevocationPubkey, toLocalDelay, localDelayedPubkey)))) else None
|
||||
val toLocalDelayedOutput_opt = if (toLocalAmount.compare(localDustLimit) > 0) Some(TxOut(toLocalAmount, pay2wsh(toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPubkey)))) else None
|
||||
val toRemoteOutput_opt = if (toRemoteAmount.compare(localDustLimit) > 0) Some(TxOut(toRemoteAmount, pay2wpkh(toRemote(remotePubkey)))) else None
|
||||
|
||||
val htlcTimeoutFee = weight2fee(spec.feeRatePerKw, htlcTimeoutWeight)
|
||||
@ -173,7 +174,7 @@ object Transactions {
|
||||
HtlcTimeoutTx(input, Transaction(
|
||||
version = 2,
|
||||
txIn = TxIn(input.outPoint, Array.emptyByteArray, 0xffffffffL) :: Nil,
|
||||
txOut = TxOut(MilliSatoshi(htlc.amountMsat) - fee, pay2wsh(htlcSuccessOrTimeout(localRevocationPubkey, toLocalDelay, localDelayedPubkey))) :: Nil,
|
||||
txOut = TxOut(MilliSatoshi(htlc.amountMsat) - fee, pay2wsh(toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPubkey))) :: Nil,
|
||||
lockTime = htlc.expiry))
|
||||
}
|
||||
|
||||
@ -187,7 +188,7 @@ object Transactions {
|
||||
HtlcSuccessTx(input, Transaction(
|
||||
version = 2,
|
||||
txIn = TxIn(input.outPoint, Array.emptyByteArray, 0xffffffffL) :: Nil,
|
||||
txOut = TxOut(MilliSatoshi(htlc.amountMsat) - fee, pay2wsh(htlcSuccessOrTimeout(localRevocationPubkey, toLocalDelay, localDelayedPubkey))) :: Nil,
|
||||
txOut = TxOut(MilliSatoshi(htlc.amountMsat) - fee, pay2wsh(toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPubkey))) :: Nil,
|
||||
lockTime = 0), htlc.paymentHash)
|
||||
}
|
||||
|
||||
@ -235,14 +236,14 @@ object Transactions {
|
||||
lockTime = htlc.expiry))
|
||||
}
|
||||
|
||||
def makeClaimHtlcDelayed(htlcSuccessOrTimeoutTx: Transaction, localRevocationPubkey: BinaryData, toLocalDelay: Int, localDelayedPubkey: BinaryData, localFinalScriptPubKey: Seq[ScriptElt], feeRatePerKw: Long): ClaimHtlcDelayedTx = {
|
||||
def makeClaimDelayedOutputTx(delayedOutputTx: Transaction, localRevocationPubkey: BinaryData, toLocalDelay: Int, localDelayedPubkey: BinaryData, localFinalScriptPubKey: Seq[ScriptElt], feeRatePerKw: Long): ClaimDelayedOutputTx = {
|
||||
val fee = weight2fee(feeRatePerKw, claimHtlcDelayedWeight)
|
||||
val redeemScript = htlcSuccessOrTimeout(localRevocationPubkey, toLocalDelay, localDelayedPubkey)
|
||||
val redeemScript = toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPubkey)
|
||||
val pubkeyScript = write(pay2wsh(redeemScript))
|
||||
val outputIndex = findPubKeyScriptIndex(htlcSuccessOrTimeoutTx, pubkeyScript)
|
||||
val outputIndex = findPubKeyScriptIndex(delayedOutputTx, pubkeyScript)
|
||||
require(outputIndex >= 0, "output not found")
|
||||
val input = InputInfo(OutPoint(htlcSuccessOrTimeoutTx, outputIndex), htlcSuccessOrTimeoutTx.txOut(outputIndex), write(redeemScript))
|
||||
ClaimHtlcDelayedTx(input, Transaction(
|
||||
val input = InputInfo(OutPoint(delayedOutputTx, outputIndex), delayedOutputTx.txOut(outputIndex), write(redeemScript))
|
||||
ClaimDelayedOutputTx(input, Transaction(
|
||||
version = 2,
|
||||
txIn = TxIn(input.outPoint, Array.emptyByteArray, toLocalDelay) :: Nil,
|
||||
txOut = TxOut(input.txOut.amount - fee, localFinalScriptPubKey) :: Nil,
|
||||
@ -251,7 +252,7 @@ object Transactions {
|
||||
|
||||
def makeMainPunishmentTx(commitTx: Transaction, remoteRevocationPubkey: BinaryData, localFinalScriptPubKey: Seq[ScriptElt], toRemoteDelay: Int, remoteDelayedPubkey: BinaryData, feeRatePerKw: Long): MainPunishmentTx = {
|
||||
val fee = weight2fee(feeRatePerKw, mainPunishmentWeight)
|
||||
val redeemScript = toLocal(remoteRevocationPubkey, toRemoteDelay, remoteDelayedPubkey)
|
||||
val redeemScript = toLocalDelayed(remoteRevocationPubkey, toRemoteDelay, remoteDelayedPubkey)
|
||||
val pubkeyScript = write(pay2wsh(redeemScript))
|
||||
val outputIndex = findPubKeyScriptIndex(commitTx, pubkeyScript)
|
||||
require(outputIndex >= 0, "output not found")
|
||||
@ -305,7 +306,7 @@ object Transactions {
|
||||
}
|
||||
|
||||
def addSigs(claimMainDelayedRevokedTx: MainPunishmentTx, revocationSig: BinaryData): MainPunishmentTx = {
|
||||
val witness = Scripts.witnessToLocalFromRevokedCommitTx(revocationSig, claimMainDelayedRevokedTx.input.redeemScript)
|
||||
val witness = Scripts.witnessToLocalDelayedWithRevocationSig(revocationSig, claimMainDelayedRevokedTx.input.redeemScript)
|
||||
claimMainDelayedRevokedTx.copy(tx = claimMainDelayedRevokedTx.tx.updateWitness(0, witness))
|
||||
}
|
||||
|
||||
@ -329,8 +330,8 @@ object Transactions {
|
||||
claimHtlcTimeoutTx.copy(tx = claimHtlcTimeoutTx.tx.updateWitness(0, witness))
|
||||
}
|
||||
|
||||
def addSigs(claimHtlcDelayed: ClaimHtlcDelayedTx, localSig: BinaryData): ClaimHtlcDelayedTx = {
|
||||
val witness = witnessHtlcDelayed(localSig, claimHtlcDelayed.input.redeemScript)
|
||||
def addSigs(claimHtlcDelayed: ClaimDelayedOutputTx, localSig: BinaryData): ClaimDelayedOutputTx = {
|
||||
val witness = witnessToLocalDelayedAfterDelay(localSig, claimHtlcDelayed.input.redeemScript)
|
||||
claimHtlcDelayed.copy(tx = claimHtlcDelayed.tx.updateWitness(0, witness))
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import fr.acinq.bitcoin.Crypto.{Scalar, sha256}
|
||||
import fr.acinq.bitcoin.Script.{pay2wsh, write}
|
||||
import fr.acinq.bitcoin.{BinaryData, Btc, Crypto, MilliBtc, MilliSatoshi, Satoshi, Script, Transaction, TxOut, millibtc2satoshi}
|
||||
import fr.acinq.eclair.channel.Helpers.Funding
|
||||
import fr.acinq.eclair.transactions.Scripts.htlcSuccessOrTimeout
|
||||
import fr.acinq.eclair.transactions.Scripts.toLocalDelayed
|
||||
import fr.acinq.eclair.transactions.Transactions._
|
||||
import fr.acinq.eclair.wire.UpdateAddHtlc
|
||||
import org.junit.runner.RunWith
|
||||
@ -53,10 +53,10 @@ class TransactionsSpec extends FunSuite {
|
||||
|
||||
{
|
||||
// ClaimHtlcDelayedTx
|
||||
// first we create a fake htlcSuccessOrTimeoutTx tx, containing only the output that will be spent by the ClaimHtlcDelayedTx
|
||||
val pubKeyScript = write(pay2wsh(htlcSuccessOrTimeout(localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint)))
|
||||
// first we create a fake htlcSuccessOrTimeoutTx tx, containing only the output that will be spent by the ClaimDelayedOutputTx
|
||||
val pubKeyScript = write(pay2wsh(toLocalDelayed(localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint)))
|
||||
val htlcSuccessOrTimeoutTx = Transaction(version = 0, txIn = Nil, txOut = TxOut(Satoshi(20000), pubKeyScript) :: Nil, lockTime = 0)
|
||||
val claimHtlcDelayedTx = makeClaimHtlcDelayed(htlcSuccessOrTimeoutTx, localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint, finalPubKeyScript, feeRatePerKw)
|
||||
val claimHtlcDelayedTx = makeClaimDelayedOutputTx(htlcSuccessOrTimeoutTx, localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint, finalPubKeyScript, feeRatePerKw)
|
||||
// we use dummy signatures to compute the weight
|
||||
val weight = Transaction.weight(addSigs(claimHtlcDelayedTx, "bb" * 71).tx)
|
||||
assert(claimHtlcDelayedWeight == weight)
|
||||
@ -65,7 +65,7 @@ class TransactionsSpec extends FunSuite {
|
||||
{
|
||||
// MainPunishmentTx
|
||||
// first we create a fake commitTx tx, containing only the output that will be spent by the MainPunishmentTx
|
||||
val pubKeyScript = write(pay2wsh(htlcSuccessOrTimeout(localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint)))
|
||||
val pubKeyScript = write(pay2wsh(toLocalDelayed(localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint)))
|
||||
val commitTx = Transaction(version = 0, txIn = Nil, txOut = TxOut(Satoshi(20000), pubKeyScript) :: Nil, lockTime = 0)
|
||||
val mainPunishmentTx = makeMainPunishmentTx(commitTx, localRevocationPriv.toPoint, finalPubKeyScript, toLocalDelay, localPaymentPriv.toPoint, feeRatePerKw)
|
||||
// we use dummy signatures to compute the weight
|
||||
@ -131,7 +131,7 @@ class TransactionsSpec extends FunSuite {
|
||||
{
|
||||
// local spends delayed output of htlc timeout tx
|
||||
val htlcTimeoutTx = htlcTimeoutTxs(0)
|
||||
val claimHtlcDelayed = makeClaimHtlcDelayed(htlcTimeoutTx.tx, localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint, finalPubKeyScript, feeRatePerKw)
|
||||
val claimHtlcDelayed = makeClaimDelayedOutputTx(htlcTimeoutTx.tx, localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint, finalPubKeyScript, feeRatePerKw)
|
||||
val localSig = sign(claimHtlcDelayed, localPaymentPriv)
|
||||
val signedTx = addSigs(claimHtlcDelayed, localSig)
|
||||
assert(checkSpendable(signedTx).isSuccess)
|
||||
@ -159,7 +159,7 @@ class TransactionsSpec extends FunSuite {
|
||||
{
|
||||
// local spends delayed output of htlc success tx
|
||||
val htlcSuccessTx = htlcSuccessTxs(0)
|
||||
val claimHtlcDelayed = makeClaimHtlcDelayed(htlcSuccessTx.tx, localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint, finalPubKeyScript, feeRatePerKw)
|
||||
val claimHtlcDelayed = makeClaimDelayedOutputTx(htlcSuccessTx.tx, localRevocationPriv.toPoint, toLocalDelay, localPaymentPriv.toPoint, finalPubKeyScript, feeRatePerKw)
|
||||
val localSig = sign(claimHtlcDelayed, localPaymentPriv)
|
||||
val signedTx = addSigs(claimHtlcDelayed, localSig)
|
||||
assert(checkSpendable(signedTx).isSuccess)
|
||||
|
Loading…
Reference in New Issue
Block a user