Skip to content

Commit

Permalink
fix(sdk): disable provider polling and correctly check done for past …
Browse files Browse the repository at this point in the history
…events (UMAprotocol#3833)

Signed-off-by: David <[email protected]>
  • Loading branch information
daywiss authored Feb 18, 2022
1 parent c2e1225 commit 0a4ce9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function Handlers(store: Store): GenericHandlers<Params, Memory> {
// we want to move start block closer to endblock to reduce the range until it stops erroring. These range functions
// will do that for us.
const rangeState = memory.state || rangeStart({ startBlock, endBlock });
const { currentStart, currentEnd, done } = rangeState;
const { currentStart, currentEnd } = rangeState;

try {
// this just queries events between start and end
Expand All @@ -54,11 +54,11 @@ export function Handlers(store: Store): GenericHandlers<Params, Memory> {
// the provider threw an error so we will reduce our range by moving startblock closer to endblock next iteration
memory.state = rangeFailureDescending(rangeState);
}
// the range functions will tell us when we have successfully queried the entire range of blocks.
if (done) return "done";
memory.iterations++;
// the range functions will tell us when we have successfully queried the entire range of blocks.
if (memory?.state?.done) return "done";
// sleep to let other contexts run, but just resume right after.
return ctx.sleep(10);
return ctx.sleep(100);
},
};
}
9 changes: 8 additions & 1 deletion packages/sdk/src/oracle/store/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ export class Services {
constructor(private state: Partial<state.ChainServices>) {}
provider(rpcUrls: string[]): void {
if (this.state?.provider) return;
const providers = rpcUrls.map((url) => ethers.getDefaultProvider(url));
const providers = rpcUrls.map((url) => {
const provider = ethers.getDefaultProvider(url);
// turn off all polling, we will poll manually
provider.polling = false;
return provider;
});
this.state.provider = new ethers.providers.FallbackProvider(providers, 1);
// turn off all polling, we will poll manually
this.state.provider.polling = false;
}
erc20s(address: string): void {
if (!this.state?.provider) return;
Expand Down

0 comments on commit 0a4ce9a

Please sign in to comment.