aepp-sdk-js icon indicating copy to clipboard operation
aepp-sdk-js copied to clipboard

Add NodeGateway retrying nonce requests if response outdated

Open davidyuk opened this issue 1 year ago • 4 comments

This PR is supported by the Æternity Crypto Foundation

We are retrying requests multiple times if the response status code is 404 or so. It is made because a public API gateway has a load balancer, and some nodes behind it can be a bit unsynced producing outdated results. The same issue with nonce tracking, node can return an outdated nonce, but it is much harder to detect. A wrong nonce completely blocks tx mining (see https://github.com/aeternity/aeternity/issues/4173).

To solve this problem I've implemented a class inherited from Node. This class extracts nonces from submitted transactions and if the nonce returned by node looks outdated then it retries the request the same way if it would be 404. Sdk tests became much more stable using this on testnet.

A general solution would be https://github.com/aeternity/aepp-sdk-js/issues/291.

davidyuk avatar Feb 15 '24 07:02 davidyuk

Codecov Report

Attention: Patch coverage is 86.95652% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 79.89%. Comparing base (a21bc1f) to head (27d1a4c). Report is 1 commits behind head on develop.

Files Patch % Lines
src/node/Gateway.ts 78.04% 5 Missing and 4 partials :warning:
src/node/Direct.ts 94.59% 0 Missing and 2 partials :warning:
src/node/Base.ts 50.00% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1946      +/-   ##
===========================================
- Coverage    79.91%   79.89%   -0.02%     
===========================================
  Files          101      103       +2     
  Lines         3450     3497      +47     
  Branches       733      742       +9     
===========================================
+ Hits          2757     2794      +37     
- Misses         381      386       +5     
- Partials       312      317       +5     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 15 '24 08:02 codecov[bot]

I think the default 8 retries are a bit too much, while currently there are no RPS limits we'll implement it at some point (as protection measure) which can cause issues.

In general I don't think the SDK should care about of the "gateway" concepts and should tread it as ordinal node/API backend, however the user/developer should be able to choose the proposed nonce strategy for any backend.

Also hardcoding the endpoints also sounds like a bad idea, yes we should keep them as defaults, but the users should be able to change it?

dincho avatar Feb 15 '24 09:02 dincho

Also hardcoding the endpoints also sounds like a bad idea, yes we should keep them as defaults, but the users should be able to change it?

Okay I was confused (didn't fully read) these lines: https://github.com/aeternity/aepp-sdk-js/pull/1946/files#diff-9f5cadd5139250f5eef2e796974c1db0f422f7adb4541f5b5b356a26c54711afR43

It still means one would get the waring if they don't use our gateways? A bit annoying I guess as there are multiple environments, user nodes, hyperchains etc.

dincho avatar Feb 15 '24 09:02 dincho

It still means one would get the waring if they don't use our gateways?

It is a hint to use NodeGateway in case the old Node class is used with our API gateways.

davidyuk avatar Feb 23 '24 07:02 davidyuk