mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 18:02:54 +01:00
limit number of payment requests
This commit is contained in:
parent
b9504acc1b
commit
983850f441
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user