From 922072fceafc571eb80add936b40fe852c3d915f Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 18 Jun 2019 10:26:12 +0200 Subject: [PATCH] Remove unnecessary println, merge master, improve handling of rollback while wait_for_funding_signed_internal --- .../blockchain/electrum/ElectrumClient.scala | 10 +++++----- .../scala/fr/acinq/eclair/channel/Channel.scala | 10 +++++++--- .../blockchain/electrum/ElectrumClientSpec.scala | 8 ++------ .../b/WaitForFundingSignedInternalStateSpec.scala | 14 ++++++++------ .../acinq/eclair/crypto/LocalKeyManagerSpec.scala | 1 - 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClient.scala b/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClient.scala index e1e1869c93..271d8039df 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClient.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClient.scala @@ -381,7 +381,7 @@ object ElectrumClient { case class BroadcastTransactionResponse(tx: Transaction, error: Option[Error]) extends Response case class GetTransactionIdFromPosition(height: Int, tx_pos: Int, merkle: Boolean = false) extends Request - case class GetTransactionIdFromPositionResponse(txid: ByteVector32, merkle: Seq[ByteVector32]) extends Response + case class GetTransactionIdFromPositionResponse(txid: ByteVector32, height: Int, tx_pos: Int, merkle: Seq[ByteVector32]) extends Response case class GetTransaction(txid: ByteVector32) extends Request case class GetTransactionResponse(tx: Transaction) extends Response @@ -593,14 +593,14 @@ object ElectrumClient { UnspentItem(ByteVector32.fromValidHex(tx_hash), tx_pos, value, height) }) ScriptHashListUnspentResponse(scripthash, items) - case GetTransactionIdFromPosition(_, _, false) => + case GetTransactionIdFromPosition(height, tx_pos, false) => val JString(tx_hash) = json.result - GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), Nil) - case GetTransactionIdFromPosition(_, _, true) => + GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), height, tx_pos, Nil) + case GetTransactionIdFromPosition(height, tx_pos, true) => val JString(tx_hash) = json.result \ "tx_hash" val JArray(hashes) = json.result \ "merkle" val leaves = hashes collect { case JString(value) => ByteVector32.fromValidHex(value) } - GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), leaves) + GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), height, tx_pos, leaves) case GetTransaction(_) => val JString(hex) = json.result GetTransactionResponse(Transaction.read(hex)) diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala b/eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala index d2da5fd66f..980f6ef7c1 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala @@ -501,20 +501,24 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId replyToUser(Left(LocalError(t))) handleLocalError(ChannelFundingError(d.temporaryChannelId), d, None) // we use a generic exception and don't send the internal error to the peer - case Event(CMD_CLOSE(_), _) => + case Event(CMD_CLOSE(_) | CMD_FORCECLOSE, d: DATA_WAIT_FOR_FUNDING_INTERNAL_SIGNED) => replyToUser(Right("closed")) + wallet.rollback(d.unsignedFundingTx) goto(CLOSED) replying "ok" case Event(e: Error, d: DATA_WAIT_FOR_FUNDING_INTERNAL_SIGNED) => replyToUser(Left(RemoteError(e))) + wallet.rollback(d.unsignedFundingTx) handleRemoteError(e, d) - case Event(INPUT_DISCONNECTED, _) => + case Event(INPUT_DISCONNECTED, d: DATA_WAIT_FOR_FUNDING_INTERNAL_SIGNED) => replyToUser(Left(LocalError(new RuntimeException("disconnected")))) + wallet.rollback(d.unsignedFundingTx) goto(CLOSED) - case Event(TickChannelOpenTimeout, _) => + case Event(TickChannelOpenTimeout, d: DATA_WAIT_FOR_FUNDING_INTERNAL_SIGNED) => replyToUser(Left(LocalError(new RuntimeException("open channel cancelled, took too long")))) + wallet.rollback(d.unsignedFundingTx) goto(CLOSED) }) diff --git a/eclair-core/src/test/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClientSpec.scala b/eclair-core/src/test/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClientSpec.scala index fb936f955a..ebe8e90906 100644 --- a/eclair-core/src/test/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClientSpec.scala +++ b/eclair-core/src/test/scala/fr/acinq/eclair/blockchain/electrum/ElectrumClientSpec.scala @@ -69,16 +69,12 @@ class ElectrumClientSpec extends TestKit(ActorSystem("test")) with FunSuiteLike test("get transaction id from position") { probe.send(client, GetTransactionIdFromPosition(height, position)) - val GetTransactionIdFromPositionResponse(txid, merkle) = probe.expectMsgType[GetTransactionIdFromPositionResponse] - assert(txid === referenceTx.txid) - assert(merkle === Nil) + probe.expectMsg(GetTransactionIdFromPositionResponse(referenceTx.txid, height, position, Nil)) } test("get transaction id from position with merkle proof") { probe.send(client, GetTransactionIdFromPosition(height, position, merkle = true)) - val GetTransactionIdFromPositionResponse(txid, merkle) = probe.expectMsgType[GetTransactionIdFromPositionResponse] - assert(txid === referenceTx.txid) - assert(merkle === merkleProof) + probe.expectMsg(GetTransactionIdFromPositionResponse(referenceTx.txid, height, position, merkleProof)) } test("get transaction") { diff --git a/eclair-core/src/test/scala/fr/acinq/eclair/channel/states/b/WaitForFundingSignedInternalStateSpec.scala b/eclair-core/src/test/scala/fr/acinq/eclair/channel/states/b/WaitForFundingSignedInternalStateSpec.scala index 2ab06d51f5..d1081fc74c 100644 --- a/eclair-core/src/test/scala/fr/acinq/eclair/channel/states/b/WaitForFundingSignedInternalStateSpec.scala +++ b/eclair-core/src/test/scala/fr/acinq/eclair/channel/states/b/WaitForFundingSignedInternalStateSpec.scala @@ -62,10 +62,11 @@ class WaitForFundingSignedInternalStateSpec extends TestkitBaseClass with StateT alice ! Error(ByteVector32.Zeroes, "oops") + awaitCond({ + val rolledBackTx = alice.underlyingActor.wallet.asInstanceOf[TestWallet].rolledback.head + rolledBackTx.txOut == fundingTx.txOut && rolledBackTx.txIn.map(_.outPoint) == fundingTx.txIn.map(_.outPoint) + }) awaitCond(alice.stateName == CLOSED) - val rolledBackTx = alice.underlyingActor.wallet.asInstanceOf[TestWallet].rolledback.head - assert(rolledBackTx.txOut == fundingTx.txOut) - assert(rolledBackTx.txIn.map(_.outPoint) == fundingTx.txIn.map(_.outPoint)) } test("recv CMD_CLOSE") { f => @@ -75,9 +76,10 @@ class WaitForFundingSignedInternalStateSpec extends TestkitBaseClass with StateT alice ! CMD_CLOSE(None) - val rolledBackTx = alice.underlyingActor.wallet.asInstanceOf[TestWallet].rolledback.head - assert(rolledBackTx.txOut == fundingTx.txOut) - assert(rolledBackTx.txIn.map(_.outPoint) == fundingTx.txIn.map(_.outPoint)) + awaitCond({ + val rolledBackTx = alice.underlyingActor.wallet.asInstanceOf[TestWallet].rolledback.head + rolledBackTx.txOut == fundingTx.txOut && rolledBackTx.txIn.map(_.outPoint) == fundingTx.txIn.map(_.outPoint) + }) awaitCond(alice.stateName == CLOSED) } diff --git a/eclair-core/src/test/scala/fr/acinq/eclair/crypto/LocalKeyManagerSpec.scala b/eclair-core/src/test/scala/fr/acinq/eclair/crypto/LocalKeyManagerSpec.scala index 710f68bf91..4336cc530e 100644 --- a/eclair-core/src/test/scala/fr/acinq/eclair/crypto/LocalKeyManagerSpec.scala +++ b/eclair-core/src/test/scala/fr/acinq/eclair/crypto/LocalKeyManagerSpec.scala @@ -116,7 +116,6 @@ class LocalKeyManagerSpec extends FunSuite { val funderChannelKeyPath = LocalKeyManager.makeChannelKeyPathFunder(inputOutpoint) // MAINNET funder funding public key from extended private key - println(s"keyManager.fundingPublicKey(funderChannelKeyPath) = ${keyManager.fundingPublicKey(funderChannelKeyPath).path}") assert(keyManager.fundingPublicKey(funderChannelKeyPath).publicKey.value === hex"0353b7dfdb0cbae349146795bd6406ff6ac5cd93bfb31bbdfc5df01b0d4da171b4") // MAINNET funder payment point from extended private key assert(keyManager.paymentPoint(funderChannelKeyPath).publicKey.value === hex"0254036505ad9aa8d8e03ed3727825eaa72ce49f5ff9f2fd286e6d20a2b88caa12")