Skip to content

Commit

Permalink
Fix failing splice tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sstone committed Feb 8, 2024
1 parent c215ad4 commit f963c21
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ sealed class InteractiveTxInput {
val publicKeyScript: ByteVector,
override val sequence: UInt,
val localAmount: MilliSatoshi,
val remoteAmount: MilliSatoshi
val remoteAmount: MilliSatoshi,
val htlcAmount: MilliSatoshi
) : InteractiveTxInput(), Incoming, Outgoing {
override val txOut: TxOut get() = TxOut((localAmount + remoteAmount).truncateToSatoshi(), publicKeyScript)
override val txOut: TxOut get() = TxOut((localAmount + remoteAmount + htlcAmount).truncateToSatoshi(), publicKeyScript)
}
}

Expand Down Expand Up @@ -298,7 +299,7 @@ data class FundingContributions(val inputs: List<InteractiveTxInput.Outgoing>, v
}
}
}
val sharedInput = sharedUtxo?.let { (i, balances) -> listOf(InteractiveTxInput.Shared(0, i.info.outPoint, i.info.txOut.publicKeyScript, 0xfffffffdU, balances.toLocal, balances.toRemote)) } ?: listOf()
val sharedInput = sharedUtxo?.let { (i, balances) -> listOf(InteractiveTxInput.Shared(0, i.info.outPoint, i.info.txOut.publicKeyScript, 0xfffffffdU, balances.toLocal, balances.toRemote, balances.toHtlcs)) } ?: listOf()
val localInputs = walletInputs.map { i ->
when {
Script.isPay2wsh(i.previousTx.txOut[i.outputIndex].publicKeyScript.toByteArray()) ->
Expand Down Expand Up @@ -731,7 +732,7 @@ data class InteractiveTxSession(
val expectedSharedOutpoint = fundingParams.sharedInput?.info?.outPoint ?: return Either.Left(InteractiveTxSessionAction.PreviousTxMissing(message.channelId, message.serialId))
val receivedSharedOutpoint = message.sharedInput ?: return Either.Left(InteractiveTxSessionAction.PreviousTxMissing(message.channelId, message.serialId))
if (expectedSharedOutpoint != receivedSharedOutpoint) return Either.Left(InteractiveTxSessionAction.PreviousTxMissing(message.channelId, message.serialId))
InteractiveTxInput.Shared(message.serialId, receivedSharedOutpoint, fundingParams.sharedInput.info.txOut.publicKeyScript, message.sequence, previousFunding.toLocal, previousFunding.toRemote)
InteractiveTxInput.Shared(message.serialId, receivedSharedOutpoint, fundingParams.sharedInput.info.txOut.publicKeyScript, message.sequence, previousFunding.toLocal, previousFunding.toRemote, previousFunding.toHtlcs)
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ data class WaitForAcceptChannel(
}
is Either.Right -> {
// The channel initiator always sends the first interactive-tx message.
val (interactiveTxSession, interactiveTxAction) = InteractiveTxSession(channelKeys, keyManager.swapInOnChainWallet, fundingParams, 0.msat, 0.msat, emptySet(), fundingContributions.value).send()
val (interactiveTxSession, interactiveTxAction) = InteractiveTxSession(staticParams.remoteNodeId, channelKeys, keyManager.swapInOnChainWallet, fundingParams, 0.msat, 0.msat, emptySet(), fundingContributions.value).send()
when (interactiveTxAction) {
is InteractiveTxSessionAction.SendMessage -> {
val nextState = WaitForFundingCreated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ data class WaitForFundingConfirmed(
addAll(latestFundingTx.sharedTx.tx.localInputs.map { Either.Left(it) })
addAll(latestFundingTx.sharedTx.tx.localOutputs.map { Either.Right(it) })
}
val session = InteractiveTxSession(channelKeys(), keyManager.swapInOnChainWallet, fundingParams, SharedFundingInputBalances(0.msat, 0.msat, 0.msat), toSend, previousFundingTxs.map { it.sharedTx }, commitments.latest.localCommit.spec.htlcs)
val session = InteractiveTxSession(staticParams.remoteNodeId, channelKeys(), keyManager.swapInOnChainWallet, fundingParams, SharedFundingInputBalances(0.msat, 0.msat, 0.msat), toSend, previousFundingTxs.map { it.sharedTx }, commitments.latest.localCommit.spec.htlcs)
val nextState = this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.InProgress(session))
Pair(nextState, listOf(ChannelAction.Message.Send(TxAckRbf(channelId, fundingParams.localContribution))))
}
Expand Down Expand Up @@ -142,7 +142,7 @@ data class WaitForFundingConfirmed(
Pair(this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.RbfAborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, ChannelFundingError(channelId).message))))
}
is Either.Right -> {
val (session, action) = InteractiveTxSession(channelKeys(), keyManager.swapInOnChainWallet, fundingParams, 0.msat, 0.msat, emptySet(), contributions.value, previousFundingTxs.map { it.sharedTx }).send()
val (session, action) = InteractiveTxSession(staticParams.remoteNodeId, channelKeys(), keyManager.swapInOnChainWallet, fundingParams, 0.msat, 0.msat, emptySet(), contributions.value, previousFundingTxs.map { it.sharedTx }).send()
when (action) {
is InteractiveTxSessionAction.SendMessage -> {
val nextState = this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.InProgress(session))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data class WaitForOpenChannel(
Pair(Aborted, listOf(ChannelAction.Message.Send(Error(temporaryChannelId, ChannelFundingError(temporaryChannelId).message))))
}
is Either.Right -> {
val interactiveTxSession = InteractiveTxSession(channelKeys, keyManager.swapInOnChainWallet, fundingParams, 0.msat, 0.msat, emptySet(), fundingContributions.value)
val interactiveTxSession = InteractiveTxSession(staticParams.remoteNodeId, channelKeys, keyManager.swapInOnChainWallet, fundingParams, 0.msat, 0.msat, emptySet(), fundingContributions.value)
val nextState = WaitForFundingCreated(
localParams,
remoteParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,25 @@ object Deserialization {
sequence = readNumber().toUInt(),
localAmount = readNumber().msat,
remoteAmount = readNumber().msat,
htlcAmount = 0.msat
)
0x02 -> InteractiveTxInput.Shared(
serialId = readNumber(),
outPoint = readOutPoint(),
publicKeyScript = readDelimitedByteArray().byteVector(),
sequence = readNumber().toUInt(),
localAmount = readNumber().msat,
remoteAmount = readNumber().msat
remoteAmount = readNumber().msat,
htlcAmount = 0.msat
)
0x03 -> InteractiveTxInput.Shared(
serialId = readNumber(),
outPoint = readOutPoint(),
publicKeyScript = readDelimitedByteArray().byteVector(),
sequence = readNumber().toUInt(),
localAmount = readNumber().msat,
remoteAmount = readNumber().msat,
htlcAmount = readNumber().msat
)
else -> error("unknown discriminator $discriminator for class ${InteractiveTxInput.Shared::class}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,14 @@ object Serialization {
}

private fun Output.writeSharedInteractiveTxInput(i: InteractiveTxInput.Shared) = i.run {
write(0x02)
write(0x03)
writeNumber(serialId)
writeBtcObject(outPoint)
writeDelimited(publicKeyScript.toByteArray())
writeNumber(sequence.toLong())
writeNumber(localAmount.toLong())
writeNumber(remoteAmount.toLong())
writeNumber(htlcAmount.toLong())
}

private fun Output.writeLocalInteractiveTxInput(i: InteractiveTxInput.Local) = when (i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ class InteractiveTxTestsCommon : LightningTestSuite() {
@Test
fun `swap-in input missing user nonce`() {
val f = createFixture(100_000.sat, listOf(150_000.sat), listOf(), 0.sat, listOf(), listOf(), FeeratePerKw(2500.sat), 330.sat, 0)
val alice0 = InteractiveTxSession(f.nodeIdB, f.channelKeysA, f.keyManagerA.swapInOnChainWallet, f.fundingParamsA, 0.msat, 0.msat, f.fundingContributionsA)
val bob0 = InteractiveTxSession(f.nodeIdA, f.channelKeysB, f.keyManagerB.swapInOnChainWallet, f.fundingParamsB, 0.msat, 0.msat, f.fundingContributionsB)
val alice0 = InteractiveTxSession(f.nodeIdB, f.channelKeysA, f.keyManagerA.swapInOnChainWallet, f.fundingParamsA, 0.msat, 0.msat, emptySet(), f.fundingContributionsA)
val bob0 = InteractiveTxSession(f.nodeIdA, f.channelKeysB, f.keyManagerB.swapInOnChainWallet, f.fundingParamsB, 0.msat, 0.msat, emptySet(), f.fundingContributionsB)
// Alice --- tx_add_input --> Bob
val (alice1, inputA) = sendMessage<TxAddInput>(alice0)
// Alice <-- tx_complete --- Bob
Expand Down Expand Up @@ -1070,7 +1070,7 @@ class InteractiveTxTestsCommon : LightningTestSuite() {
@Test
fun `previous attempts not double-spent`() {
val f = createFixture(100_000.sat, listOf(120_000.sat), listOf(), 0.sat, listOf(), listOf(), FeeratePerKw(5000.sat), 330.sat, 0)
val sharedOutput = InteractiveTxOutput.Shared(0, f.fundingParamsA.fundingPubkeyScript(f.channelKeysA), 100_000_000.msat, 0.msat)
val sharedOutput = InteractiveTxOutput.Shared(0, f.fundingParamsA.fundingPubkeyScript(f.channelKeysA), 100_000_000.msat, 0.msat, 0.msat)
val previousTx1 = Transaction(2, listOf(), listOf(TxOut(150_000.sat, Script.pay2wpkh(randomKey().publicKey()))), 0)
val previousTx2 = Transaction(2, listOf(), listOf(TxOut(160_000.sat, Script.pay2wpkh(randomKey().publicKey())), TxOut(200_000.sat, Script.pay2wpkh(randomKey().publicKey()))), 0)
val validScript = Script.write(Script.pay2wpkh(randomKey().publicKey())).byteVector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class QuiescenceTestsCommon : LightningTestSuite() {

companion object {
private fun createWalletWithFunds(keyManager: KeyManager, utxos: List<Satoshi>): List<WalletState.Utxo> {
val script = keyManager.swapInOnChainWallet.pubkeyScript
val script = keyManager.swapInOnChainWallet.swapInProtocol.pubkeyScript
return utxos.map { amount ->
val txIn = listOf(TxIn(OutPoint(TxId(Lightning.randomBytes32()), 2), 0))
val txOut = listOf(TxOut(amount, script), TxOut(150.sat, Script.pay2wpkh(Lightning.randomKey().publicKey())))
Expand Down

0 comments on commit f963c21

Please sign in to comment.