1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 14:40:34 +01:00

Minor refactoring (#2538)

Minor refactoring with no functional changes.
This commit is contained in:
Pierre-Marie Padiou 2023-01-02 09:48:26 +01:00 committed by GitHub
parent 431df1fddb
commit f0d12eb216
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 99 additions and 109 deletions

View file

@ -484,7 +484,7 @@ final case class DATA_WAIT_FOR_FUNDING_SIGNED(channelId: ByteVector32,
channelFeatures: ChannelFeatures,
lastSent: FundingCreated) extends TransientChannelData
final case class DATA_WAIT_FOR_FUNDING_CONFIRMED(commitments: Commitments,
fundingTx: Option[Transaction],
fundingTx_opt: Option[Transaction],
waitingSince: BlockHeight, // how long have we been waiting for the funding tx to confirm
deferred: Option[ChannelReady],
lastSent: Either[FundingCreated, FundingSigned]) extends PersistentChannelData

View file

@ -1323,7 +1323,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder, val
case Event(c: CMD_UPDATE_RELAY_FEE, d: DATA_NORMAL) => handleUpdateRelayFeeDisconnected(c, d)
case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.fundingTxId => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx)
case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.fundingTxId => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx_opt)
case Event(BITCOIN_FUNDING_PUBLISH_FAILED, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => handleFundingPublishFailed(d)
@ -1525,7 +1525,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder, val
case Event(c: CurrentFeerates, d: PersistentChannelData) => handleCurrentFeerateDisconnected(c, d)
case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.fundingTxId => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx)
case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.fundingTxId => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx_opt)
case Event(BITCOIN_FUNDING_PUBLISH_FAILED, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => handleFundingPublishFailed(d)

View file

@ -406,11 +406,11 @@ trait ChannelOpenSingleFunded extends SingleFundingHandlers with ErrorHandlers {
delayEarlyAnnouncementSigs(remoteAnnSigs)
stay()
case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.fundingTxId => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx)
case Event(getTxResponse: GetTxWithMetaResponse, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) if getTxResponse.txid == d.commitments.fundingTxId => handleGetFundingTx(getTxResponse, d.waitingSince, d.fundingTx_opt)
case Event(BITCOIN_FUNDING_PUBLISH_FAILED, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => handleFundingPublishFailed(d)
case Event(ProcessCurrentBlockHeight(c), d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => d.fundingTx match {
case Event(ProcessCurrentBlockHeight(c), d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => d.fundingTx_opt match {
case Some(_) => stay() // we are funder, we're still waiting for the funding tx to be confirmed
case None if c.blockHeight - d.waitingSince > FUNDING_TIMEOUT_FUNDEE =>
log.warning(s"funding tx hasn't been published in ${c.blockHeight - d.waitingSince} blocks")

View file

@ -182,7 +182,7 @@ trait ErrorHandlers extends CommonHandlers {
val nextData = d match {
case closing: DATA_CLOSING => closing.copy(localCommitPublished = Some(localCommitPublished))
case negotiating: DATA_NEGOTIATING => DATA_CLOSING(d.commitments, fundingTx = None, waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, negotiating.closingTxProposed.flatten.map(_.unsignedTx), localCommitPublished = Some(localCommitPublished))
case waitForFundingConfirmed: DATA_WAIT_FOR_FUNDING_CONFIRMED => DATA_CLOSING(d.commitments, fundingTx = waitForFundingConfirmed.fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = Nil, localCommitPublished = Some(localCommitPublished))
case waitForFundingConfirmed: DATA_WAIT_FOR_FUNDING_CONFIRMED => DATA_CLOSING(d.commitments, fundingTx = waitForFundingConfirmed.fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = Nil, localCommitPublished = Some(localCommitPublished))
case waitForFundingConfirmed: DATA_WAIT_FOR_DUAL_FUNDING_CONFIRMED => DATA_CLOSING(d.commitments, fundingTx = Some(DualFundedUnconfirmedFundingTx(waitForFundingConfirmed.fundingTx)), waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = waitForFundingConfirmed.previousFundingTxs, mutualCloseProposed = Nil, localCommitPublished = Some(localCommitPublished))
case _ => DATA_CLOSING(d.commitments, fundingTx = None, waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = Nil, localCommitPublished = Some(localCommitPublished))
}
@ -228,7 +228,7 @@ trait ErrorHandlers extends CommonHandlers {
val nextData = d match {
case closing: DATA_CLOSING => closing.copy(remoteCommitPublished = Some(remoteCommitPublished))
case negotiating: DATA_NEGOTIATING => DATA_CLOSING(d.commitments, fundingTx = None, waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = negotiating.closingTxProposed.flatten.map(_.unsignedTx), remoteCommitPublished = Some(remoteCommitPublished))
case waitForFundingConfirmed: DATA_WAIT_FOR_FUNDING_CONFIRMED => DATA_CLOSING(d.commitments, fundingTx = waitForFundingConfirmed.fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = Nil, remoteCommitPublished = Some(remoteCommitPublished))
case waitForFundingConfirmed: DATA_WAIT_FOR_FUNDING_CONFIRMED => DATA_CLOSING(d.commitments, fundingTx = waitForFundingConfirmed.fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = Nil, remoteCommitPublished = Some(remoteCommitPublished))
case waitForFundingConfirmed: DATA_WAIT_FOR_DUAL_FUNDING_CONFIRMED => DATA_CLOSING(d.commitments, fundingTx = Some(DualFundedUnconfirmedFundingTx(waitForFundingConfirmed.fundingTx)), waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = waitForFundingConfirmed.previousFundingTxs, mutualCloseProposed = Nil, remoteCommitPublished = Some(remoteCommitPublished))
case _ => DATA_CLOSING(d.commitments, fundingTx = None, waitingSince = nodeParams.currentBlockHeight, alternativeCommitments = Nil, mutualCloseProposed = Nil, remoteCommitPublished = Some(remoteCommitPublished))
}

View file

@ -357,14 +357,14 @@ private[channel] object ChannelCodecs0 {
// this is a decode-only codec compatible with versions 997acee and below, with placeholders for new fields
val DATA_WAIT_FOR_FUNDING_CONFIRMED_01_Codec: Codec[DATA_WAIT_FOR_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | provide[Option[Transaction]](None)) ::
("fundingTx_opt" | provide[Option[Transaction]](None)) ::
("waitingSince" | provide(BlockHeight(TimestampSecond.now().toLong))) ::
("deferred" | optional(bool, channelReadyCodec)) ::
("lastSent" | either(bool, fundingCreatedCodec, fundingSignedCodec))).as[DATA_WAIT_FOR_FUNDING_CONFIRMED].decodeOnly
val DATA_WAIT_FOR_FUNDING_CONFIRMED_08_Codec: Codec[DATA_WAIT_FOR_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool, txCodec)) ::
("fundingTx_opt" | optional(bool, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("deferred" | optional(bool, channelReadyCodec)) ::
("lastSent" | either(bool, fundingCreatedCodec, fundingSignedCodec))).as[DATA_WAIT_FOR_FUNDING_CONFIRMED].decodeOnly
@ -425,7 +425,7 @@ private[channel] object ChannelCodecs0 {
// this is a decode-only codec compatible with versions 818199e and below, with placeholders for new fields
val DATA_CLOSING_06_Codec: Codec[DATA_CLOSING] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | provide[Option[Transaction]](None)) ::
("fundingTx_opt" | provide[Option[Transaction]](None)) ::
("waitingSince" | provide(BlockHeight(TimestampSecond.now().toLong))) ::
("mutualCloseProposed" | listOfN(uint16, closingTxCodec)) ::
("mutualClosePublished" | listOfN(uint16, closingTxCodec)) ::
@ -434,13 +434,13 @@ private[channel] object ChannelCodecs0 {
("nextRemoteCommitPublished" | optional(bool, remoteCommitPublishedCodec)) ::
("futureRemoteCommitPublished" | optional(bool, remoteCommitPublishedCodec)) ::
("revokedCommitPublished" | listOfN(uint16, revokedCommitPublishedCodec))).map {
case commitments :: fundingTx :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
case commitments :: fundingTx_opt :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
}.decodeOnly
val DATA_CLOSING_09_Codec: Codec[DATA_CLOSING] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool, txCodec)) ::
("fundingTx_opt" | optional(bool, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("mutualCloseProposed" | listOfN(uint16, closingTxCodec)) ::
("mutualClosePublished" | listOfN(uint16, closingTxCodec)) ::
@ -449,8 +449,8 @@ private[channel] object ChannelCodecs0 {
("nextRemoteCommitPublished" | optional(bool, remoteCommitPublishedCodec)) ::
("futureRemoteCommitPublished" | optional(bool, remoteCommitPublishedCodec)) ::
("revokedCommitPublished" | listOfN(uint16, revokedCommitPublishedCodec))).map {
case commitments :: fundingTx :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
case commitments :: fundingTx_opt :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
}.decodeOnly
val channelReestablishCodec: Codec[ChannelReestablish] = (

View file

@ -234,7 +234,7 @@ private[channel] object ChannelCodecs1 {
val DATA_WAIT_FOR_FUNDING_CONFIRMED_20_Codec: Codec[DATA_WAIT_FOR_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, txCodec)) ::
("fundingTx_opt" | optional(bool8, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("deferred" | optional(bool8, lengthDelimited(channelReadyCodec))) ::
("lastSent" | either(bool8, lengthDelimited(fundingCreatedCodec), lengthDelimited(fundingSignedCodec)))).as[DATA_WAIT_FOR_FUNDING_CONFIRMED]
@ -275,7 +275,7 @@ private[channel] object ChannelCodecs1 {
val DATA_CLOSING_25_Codec: Codec[DATA_CLOSING] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, txCodec)) ::
("fundingTx_opt" | optional(bool8, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("mutualCloseProposed" | listOfN(uint16, closingTxCodec)) ::
("mutualClosePublished" | listOfN(uint16, closingTxCodec)) ::
@ -284,8 +284,8 @@ private[channel] object ChannelCodecs1 {
("nextRemoteCommitPublished" | optional(bool8, remoteCommitPublishedCodec)) ::
("futureRemoteCommitPublished" | optional(bool8, remoteCommitPublishedCodec)) ::
("revokedCommitPublished" | listOfN(uint16, revokedCommitPublishedCodec))).map {
case commitments :: fundingTx :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
case commitments :: fundingTx_opt :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
}.decodeOnly
val DATA_WAIT_FOR_REMOTE_PUBLISH_FUTURE_COMMITMENT_26_Codec: Codec[DATA_WAIT_FOR_REMOTE_PUBLISH_FUTURE_COMMITMENT] = (

View file

@ -269,7 +269,7 @@ private[channel] object ChannelCodecs2 {
val DATA_WAIT_FOR_FUNDING_CONFIRMED_00_Codec: Codec[DATA_WAIT_FOR_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, txCodec)) ::
("fundingTx_opt" | optional(bool8, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("deferred" | optional(bool8, lengthDelimited(channelReadyCodec))) ::
("lastSent" | either(bool8, lengthDelimited(fundingCreatedCodec), lengthDelimited(fundingSignedCodec)))).as[DATA_WAIT_FOR_FUNDING_CONFIRMED]
@ -310,7 +310,7 @@ private[channel] object ChannelCodecs2 {
val DATA_CLOSING_05_Codec: Codec[DATA_CLOSING] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, txCodec)) ::
("fundingTx_opt" | optional(bool8, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("mutualCloseProposed" | listOfN(uint16, closingTxCodec)) ::
("mutualClosePublished" | listOfN(uint16, closingTxCodec)) ::
@ -319,8 +319,8 @@ private[channel] object ChannelCodecs2 {
("nextRemoteCommitPublished" | optional(bool8, remoteCommitPublishedCodec)) ::
("futureRemoteCommitPublished" | optional(bool8, remoteCommitPublishedCodec)) ::
("revokedCommitPublished" | listOfN(uint16, revokedCommitPublishedCodec))).map {
case commitments :: fundingTx :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
case commitments :: fundingTx_opt :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
}.decodeOnly
val DATA_WAIT_FOR_REMOTE_PUBLISH_FUTURE_COMMITMENT_06_Codec: Codec[DATA_WAIT_FOR_REMOTE_PUBLISH_FUTURE_COMMITMENT] = (

View file

@ -16,7 +16,7 @@
package fr.acinq.eclair.wire.internal.channel.version3
import fr.acinq.bitcoin.scalacompat.DeterministicWallet.{ExtendedPrivateKey, KeyPath}
import fr.acinq.bitcoin.scalacompat.DeterministicWallet.KeyPath
import fr.acinq.bitcoin.scalacompat.{OutPoint, Transaction, TxOut}
import fr.acinq.eclair.channel.InteractiveTxBuilder._
import fr.acinq.eclair.channel._
@ -38,16 +38,6 @@ private[channel] object ChannelCodecs3 {
val keyPathCodec: Codec[KeyPath] = ("path" | listOfN(uint16, uint32)).xmap[KeyPath](l => KeyPath(l), keyPath => keyPath.path.toList).as[KeyPath]
val extendedPrivateKeyCodec: Codec[ExtendedPrivateKey] = (
("secretkeybytes" | bytes32) ::
("chaincode" | bytes32) ::
("depth" | uint16) ::
("path" | keyPathCodec) ::
("parent" | int64)).xmap(
{ case a :: b :: c :: d :: e :: HNil => ExtendedPrivateKey(a, b, c, d, e) },
{ exp: ExtendedPrivateKey => exp.secretkeybytes :: exp.chaincode :: exp.depth :: exp.path :: exp.parent :: HNil }
)
val channelConfigCodec: Codec[ChannelConfig] = lengthDelimited(bytes).xmap(b => {
val activated: Set[ChannelConfigOption] = b.bits.toIndexedSeq.reverse.zipWithIndex.collect {
case (true, 0) => ChannelConfig.FundingPubKeyBasedChannelKeyPath
@ -284,59 +274,6 @@ private[channel] object ChannelCodecs3 {
("remotePerCommitmentSecrets" | byteAligned(ShaChain.shaChainCodec))
})).as[Commitments]
val closingFeeratesCodec: Codec[ClosingFeerates] = (
("preferred" | feeratePerKw) ::
("min" | feeratePerKw) ::
("max" | feeratePerKw)).as[ClosingFeerates]
val closingTxProposedCodec: Codec[ClosingTxProposed] = (
("unsignedTx" | closingTxCodec) ::
("localClosingSigned" | lengthDelimited(closingSignedCodec))).as[ClosingTxProposed]
val localCommitPublishedCodec: Codec[LocalCommitPublished] = (
("commitTx" | txCodec) ::
("claimMainDelayedOutputTx" | optional(bool8, claimLocalDelayedOutputTxCodec)) ::
("htlcTxs" | mapCodec(outPointCodec, optional(bool8, htlcTxCodec))) ::
("claimHtlcDelayedTx" | listOfN(uint16, htlcDelayedTxCodec)) ::
("claimAnchorTxs" | listOfN(uint16, claimAnchorOutputTxCodec)) ::
("spent" | spentMapCodec)).as[LocalCommitPublished]
val remoteCommitPublishedCodec: Codec[RemoteCommitPublished] = (
("commitTx" | txCodec) ::
("claimMainOutputTx" | optional(bool8, claimRemoteCommitMainOutputTxCodec)) ::
("claimHtlcTxs" | mapCodec(outPointCodec, optional(bool8, claimHtlcTxCodec))) ::
("claimAnchorTxs" | listOfN(uint16, claimAnchorOutputTxCodec)) ::
("spent" | spentMapCodec)).as[RemoteCommitPublished]
val revokedCommitPublishedCodec: Codec[RevokedCommitPublished] = (
("commitTx" | txCodec) ::
("claimMainOutputTx" | optional(bool8, claimRemoteCommitMainOutputTxCodec)) ::
("mainPenaltyTx" | optional(bool8, mainPenaltyTxCodec)) ::
("htlcPenaltyTxs" | listOfN(uint16, htlcPenaltyTxCodec)) ::
("claimHtlcDelayedPenaltyTxs" | listOfN(uint16, claimHtlcDelayedOutputPenaltyTxCodec)) ::
("spent" | spentMapCodec)).as[RevokedCommitPublished]
val DATA_WAIT_FOR_FUNDING_CONFIRMED_00_Codec: Codec[DATA_WAIT_FOR_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, txCodec)) ::
// TODO: next time we define a new channel codec version, we should use the blockHeight codec here (32 bytes)
("waitingSince" | int64.as[BlockHeight]) ::
("deferred" | optional(bool8, lengthDelimited(channelReadyCodec))) ::
("lastSent" | either(bool8, lengthDelimited(fundingCreatedCodec), lengthDelimited(fundingSignedCodec)))).as[DATA_WAIT_FOR_FUNDING_CONFIRMED]
val DATA_WAIT_FOR_CHANNEL_READY_01_Codec: Codec[DATA_WAIT_FOR_CHANNEL_READY] = (
("commitments" | commitmentsCodec) ::
("shortChannelId" | realshortchannelid) ::
("lastSent" | lengthDelimited(channelReadyCodec))).map {
case commitments :: shortChannelId :: lastSent :: HNil =>
DATA_WAIT_FOR_CHANNEL_READY(commitments, shortIds = ShortIds(real = RealScidStatus.Temporary(shortChannelId), localAlias = Alias(shortChannelId.toLong), remoteAlias_opt = None), lastSent = lastSent)
}.decodeOnly
val DATA_WAIT_FOR_CHANNEL_READY_0a_Codec: Codec[DATA_WAIT_FOR_CHANNEL_READY] = (
("commitments" | commitmentsCodec) ::
("shortIds" | shortids) ::
("lastSent" | lengthDelimited(channelReadyCodec))).as[DATA_WAIT_FOR_CHANNEL_READY]
private val remoteTxAddInputCodec: Codec[RemoteTxAddInput] = (
("serialId" | uint64) ::
("outPoint" | outPointCodec) ::
@ -383,6 +320,59 @@ private[channel] object ChannelCodecs3 {
("targetFeerate" | feeratePerKw) ::
("requireConfirmedInputs" | (("forLocal" | bool8) :: ("forRemote" | bool8)).as[RequireConfirmedInputs])).as[InteractiveTxParams]
val closingFeeratesCodec: Codec[ClosingFeerates] = (
("preferred" | feeratePerKw) ::
("min" | feeratePerKw) ::
("max" | feeratePerKw)).as[ClosingFeerates]
val closingTxProposedCodec: Codec[ClosingTxProposed] = (
("unsignedTx" | closingTxCodec) ::
("localClosingSigned" | lengthDelimited(closingSignedCodec))).as[ClosingTxProposed]
val localCommitPublishedCodec: Codec[LocalCommitPublished] = (
("commitTx" | txCodec) ::
("claimMainDelayedOutputTx" | optional(bool8, claimLocalDelayedOutputTxCodec)) ::
("htlcTxs" | mapCodec(outPointCodec, optional(bool8, htlcTxCodec))) ::
("claimHtlcDelayedTx" | listOfN(uint16, htlcDelayedTxCodec)) ::
("claimAnchorTxs" | listOfN(uint16, claimAnchorOutputTxCodec)) ::
("spent" | spentMapCodec)).as[LocalCommitPublished]
val remoteCommitPublishedCodec: Codec[RemoteCommitPublished] = (
("commitTx" | txCodec) ::
("claimMainOutputTx" | optional(bool8, claimRemoteCommitMainOutputTxCodec)) ::
("claimHtlcTxs" | mapCodec(outPointCodec, optional(bool8, claimHtlcTxCodec))) ::
("claimAnchorTxs" | listOfN(uint16, claimAnchorOutputTxCodec)) ::
("spent" | spentMapCodec)).as[RemoteCommitPublished]
val revokedCommitPublishedCodec: Codec[RevokedCommitPublished] = (
("commitTx" | txCodec) ::
("claimMainOutputTx" | optional(bool8, claimRemoteCommitMainOutputTxCodec)) ::
("mainPenaltyTx" | optional(bool8, mainPenaltyTxCodec)) ::
("htlcPenaltyTxs" | listOfN(uint16, htlcPenaltyTxCodec)) ::
("claimHtlcDelayedPenaltyTxs" | listOfN(uint16, claimHtlcDelayedOutputPenaltyTxCodec)) ::
("spent" | spentMapCodec)).as[RevokedCommitPublished]
val DATA_WAIT_FOR_FUNDING_CONFIRMED_00_Codec: Codec[DATA_WAIT_FOR_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx_opt" | optional(bool8, txCodec)) ::
// TODO: next time we define a new channel codec version, we should use the blockHeight codec here (32 bytes)
("waitingSince" | int64.as[BlockHeight]) ::
("deferred" | optional(bool8, lengthDelimited(channelReadyCodec))) ::
("lastSent" | either(bool8, lengthDelimited(fundingCreatedCodec), lengthDelimited(fundingSignedCodec)))).as[DATA_WAIT_FOR_FUNDING_CONFIRMED]
val DATA_WAIT_FOR_CHANNEL_READY_01_Codec: Codec[DATA_WAIT_FOR_CHANNEL_READY] = (
("commitments" | commitmentsCodec) ::
("shortChannelId" | realshortchannelid) ::
("lastSent" | lengthDelimited(channelReadyCodec))).map {
case commitments :: shortChannelId :: lastSent :: HNil =>
DATA_WAIT_FOR_CHANNEL_READY(commitments, shortIds = ShortIds(real = RealScidStatus.Temporary(shortChannelId), localAlias = Alias(shortChannelId.toLong), remoteAlias_opt = None), lastSent = lastSent)
}.decodeOnly
val DATA_WAIT_FOR_CHANNEL_READY_0a_Codec: Codec[DATA_WAIT_FOR_CHANNEL_READY] = (
("commitments" | commitmentsCodec) ::
("shortIds" | shortids) ::
("lastSent" | lengthDelimited(channelReadyCodec))).as[DATA_WAIT_FOR_CHANNEL_READY]
val DATA_WAIT_FOR_DUAL_FUNDING_CONFIRMED_0b_Codec: Codec[DATA_WAIT_FOR_DUAL_FUNDING_CONFIRMED] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | signedSharedTransactionCodec) ::
@ -456,7 +446,7 @@ private[channel] object ChannelCodecs3 {
val DATA_CLOSING_05_Codec: Codec[DATA_CLOSING] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, txCodec)) ::
("fundingTx_opt" | optional(bool8, txCodec)) ::
("waitingSince" | int64.as[BlockHeight]) ::
("mutualCloseProposed" | listOfN(uint16, closingTxCodec)) ::
("mutualClosePublished" | listOfN(uint16, closingTxCodec)) ::
@ -465,8 +455,8 @@ private[channel] object ChannelCodecs3 {
("nextRemoteCommitPublished" | optional(bool8, remoteCommitPublishedCodec)) ::
("futureRemoteCommitPublished" | optional(bool8, remoteCommitPublishedCodec)) ::
("revokedCommitPublished" | listOfN(uint16, revokedCommitPublishedCodec))).map {
case commitments :: fundingTx :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
case commitments :: fundingTx_opt :: waitingSince :: mutualCloseProposed :: mutualClosePublished :: localCommitPublished :: remoteCommitPublished :: nextRemoteCommitPublished :: futureRemoteCommitPublished :: revokedCommitPublished :: HNil =>
DATA_CLOSING(commitments, fundingTx_opt.map(tx => SingleFundedUnconfirmedFundingTx(tx)), waitingSince, Nil, mutualCloseProposed, mutualClosePublished, localCommitPublished, remoteCommitPublished, nextRemoteCommitPublished, futureRemoteCommitPublished, revokedCommitPublished)
}.decodeOnly
val unconfirmedFundingTxCodec: Codec[UnconfirmedFundingTx] = discriminated[UnconfirmedFundingTx].by(uint8)
@ -475,7 +465,7 @@ private[channel] object ChannelCodecs3 {
val DATA_CLOSING_0d_Codec: Codec[DATA_CLOSING] = (
("commitments" | commitmentsCodec) ::
("fundingTx" | optional(bool8, unconfirmedFundingTxCodec)) ::
("fundingTx_opt" | optional(bool8, unconfirmedFundingTxCodec)) ::
("waitingSince" | blockHeight) ::
("alternativeCommitments" | listOfN(uint16, dualFundingTxCodec)) ::
("mutualCloseProposed" | listOfN(uint16, closingTxCodec)) ::

View file

@ -105,7 +105,7 @@
},
"remotePerCommitmentSecrets" : null
},
"fundingTx" : {
"fundingTx_opt" : {
"txid" : "f4e3ba374da1a85abcd12a86c9a25b1391bda144619c770fe03f3881c6ad17e9",
"tx" : "020000000101010101010101010101010101010101010101010101010101010101010101012a00000000ffffffff0140420f0000000000220020a5fb8f636bb73759b4c7e5edd55fd8e9e8e5467c7079709cd22fb519c79ab8b300000000"
},

View file

@ -90,7 +90,7 @@ class FuzzySpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with Channe
bob2blockchain.expectMsgType[WatchFundingSpent]
bob2blockchain.expectMsgType[WatchFundingConfirmed]
awaitCond(alice.stateName == WAIT_FOR_FUNDING_CONFIRMED)
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! WatchFundingConfirmedTriggered(BlockHeight(400000), 42, fundingTx)
bob ! WatchFundingConfirmedTriggered(BlockHeight(400000), 42, fundingTx)
alice2blockchain.expectMsgType[WatchFundingLost]

View file

@ -76,7 +76,7 @@ class WaitForChannelReadyStateSpec extends TestKitBaseClass with FixtureAnyFunSu
bob2blockchain.expectMsgType[WatchFundingConfirmed]
awaitCond(alice.stateName == WAIT_FOR_FUNDING_CONFIRMED)
awaitCond(bob.stateName == WAIT_FOR_FUNDING_CONFIRMED)
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! WatchFundingConfirmedTriggered(BlockHeight(400000), 42, fundingTx)
bob ! WatchFundingConfirmedTriggered(BlockHeight(400000), 42, fundingTx)
}

View file

@ -82,7 +82,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
test("recv ChannelReady (funder, with remote alias)") { f =>
import f._
// make bob send a ChannelReady msg
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
bob ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, fundingTx)
val bobChannelReady = bob2alice.expectMsgType[ChannelReady]
assert(bobChannelReady.alias_opt.isDefined)
@ -99,7 +99,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
test("recv ChannelReady (funder, no remote alias)") { f =>
import f._
// make bob send a ChannelReady msg
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
bob ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, fundingTx)
val channelReadyNoAlias = bob2alice.expectMsgType[ChannelReady].copy(tlvStream = TlvStream.empty)
// test starts here
@ -114,7 +114,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
test("recv ChannelReady (fundee)") { f =>
import f._
// make alice send a ChannelReady msg
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, fundingTx)
val channelReady = alice2bob.expectMsgType[ChannelReady]
// test starts here
@ -133,7 +133,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
val listener = TestProbe()
alice.underlying.system.eventStream.subscribe(listener.ref, classOf[TransactionPublished])
alice.underlying.system.eventStream.subscribe(listener.ref, classOf[TransactionConfirmed])
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, fundingTx)
assert(listener.expectMsgType[TransactionConfirmed].tx == fundingTx)
awaitCond(alice.stateName == WAIT_FOR_CHANNEL_READY)
@ -150,7 +150,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
bob.underlying.system.eventStream.subscribe(listener.ref, classOf[TransactionPublished])
bob.underlying.system.eventStream.subscribe(listener.ref, classOf[TransactionConfirmed])
// make bob send a ChannelReady msg
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
bob ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, fundingTx)
val txPublished = listener.expectMsgType[TransactionPublished]
assert(txPublished.tx == fundingTx)
@ -165,7 +165,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
test("recv WatchFundingConfirmedTriggered (bad funding pubkey script)") { f =>
import f._
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
val badOutputScript = fundingTx.txOut.head.copy(publicKeyScript = Script.write(multiSig2of2(randomKey().publicKey, randomKey().publicKey)))
val badFundingTx = fundingTx.copy(txOut = Seq(badOutputScript))
alice ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, badFundingTx)
@ -174,7 +174,7 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
test("recv WatchFundingConfirmedTriggered (bad funding amount)") { f =>
import f._
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
val badOutputAmount = fundingTx.txOut.head.copy(amount = 1234567.sat)
val badFundingTx = fundingTx.copy(txOut = Seq(badOutputAmount))
alice ! WatchFundingConfirmedTriggered(BlockHeight(42000), 42, badFundingTx)

View file

@ -156,7 +156,7 @@ class ClosingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
test("recv GetTxResponse (funder, tx found)", Tag("funding_unconfirmed")) { f =>
import f._
val sender = TestProbe()
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! CMD_FORCECLOSE(sender.ref)
awaitCond(alice.stateName == CLOSING)
alice2bob.expectMsgType[Error]
@ -175,7 +175,7 @@ class ClosingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
test("recv GetTxResponse (funder, tx not found)", Tag("funding_unconfirmed")) { f =>
import f._
val sender = TestProbe()
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! CMD_FORCECLOSE(sender.ref)
awaitCond(alice.stateName == CLOSING)
alice2bob.expectMsgType[Error]
@ -194,7 +194,7 @@ class ClosingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
test("recv GetTxResponse (fundee, tx found)", Tag("funding_unconfirmed")) { f =>
import f._
val sender = TestProbe()
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
bob ! CMD_FORCECLOSE(sender.ref)
awaitCond(bob.stateName == CLOSING)
bob2alice.expectMsgType[Error]
@ -213,7 +213,7 @@ class ClosingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
test("recv GetTxResponse (fundee, tx not found)", Tag("funding_unconfirmed")) { f =>
import f._
val sender = TestProbe()
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
bob ! CMD_FORCECLOSE(sender.ref)
awaitCond(bob.stateName == CLOSING)
bob2alice.expectMsgType[Error]
@ -232,7 +232,7 @@ class ClosingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
test("recv GetTxResponse (fundee, tx not found, timeout)", Tag("funding_unconfirmed")) { f =>
import f._
val sender = TestProbe()
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
bob ! CMD_FORCECLOSE(sender.ref)
awaitCond(bob.stateName == CLOSING)
bob2alice.expectMsgType[Error]

View file

@ -177,7 +177,7 @@ object MinimalNodeFixture extends Assertions with Eventually with IntegrationPat
def confirmChannel(node1: MinimalNodeFixture, node2: MinimalNodeFixture, channelId: ByteVector32, blockHeight: BlockHeight, txIndex: Int)(implicit system: ActorSystem): Option[RealScidStatus.Temporary] = {
assert(getChannelState(node1, channelId) == WAIT_FOR_FUNDING_CONFIRMED)
val data1Before = getChannelData(node1, channelId).asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED]
val fundingTx = data1Before.fundingTx.get
val fundingTx = data1Before.fundingTx_opt.get
val watch1 = node1.watcher.fishForMessage() { case w: WatchFundingConfirmed if w.txId == fundingTx.txid => true; case _ => false }.asInstanceOf[WatchFundingConfirmed]
val watch2 = node2.watcher.fishForMessage() { case w: WatchFundingConfirmed if w.txId == fundingTx.txid => true; case _ => false }.asInstanceOf[WatchFundingConfirmed]

View file

@ -88,7 +88,7 @@ class RustyTestsSpec extends TestKitBaseClass with Matchers with FixtureAnyFunSu
bob2blockchain.expectMsgType[WatchFundingSpent]
bob2blockchain.expectMsgType[WatchFundingConfirmed]
awaitCond(alice.stateName == WAIT_FOR_FUNDING_CONFIRMED)
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.get
val fundingTx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.get
alice ! WatchFundingConfirmedTriggered(BlockHeight(400000), 42, fundingTx)
bob ! WatchFundingConfirmedTriggered(BlockHeight(400000), 42, fundingTx)
alice2blockchain.expectMsgType[WatchFundingLost]

View file

@ -88,7 +88,7 @@ class ChannelCodecsSpec extends AnyFunSuite {
assert(bin_old.startsWith(hex"000001"))
// let's decode the old data (this will use the old codec that provides default values for new fields)
val data_new = channelDataCodec.decode(bin_old.toBitVector).require.value
assert(data_new.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx.isEmpty)
assert(data_new.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].fundingTx_opt.isEmpty)
assert(TimestampSecond.now().toLong - data_new.asInstanceOf[DATA_WAIT_FOR_FUNDING_CONFIRMED].waitingSince.toLong < 3600) // we just set this to current time
// and re-encode it with the new codec
val bin_new = ByteVector(channelDataCodec.encode(data_new).require.toByteVector.toArray)