Skip to content

Commit

Permalink
Remove unnecessary println, merge master, improve handling of rollbac…
Browse files Browse the repository at this point in the history
…k while wait_for_funding_signed_internal
  • Loading branch information
araspitzu committed Jun 18, 2019
1 parent 602e73b commit 922072f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 7 additions & 3 deletions eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 922072f

Please sign in to comment.