Skip to content

Commit

Permalink
fix: use more reliable way to choose provider (stephenh#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Aug 19, 2022
1 parent 7ac7428 commit ba56fa9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start_ts_solana": "ts-node --files src/processor.ts ../examples/mirrorworld/src/processor.ts",
"start": "ts-node --files src/processor.ts ../examples/x2y2/dist/lib.js",
"start_js": "node dist/processor.js ../examples/x2y2/dist/lib.js",
"ts-start": "ts-node --files src/processor.ts src/test-case/erc20.ts",
"ts-start": "ts-node --files src/processor.ts ~/src/sentio-processor/goldfinch/src/processor.ts",
"cli": "yarn build && node dist/cli/cli.js",
"test": "ts-mocha --paths src/**/*.test.ts src/*.test.ts",
"gen_test_abi": "yarn gen_evm_abi && yarn gen_solana_abi",
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function GetRecordMetaData(ctx: Context<any, any> | SolanaContext, name: string,
} else if (ctx instanceof SolanaContext) {
return {
contractAddress: ctx.address,
blockNumber: Long.fromNumber(0), // TODO need number type to be long
blockNumber: Long.ZERO, // TODO need number type to be long
transactionIndex: 0,
logIndex: 0,
chainId: 'SOL:mainnet', // TODO set in context
Expand Down
15 changes: 9 additions & 6 deletions sdk/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ export function setProvider(config: any) {
const chainConfig = config[chainIdStr]
const chainId = Number(chainIdStr)

let providers: StaticJsonRpcProvider[] = []
for (const http of chainConfig.Https) {
providers.push(new StaticJsonRpcProvider(http, chainId))
}
// let providers: StaticJsonRpcProvider[] = []
// for (const http of chainConfig.Https) {
// providers.push(new StaticJsonRpcProvider(http, chainId))
// }
// random shuffle
providers = providers.sort(() => Math.random() - 0.5)
// providers = providers.sort(() => Math.random() - 0.5)

// const provider = new FallbackProvider(providers)
const idx = Math.floor(Math.random() * chainConfig.Https.length)
const provider = new StaticJsonRpcProvider(chainConfig.Https[idx], chainId)

const provider = new FallbackProvider(providers)
globalThis.SentioProvider.set(chainId, provider)
}
}
2 changes: 1 addition & 1 deletion sdk/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {

if (
processor.config.endBlock &&
processor.config.endBlock > Long.fromNumber(0) &&
processor.config.endBlock > Long.ZERO &&
Long.fromNumber(block.number) > processor.config.endBlock
) {
continue
Expand Down

0 comments on commit ba56fa9

Please sign in to comment.