Skip to content

Commit

Permalink
Update funding timeout fundee
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bast committed Feb 17, 2021
1 parent c785b23 commit 7d17722
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/fr/acinq/eclair/channel/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,7 @@ object Channel {
val MAX_TO_SELF_DELAY = CltvExpiryDelta(2016)

// as a fundee, we will wait that block count for the funding tx to confirm (funder will rely on the funding tx being double-spent)
const val FUNDING_TIMEOUT_FUNDEE_BLOCK = 720
const val FUNDING_TIMEOUT_FUNDEE_BLOCK = 2016

fun handleSync(channelReestablish: ChannelReestablish, d: ChannelStateWithCommitments, keyManager: KeyManager, log: Logger): Pair<Commitments, List<ChannelAction>> {
val sendQueue = ArrayList<ChannelAction>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ class ClosingTestsCommon : EclairTestSuite() {
assertNotNull(fundingTx)

// test starts here
val (bob1, _) = bob.process(ChannelEvent.NewBlock(bob.currentBlockHeight + 721, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
val (bob1, _) = bob.process(ChannelEvent.NewBlock(bob.currentBlockHeight + Channel.FUNDING_TIMEOUT_FUNDEE_BLOCK + 1, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
val (bob2, actions2) = bob1.process(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(fundingTx.txid, null, currentTimestampMillis())))
assertTrue { bob2 is Aborted }
assertEquals(1, actions2.size)
Expand Down Expand Up @@ -1341,11 +1341,11 @@ class ClosingTestsCommon : EclairTestSuite() {
val (bob1, _) = bob.process(ChannelEvent.WatchReceived(WatchEventSpent(bob.channelId, BITCOIN_FUNDING_SPENT, alice.commitments.localCommit.publishableTxs.commitTx.tx)))
assertTrue(bob1 is Closing)

// The funding tx isn't confirmed yet, but we give it 720 blocks to (hopefully) confirm. If it doesn't confirm within that delay, we will simply forget the channel.
// The funding tx isn't confirmed yet, but we give it 2016 blocks to (hopefully) confirm. If it doesn't confirm within that delay, we will simply forget the channel.
val (bob2, _) = bob1.process(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(bob.commitments.commitInput.outPoint.txid, null, currentTimestampMillis())))
assertEquals(bob1, bob2)
// Fast forward 721 blocks later
val (bob3, _) = bob2.process(ChannelEvent.NewBlock(bob2.currentBlockHeight + 721, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
// Fast forward after the funding timeout.
val (bob3, _) = bob2.process(ChannelEvent.NewBlock(bob2.currentBlockHeight + Channel.FUNDING_TIMEOUT_FUNDEE_BLOCK + 1, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
// We give up, Channel is aborted
val (bob4, actions4) = bob3.process(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(bob.commitments.commitInput.outPoint.txid, null, currentTimestampMillis())))
assertTrue { bob4 is Aborted }
Expand Down Expand Up @@ -1531,7 +1531,7 @@ class ClosingTestsCommon : EclairTestSuite() {
// fundee
val bob1 = run {
val (bob1, actions1) = bob.process(ChannelEvent.ExecuteCommand(CMD_FORCECLOSE))
assertTrue { bob1 is Closing } ; bob1 as Closing
assertTrue(bob1 is Closing)
assertEquals(6, actions1.size)

val error = actions1.hasOutgoingMessage<Error>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import fr.acinq.eclair.MilliSatoshi
import fr.acinq.eclair.blockchain.*
import fr.acinq.eclair.channel.*
import fr.acinq.eclair.channel.TestsHelper.processEx
import fr.acinq.eclair.io.WrappedChannelEvent
import fr.acinq.eclair.tests.TestConstants
import fr.acinq.eclair.tests.utils.EclairTestSuite
import fr.acinq.eclair.transactions.Scripts
import fr.acinq.eclair.utils.*
import fr.acinq.eclair.utils.currentTimestampMillis
import fr.acinq.eclair.utils.msat
import fr.acinq.eclair.utils.sat
import fr.acinq.eclair.wire.*
import kotlin.test.*

Expand Down Expand Up @@ -278,11 +279,11 @@ class WaitForFundingConfirmedTestsCommon : EclairTestSuite() {
assertTrue { bob2 is Syncing && bob2.state is WaitForFundingConfirmed }

// Actual test start here
// Nothing happens, we need to wait 720 blocks for the funding tx to be confirmed
// Nothing happens, we need to wait 2016 blocks for the funding tx to be confirmed
val (bob3, _) = bob2.processEx(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(bob.commitments.commitInput.outPoint.txid, null, currentTimestampMillis())))
assertEquals(bob2, bob3)
// Fast forward 721 blocks later
val (bob4, _) = bob3.processEx(ChannelEvent.NewBlock(bob3.currentBlockHeight + 721, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
// Fast forward after the funding timeout
val (bob4, _) = bob3.processEx(ChannelEvent.NewBlock(bob3.currentBlockHeight + Channel.FUNDING_TIMEOUT_FUNDEE_BLOCK + 1, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
// We give up, Channel is aborted
val (bob5, actions5) = bob4.processEx(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(bob.commitments.commitInput.outPoint.txid, null, currentTimestampMillis())))
assertTrue { bob5 is Aborted }
Expand All @@ -298,11 +299,11 @@ class WaitForFundingConfirmedTestsCommon : EclairTestSuite() {
assertTrue { bob1 is Offline && bob1.state is WaitForFundingConfirmed }

// Actual test start here
// Nothing happens, we need to wait 720 blocks for the funding tx to be confirmed
// Nothing happens, we need to wait 2016 blocks for the funding tx to be confirmed
val (bob2, _) = bob1.processEx(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(bob.commitments.commitInput.outPoint.txid, null, currentTimestampMillis())))
assertEquals(bob1, bob2)
// Fast forward 721 blocks later
val (bob3, _) = bob2.processEx(ChannelEvent.NewBlock(bob2.currentBlockHeight + 721, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
// Fast forward after the funding timeout
val (bob3, _) = bob2.processEx(ChannelEvent.NewBlock(bob2.currentBlockHeight + Channel.FUNDING_TIMEOUT_FUNDEE_BLOCK + 1, BlockHeader(0, ByteVector32.Zeroes, ByteVector32.Zeroes, 0, 0, 0)))
// We give up, Channel is aborted
val (bob4, actions4) = bob3.processEx(ChannelEvent.GetFundingTxResponse(GetTxWithMetaResponse(bob.commitments.commitInput.outPoint.txid, null, currentTimestampMillis())))
assertTrue { bob4 is Aborted }
Expand Down

0 comments on commit 7d17722

Please sign in to comment.