Skip to content

Commit

Permalink
v10.18.6: fix endless retries
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed May 16, 2024
1 parent 4dac54c commit a7d7952
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 48 deletions.
2 changes: 1 addition & 1 deletion dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdn.ethers.io/lib/ethers-5.7.umd.min.js" type="application/javascript"></script>
<script crossorigin src="https://unpkg.com/@depay/solana-web3.js@1"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-blockchains@9"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-blockchains@9.3.6"></script>
<script src="tmp/index.dev.js"></script>
</head>
<body>
Expand Down
9 changes: 5 additions & 4 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const setConfiguration = (configuration) =>{
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const MAX_RETRY = 3;

class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {

Expand All @@ -97,7 +98,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
return Promise.resolve(Blockchains.findByName(this._network).id)
}

requestChunk(chunk, endpoint) {
requestChunk(chunk, endpoint, attempt) {

try {

Expand All @@ -120,11 +121,11 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
if(attempt < MAX_RETRY && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -178,7 +179,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk, this._endpoint)
return this.requestChunk(chunk, this._endpoint, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL);
}
Expand Down
18 changes: 10 additions & 8 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const setConfiguration = (configuration) =>{
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL$1 = 10;
const CHUNK_SIZE$1 = 99;
const MAX_RETRY$1 = 3;

class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {

Expand All @@ -45,7 +46,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
return Promise.resolve(Blockchains.findByName(this._network).id)
}

requestChunk(chunk, endpoint) {
requestChunk(chunk, endpoint, attempt) {

try {

Expand All @@ -68,11 +69,11 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
if(attempt < MAX_RETRY$1 && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -126,7 +127,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk, this._endpoint)
return this.requestChunk(chunk, this._endpoint, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL$1);
}
Expand Down Expand Up @@ -249,6 +250,7 @@ var EVM = {
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const MAX_RETRY = 3;

class StaticJsonRpcSequentialProvider extends Connection {

Expand All @@ -263,18 +265,18 @@ class StaticJsonRpcSequentialProvider extends Connection {
this._rpcRequest = this._rpcRequestReplacement.bind(this);
}

requestChunk(chunk) {
requestChunk(chunk, attempt) {

const batch = chunk.map((inflight) => inflight.request);

const handleError = (error)=>{
if(error && [
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new Connection(this._endpoint);
this.requestChunk(chunk);
this.requestChunk(chunk, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -337,7 +339,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk)
return this.requestChunk(chunk, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL);
}
Expand Down
9 changes: 5 additions & 4 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const setConfiguration = (configuration) =>{
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const MAX_RETRY = 3;

class StaticJsonRpcSequentialProvider extends Connection {

Expand All @@ -43,18 +44,18 @@ class StaticJsonRpcSequentialProvider extends Connection {
this._rpcRequest = this._rpcRequestReplacement.bind(this);
}

requestChunk(chunk) {
requestChunk(chunk, attempt) {

const batch = chunk.map((inflight) => inflight.request);

const handleError = (error)=>{
if(error && [
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new Connection(this._endpoint);
this.requestChunk(chunk);
this.requestChunk(chunk, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -117,7 +118,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk)
return this.requestChunk(chunk, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL);
}
Expand Down
9 changes: 5 additions & 4 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const MAX_RETRY = 3;

class StaticJsonRpcBatchProvider extends ethers.ethers.providers.JsonRpcProvider {

Expand All @@ -104,7 +105,7 @@
return Promise.resolve(Blockchains__default["default"].findByName(this._network).id)
}

requestChunk(chunk, endpoint) {
requestChunk(chunk, endpoint, attempt) {

try {

Expand All @@ -127,11 +128,11 @@
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
if(attempt < MAX_RETRY && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -185,7 +186,7 @@
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk, this._endpoint)
return this.requestChunk(chunk, this._endpoint, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL);
}
Expand Down
18 changes: 10 additions & 8 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL$1 = 10;
const CHUNK_SIZE$1 = 99;
const MAX_RETRY$1 = 3;

class StaticJsonRpcBatchProvider extends ethers.ethers.providers.JsonRpcProvider {

Expand All @@ -51,7 +52,7 @@
return Promise.resolve(Blockchains__default["default"].findByName(this._network).id)
}

requestChunk(chunk, endpoint) {
requestChunk(chunk, endpoint, attempt) {

try {

Expand All @@ -74,11 +75,11 @@
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
if(attempt < MAX_RETRY$1 && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -132,7 +133,7 @@
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk, this._endpoint)
return this.requestChunk(chunk, this._endpoint, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL$1);
}
Expand Down Expand Up @@ -255,6 +256,7 @@
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const MAX_RETRY = 3;

class StaticJsonRpcSequentialProvider extends solanaWeb3_js.Connection {

Expand All @@ -269,18 +271,18 @@
this._rpcRequest = this._rpcRequestReplacement.bind(this);
}

requestChunk(chunk) {
requestChunk(chunk, attempt) {

const batch = chunk.map((inflight) => inflight.request);

const handleError = (error)=>{
if(error && [
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new solanaWeb3_js.Connection(this._endpoint);
this.requestChunk(chunk);
this.requestChunk(chunk, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -343,7 +345,7 @@
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk)
return this.requestChunk(chunk, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL);
}
Expand Down
9 changes: 5 additions & 4 deletions dist/umd/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;
const MAX_RETRY = 3;

class StaticJsonRpcSequentialProvider extends solanaWeb3_js.Connection {

Expand All @@ -49,18 +50,18 @@
this._rpcRequest = this._rpcRequestReplacement.bind(this);
}

requestChunk(chunk) {
requestChunk(chunk, attempt) {

const batch = chunk.map((inflight) => inflight.request);

const handleError = (error)=>{
if(error && [
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new solanaWeb3_js.Connection(this._endpoint);
this.requestChunk(chunk);
this.requestChunk(chunk, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
Expand Down Expand Up @@ -123,7 +124,7 @@
chunks.forEach((chunk)=>{
// Get the request as an array of requests
chunk.map((inflight) => inflight.request);
return this.requestChunk(chunk)
return this.requestChunk(chunk, 1)
});
}, getConfiguration().batchInterval || BATCH_INTERVAL);
}
Expand Down
4 changes: 2 additions & 2 deletions package.evm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client-evm",
"moduleName": "Web3Client",
"version": "10.18.5",
"version": "10.18.6",
"description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.",
"main": "dist/umd/index.evm.js",
"module": "dist/esm/index.evm.js",
Expand All @@ -23,7 +23,7 @@
"homepage": "https://depay.com",
"private": false,
"peerDependencies": {
"@depay/web3-blockchains": "^9.1.4",
"@depay/web3-blockchains": "^9.3.6",
"ethers": "^5.7.1"
},
"engines": {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client",
"moduleName": "Web3Client",
"version": "10.18.5",
"version": "10.18.6",
"description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"private": false,
"peerDependencies": {
"@depay/solana-web3.js": "^1.25.1",
"@depay/web3-blockchains": "^9.1.4",
"@depay/web3-blockchains": "^9.3.6",
"ethers": "^5.7.1"
},
"engines": {
Expand All @@ -44,7 +44,7 @@
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"@depay/solana-web3.js": "^1.25.1",
"@depay/web3-blockchains": "^9.1.4",
"@depay/web3-blockchains": "^9.3.6",
"@depay/web3-mock": "^14.17.0",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-json": "^4.1.0",
Expand Down
4 changes: 2 additions & 2 deletions package.solana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client-solana",
"moduleName": "Web3Client",
"version": "10.18.5",
"version": "10.18.6",
"description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.",
"main": "dist/umd/index.solana.js",
"module": "dist/esm/index.solana.js",
Expand All @@ -23,7 +23,7 @@
"homepage": "https://depay.com",
"private": false,
"peerDependencies": {
"@depay/web3-blockchains": "^9.1.4",
"@depay/web3-blockchains": "^9.3.6",
"@depay/solana-web3.js": "^1.25.1",
"ethers": "^5.7.1"
},
Expand Down
Loading

0 comments on commit a7d7952

Please sign in to comment.