@atomiqlabs/chain-evm 1.0.0-dev.85 → 1.0.0-dev.87
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.
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReconnectingWebSocketProvider = void 0;
|
|
4
4
|
const SocketProvider_1 = require("./SocketProvider");
|
|
5
|
+
const Utils_1 = require("../../utils/Utils");
|
|
6
|
+
const logger = (0, Utils_1.getLogger)("ReconnectingWebSocketProvider: ");
|
|
5
7
|
class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
6
8
|
constructor(url, network, options) {
|
|
7
9
|
super(network, options);
|
|
@@ -23,7 +25,7 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
23
25
|
this._send({ method: "eth_chainId", params: [], id: 1000000000, jsonrpc: "2.0" }).catch(e => {
|
|
24
26
|
//Error
|
|
25
27
|
if (e.code === "NETWORK_ERROR") {
|
|
26
|
-
|
|
28
|
+
logger.error("connect(): pingInterval: Websocket ping error: ", e);
|
|
27
29
|
if (this.websocket != null) {
|
|
28
30
|
this.websocket.close();
|
|
29
31
|
this.disconnectedAndScheduleReconnect();
|
|
@@ -31,20 +33,21 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
35
|
}, this.pingIntervalSeconds * 1000);
|
|
36
|
+
logger.info("connect(): Websocket connected!");
|
|
34
37
|
};
|
|
35
38
|
this.websocket.onerror = (err) => {
|
|
36
|
-
|
|
39
|
+
logger.error(`connect(): onerror: Websocket connection error: `, err);
|
|
37
40
|
this.disconnectedAndScheduleReconnect();
|
|
38
41
|
};
|
|
39
42
|
this.websocket.onmessage = (message) => {
|
|
40
43
|
this._processMessage(message.data);
|
|
41
44
|
};
|
|
42
45
|
this.websocket.onclose = (event) => {
|
|
43
|
-
|
|
46
|
+
logger.error(`connect(): onclose: Websocket connection closed: `, event);
|
|
44
47
|
this.disconnectedAndScheduleReconnect();
|
|
45
48
|
};
|
|
46
49
|
this.connectTimer = setTimeout(() => {
|
|
47
|
-
|
|
50
|
+
logger.warn("connect(): Websocket connection taking too long, (above " + this.connectionTimeout + " seconds!), closing and re-attempting connection");
|
|
48
51
|
this.websocket.close();
|
|
49
52
|
this.disconnectedAndScheduleReconnect();
|
|
50
53
|
}, this.connectionTimeout * 1000);
|
|
@@ -55,7 +58,8 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
55
58
|
if (this.websocket == null)
|
|
56
59
|
return;
|
|
57
60
|
this.websocket.onclose = null;
|
|
58
|
-
|
|
61
|
+
//Register dummy handler, otherwise we get unhandled `error` event which crashes the whole thing
|
|
62
|
+
this.websocket.onerror = (err) => logger.error("disconnectedAndScheduleReconnect(): Post-close onerror: ", err);
|
|
59
63
|
this.websocket.onmessage = null;
|
|
60
64
|
this.websocket.onopen = null;
|
|
61
65
|
this.websocket = null;
|
|
@@ -64,7 +68,7 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
64
68
|
if (this.connectTimer != null)
|
|
65
69
|
clearInterval(this.connectTimer);
|
|
66
70
|
this._disconnected();
|
|
67
|
-
|
|
71
|
+
logger.info(`disconnectedAndScheduleReconnect(): Retrying in ${this.reconnectSeconds} seconds...`);
|
|
68
72
|
this.reconnectTimer = setTimeout(() => this.connect(), this.reconnectSeconds * 1000);
|
|
69
73
|
}
|
|
70
74
|
async _write(message) {
|
|
@@ -101,8 +101,14 @@ class EVMPersistentSigner extends EVMSigner_1.EVMSigner {
|
|
|
101
101
|
//Too big of an increase over the current fee rate, don't fee bump
|
|
102
102
|
this.logger.debug("checkPastTransactions(): Tx yet unconfirmed but not increasing fee for ", lastTx.hash);
|
|
103
103
|
await this.chainInterface.provider.broadcastTransaction(lastTx.serialized).catch(e => {
|
|
104
|
-
if (e.code === "NONCE_EXPIRED")
|
|
104
|
+
if (e.code === "NONCE_EXPIRED") {
|
|
105
|
+
this.logger.debug("checkPastTransactions(): Tx re-broadcast success, tx already confirmed: ", lastTx.hash);
|
|
105
106
|
return;
|
|
107
|
+
}
|
|
108
|
+
if (e.error?.message === "already known") {
|
|
109
|
+
this.logger.debug("checkPastTransactions(): Tx re-broadcast success, tx already known to the RPC: ", lastTx.hash);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
106
112
|
this.logger.error("checkPastTransactions(): Tx re-broadcast error", e);
|
|
107
113
|
});
|
|
108
114
|
data.lastBumped = Date.now();
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {JsonRpcApiProviderOptions} from "ethers";
|
|
2
2
|
import type {Networkish, WebSocketLike} from "ethers";
|
|
3
3
|
import {SocketProvider} from "./SocketProvider";
|
|
4
|
+
import {getLogger} from "../../utils/Utils";
|
|
4
5
|
|
|
6
|
+
const logger = getLogger("ReconnectingWebSocketProvider: ");
|
|
5
7
|
|
|
6
8
|
export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
7
9
|
|
|
@@ -36,7 +38,7 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
36
38
|
this._send({method: "eth_chainId", params: [], id: 1_000_000_000, jsonrpc: "2.0"}).catch(e => {
|
|
37
39
|
//Error
|
|
38
40
|
if(e.code==="NETWORK_ERROR") {
|
|
39
|
-
|
|
41
|
+
logger.error("connect(): pingInterval: Websocket ping error: ", e);
|
|
40
42
|
if(this.websocket!=null) {
|
|
41
43
|
this.websocket.close();
|
|
42
44
|
this.disconnectedAndScheduleReconnect();
|
|
@@ -44,10 +46,12 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
44
46
|
}
|
|
45
47
|
});
|
|
46
48
|
}, this.pingIntervalSeconds * 1000);
|
|
49
|
+
|
|
50
|
+
logger.info("connect(): Websocket connected!");
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
this.websocket.onerror = (err) => {
|
|
50
|
-
|
|
54
|
+
logger.error(`connect(): onerror: Websocket connection error: `, err);
|
|
51
55
|
this.disconnectedAndScheduleReconnect();
|
|
52
56
|
};
|
|
53
57
|
|
|
@@ -56,12 +60,12 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
this.websocket.onclose = (event) => {
|
|
59
|
-
|
|
63
|
+
logger.error(`connect(): onclose: Websocket connection closed: `, event);
|
|
60
64
|
this.disconnectedAndScheduleReconnect();
|
|
61
65
|
};
|
|
62
66
|
|
|
63
67
|
this.connectTimer = setTimeout(() => {
|
|
64
|
-
|
|
68
|
+
logger.warn("connect(): Websocket connection taking too long, (above "+this.connectionTimeout+" seconds!), closing and re-attempting connection");
|
|
65
69
|
this.websocket.close();
|
|
66
70
|
this.disconnectedAndScheduleReconnect();
|
|
67
71
|
}, this.connectionTimeout * 1000);
|
|
@@ -71,7 +75,8 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
71
75
|
if(this.destroyed) return;
|
|
72
76
|
if(this.websocket==null) return;
|
|
73
77
|
this.websocket.onclose = null;
|
|
74
|
-
|
|
78
|
+
//Register dummy handler, otherwise we get unhandled `error` event which crashes the whole thing
|
|
79
|
+
this.websocket.onerror = (err) => logger.error("disconnectedAndScheduleReconnect(): Post-close onerror: ", err);
|
|
75
80
|
this.websocket.onmessage = null;
|
|
76
81
|
this.websocket.onopen = null;
|
|
77
82
|
this.websocket = null;
|
|
@@ -80,7 +85,7 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
80
85
|
|
|
81
86
|
this._disconnected();
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
logger.info(`disconnectedAndScheduleReconnect(): Retrying in ${this.reconnectSeconds} seconds...`);
|
|
84
89
|
this.reconnectTimer = setTimeout(() => this.connect(), this.reconnectSeconds * 1000);
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -163,7 +163,14 @@ export class EVMPersistentSigner extends EVMSigner {
|
|
|
163
163
|
//Too big of an increase over the current fee rate, don't fee bump
|
|
164
164
|
this.logger.debug("checkPastTransactions(): Tx yet unconfirmed but not increasing fee for ", lastTx.hash);
|
|
165
165
|
await this.chainInterface.provider.broadcastTransaction(lastTx.serialized).catch(e => {
|
|
166
|
-
if(e.code==="NONCE_EXPIRED")
|
|
166
|
+
if(e.code==="NONCE_EXPIRED") {
|
|
167
|
+
this.logger.debug("checkPastTransactions(): Tx re-broadcast success, tx already confirmed: ", lastTx.hash);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if(e.error?.message==="already known") {
|
|
171
|
+
this.logger.debug("checkPastTransactions(): Tx re-broadcast success, tx already known to the RPC: ", lastTx.hash);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
167
174
|
this.logger.error("checkPastTransactions(): Tx re-broadcast error", e)
|
|
168
175
|
});
|
|
169
176
|
data.lastBumped = Date.now();
|