1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 10:39:19 +01:00

removed Publish, now we always use PublishAsap

This commit is contained in:
pm47 2017-01-20 14:09:34 +01:00
parent 8a29a7cd02
commit 373df9cdd0
12 changed files with 82 additions and 72 deletions

View File

@ -54,7 +54,7 @@ class PeerWatcher(client: ExtendedBitcoinClient, blockCount: Long)(implicit ec:
case CurrentBlockCount(count) => {
val toPublish = block2tx.filterKeys(_ <= count)
toPublish.values.flatten.map(tx => self ! Publish(tx))
toPublish.values.flatten.map(publish)
context.become(watching(watches, block2tx -- toPublish.keys, count))
}
@ -65,19 +65,13 @@ class PeerWatcher(client: ExtendedBitcoinClient, blockCount: Long)(implicit ec:
context.watch(w.channel)
context.become(watching(watches + w, block2tx, currentBlockCount))
case Publish(tx) =>
log.info(s"publishing tx $tx")
client.publishTransaction(tx).onFailure {
case t: Throwable => log.error(t, s"cannot publish tx ${BinaryData(Transaction.write(tx))}")
}
case PublishAsap(tx) =>
val cltvTimeout = Scripts.cltvTimeout(tx)
val csvTimeout = currentBlockCount + Scripts.csvTimeout(tx)
// absolute timeout in blocks
val timeout = Math.max(cltvTimeout, csvTimeout)
if (timeout <= currentBlockCount) {
self ! Publish(tx)
publish(tx)
} else {
log.info(s"delaying publication of tx $tx until block=$timeout (curblock=$currentBlockCount)")
val block2tx1 = block2tx.updated(timeout, tx +: block2tx.getOrElse(timeout, Seq.empty[Transaction]))
@ -93,6 +87,10 @@ class PeerWatcher(client: ExtendedBitcoinClient, blockCount: Long)(implicit ec:
context.become(watching(watches -- deprecatedWatches, block2tx, currentBlockCount))
}
def publish(tx: Transaction) = client.publishTransaction(tx).onFailure {
case t: Throwable => log.error(t, s"cannot publish tx ${BinaryData(Transaction.write(tx))}")
}
}
object PeerWatcher {

View File

@ -18,7 +18,9 @@ final case class WatchSpent(channel: ActorRef, txId: BinaryData, outputIndex: In
// notify me if confirmation number gets below minDepth
final case class WatchLost(channel: ActorRef, txId: BinaryData, minDepth: Long, event: BitcoinEvent) extends Watch
final case class Publish(tx: Transaction)
/**
* Publish the provided tx as soon as possible depending on locktime and csv
*/
final case class PublishAsap(tx: Transaction)
final case class MakeFundingTx(ourCommitPub: BinaryData, theirCommitPub: BinaryData, amount: Satoshi)

View File

@ -256,7 +256,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
val commitInput = localCommitTx.input
blockchain ! WatchSpent(self, commitInput.outPoint.txid, commitInput.outPoint.index.toInt, minDepth = 0, BITCOIN_FUNDING_SPENT) // TODO: should we wait for an acknowledgment from the watcher?
blockchain ! WatchConfirmed(self, commitInput.outPoint.txid, params.minimumDepth, BITCOIN_FUNDING_DEPTHOK)
blockchain ! Publish(fundingTx)
blockchain ! PublishAsap(fundingTx)
val commitments = Commitments(params.localParams, params.remoteParams,
LocalCommit(0, localSpec, PublishableTxs(signedLocalCommitTx, Nil)), remoteCommit,
LocalChanges(Nil, Nil, Nil), RemoteChanges(Nil, Nil),
@ -299,7 +299,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
case Event((BITCOIN_FUNDING_SPENT, _), d: DATA_WAIT_FOR_FUNDING_LOCKED_INTERNAL) => handleInformationLeak(d)
case Event(cmd: CMD_CLOSE, d: DATA_WAIT_FOR_FUNDING_LOCKED_INTERNAL) =>
blockchain ! Publish(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! PublishAsap(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! WatchConfirmed(self, d.commitments.localCommit.publishableTxs.commitTx.tx.txid, d.params.minimumDepth, BITCOIN_CLOSE_DONE)
// there can't be htlcs at this stage
val localCommitPublished = LocalCommitPublished(d.commitments.localCommit.publishableTxs.commitTx.tx, None, Nil, Nil, Nil)
@ -307,7 +307,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
case Event(e: Error, d: DATA_WAIT_FOR_FUNDING_LOCKED_INTERNAL) =>
log.error(s"peer sent $e, closing connection") // see bolt #2: A node MUST fail the connection if it receives an err message
blockchain ! Publish(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! PublishAsap(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! WatchConfirmed(self, d.commitments.localCommit.publishableTxs.commitTx.tx.txid, d.params.minimumDepth, BITCOIN_CLOSE_DONE)
// there can't be htlcs at this stage
// TODO: LocalCommitPublished.claimDelayedOutputTx should be defined
@ -326,7 +326,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
case Event((BITCOIN_FUNDING_SPENT, _), d: DATA_NORMAL) => handleInformationLeak(d)
case Event(cmd: CMD_CLOSE, d: DATA_NORMAL) =>
blockchain ! Publish(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! PublishAsap(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! WatchConfirmed(self, d.commitments.localCommit.publishableTxs.commitTx.tx.txid, d.params.minimumDepth, BITCOIN_CLOSE_DONE)
// there can't be htlcs at this stage
// TODO: LocalCommitPublished.claimDelayedOutputTx should be defined
@ -784,7 +784,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
def publishMutualClosing(mutualClosing: Transaction) = {
log.info(s"closingTxId=${mutualClosing.txid}")
blockchain ! Publish(mutualClosing)
blockchain ! PublishAsap(mutualClosing)
// TODO: hardcoded mindepth
blockchain ! WatchConfirmed(self, mutualClosing.txid, 3, BITCOIN_CLOSE_DONE)
}
@ -792,7 +792,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
def spendLocalCurrent(d: HasCommitments) = {
val tx = d.commitments.localCommit.publishableTxs.commitTx.tx
blockchain ! Publish(tx)
blockchain ! PublishAsap(tx)
// TODO hardcoded mindepth + shouldn't we watch the claim tx instead?
blockchain ! WatchConfirmed(self, tx.txid, 3, BITCOIN_SPEND_OURS_DONE)
@ -841,11 +841,11 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
// TODO hardcoded mindepth + shouldn't we watch the claim tx instead?
blockchain ! WatchConfirmed(self, tx.txid, 3, BITCOIN_PUNISHMENT_DONE)
revokedCommitPublished.claimMainOutputTx.foreach(tx => blockchain ! Publish(tx))
revokedCommitPublished.mainPunishmentTx.foreach(tx => blockchain ! Publish(tx))
revokedCommitPublished.claimHtlcTimeoutTxs.foreach(tx => blockchain ! Publish(tx))
revokedCommitPublished.htlcTimeoutTxs.foreach(tx => blockchain ! Publish(tx))
revokedCommitPublished.htlcPunishmentTxs.foreach(tx => blockchain ! Publish(tx))
revokedCommitPublished.claimMainOutputTx.foreach(tx => blockchain ! PublishAsap(tx))
revokedCommitPublished.mainPunishmentTx.foreach(tx => blockchain ! PublishAsap(tx))
revokedCommitPublished.claimHtlcTimeoutTxs.foreach(tx => blockchain ! PublishAsap(tx))
revokedCommitPublished.htlcTimeoutTxs.foreach(tx => blockchain ! PublishAsap(tx))
revokedCommitPublished.htlcPunishmentTxs.foreach(tx => blockchain ! PublishAsap(tx))
val nextData = d match {
case closing: DATA_CLOSING => closing.copy(revokedCommitPublished = closing.revokedCommitPublished :+ revokedCommitPublished)
@ -865,7 +865,7 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, paymentHandler: Acto
// TODO! channel id
them ! Error(0, "Anchor has been spent".getBytes)
// TODO: not enough
blockchain ! Publish(d.commitments.localCommit.publishableTxs.commitTx.tx)
blockchain ! PublishAsap(d.commitments.localCommit.publishableTxs.commitTx.tx)
goto(ERR_INFORMATION_LEAK)
}

View File

@ -172,13 +172,23 @@ object Scripts {
} map (_._2)
/**
*
* @param tx
* @return the block height before which this tx cannot be published
* This function interprets the locktime for the given transaction, and returns the block height before which this tx cannot be published.
* By convention in bitcoin, depending of the value of locktime it might be a number of blocks or a number of seconds since epoch.
* This function does not support the case when the locktime is a number of seconds that is not way in the past.
* NB: We use this property in lightning to store data in this field.
* @return the block height before which this tx cannot be published.
*/
def cltvTimeout(tx: Transaction): Long = {
require(tx.lockTime <= LockTimeThreshold)
tx.lockTime
if (tx.lockTime <= LockTimeThreshold) {
// locktime is a number of blocks
tx.lockTime
}
else {
// locktime is a unix epoch timestamp
require(tx.lockTime <= 0x20FFFFFF, "locktime should be lesser than 0x20FFFFFF")
// since locktime is very well in the past (0x20FFFFFF is in 1987), it is equivalent to no locktime at all
0
}
}
/**

View File

@ -37,7 +37,7 @@ trait StateTestsHelperMethods extends TestKitBase {
alice2blockchain.expectMsgType[WatchSpent]
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.forward(blockchainA)
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
alice2blockchain.forward(blockchainA)
bob2blockchain.expectMsgType[WatchSpent]
bob2blockchain.expectMsgType[WatchConfirmed]

View File

@ -54,7 +54,7 @@ class WaitForFundingSignedStateSpec extends StateSpecBaseClass {
awaitCond(alice.stateName == WAIT_FOR_FUNDING_LOCKED_INTERNAL)
alice2blockchain.expectMsgType[WatchSpent]
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
}
}

View File

@ -45,7 +45,7 @@ class WaitForFundingLockedInternalStateSpec extends StateSpecBaseClass {
bob2alice.forward(alice)
alice2blockchain.expectMsgType[WatchSpent]
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
awaitCond(alice.stateName == WAIT_FOR_FUNDING_LOCKED_INTERNAL)
}
test((alice, bob, alice2bob, bob2alice, alice2blockchain, blockchainA))
@ -94,7 +94,7 @@ class WaitForFundingLockedInternalStateSpec extends StateSpecBaseClass {
val tx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_LOCKED_INTERNAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! (BITCOIN_FUNDING_SPENT, null)
alice2bob.expectMsgType[Error]
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
awaitCond(alice.stateName == ERR_INFORMATION_LEAK)
}
}
@ -104,7 +104,7 @@ class WaitForFundingLockedInternalStateSpec extends StateSpecBaseClass {
val tx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_LOCKED_INTERNAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes)
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -114,7 +114,7 @@ class WaitForFundingLockedInternalStateSpec extends StateSpecBaseClass {
val tx = alice.stateData.asInstanceOf[DATA_WAIT_FOR_FUNDING_LOCKED_INTERNAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! CMD_CLOSE(None)
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}

View File

@ -46,7 +46,7 @@ class WaitForFundingLockedStateSpec extends StateSpecBaseClass {
alice2blockchain.expectMsgType[WatchSpent]
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.forward(blockchainA)
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
alice2blockchain.forward(blockchainA)
bob2blockchain.expectMsgType[WatchSpent]
bob2blockchain.expectMsgType[WatchConfirmed]
@ -83,7 +83,7 @@ class WaitForFundingLockedStateSpec extends StateSpecBaseClass {
val tx = alice.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! (BITCOIN_FUNDING_SPENT, null)
alice2bob.expectMsgType[Error]
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
awaitCond(alice.stateName == ERR_INFORMATION_LEAK)
}
}
@ -93,7 +93,7 @@ class WaitForFundingLockedStateSpec extends StateSpecBaseClass {
val tx = alice.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes)
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -103,7 +103,7 @@ class WaitForFundingLockedStateSpec extends StateSpecBaseClass {
val tx = alice.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! CMD_CLOSE(None)
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}

View File

@ -117,7 +117,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
alice2bob.forward(bob, htlc)
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -130,7 +130,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
alice2bob.forward(bob, UpdateAddHtlc(0, 44, 500000000, 144, "33" * 32, ""))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -143,7 +143,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
alice2bob.forward(bob, UpdateAddHtlc(0, 44, 500000000, 144, "33" * 32, ""))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -303,7 +303,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(bob, CommitSig(0, "00" * 64, Nil))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -318,7 +318,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(bob, CommitSig(0, "00" * 64, Nil))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -423,7 +423,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(alice, RevokeAndAck(0, "11" * 32, "22" * 32, Nil))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -436,7 +436,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(alice, RevokeAndAck(0, "11" * 32, "22" * 32, Nil))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -527,7 +527,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(alice, UpdateFulfillHtlc(0, 42, "00" * 32))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -543,7 +543,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(alice, UpdateFulfillHtlc(0, 42, "00" * 32))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -621,7 +621,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
sender.send(alice, UpdateFailHtlc(0, 42, "some reason".getBytes()))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -720,7 +720,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
// actual test begins
sender.send(bob, Shutdown(0, Script.write(TestConstants.Alice.channelParams.defaultFinalScriptPubKey)))
bob2alice.expectMsgType[Error]
bob2blockchain.expectMsgType[Publish]
bob2blockchain.expectMsgType[PublishAsap]
bob2blockchain.expectMsgType[WatchConfirmed]
awaitCond(bob.stateName == CLOSING)
}
@ -839,8 +839,8 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
alice2bob.expectMsgType[Error]
alice2blockchain.expectMsgType[WatchConfirmed]
val mainTx = alice2blockchain.expectMsgType[Publish].tx
val punishTx = alice2blockchain.expectMsgType[Publish].tx
val mainTx = alice2blockchain.expectMsgType[PublishAsap].tx
val punishTx = alice2blockchain.expectMsgType[PublishAsap].tx
alice2blockchain.expectNoMsg(1 second)
Transaction.correctlySpends(mainTx, Seq(revokedTx), ScriptFlags.STANDARD_SCRIPT_VERIFY_FLAGS)
@ -881,7 +881,7 @@ class NormalStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
// an error occurs and alice publishes her commit tx
val aliceCommitTx = alice.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes())
alice2blockchain.expectMsg(Publish(aliceCommitTx))
alice2blockchain.expectMsg(PublishAsap(aliceCommitTx))
assert(aliceCommitTx.txOut.size == 6) // two main outputs and 4 pending htlcs
alice2blockchain.expectMsgType[WatchConfirmed].txId == aliceCommitTx.txid

View File

@ -119,7 +119,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(alice, fulfill)
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -131,7 +131,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(alice, UpdateFulfillHtlc(0, 42, "00" * 32))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -174,7 +174,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(alice, UpdateFailHtlc(0, 42, "some reason".getBytes()))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -244,7 +244,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(bob, CommitSig(0, "00" * 64, Nil))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -256,7 +256,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(bob, CommitSig(0, "00" * 64, Nil))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -332,7 +332,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(bob, RevokeAndAck(0, "11" * 32, "22" * 32, Nil))
bob2alice.expectMsgType[Error]
awaitCond(bob.stateName == CLOSING)
bob2blockchain.expectMsg(Publish(tx))
bob2blockchain.expectMsg(PublishAsap(tx))
bob2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -345,7 +345,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
sender.send(alice, RevokeAndAck(0, "11" * 32, "22" * 32, Nil))
alice2bob.expectMsgType[Error]
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}
@ -395,8 +395,8 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
alice2bob.expectMsgType[Error]
alice2blockchain.expectMsgType[WatchConfirmed]
val mainTx = alice2blockchain.expectMsgType[Publish].tx
val punishTx = alice2blockchain.expectMsgType[Publish].tx
val mainTx = alice2blockchain.expectMsgType[PublishAsap].tx
val punishTx = alice2blockchain.expectMsgType[PublishAsap].tx
alice2blockchain.expectNoMsg(1 second)
Transaction.correctlySpends(mainTx, Seq(revokedTx), ScriptFlags.STANDARD_SCRIPT_VERIFY_FLAGS)
@ -415,7 +415,7 @@ class ShutdownStateSpec extends StateSpecBaseClass with StateTestsHelperMethods
within(30 seconds) {
val aliceCommitTx = alice.stateData.asInstanceOf[DATA_SHUTDOWN].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes)
alice2blockchain.expectMsg(Publish(aliceCommitTx))
alice2blockchain.expectMsg(PublishAsap(aliceCommitTx))
assert(aliceCommitTx.txOut.size == 4) // two main outputs and two htlcs
alice2blockchain.expectMsgType[WatchConfirmed].txId == aliceCommitTx.txid

View File

@ -65,9 +65,9 @@ class NegotiatingStateSpec extends StateSpecBaseClass with StateTestsHelperMetho
bobCloseFee = bob2alice.expectMsgType[ClosingSigned].feeSatoshis
bob2alice.forward(alice)
} while (aliceCloseFee != bobCloseFee)
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
alice2blockchain.expectMsgType[WatchConfirmed]
bob2blockchain.expectMsgType[Publish]
bob2blockchain.expectMsgType[PublishAsap]
bob2blockchain.expectMsgType[WatchConfirmed]
awaitCond(alice.stateName == CLOSING)
awaitCond(bob.stateName == CLOSING)
@ -89,7 +89,7 @@ class NegotiatingStateSpec extends StateSpecBaseClass with StateTestsHelperMetho
// bob publishes the mutual close and alice is notified that the funding tx has been spent
// actual test starts here
assert(alice.stateName == NEGOTIATING)
val mutualCloseTx = bob2blockchain.expectMsgType[Publish].tx
val mutualCloseTx = bob2blockchain.expectMsgType[PublishAsap].tx
bob2blockchain.expectMsgType[WatchConfirmed]
alice ! (BITCOIN_FUNDING_SPENT, mutualCloseTx)
alice2blockchain.expectNoMsg(1 second)
@ -102,7 +102,7 @@ class NegotiatingStateSpec extends StateSpecBaseClass with StateTestsHelperMetho
val tx = alice.stateData.asInstanceOf[DATA_NEGOTIATING].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes())
awaitCond(alice.stateName == CLOSING)
alice2blockchain.expectMsg(Publish(tx))
alice2blockchain.expectMsg(PublishAsap(tx))
alice2blockchain.expectMsgType[WatchConfirmed]
}
}

View File

@ -82,9 +82,9 @@ class ClosingStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
bobCloseFee = bob2alice.expectMsgType[ClosingSigned].feeSatoshis
bob2alice.forward(alice)
} while (aliceCloseFee != bobCloseFee)
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
alice2blockchain.expectMsgType[WatchConfirmed]
bob2blockchain.expectMsgType[Publish]
bob2blockchain.expectMsgType[PublishAsap]
bob2blockchain.expectMsgType[WatchConfirmed]
awaitCond(alice.stateName == CLOSING)
awaitCond(bob.stateName == CLOSING)
@ -106,7 +106,7 @@ class ClosingStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
// an error occurs and alice publishes her commit tx
val aliceCommitTx = alice.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes)
alice2blockchain.expectMsg(Publish(aliceCommitTx))
alice2blockchain.expectMsg(PublishAsap(aliceCommitTx))
alice2blockchain.expectMsgType[WatchConfirmed].txId == aliceCommitTx.txid
awaitCond(alice.stateName == CLOSING)
val initialState = alice.stateData.asInstanceOf[DATA_CLOSING]
@ -124,7 +124,7 @@ class ClosingStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
// an error occurs and alice publishes her commit tx
val aliceCommitTx = alice.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice ! Error(0, "oops".getBytes())
alice2blockchain.expectMsg(Publish(aliceCommitTx))
alice2blockchain.expectMsg(PublishAsap(aliceCommitTx))
alice2blockchain.expectMsgType[WatchConfirmed].txId == aliceCommitTx.txid
awaitCond(alice.stateName == CLOSING)
assert(alice.stateData.asInstanceOf[DATA_CLOSING].localCommitPublished.isDefined)
@ -180,7 +180,7 @@ class ClosingStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
// alice publishes and watches the punishment tx
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
awaitCond(alice.stateData.asInstanceOf[DATA_CLOSING].revokedCommitPublished.size == 1)
awaitCond(alice.stateData.asInstanceOf[DATA_CLOSING].copy(revokedCommitPublished = Nil) == initialState)
@ -195,8 +195,8 @@ class ClosingStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
alice ! (BITCOIN_FUNDING_SPENT, bobRevokedTx)
// alice publishes and watches the punishment tx
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
alice2blockchain.expectMsgType[PublishAsap]
}
assert(alice.stateData.asInstanceOf[DATA_CLOSING].revokedCommitPublished.size == bobCommitTxes.size - 1)
}
@ -211,7 +211,7 @@ class ClosingStateSpec extends StateSpecBaseClass with StateTestsHelperMethods {
alice ! (BITCOIN_FUNDING_SPENT, bobRevokedTx)
// alice publishes and watches the punishment tx
alice2blockchain.expectMsgType[WatchConfirmed]
alice2blockchain.expectMsgType[Publish]
alice2blockchain.expectMsgType[PublishAsap]
// TODO
// awaitCond(alice.stateData.asInstanceOf[DATA_CLOSING] == initialState.copy(revokedCommitPublished = Seq(RevokedCommitPublished(bobRevokedTx))))