@fiber-pay/runtime 0.1.0-rc.2 → 0.1.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1948,6 +1948,7 @@ var PATTERNS = [
|
|
|
1948
1948
|
// Peer / connectivity
|
|
1949
1949
|
{ pattern: /peer.*offline|peer.*unreachable|peer.*disconnect/i, category: "peer_offline", retryable: true },
|
|
1950
1950
|
{ pattern: /connection.*refused|connection.*reset/i, category: "peer_offline", retryable: true },
|
|
1951
|
+
{ pattern: /fetch failed/i, category: "peer_offline", retryable: true },
|
|
1951
1952
|
{ pattern: /peer.*feature not found|waiting for peer to send init message/i, category: "peer_offline", retryable: true },
|
|
1952
1953
|
{ pattern: /channel.*already.*exist|duplicat(e|ed).*channel/i, category: "temporary_failure", retryable: true },
|
|
1953
1954
|
// Timeout
|
|
@@ -2100,8 +2101,12 @@ function transitionJobState(job, machine, event, options) {
|
|
|
2100
2101
|
}
|
|
2101
2102
|
function applyRetryOrFail(job, classifiedError, policy, options) {
|
|
2102
2103
|
const now = options?.now ?? Date.now();
|
|
2103
|
-
|
|
2104
|
-
|
|
2104
|
+
const effectivePolicy = {
|
|
2105
|
+
...policy,
|
|
2106
|
+
maxRetries: job.maxRetries
|
|
2107
|
+
};
|
|
2108
|
+
if (shouldRetry(classifiedError, job.retryCount, effectivePolicy)) {
|
|
2109
|
+
const delay = computeRetryDelay(job.retryCount, effectivePolicy);
|
|
2105
2110
|
const retryTransition = options?.machine && options.retryEvent ? transitionJobState(job, options.machine, options.retryEvent, { now }) : { ...job, state: "waiting_retry", updatedAt: now };
|
|
2106
2111
|
return {
|
|
2107
2112
|
...retryTransition,
|
|
@@ -2723,7 +2728,7 @@ async function* runChannelJob(job, rpc, policy, signal) {
|
|
|
2723
2728
|
}
|
|
2724
2729
|
throw new Error(`Unsupported channel action: ${current.params.action}`);
|
|
2725
2730
|
} catch (error) {
|
|
2726
|
-
const classified =
|
|
2731
|
+
const classified = classifyChannelError(error);
|
|
2727
2732
|
current = applyRetryOrFail(current, classified, policy, {
|
|
2728
2733
|
machine: channelStateMachine,
|
|
2729
2734
|
retryEvent: "payment_failed_retryable",
|
|
@@ -2732,6 +2737,32 @@ async function* runChannelJob(job, rpc, policy, signal) {
|
|
|
2732
2737
|
yield current;
|
|
2733
2738
|
}
|
|
2734
2739
|
}
|
|
2740
|
+
function classifyChannelError(error) {
|
|
2741
|
+
const base = classifyRpcError(error);
|
|
2742
|
+
if (base.retryable) {
|
|
2743
|
+
return base;
|
|
2744
|
+
}
|
|
2745
|
+
const raw = base.rawError ?? base.message;
|
|
2746
|
+
if (/channel\s+not\s+found|no\s+channel\s+with\s+.*\s+found|no\s+channel\s+.*\s+found/i.test(
|
|
2747
|
+
raw
|
|
2748
|
+
)) {
|
|
2749
|
+
return {
|
|
2750
|
+
...base,
|
|
2751
|
+
category: "temporary_failure",
|
|
2752
|
+
retryable: true,
|
|
2753
|
+
rawError: raw
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
if (/invalid\s+state|negotiatingfunding|cannot\s+.*\s+in\s+.*state/i.test(raw)) {
|
|
2757
|
+
return {
|
|
2758
|
+
...base,
|
|
2759
|
+
category: "temporary_failure",
|
|
2760
|
+
retryable: true,
|
|
2761
|
+
rawError: raw
|
|
2762
|
+
};
|
|
2763
|
+
}
|
|
2764
|
+
return base;
|
|
2765
|
+
}
|
|
2735
2766
|
async function findTargetChannel(rpc, peerId, channelId) {
|
|
2736
2767
|
const channels = await rpc.listChannels({
|
|
2737
2768
|
peer_id: peerId,
|