-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework ElectrumClient
#512
Commits on Jul 11, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 813b520 - Browse repository at this point
Copy the full SHA 813b520View commit details -
Move socketBuilder to connect()
This is only used when connecting, it doesn't need to be an argument of the `ElectrumClient`.
Configuration menu - View commit details
-
Copy full SHA for 94f2b90 - Browse repository at this point
Copy the full SHA 94f2b90View commit details -
Refactor and document
linesFlow
TCP sockets with electrum servers require some non-trivial code to reconstruct individual messages from the bytes received on the socket. We process bytes in chunks, then reconstruct utf8 strings, and finally split those strings at newline characters into individual messages. We document that code, rename fields to make it easier to understand, and add unit tests. We remove it from the TCP socket abstraction, since this is specific to electrum connections. We also change the behavior in case the socket is closed while we have buffered a partial message: it doesn't make sense to emit it, as listeners won't be able to decode it.
Configuration menu - View commit details
-
Copy full SHA for 214848e - Browse repository at this point
Copy the full SHA 214848eView commit details -
Remove duplicate
connectionState
flowThis is a pure 1:1 mapping from `connectionStatus`, there is no reason for that duplication. Clients can trivially migrate or `map` using the `toConnectionState` helper function.
Configuration menu - View commit details
-
Copy full SHA for e66b313 - Browse repository at this point
Copy the full SHA e66b313View commit details -
We clean up the coroutine hierarchy: the `ElectrumClient` has a single internal coroutine that is launched once the connection has been established with the electrum server. This coroutine launches three child coroutines and uses supervision to gracefully stop if the connection is closed or an error is received. Connection establishment happens in the context of the job that calls `connect()` and doesn't throw exceptions. We revert the introduction of a `CoroutineExceptionHandler` inside the JVM socket code, as it shouldn't be needed anymore.
Configuration menu - View commit details
-
Copy full SHA for eabcdc4 - Browse repository at this point
Copy the full SHA eabcdc4View commit details -
Add timeout to connection establishment
Otherwise we may be stuck in the `Connecting` state.
Configuration menu - View commit details
-
Copy full SHA for e914f3e - Browse repository at this point
Copy the full SHA e914f3eView commit details -
Remove unnecessary RPC calls exposed
We just keep `getHeader` / `getHeaders` which can be handy.
Configuration menu - View commit details
-
Copy full SHA for 0377d0d - Browse repository at this point
Copy the full SHA 0377d0dView commit details
Commits on Jul 12, 2023
-
On most RPC calls, we can gracefully handle server errors. Since we cannot trust the electrum server anyway, and they may lie to us by omission, this doesn't downgrade the security model. The previous behavior was to throw an exception, which was never properly handled and would just result in a crash of the wallet application.
Configuration menu - View commit details
-
Copy full SHA for 253b853 - Browse repository at this point
Copy the full SHA 253b853View commit details -
Add timeout and retry to RPC calls
We add an explicit timeout to RPC calls and a retry. If that retry also fails, two strategies are available: - handle the error and gracefully degrade (non-critical RPC calls) - disconnect and retry with new electrum server (critical RPCs such as subscriptions) The timeout can be updated by the application, for example when a slow network is detected or when Tor is activated.
Configuration menu - View commit details
-
Copy full SHA for 13b06fa - Browse repository at this point
Copy the full SHA 13b06faView commit details
Commits on Jul 28, 2023
-
When connecting to an invalid address in tests on iOS, the error isn't reported by the native socket which just hangs until the test times out. We lower the timeout on the `connect` call, which previously had the same value as the test timeout. We thus fail the connection attempt after 1 second and are able to reconnect to a different server. The very low RPC timeout was flaky on iOS: because the clock used depends on the actual dispatcher, it sometimes triggered only after receiving a valid response from the server, which made the test fail. Setting it to 0ms ensures that the is immediately cancelled with a timeout exception regardless of the dispatcher used.
Configuration menu - View commit details
-
Copy full SHA for d60e6e7 - Browse repository at this point
Copy the full SHA d60e6e7View commit details -
Add CoroutineExceptionHandler on tls sockets
We actually still need it until ktorio/ktor#3690 is integrated into a ktor release.
Configuration menu - View commit details
-
Copy full SHA for 2b70f09 - Browse repository at this point
Copy the full SHA 2b70f09View commit details
Commits on Aug 8, 2023
-
Configuration menu - View commit details
-
Copy full SHA for d691a0b - Browse repository at this point
Copy the full SHA d691a0bView commit details -
Close TCP socket when race with timeout
Since `withTimeout` runs concurrently, it may throw the timeout exception after we've established the TCP connection, so we need to release it if we can (if we have a pointer to it).
Configuration menu - View commit details
-
Copy full SHA for 4502d86 - Browse repository at this point
Copy the full SHA 4502d86View commit details
Commits on Aug 11, 2023
-
Configuration menu - View commit details
-
Copy full SHA for b2f72d3 - Browse repository at this point
Copy the full SHA b2f72d3View commit details -
Configuration menu - View commit details
-
Copy full SHA for ad86714 - Browse repository at this point
Copy the full SHA ad86714View commit details
Commits on Sep 6, 2023
-
Remove currentBlockHeight from extensions methods
We can actually get it from the connection status, which simplifies the way callers use those functions.
Configuration menu - View commit details
-
Copy full SHA for 75ab436 - Browse repository at this point
Copy the full SHA 75ab436View commit details