diff --git a/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala b/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala index 3b991db0dd..850ff5122f 100644 --- a/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala +++ b/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala @@ -83,6 +83,7 @@ object EclairBench extends App with EclairRpcTestUtil { .createInvoice("test " + System.currentTimeMillis(), amount) paymentHash = invoice.lnTags.paymentHash.hash _ = logPaymentHash(paymentHash) + p = promises.get(paymentHash) id <- node.sendToNode(testNodeInfo.nodeId, invoice.amount.get.toMSat, invoice.lnTags.paymentHash.hash, @@ -90,8 +91,9 @@ object EclairBench extends App with EclairRpcTestUtil { None, None, None) + _ = logPaymentId(paymentHash, id) + _ <- p.future } yield { - logPaymentId(paymentHash, id) Progress.inc() acc :+ id } @@ -119,6 +121,7 @@ object EclairBench extends App with EclairRpcTestUtil { paymentLog.values().asScala.forall(_.completed), duration = 1.second, maxTries = 100) + .recover(_.printStackTrace()) _ = println("\nDone!") } yield { paymentLog diff --git a/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala b/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala index 10dbe5504b..1b7089bd2c 100644 --- a/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala +++ b/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala @@ -11,6 +11,8 @@ import org.bitcoins.eclair.rpc.api.WebSocketEvent.{ } import org.bitcoins.eclair.rpc.api.{PaymentId, WebSocketEvent} +import scala.concurrent.Promise + object PaymentLog { case class PaymentLogEntry( @@ -64,8 +66,14 @@ object PaymentLog { val paymentLog = new ConcurrentHashMap[Sha256Digest, PaymentLogEntry]() + val promises = + new ConcurrentHashMap[Sha256Digest, Promise[Unit]]() + def logPaymentHash(paymentHash: Sha256Digest): PaymentLogEntry = { - paymentLog.putIfAbsent(paymentHash, PaymentLogEntry(paymentHash)) + val entry = + paymentLog.putIfAbsent(paymentHash, PaymentLogEntry(paymentHash)) + promises.putIfAbsent(paymentHash, Promise()) + entry } def logPaymentId( @@ -99,7 +107,7 @@ object PaymentLog { throw new RuntimeException("Can't extract payment hash") } - paymentLog.compute( + val entry = paymentLog.compute( hash, new BiFunction[Sha256Digest, PaymentLogEntry, PaymentLogEntry] { override def apply( @@ -114,6 +122,23 @@ object PaymentLog { } } ) + promises.compute( + hash, + new BiFunction[Sha256Digest, Promise[Unit], Promise[Unit]] { + override def apply( + hash: Sha256Digest, + old: Promise[Unit]): Promise[Unit] = { + val promise = if (old == null) { + Promise[Unit]() + } else { + old + } + promise.success(()) + promise + } + } + ) + entry } }