mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-23 15:39:22 +01:00
limit number of payment requests
This commit is contained in:
parent
7e77499087
commit
c7c935d682
2 changed files with 31 additions and 3 deletions
|
@ -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…
Add table
Reference in a new issue