Txm no longer receives Viem objects#298
Conversation
Deploying happychain with
|
| Latest commit: |
1b25f8b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://02f20aa0.happychain.pages.dev |
| Branch Preview URL: | https://gabriel-txm-timeout.happychain.pages.dev |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
| transport: webSocket(), | ||
| chain: anvil, | ||
| privateKey: env.PRIVATE_KEY, | ||
| chainId: 31337, |
There was a problem hiding this comment.
suggestion: why dont we put the chainId in the env file?
| this.blockTime = _config.blockTime || 2n | ||
| this.finalizedTransactionPurgeTime = _config.finalizedTransactionPurgeTime || 2 * 60 * 1000 | ||
|
|
||
| if ((timeout + retryDelay) * retries > this.blockTime * 1000n) { |
There was a problem hiding this comment.
maybe its me but this line feels like a lot to parse 😅
There was a problem hiding this comment.
I'm pretty okay with it. Maybe:
const timePerRetry = timeout + retryDelay
if (timePerRetry * retries > this.blockTime * 1000n) {
| let transport: ViemTransport | ||
| if (protocol.value === "http") { | ||
| transport = viemHttpTransport(_config.rpc.url, { | ||
| timeout, | ||
| retryCount: retries, | ||
| retryDelay, | ||
| }) | ||
| } else { | ||
| transport = viemWebSocketTransport(_config.rpc.url, { | ||
| timeout, | ||
| retryCount: retries, | ||
| retryDelay, | ||
| }) | ||
| } |
There was a problem hiding this comment.
might be nice to extract this to some utility
const transport = getViemTransport(protocol, _config.rpc)There was a problem hiding this comment.
I don't mind too much, it's only used here, and this is pretty simple function that is just a long list of things being initialized, so it's not like it pollutes reasoning about what's otherwise a complex flow.
| // Get the chain ID of the RPC node | ||
| const rpcChainIdPromise = this.viemClient.safeGetChainId() | ||
|
|
||
| // Start the transaction repository | ||
| await this.transactionRepository.start() | ||
|
|
||
| // Start the nonce manager, which depends on the transaction repository | ||
| await this.nonceManager.start() | ||
|
|
||
| const rpcChainId = await rpcChainIdPromise |
There was a problem hiding this comment.
why seperate rpcChainIdPromise like this?
const rpcChainId = await this.viemClient.safeGetChainId()There was a problem hiding this comment.
Latency optimization: kick off the call early, then do the initialization, then come back and wait until the id is there. Otherwise we would have to wait the entire network roundtrip for chainid without doing any useful work locally.
There was a problem hiding this comment.
Yes, I do it this way for the reasons @norswap mentions
28048b1 to
b3b5c1d
Compare
0f3cbd7 to
7bd3300
Compare
b3b5c1d to
83842ef
Compare
7bd3300 to
ade9e83
Compare
83842ef to
2765c4e
Compare
ade9e83 to
ba1b173
Compare
2765c4e to
e1e535a
Compare
a599824 to
3674db3
Compare
e1e535a to
6d6cd5c
Compare
3674db3 to
1b25f8b
Compare

Linked issues
closes https://linear.app/happychain/issue/HAPPY-135/txmanager-add-timeouts-to-rpc-calls
Description
We aimed to configure a timeout for the RPC calls, but to achieve this, we ultimately decided not to expose viem objects in the TXM API. This ensures the TXM remains agnostic of the Web3 library we are using. For more context, please refer to the related issue
Toggle Checklist
Checklist
Basics
norswap/build-system-caching).Correctness
C1. Builds and passes tests.
C2. The code is properly parameterized & compatible with different environments.
C3. I have manually tested my changes & connected features.
C4. I have performed a thorough self-review of my code after submitting the PR.
Architecture & Documentation