limit number of payment requests

This commit is contained in:
rorp 2020-01-16 13:01:54 -08:00
parent b9504acc1b
commit 983850f441
2 changed files with 31 additions and 3 deletions

View File

@ -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

View File

@ -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
}
}