We've already switched from using the batch RPC API to JSON REST API in https://github.com/Agoric/ui-kit/pull/55. But, we were still using a Promise.all() with the new interface, effectively batching those queries together. This PR makes each vstorage path poll asynchronously on separate timers.
Importantly, this changes the error handling to be more manageable. Instead of having a separate error handler for each watchLatest, it just uses a single onError callback given to chainStorageWatcher constructor. The new JSON API doesn't include an optional error message+code in response objects--it's limited to just http-level error codes, and in the case of missing vstorage data, an empty value in the response. This allows us to use axios to automatically retry on 500-level errors a couple times before invoking onError.
This updated error handling allows for clients to more easily manage faulty RPC nodes. Instead of adding an error handler to every place watchLatest is used, and use the result to decipher whether the vstorage data is missing or the RPC node is failing, it can just use the single onError callback on the chainStorageWatcher, and trust that the chainStorageWatcher already retried a couple times. This gives the client a reliable way to know when to notify the user of an RPC outage and/or prompt them to select a different node (assuming a node selector is available).
For queryOnce, it also no longer batches with other requests, and uses axios to retry before throwing an error, more similar to a regular fetch request.
Added some test cases for the updated error handling.
refs https://github.com/Agoric/agoric-sdk/issues/8505
We've already switched from using the batch RPC API to JSON REST API in https://github.com/Agoric/ui-kit/pull/55. But, we were still using a
Promise.all()
with the new interface, effectively batching those queries together. This PR makes each vstorage path poll asynchronously on separate timers.Importantly, this changes the error handling to be more manageable. Instead of having a separate error handler for each
watchLatest
, it just uses a singleonError
callback given tochainStorageWatcher
constructor. The new JSON API doesn't include an optional error message+code in response objects--it's limited to just http-level error codes, and in the case of missing vstorage data, an emptyvalue
in the response. This allows us to use axios to automatically retry on 500-level errors a couple times before invokingonError
.This updated error handling allows for clients to more easily manage faulty RPC nodes. Instead of adding an error handler to every place
watchLatest
is used, and use the result to decipher whether the vstorage data is missing or the RPC node is failing, it can just use the singleonError
callback on thechainStorageWatcher
, and trust that thechainStorageWatcher
already retried a couple times. This gives the client a reliable way to know when to notify the user of an RPC outage and/or prompt them to select a different node (assuming a node selector is available).For
queryOnce
, it also no longer batches with other requests, and uses axios to retry before throwing an error, more similar to a regularfetch
request.Added some test cases for the updated error handling.