Skip to content

Commit 735513f

Browse files
committed
add warmup budget to PaddedRSTransport
Adds a 1024 (unpadded) byte sending budget to the PaddedRSTransport below which messages are instantly flushed down the socket before the transport will beginn waiting for the buffer to reach MIN_PACKET_SIZE (1024). This allows to get the first couple of messages sent quickly when a wallet connects to improve its ux.
1 parent f62f986 commit 735513f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/electrumx/server/transport.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class PaddedRSTransport(RSTransport):
2424

2525
MIN_PACKET_SIZE = 1024
2626
WAIT_FOR_BUFFER_GROWTH_SECONDS = 1.0
27+
# amount of (unpadded) bytes sent instantly before beginning with polling.
28+
# This makes the initial handshake where a few small messages are exchanged faster.
29+
WARMUP_BUDGET_SIZE = 1024
2730

2831
session: Optional['RPCSessionWithTaskGroup']
2932

@@ -57,6 +60,7 @@ def _maybe_consume_sbuffer(self) -> None:
5760
self._force_send
5861
or len(buf) >= self.MIN_PACKET_SIZE
5962
or self._last_send + self.WAIT_FOR_BUFFER_GROWTH_SECONDS < time.monotonic()
63+
or self.session.send_size < self.WARMUP_BUDGET_SIZE
6064
):
6165
return
6266
assert buf[-2:] in (b"}\n", b"]\n"), f"unexpected json-rpc terminator: {buf[-2:]=!r}"

0 commit comments

Comments
 (0)