-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add basic failover functionality #9
Conversation
@@ -333,6 +333,19 @@ export class JsonRpcProvider extends Provider { | |||
return await this.sendJsonRpc('gas_price', [blockId]); | |||
} | |||
|
|||
/** | |||
* Part of the RPC failover design. | |||
* Changing current (first) rpc server and moves it to the and of the queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Changing current (first) rpc server and moves it to the and of the queue. | |
* Changing current (first) rpc server and moves it to the end of the queue. |
test('JsonRpc rotateRpcServers', async () => { | ||
const SERVER_1 = 'server1'; | ||
const SERVER_2 = 'server2'; | ||
const SERVER_3 = 'server3'; | ||
const provider = new JsonRpcProvider({ url: [SERVER_1, SERVER_2, SERVER_3] }); | ||
expect(provider.connection.url.length).toEqual(3); | ||
expect(provider.connection.url[0]).toMatch(SERVER_1); | ||
expect(provider.connection.url[1]).toMatch(SERVER_2); | ||
expect(provider.connection.url[2]).toMatch(SERVER_3); | ||
provider.rotateRpcServers(); | ||
expect(provider.connection.url.length).toEqual(3); | ||
expect(provider.connection.url[0]).toMatch(SERVER_2); | ||
expect(provider.connection.url[1]).toMatch(SERVER_3); | ||
expect(provider.connection.url[2]).toMatch(SERVER_1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a bad case test which contains bad configuration. The error should be caught at construction time I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add
packages/wallet-account/src/near.ts
Outdated
/** | ||
* RPC API Keys. Used to authenticate users on RPC Server. | ||
*/ | ||
apiKeys: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be { [url: string]: string };
Pre-flight checklist
pnpm changeset
to create achangeset
JSON document appropriate for this change.Motivation
Added support for multiple API Keys (since we can have multiple RPC Servers)
Added basic failover functionality
With this design of failover, we will change (rotate) our server when needed and stick to this new server for our next calls. It will help to avoid long responses when first (or more) servers are down.
For now, server rotation is happening only on Timeout error.
Also, check this comment: near#733 (comment)
Test Plan
Added unit tests.
Related issues/PRs
near#733
near#760