Skip to content

Commit

Permalink
v2.11.4: fixes Solana RPC failover
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Jul 1, 2024
1 parent a635ab0 commit 4d000a7
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 37 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** DePay Web3 Payments for WooCommerce Changelog ***

2024-7-1 - version 2.11.4
* fixes Solana RPC failover

2024-6-17 - version 2.11.3
* fixes more mobile & wallet connect edgecases

Expand Down
4 changes: 2 additions & 2 deletions depay-woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* WC tested up to: 8.7.0
* Requires at least: 5.8
* Requires PHP: 7.0
* Version: 2.11.3
* Version: 2.11.4
*
* @package DePay\Payments
*/
Expand All @@ -21,7 +21,7 @@
define( 'DEPAY_WC_PLUGIN_FILE', __FILE__ );
define( 'DEPAY_WC_ABSPATH', __DIR__ . '/' );
define( 'DEPAY_MIN_WC_ADMIN_VERSION', '0.23.2' );
define( 'DEPAY_CURRENT_VERSION', '2.11.3' );
define( 'DEPAY_CURRENT_VERSION', '2.11.4' );

require_once DEPAY_WC_ABSPATH . '/vendor/autoload.php';

Expand Down
5 changes: 3 additions & 2 deletions dist/web3-blockchains.js

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

79 changes: 53 additions & 26 deletions dist/web3-client.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,30 +271,55 @@
this._rpcRequest = this._rpcRequestReplacement.bind(this);
}

requestChunk(chunk) {
handleError(error, attempt, chunk) {
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, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
}

const batch = chunk.map((inflight) => inflight.request);
batchRequest(requests, attempt) {
return new Promise((resolve, reject) => {
if (requests.length === 0) resolve([]); // Do nothing if requests is empty

const handleError = (error)=>{
if(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);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
};
const batch = requests.map(params => {
return this._rpcClient.request(params.methodName, params.args)
});

fetch(
this._endpoint,
{
method: 'POST',
body: JSON.stringify(batch),
headers: { 'Content-Type': 'application/json' },
}
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
resolve(parsedJson);
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
}
}).catch(reject);
})
}

requestChunk(chunk, attempt) {

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

try {
return this._provider._rpcBatchRequest(batch)
return this.batchRequest(batch, attempt)
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$2([payload, 'optionalAccess', _ => _.error])) {
Expand All @@ -306,8 +333,8 @@
inflightRequest.reject();
}
});
}).catch(handleError)
} catch (error){ return handleError(error) }
}).catch((error)=>this.handleError(error, attempt, chunk))
} catch (error){ return this.handleError(error, attempt, chunk) }
}

_rpcRequestReplacement(methodName, args) {
Expand Down Expand Up @@ -343,7 +370,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 dist/widgets.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion languages/depay-woocommerce-payments.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
"Project-Id-Version: DePay WooCommerce Payments 2.11.3\n"
"Project-Id-Version: DePay WooCommerce Payments 2.11.4\n"
"Report-Msgid-Bugs-To: "
"[email protected]\n"
"MIME-Version: 1.0\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-woocommerce-depay-payments",
"moduleName": "WooCommerceDePayPayments",
"version": "2.11.3",
"version": "2.11.4",
"description": "WooCommerce DePay plugin to accept Web3 payments directly into your wallet with on-the-fly conversion.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: web3, payments, woocommerce, depay, cryptocurrency
Requires at least: 6.0
Tested up to: 6.5
Requires PHP: 7.2
Stable tag: 2.11.3
Stable tag: 2.11.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down
4 changes: 2 additions & 2 deletions src/widgets.bundle.js

Large diffs are not rendered by default.

0 comments on commit 4d000a7

Please sign in to comment.