-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove polling rpcs from default fallback config
- Loading branch information
1 parent
b7e7129
commit 11ab19a
Showing
4 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { | ||
FallbackProviderJsonConfig, | ||
createFallbackProviderFromJsonConfig, | ||
} from '../fallback-provider'; | ||
|
||
chai.use(chaiAsPromised); | ||
const { expect } = chai; | ||
|
||
describe('available-rpc', () => { | ||
it('Should check fallback provider cascade', async () => { | ||
const config: FallbackProviderJsonConfig = { | ||
chainId: 1, | ||
providers: [ | ||
{ | ||
provider: | ||
'https://eth-mainnet.gateway.pokt.network/v1/lb/627a4b6e18e53a003a6b6c26', | ||
priority: 1, | ||
weight: 2, | ||
stallTimeout: 2500, | ||
}, | ||
{ | ||
provider: 'https://railwayapi.xyz/rpc/alchemy/eth-mainnet', | ||
priority: 2, | ||
weight: 1, | ||
}, | ||
{ provider: 'https://cloudflare-eth.com/', priority: 3, weight: 1 }, | ||
{ provider: 'https://rpc.ankr.com/eth', priority: 3, weight: 1 }, | ||
], | ||
}; | ||
|
||
const fallbackProvider = createFallbackProviderFromJsonConfig(config); | ||
|
||
await fallbackProvider.getBlockNumber(); | ||
}); | ||
|
||
it('Should sort ascending and descending', () => { | ||
const allConfigs = [ | ||
{ | ||
priority: 3, | ||
}, | ||
{ | ||
priority: 1, | ||
}, | ||
{ | ||
priority: 2, | ||
}, | ||
]; | ||
|
||
// Ascending | ||
allConfigs.sort((a, b) => a.priority - b.priority); | ||
expect(allConfigs.map(c => c.priority)).to.deep.equal([1, 2, 3]); | ||
|
||
// Descending | ||
allConfigs.sort((a, b) => b.priority - a.priority); | ||
expect(allConfigs.map(c => c.priority)).to.deep.equal([3, 2, 1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
src/utils/polling-json-rpc-provider.ts → src/utils/configured-json-rpc-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import { JsonRpcProvider, JsonRpcApiProviderOptions, Network } from 'ethers'; | ||
|
||
/** | ||
* Uses a setting in JsonRpcProvider to poll for events, | ||
* rather than using sparsely-implemented eth_filter events. | ||
*/ | ||
export class PollingJsonRpcProvider extends JsonRpcProvider { | ||
export class ConfiguredJsonRpcProvider extends JsonRpcProvider { | ||
constructor(url: string, network: Network, disableBatching = false) { | ||
const options: JsonRpcApiProviderOptions = { | ||
polling: true, | ||
staticNetwork: network, | ||
}; | ||
if (disableBatching) { | ||
options.batchMaxCount = 1; | ||
} | ||
super(url, network, options); | ||
this.pollingInterval = 30000; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters