Skip to content

Commit

Permalink
remove retry and signal for json-rpc calls
Browse files Browse the repository at this point in the history
eth-fun takes care of retry so we don't need to in extraction-worker.

Timeout signal should be created by eth-fun for each retry.

Updated eth-fun to the latest version.
  • Loading branch information
il3ven committed Jul 31, 2023
1 parent 5563e3b commit 64e1e51
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 65 deletions.
56 changes: 36 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The purpose of the neume-network/core Extraction Worker (short: \"EW\") is to parallelize retrieving distributed information from various data sources by abstracting away the complexity of scaling processes accross a distributed system such as e.g. multiple node.js Worker threads.",
"main": "./src/worker.mjs",
"exports": "./src/worker.mjs",
"types": "./src/worker.d.ts",
"types": "./src/worker.d.mts",
"ava": {
"files": [
"!test/start.mjs"
Expand Down Expand Up @@ -68,7 +68,7 @@
"cross-fetch": "3.1.5",
"debug": "4.3.4",
"dotenv": "16.0.0",
"eth-fun": "github:il3ven/eth-fun#fork",
"eth-fun": "github:il3ven/eth-fun#1a57ff48ed7cfa05367bfa4497c51542b345c52b",
"fastq": "1.13.0",
"limiter": "2.0.1",
"multiformats": "9.9.0"
Expand Down
66 changes: 23 additions & 43 deletions src/eth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,31 @@ import {
getTransactionReceipt,
getLogs,
} from "eth-fun";
import retry from "async-retry";

import { NotImplementedError } from "./errors.mjs";

// NOTE: `AbortSignal.timeout` isn't yet supported:
// https://github.com/mysticatea/abort-controller/issues/35
export const AbortSignal = {
timeout: function (value) {
const controller = new AbortController();
setTimeout(() => controller.abort(), value);
return controller.signal;
},
};

export async function translate(options, method, params) {
return retry(async (bail) => {
if (options.timeout) {
options.signal = AbortSignal.timeout(
options.timeout ?? timeoutFromConfig
);
delete options.timeout;
}

if (method === "eth_getTransactionReceipt") {
return await getTransactionReceipt(options, params[0]);
} else if (method === "eth_getBlockByNumber") {
// NOTE: `getBlockByNumber` expects the `blockNumber` input to be an
// hexadecimal (`0x...`) value.
return await getBlockByNumber(options, ...params);
} else if (method === "eth_blockNumber") {
return await blockNumber(options);
} else if (method === "eth_call") {
const { from, to, data } = params[0];
return await call(options, from, to, data, params[1]);
} else if (method === "eth_getLogs") {
const { fromBlock, toBlock, address, topics, limit } = params[0];
return await getLogs(options, {
fromBlock,
toBlock,
address,
topics,
limit,
});
} else {
bail(new NotImplementedError());
}
});
if (method === "eth_getTransactionReceipt") {
return await getTransactionReceipt(options, params[0]);
} else if (method === "eth_getBlockByNumber") {
// NOTE: `getBlockByNumber` expects the `blockNumber` input to be an
// hexadecimal (`0x...`) value.
return await getBlockByNumber(options, ...params);
} else if (method === "eth_blockNumber") {
return await blockNumber(options);
} else if (method === "eth_call") {
const { from, to, data } = params[0];
return await call(options, from, to, data, params[1]);
} else if (method === "eth_getLogs") {
const { fromBlock, toBlock, address, topics, limit } = params[0];
return await getLogs(options, {
fromBlock,
toBlock,
address,
topics,
limit,
});
} else {
new NotImplementedError();
}
}

0 comments on commit 64e1e51

Please sign in to comment.