@atomiqlabs/chain-evm 2.4.2 → 2.4.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/evm/btcrelay/EVMBtcRelay.d.ts +2 -0
- package/dist/evm/btcrelay/EVMBtcRelay.js +11 -9
- package/dist/evm/chain/EVMChainInterface.js +1 -1
- package/dist/evm/chain/EVMModule.d.ts +2 -1
- package/dist/evm/chain/EVMModule.js +1 -1
- package/dist/evm/events/EVMChainEventsBrowser.d.ts +2 -1
- package/dist/evm/events/EVMChainEventsBrowser.js +1 -4
- package/dist/evm/providers/ReconnectingWebSocketProvider.d.ts +2 -0
- package/dist/evm/providers/ReconnectingWebSocketProvider.js +22 -8
- package/dist/evm/spv_swap/EVMSpvVaultContract.js +1 -1
- package/dist/evm/swaps/EVMSwapContract.d.ts +1 -0
- package/dist/evm/swaps/EVMSwapContract.js +5 -5
- package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +2 -2
- package/dist/evm/wallet/EVMPersistentSigner.js +1 -1
- package/package.json +1 -1
- package/src/evm/btcrelay/EVMBtcRelay.ts +16 -11
- package/src/evm/chain/EVMChainInterface.ts +1 -1
- package/src/evm/chain/EVMModule.ts +3 -2
- package/src/evm/events/EVMChainEventsBrowser.ts +3 -2
- package/src/evm/providers/ReconnectingWebSocketProvider.ts +21 -11
- package/src/evm/spv_swap/EVMSpvVaultContract.ts +3 -2
- package/src/evm/swaps/EVMSwapContract.ts +9 -7
- package/src/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +0 -1
- package/src/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +2 -2
- package/src/evm/wallet/EVMPersistentSigner.ts +1 -1
|
@@ -13,6 +13,8 @@ import { EVMChainInterface } from "../chain/EVMChainInterface";
|
|
|
13
13
|
* @category BTC Relay
|
|
14
14
|
*/
|
|
15
15
|
export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<BtcRelayTypechain> implements BtcRelay<EVMBtcStoredHeader, EVMTx, B, EVMSigner> {
|
|
16
|
+
private readonly logger;
|
|
17
|
+
readonly chainId: string;
|
|
16
18
|
/**
|
|
17
19
|
* @internal
|
|
18
20
|
*/
|
|
@@ -21,7 +21,6 @@ function serializeBlockHeader(e) {
|
|
|
21
21
|
hash: Buffer.from(e.getHash(), "hex").reverse()
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
const logger = (0, Utils_1.getLogger)("EVMBtcRelay: ");
|
|
25
24
|
/**
|
|
26
25
|
* EVM BTC Relay bitcoin light client contract representation.
|
|
27
26
|
*
|
|
@@ -90,6 +89,8 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
90
89
|
this.commitHashCache = new promise_cache_ts_1.PromiseLruCache(1000);
|
|
91
90
|
this.blockHashCache = new promise_cache_ts_1.PromiseLruCache(1000);
|
|
92
91
|
this._bitcoinRpc = bitcoinRpc;
|
|
92
|
+
this.logger = (0, Utils_1.getLogger)("EVMBtcRelay(" + chainInterface.chainId + "): ");
|
|
93
|
+
this.chainId = chainInterface.chainId;
|
|
93
94
|
}
|
|
94
95
|
/**
|
|
95
96
|
* Computes subsequent committed headers as they will appear on-chain once transactions
|
|
@@ -238,7 +239,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
238
239
|
const chainCommitment = await this.contract.getCommitHash(storedBlockHeader.getBlockheight());
|
|
239
240
|
if (chainCommitment !== commitHash)
|
|
240
241
|
return null;
|
|
241
|
-
logger.debug("retrieveLogAndBlockheight(): block found," +
|
|
242
|
+
this.logger.debug("retrieveLogAndBlockheight(): block found," +
|
|
242
243
|
" commit hash: " + commitHash + " blockhash: " + blockData.blockhash + " current btc relay height: " + blockHeight);
|
|
243
244
|
return { header: storedBlockHeader, height: blockHeight };
|
|
244
245
|
}
|
|
@@ -254,7 +255,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
254
255
|
const chainCommitment = await this.contract.getCommitHash(storedBlockHeader.getBlockheight());
|
|
255
256
|
if (chainCommitment !== commitHash)
|
|
256
257
|
return null;
|
|
257
|
-
logger.debug("retrieveLogByCommitHash(): block found," +
|
|
258
|
+
this.logger.debug("retrieveLogByCommitHash(): block found," +
|
|
258
259
|
" commit hash: " + commitmentHashStr + " blockhash: " + blockData.blockhash + " height: " + storedBlockHeader.getBlockheight());
|
|
259
260
|
return storedBlockHeader;
|
|
260
261
|
}
|
|
@@ -284,7 +285,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
284
285
|
};
|
|
285
286
|
});
|
|
286
287
|
if (data != null)
|
|
287
|
-
logger.debug("retrieveLatestKnownBlockLog(): block found," +
|
|
288
|
+
this.logger.debug("retrieveLatestKnownBlockLog(): block found," +
|
|
288
289
|
" commit hash: " + data.commitHash + " blockhash: " + data.resultBitcoinHeader.getHash() +
|
|
289
290
|
" height: " + data.resultStoredHeader.getBlockheight());
|
|
290
291
|
return data;
|
|
@@ -294,7 +295,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
294
295
|
*/
|
|
295
296
|
async saveMainHeaders(signer, mainHeaders, storedHeader, feeRate) {
|
|
296
297
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
297
|
-
logger.debug("saveMainHeaders(): submitting main blockheaders, count: " + mainHeaders.length);
|
|
298
|
+
this.logger.debug("saveMainHeaders(): submitting main blockheaders, count: " + mainHeaders.length);
|
|
298
299
|
return this._saveHeaders(signer, mainHeaders, storedHeader, 0, feeRate, 0);
|
|
299
300
|
}
|
|
300
301
|
/**
|
|
@@ -303,7 +304,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
303
304
|
async saveNewForkHeaders(signer, forkHeaders, storedHeader, tipWork, feeRate) {
|
|
304
305
|
let forkId = Math.floor(Math.random() * 0xFFFFFFFFFFFF);
|
|
305
306
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
306
|
-
logger.debug("saveNewForkHeaders(): submitting new fork & blockheaders," +
|
|
307
|
+
this.logger.debug("saveNewForkHeaders(): submitting new fork & blockheaders," +
|
|
307
308
|
" count: " + forkHeaders.length + " forkId: 0x" + forkId.toString(16));
|
|
308
309
|
const result = await this._saveHeaders(signer, forkHeaders, storedHeader, forkId, feeRate, 100);
|
|
309
310
|
if (result.forkId !== 0 && base_1.StatePredictorUtils.gtBuffer(result.lastStoredHeader.getChainWork(), tipWork)) {
|
|
@@ -317,7 +318,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
317
318
|
*/
|
|
318
319
|
async saveForkHeaders(signer, forkHeaders, storedHeader, forkId, tipWork, feeRate) {
|
|
319
320
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
320
|
-
logger.debug("saveForkHeaders(): submitting blockheaders to existing fork," +
|
|
321
|
+
this.logger.debug("saveForkHeaders(): submitting blockheaders to existing fork," +
|
|
321
322
|
" count: " + forkHeaders.length + " forkId: 0x" + forkId.toString(16));
|
|
322
323
|
const result = await this._saveHeaders(signer, forkHeaders, storedHeader, forkId, feeRate, 100);
|
|
323
324
|
if (result.forkId !== 0 && base_1.StatePredictorUtils.gtBuffer(result.lastStoredHeader.getChainWork(), tipWork)) {
|
|
@@ -331,7 +332,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
331
332
|
*/
|
|
332
333
|
async saveShortForkHeaders(signer, forkHeaders, storedHeader, tipWork, feeRate) {
|
|
333
334
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
334
|
-
logger.debug("saveShortForkHeaders(): submitting short fork blockheaders," +
|
|
335
|
+
this.logger.debug("saveShortForkHeaders(): submitting short fork blockheaders," +
|
|
335
336
|
" count: " + forkHeaders.length);
|
|
336
337
|
const result = await this._saveHeaders(signer, forkHeaders, storedHeader, -1, feeRate, 0);
|
|
337
338
|
if (result.forkId !== 0 && base_1.StatePredictorUtils.gtBuffer(result.lastStoredHeader.getChainWork(), tipWork)) {
|
|
@@ -354,7 +355,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
354
355
|
return 0n;
|
|
355
356
|
const synchronizationFee = (BigInt(blockheightDelta) * await this.getFeePerBlock(feeRate))
|
|
356
357
|
+ EVMFees_1.EVMFees.getGasFee(EVMBtcRelay._GasCosts.GAS_BASE_MAIN * Math.ceil(blockheightDelta / this.maxHeadersPerTx), feeRate);
|
|
357
|
-
logger.debug("estimateSynchronizeFee(): required blockheight: " + requiredBlockheight +
|
|
358
|
+
this.logger.debug("estimateSynchronizeFee(): required blockheight: " + requiredBlockheight +
|
|
358
359
|
" blockheight delta: " + blockheightDelta + " fee: " + synchronizationFee.toString(10));
|
|
359
360
|
return synchronizationFee;
|
|
360
361
|
}
|
|
@@ -421,6 +422,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
421
422
|
return null;
|
|
422
423
|
//TODO: We don't have to synchronize to tip, only to our required blockheight
|
|
423
424
|
const resp = await synchronizer.syncToLatestTxs(signer.toString(), feeRate);
|
|
425
|
+
const logger = (0, Utils_1.getLogger)("EVMBtcRelay(" + btcRelay.Chain.chainId + "): ");
|
|
424
426
|
logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay not synchronized to required blockheight, " +
|
|
425
427
|
"synchronizing ourselves in " + resp.txs.length + " txs");
|
|
426
428
|
logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay computed header map: ", resp.computedHeaderMap);
|
|
@@ -30,7 +30,7 @@ class EVMChainInterface {
|
|
|
30
30
|
(_c = this._config).finalityCheckStrategy ?? (_c.finalityCheckStrategy = { type: "timer" });
|
|
31
31
|
(_d = this._config.finalityCheckStrategy).delayMs ?? (_d.delayMs = 1000);
|
|
32
32
|
this.bitcoinNetwork = bitcoinNetwork;
|
|
33
|
-
this.logger = (0, Utils_1.getLogger)("EVMChainInterface(" + this.
|
|
33
|
+
this.logger = (0, Utils_1.getLogger)("EVMChainInterface(" + this.chainId + "): ");
|
|
34
34
|
this.Fees = evmFeeEstimator;
|
|
35
35
|
this.Tokens = new EVMTokens_1.EVMTokens(this);
|
|
36
36
|
this.Transactions = new EVMTransactions_1.EVMTransactions(this);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LoggerType } from "../../utils/Utils";
|
|
1
2
|
import { JsonRpcApiProvider } from "ethers";
|
|
2
3
|
import { EVMChainInterface, EVMRetryPolicy } from "./EVMChainInterface";
|
|
3
4
|
/**
|
|
@@ -9,6 +10,6 @@ export declare class EVMModule<ChainId extends string = string> {
|
|
|
9
10
|
protected readonly provider: JsonRpcApiProvider;
|
|
10
11
|
protected readonly retryPolicy?: EVMRetryPolicy;
|
|
11
12
|
protected readonly root: EVMChainInterface<ChainId>;
|
|
12
|
-
protected readonly logger:
|
|
13
|
+
protected readonly logger: LoggerType;
|
|
13
14
|
constructor(root: EVMChainInterface<ChainId>);
|
|
14
15
|
}
|
|
@@ -9,10 +9,10 @@ const Utils_1 = require("../../utils/Utils");
|
|
|
9
9
|
*/
|
|
10
10
|
class EVMModule {
|
|
11
11
|
constructor(root) {
|
|
12
|
-
this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
|
|
13
12
|
this.provider = root.provider;
|
|
14
13
|
this.retryPolicy = root._retryPolicy;
|
|
15
14
|
this.root = root;
|
|
15
|
+
this.logger = (0, Utils_1.getLogger)(this.constructor.name + "(" + root.chainId + "): ");
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.EVMModule = EVMModule;
|
|
@@ -2,6 +2,7 @@ import { ChainEvents, EventListener } from "@atomiqlabs/base";
|
|
|
2
2
|
import { EVMSwapData } from "../swaps/EVMSwapData";
|
|
3
3
|
import { Block, JsonRpcApiProvider, EventFilter, Log } from "ethers";
|
|
4
4
|
import { EVMSwapContract } from "../swaps/EVMSwapContract";
|
|
5
|
+
import { LoggerType } from "../../utils/Utils";
|
|
5
6
|
import { EVMSpvVaultContract } from "../spv_swap/EVMSpvVaultContract";
|
|
6
7
|
import { EVMChainInterface } from "../chain/EVMChainInterface";
|
|
7
8
|
import { TypedEventLog } from "../typechain/common";
|
|
@@ -55,7 +56,7 @@ export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, E
|
|
|
55
56
|
/**
|
|
56
57
|
* @internal
|
|
57
58
|
*/
|
|
58
|
-
protected readonly logger:
|
|
59
|
+
protected readonly logger: LoggerType;
|
|
59
60
|
/**
|
|
60
61
|
* @internal
|
|
61
62
|
*/
|
|
@@ -22,10 +22,6 @@ class EVMChainEventsBrowser {
|
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
24
|
this.listeners = [];
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
this.logger = (0, Utils_1.getLogger)("EVMChainEventsBrowser: ");
|
|
29
25
|
/**
|
|
30
26
|
* @internal
|
|
31
27
|
*/
|
|
@@ -47,6 +43,7 @@ class EVMChainEventsBrowser {
|
|
|
47
43
|
this.evmSwapContract = evmSwapContract;
|
|
48
44
|
this.evmSpvVaultContract = evmSpvVaultContract;
|
|
49
45
|
this.pollIntervalSeconds = pollIntervalSeconds;
|
|
46
|
+
this.logger = (0, Utils_1.getLogger)("EVMChainEventsBrowser(" + evmSwapContract.chainId + "): ");
|
|
50
47
|
this.spvVaultContractLogFilter = {
|
|
51
48
|
address: this.evmSpvVaultContract._contractAddress
|
|
52
49
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JsonRpcApiProviderOptions } from "ethers";
|
|
2
2
|
import type { Networkish, WebSocketLike } from "ethers";
|
|
3
3
|
import { SocketProvider } from "./SocketProvider";
|
|
4
|
+
import { LoggerType } from "../../utils/Utils";
|
|
4
5
|
/**
|
|
5
6
|
* WebSocket RPC provider with automatic reconnect, heartbeat ping and connection timeout handling.
|
|
6
7
|
*
|
|
@@ -19,6 +20,7 @@ export declare class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
19
20
|
onclose?: (...args: any[]) => void;
|
|
20
21
|
ping?: () => void;
|
|
21
22
|
});
|
|
23
|
+
readonly logger: LoggerType;
|
|
22
24
|
constructor(url: string | (() => WebSocketLike), network?: Networkish, options?: JsonRpcApiProviderOptions);
|
|
23
25
|
private connect;
|
|
24
26
|
private disconnectedAndScheduleReconnect;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReconnectingWebSocketProvider = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
4
5
|
const SocketProvider_1 = require("./SocketProvider");
|
|
5
6
|
const Utils_1 = require("../../utils/Utils");
|
|
6
|
-
|
|
7
|
+
function getChainIdentifier(network) {
|
|
8
|
+
if (network == null)
|
|
9
|
+
return "UNKNOWN";
|
|
10
|
+
if (typeof (network) === "bigint")
|
|
11
|
+
return network.toString(10);
|
|
12
|
+
if (typeof (network) === "number")
|
|
13
|
+
return network.toString(10);
|
|
14
|
+
if (typeof (network) === "string")
|
|
15
|
+
return network;
|
|
16
|
+
if (network instanceof ethers_1.Network)
|
|
17
|
+
return network.name ?? network.chainId.toString(10);
|
|
18
|
+
return network.name ?? network.chainId?.toString(10) ?? "UNKNOWN";
|
|
19
|
+
}
|
|
7
20
|
/**
|
|
8
21
|
* WebSocket RPC provider with automatic reconnect, heartbeat ping and connection timeout handling.
|
|
9
22
|
*
|
|
@@ -17,6 +30,7 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
17
30
|
this.pingIntervalSeconds = 30;
|
|
18
31
|
this.connectionTimeout = 10;
|
|
19
32
|
this.websocket = null;
|
|
33
|
+
this.logger = (0, Utils_1.getLogger)("ReconnectingWebSocketProvider(" + getChainIdentifier(network) + "): ");
|
|
20
34
|
this.wsCtor = typeof (url) === "string" ? () => new WebSocket(url) : url;
|
|
21
35
|
this.connect();
|
|
22
36
|
}
|
|
@@ -31,7 +45,7 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
31
45
|
this._send({ method: "eth_chainId", params: [], id: 1000000000, jsonrpc: "2.0" }).catch(e => {
|
|
32
46
|
//Error
|
|
33
47
|
if (e.code === "NETWORK_ERROR") {
|
|
34
|
-
logger.error("connect(): pingInterval: Websocket ping error: ", e);
|
|
48
|
+
this.logger.error("connect(): pingInterval: Websocket ping error: ", e);
|
|
35
49
|
if (this.websocket != null) {
|
|
36
50
|
this.websocket.close();
|
|
37
51
|
this.disconnectedAndScheduleReconnect();
|
|
@@ -39,21 +53,21 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
39
53
|
}
|
|
40
54
|
});
|
|
41
55
|
}, this.pingIntervalSeconds * 1000);
|
|
42
|
-
logger.info("connect(): Websocket connected!");
|
|
56
|
+
this.logger.info("connect(): Websocket connected!");
|
|
43
57
|
};
|
|
44
58
|
this.websocket.onerror = (err) => {
|
|
45
|
-
logger.error(`connect(): onerror: Websocket connection error: `, err.error ?? err);
|
|
59
|
+
this.logger.error(`connect(): onerror: Websocket connection error: `, err.error ?? err);
|
|
46
60
|
this.disconnectedAndScheduleReconnect();
|
|
47
61
|
};
|
|
48
62
|
this.websocket.onmessage = (message) => {
|
|
49
63
|
this._processMessage(message.data);
|
|
50
64
|
};
|
|
51
65
|
this.websocket.onclose = (event) => {
|
|
52
|
-
logger.error(`connect(): onclose: Websocket connection closed: `, event);
|
|
66
|
+
this.logger.error(`connect(): onclose: Websocket connection closed: `, event);
|
|
53
67
|
this.disconnectedAndScheduleReconnect();
|
|
54
68
|
};
|
|
55
69
|
this.connectTimer = setTimeout(() => {
|
|
56
|
-
logger.warn("connect(): Websocket connection taking too long, (above " + this.connectionTimeout + " seconds!), closing and re-attempting connection");
|
|
70
|
+
this.logger.warn("connect(): Websocket connection taking too long, (above " + this.connectionTimeout + " seconds!), closing and re-attempting connection");
|
|
57
71
|
this.websocket.close();
|
|
58
72
|
this.disconnectedAndScheduleReconnect();
|
|
59
73
|
}, this.connectionTimeout * 1000);
|
|
@@ -65,7 +79,7 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
65
79
|
return;
|
|
66
80
|
this.websocket.onclose = undefined;
|
|
67
81
|
//Register dummy handler, otherwise we get unhandled `error` event which crashes the whole thing
|
|
68
|
-
this.websocket.onerror = (err) => logger.error("disconnectedAndScheduleReconnect(): Post-close onerror: ", err.error ?? err);
|
|
82
|
+
this.websocket.onerror = (err) => this.logger.error("disconnectedAndScheduleReconnect(): Post-close onerror: ", err.error ?? err);
|
|
69
83
|
this.websocket.onmessage = null;
|
|
70
84
|
this.websocket.onopen = null;
|
|
71
85
|
this.websocket = null;
|
|
@@ -74,7 +88,7 @@ class ReconnectingWebSocketProvider extends SocketProvider_1.SocketProvider {
|
|
|
74
88
|
if (this.connectTimer != null)
|
|
75
89
|
clearInterval(this.connectTimer);
|
|
76
90
|
this._disconnected();
|
|
77
|
-
logger.info(`disconnectedAndScheduleReconnect(): Retrying in ${this.reconnectSeconds} seconds...`);
|
|
91
|
+
this.logger.info(`disconnectedAndScheduleReconnect(): Retrying in ${this.reconnectSeconds} seconds...`);
|
|
78
92
|
this.reconnectTimer = setTimeout(() => this.connect(), this.reconnectSeconds * 1000);
|
|
79
93
|
}
|
|
80
94
|
async _write(message) {
|
|
@@ -49,8 +49,8 @@ class EVMSpvVaultContract extends EVMContractBase_1.EVMContractBase {
|
|
|
49
49
|
constructor(chainInterface, btcRelay, bitcoinRpc, contractAddress, contractDeploymentHeight) {
|
|
50
50
|
super(chainInterface, contractAddress, SpvVaultContractAbi_1.SpvVaultContractAbi, contractDeploymentHeight);
|
|
51
51
|
this.claimTimeout = 180;
|
|
52
|
-
this.logger = (0, Utils_1.getLogger)("EVMSpvVaultContract: ");
|
|
53
52
|
this.vaultParamsCache = new promise_cache_ts_1.PromiseLruCache(5000);
|
|
53
|
+
this.logger = (0, Utils_1.getLogger)("EVMSpvVaultContract(" + chainInterface.chainId + "): ");
|
|
54
54
|
this.chainId = chainInterface.chainId;
|
|
55
55
|
this.btcRelay = btcRelay;
|
|
56
56
|
this.bitcoinRpc = bitcoinRpc;
|
|
@@ -23,6 +23,7 @@ import { EVMSwapClaim } from "./modules/EVMSwapClaim";
|
|
|
23
23
|
* @category Swaps
|
|
24
24
|
*/
|
|
25
25
|
export declare class EVMSwapContract<ChainId extends string = string> extends EVMContractBase<EscrowManager> implements SwapContract<EVMSwapData, EVMTx, never, EVMPreFetchVerification, EVMSigner, ChainId> {
|
|
26
|
+
private readonly logger;
|
|
26
27
|
readonly supportsInitWithoutClaimer = true;
|
|
27
28
|
readonly chainId: ChainId;
|
|
28
29
|
readonly claimWithSecretTimeout: number;
|
|
@@ -18,7 +18,6 @@ const Utils_1 = require("../../utils/Utils");
|
|
|
18
18
|
const ESCROW_STATE_COMMITTED = 1;
|
|
19
19
|
const ESCROW_STATE_CLAIMED = 2;
|
|
20
20
|
const ESCROW_STATE_REFUNDED = 3;
|
|
21
|
-
const logger = (0, Utils_1.getLogger)("EVMSwapContract: ");
|
|
22
21
|
/**
|
|
23
22
|
* EVM swap contract (escrow manager) representation handling PrTLC (on-chain) and HTLC (lightning)
|
|
24
23
|
* based swaps.
|
|
@@ -67,6 +66,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
67
66
|
});
|
|
68
67
|
this._timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
|
|
69
68
|
this._refundHandlersByAddress[this._timelockRefundHandler.address.toLowerCase()] = this._timelockRefundHandler;
|
|
69
|
+
this.logger = (0, Utils_1.getLogger)("EVMSwapContract(" + this.chainId + "): ");
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* @inheritDoc
|
|
@@ -346,13 +346,13 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
346
346
|
const claimHandlerHex = event.args.claimHandler;
|
|
347
347
|
const claimHandler = this._claimHandlersByAddress[claimHandlerHex.toLowerCase()];
|
|
348
348
|
if (claimHandler == null) {
|
|
349
|
-
logger.warn(`getHistoricalSwaps(): Unknown claim handler in tx ${event.transactionHash} with claim handler: ` + claimHandlerHex);
|
|
349
|
+
this.logger.warn(`getHistoricalSwaps(): Unknown claim handler in tx ${event.transactionHash} with claim handler: ` + claimHandlerHex);
|
|
350
350
|
return null;
|
|
351
351
|
}
|
|
352
352
|
const txTrace = await this.Chain.Transactions.traceTransaction(event.transactionHash);
|
|
353
353
|
const data = this.findInitSwapData(txTrace, event.args.escrowHash, claimHandler);
|
|
354
354
|
if (data == null) {
|
|
355
|
-
logger.warn(`getHistoricalSwaps(): Cannot parse swap data from tx ${event.transactionHash} with escrow hash: ` + escrowHash);
|
|
355
|
+
this.logger.warn(`getHistoricalSwaps(): Cannot parse swap data from tx ${event.transactionHash} with escrow hash: ` + escrowHash);
|
|
356
356
|
return null;
|
|
357
357
|
}
|
|
358
358
|
swapsOpened[escrowHash] = {
|
|
@@ -410,8 +410,8 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
410
410
|
//We have to fetch separately the different directions
|
|
411
411
|
await this._Events.findInContractEventsForward(["Initialize", "Claim", "Refund"], [signer, null], processor, startBlockheight);
|
|
412
412
|
await this._Events.findInContractEventsForward(["Initialize", "Claim", "Refund"], [null, signer], processor, startBlockheight);
|
|
413
|
-
logger.debug(`getHistoricalSwaps(): Found ${Object.keys(resultingSwaps).length} settled swaps!`);
|
|
414
|
-
logger.debug(`getHistoricalSwaps(): Found ${Object.keys(swapsOpened).length} unsettled swaps!`);
|
|
413
|
+
this.logger.debug(`getHistoricalSwaps(): Found ${Object.keys(resultingSwaps).length} settled swaps!`);
|
|
414
|
+
this.logger.debug(`getHistoricalSwaps(): Found ${Object.keys(swapsOpened).length} unsettled swaps!`);
|
|
415
415
|
for (let escrowHash in swapsOpened) {
|
|
416
416
|
const foundSwapData = swapsOpened[escrowHash];
|
|
417
417
|
resultingSwaps[escrowHash] = {
|
|
@@ -6,7 +6,7 @@ const EVMBtcRelay_1 = require("../../../../btcrelay/EVMBtcRelay");
|
|
|
6
6
|
const Utils_1 = require("../../../../../utils/Utils");
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const buffer_1 = require("buffer");
|
|
9
|
-
const logger = (0, Utils_1.getLogger)("IBitcoinClaimHandler
|
|
9
|
+
const logger = (0, Utils_1.getLogger)("IBitcoinClaimHandler");
|
|
10
10
|
/**
|
|
11
11
|
* Shared base implementation for bitcoin-backed claim handlers.
|
|
12
12
|
*
|
|
@@ -37,7 +37,7 @@ class IBitcoinClaimHandler {
|
|
|
37
37
|
const merkleProof = await btcRelay._bitcoinRpc.getMerkleProof(tx.txid, tx.blockhash);
|
|
38
38
|
if (merkleProof == null)
|
|
39
39
|
throw new Error(`Failed to generate merkle proof for tx: ${tx.txid}!`);
|
|
40
|
-
logger.debug("getWitness(): merkle proof computed: ", merkleProof);
|
|
40
|
+
logger.debug("(" + btcRelay.chainId + "): getWitness(): merkle proof computed: ", merkleProof);
|
|
41
41
|
const txs = [];
|
|
42
42
|
if (commitedHeader == null) {
|
|
43
43
|
const headers = await EVMBtcRelay_1.EVMBtcRelay.getCommitedHeadersAndSynchronize(signer, btcRelay, [{ blockheight: tx.height, requiredConfirmations, blockhash: tx.blockhash }], txs, synchronizer, feeRate);
|
|
@@ -32,7 +32,7 @@ class EVMPersistentSigner extends EVMSigner_1.EVMSigner {
|
|
|
32
32
|
this.minFeeIncreasePpm = minFeeIncreasePpm ?? MIN_FEE_INCREASE_PPM;
|
|
33
33
|
this.waitBeforeBump = waitBeforeBumpMillis ?? WAIT_BEFORE_BUMP;
|
|
34
34
|
this.safeBlockTag = chainInterface._config.safeBlockTag;
|
|
35
|
-
this.logger = (0, Utils_1.getLogger)("EVMPersistentSigner(" + address + "): ");
|
|
35
|
+
this.logger = (0, Utils_1.getLogger)("EVMPersistentSigner(" + this.chainInterface.chainId + "," + address + "): ");
|
|
36
36
|
}
|
|
37
37
|
async load() {
|
|
38
38
|
const fileExists = await fs.access(this.directory + "/txs.json", fs.constants.F_OK).then(() => true).catch(() => false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {BitcoinNetwork, BitcoinRpc, BtcBlock, BtcRelay, RelaySynchronizer, StatePredictorUtils} from "@atomiqlabs/base";
|
|
2
2
|
import {EVMBtcHeader} from "./headers/EVMBtcHeader";
|
|
3
|
-
import {getLogger} from "../../utils/Utils";
|
|
3
|
+
import {getLogger, LoggerType} from "../../utils/Utils";
|
|
4
4
|
import {EVMContractBase, TypedFunctionCall} from "../contract/EVMContractBase";
|
|
5
5
|
import {BtcRelay as BtcRelayTypechain} from "./BtcRelayTypechain";
|
|
6
6
|
import {EVMBtcStoredHeader} from "./headers/EVMBtcStoredHeader";
|
|
@@ -24,8 +24,6 @@ function serializeBlockHeader(e: BtcBlock): EVMBtcHeader {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const logger = getLogger("EVMBtcRelay: ");
|
|
28
|
-
|
|
29
27
|
/**
|
|
30
28
|
* EVM BTC Relay bitcoin light client contract representation.
|
|
31
29
|
*
|
|
@@ -35,6 +33,10 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
35
33
|
extends EVMContractBase<BtcRelayTypechain>
|
|
36
34
|
implements BtcRelay<EVMBtcStoredHeader, EVMTx, B, EVMSigner> {
|
|
37
35
|
|
|
36
|
+
private readonly logger: LoggerType;
|
|
37
|
+
|
|
38
|
+
readonly chainId: string;
|
|
39
|
+
|
|
38
40
|
/**
|
|
39
41
|
* @internal
|
|
40
42
|
*/
|
|
@@ -118,6 +120,8 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
118
120
|
) {
|
|
119
121
|
super(chainInterface, contractAddress, BtcRelayAbi, contractDeploymentHeight);
|
|
120
122
|
this._bitcoinRpc = bitcoinRpc;
|
|
123
|
+
this.logger = getLogger("EVMBtcRelay("+chainInterface.chainId+"): ");
|
|
124
|
+
this.chainId = chainInterface.chainId;
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
/**
|
|
@@ -298,7 +302,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
298
302
|
const chainCommitment = await this.contract.getCommitHash(storedBlockHeader.getBlockheight());
|
|
299
303
|
if(chainCommitment!==commitHash) return null;
|
|
300
304
|
|
|
301
|
-
logger.debug("retrieveLogAndBlockheight(): block found," +
|
|
305
|
+
this.logger.debug("retrieveLogAndBlockheight(): block found," +
|
|
302
306
|
" commit hash: "+commitHash+" blockhash: "+blockData.blockhash+" current btc relay height: "+blockHeight);
|
|
303
307
|
|
|
304
308
|
return {header: storedBlockHeader, height: blockHeight};
|
|
@@ -317,7 +321,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
317
321
|
const chainCommitment = await this.contract.getCommitHash(storedBlockHeader.getBlockheight());
|
|
318
322
|
if(chainCommitment!==commitHash) return null;
|
|
319
323
|
|
|
320
|
-
logger.debug("retrieveLogByCommitHash(): block found," +
|
|
324
|
+
this.logger.debug("retrieveLogByCommitHash(): block found," +
|
|
321
325
|
" commit hash: "+commitmentHashStr+" blockhash: "+blockData.blockhash+" height: "+storedBlockHeader.getBlockheight());
|
|
322
326
|
|
|
323
327
|
return storedBlockHeader;
|
|
@@ -357,7 +361,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
357
361
|
}
|
|
358
362
|
)
|
|
359
363
|
|
|
360
|
-
if(data!=null) logger.debug("retrieveLatestKnownBlockLog(): block found," +
|
|
364
|
+
if(data!=null) this.logger.debug("retrieveLatestKnownBlockLog(): block found," +
|
|
361
365
|
" commit hash: "+data.commitHash+" blockhash: "+data.resultBitcoinHeader.getHash()+
|
|
362
366
|
" height: "+data.resultStoredHeader.getBlockheight());
|
|
363
367
|
|
|
@@ -369,7 +373,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
369
373
|
*/
|
|
370
374
|
public async saveMainHeaders(signer: string, mainHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, feeRate?: string) {
|
|
371
375
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
372
|
-
logger.debug("saveMainHeaders(): submitting main blockheaders, count: "+mainHeaders.length);
|
|
376
|
+
this.logger.debug("saveMainHeaders(): submitting main blockheaders, count: "+mainHeaders.length);
|
|
373
377
|
return this._saveHeaders(signer, mainHeaders, storedHeader, 0, feeRate, 0);
|
|
374
378
|
}
|
|
375
379
|
|
|
@@ -380,7 +384,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
380
384
|
let forkId: number = Math.floor(Math.random() * 0xFFFFFFFFFFFF);
|
|
381
385
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
382
386
|
|
|
383
|
-
logger.debug("saveNewForkHeaders(): submitting new fork & blockheaders," +
|
|
387
|
+
this.logger.debug("saveNewForkHeaders(): submitting new fork & blockheaders," +
|
|
384
388
|
" count: "+forkHeaders.length+" forkId: 0x"+forkId.toString(16));
|
|
385
389
|
|
|
386
390
|
const result = await this._saveHeaders(signer, forkHeaders, storedHeader, forkId, feeRate, 100);
|
|
@@ -397,7 +401,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
397
401
|
public async saveForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, forkId: number, tipWork: Buffer, feeRate?: string) {
|
|
398
402
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
399
403
|
|
|
400
|
-
logger.debug("saveForkHeaders(): submitting blockheaders to existing fork," +
|
|
404
|
+
this.logger.debug("saveForkHeaders(): submitting blockheaders to existing fork," +
|
|
401
405
|
" count: "+forkHeaders.length+" forkId: 0x"+forkId.toString(16));
|
|
402
406
|
|
|
403
407
|
const result = await this._saveHeaders(signer, forkHeaders, storedHeader, forkId, feeRate, 100);
|
|
@@ -414,7 +418,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
414
418
|
public async saveShortForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, tipWork: Buffer, feeRate?: string) {
|
|
415
419
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
416
420
|
|
|
417
|
-
logger.debug("saveShortForkHeaders(): submitting short fork blockheaders," +
|
|
421
|
+
this.logger.debug("saveShortForkHeaders(): submitting short fork blockheaders," +
|
|
418
422
|
" count: "+forkHeaders.length);
|
|
419
423
|
|
|
420
424
|
const result = await this._saveHeaders(signer, forkHeaders, storedHeader, -1, feeRate, 0);
|
|
@@ -441,7 +445,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
441
445
|
|
|
442
446
|
const synchronizationFee = (BigInt(blockheightDelta) * await this.getFeePerBlock(feeRate))
|
|
443
447
|
+ EVMFees.getGasFee(EVMBtcRelay._GasCosts.GAS_BASE_MAIN * Math.ceil(blockheightDelta / this.maxHeadersPerTx), feeRate);
|
|
444
|
-
logger.debug("estimateSynchronizeFee(): required blockheight: "+requiredBlockheight+
|
|
448
|
+
this.logger.debug("estimateSynchronizeFee(): required blockheight: "+requiredBlockheight+
|
|
445
449
|
" blockheight delta: "+blockheightDelta+" fee: "+synchronizationFee.toString(10));
|
|
446
450
|
|
|
447
451
|
return synchronizationFee;
|
|
@@ -529,6 +533,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
529
533
|
|
|
530
534
|
//TODO: We don't have to synchronize to tip, only to our required blockheight
|
|
531
535
|
const resp = await synchronizer.syncToLatestTxs(signer.toString(), feeRate);
|
|
536
|
+
const logger = getLogger("EVMBtcRelay("+btcRelay.Chain.chainId+"): ");
|
|
532
537
|
logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay not synchronized to required blockheight, "+
|
|
533
538
|
"synchronizing ourselves in "+resp.txs.length+" txs");
|
|
534
539
|
logger.debug("getCommitedHeaderAndSynchronize(): BTC Relay computed header map: ",resp.computedHeaderMap);
|
|
@@ -151,7 +151,7 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
151
151
|
|
|
152
152
|
this.bitcoinNetwork = bitcoinNetwork;
|
|
153
153
|
|
|
154
|
-
this.logger = getLogger("EVMChainInterface("+this.
|
|
154
|
+
this.logger = getLogger("EVMChainInterface("+this.chainId+"): ");
|
|
155
155
|
|
|
156
156
|
this.Fees = evmFeeEstimator;
|
|
157
157
|
this.Tokens = new EVMTokens(this);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {getLogger} from "../../utils/Utils";
|
|
1
|
+
import {getLogger, LoggerType} from "../../utils/Utils";
|
|
2
2
|
import {JsonRpcApiProvider} from "ethers";
|
|
3
3
|
import {EVMChainInterface, EVMRetryPolicy} from "./EVMChainInterface";
|
|
4
4
|
|
|
@@ -13,7 +13,7 @@ export class EVMModule<ChainId extends string = string> {
|
|
|
13
13
|
protected readonly retryPolicy?: EVMRetryPolicy;
|
|
14
14
|
protected readonly root: EVMChainInterface<ChainId>;
|
|
15
15
|
|
|
16
|
-
protected readonly logger
|
|
16
|
+
protected readonly logger: LoggerType;
|
|
17
17
|
|
|
18
18
|
constructor(
|
|
19
19
|
root: EVMChainInterface<ChainId>
|
|
@@ -21,6 +21,7 @@ export class EVMModule<ChainId extends string = string> {
|
|
|
21
21
|
this.provider = root.provider;
|
|
22
22
|
this.retryPolicy = root._retryPolicy;
|
|
23
23
|
this.root = root;
|
|
24
|
+
this.logger = getLogger(this.constructor.name+"("+root.chainId+"): ");
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
}
|
|
@@ -11,7 +11,7 @@ import {IClaimHandler} from "../swaps/handlers/claim/ClaimHandlers";
|
|
|
11
11
|
import {EVMSwapData} from "../swaps/EVMSwapData";
|
|
12
12
|
import {Block, hexlify, JsonRpcApiProvider, EventFilter, Log} from "ethers";
|
|
13
13
|
import { EVMSwapContract } from "../swaps/EVMSwapContract";
|
|
14
|
-
import {getLogger, onceAsync} from "../../utils/Utils";
|
|
14
|
+
import {getLogger, LoggerType, onceAsync} from "../../utils/Utils";
|
|
15
15
|
import {EVMSpvVaultContract, unpackOwnerAndVaultId} from "../spv_swap/EVMSpvVaultContract";
|
|
16
16
|
import { EVMChainInterface } from "../chain/EVMChainInterface";
|
|
17
17
|
import {TypedEventLog} from "../typechain/common";
|
|
@@ -75,7 +75,7 @@ export class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventL
|
|
|
75
75
|
/**
|
|
76
76
|
* @internal
|
|
77
77
|
*/
|
|
78
|
-
protected readonly logger
|
|
78
|
+
protected readonly logger: LoggerType;
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* @internal
|
|
@@ -118,6 +118,7 @@ export class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventL
|
|
|
118
118
|
this.evmSwapContract = evmSwapContract;
|
|
119
119
|
this.evmSpvVaultContract = evmSpvVaultContract;
|
|
120
120
|
this.pollIntervalSeconds = pollIntervalSeconds;
|
|
121
|
+
this.logger = getLogger("EVMChainEventsBrowser("+evmSwapContract.chainId+"): ");
|
|
121
122
|
|
|
122
123
|
this.spvVaultContractLogFilter = {
|
|
123
124
|
address: this.evmSpvVaultContract._contractAddress
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {JsonRpcApiProviderOptions} from "ethers";
|
|
1
|
+
import {JsonRpcApiProviderOptions, Network} from "ethers";
|
|
2
2
|
import type {Networkish, WebSocketLike} from "ethers";
|
|
3
3
|
import {SocketProvider} from "./SocketProvider";
|
|
4
|
-
import {getLogger} from "../../utils/Utils";
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {getLogger, LoggerType} from "../../utils/Utils";
|
|
5
|
+
|
|
6
|
+
function getChainIdentifier(network?: Networkish): string {
|
|
7
|
+
if(network==null) return "UNKNOWN";
|
|
8
|
+
if(typeof(network)==="bigint") return network.toString(10);
|
|
9
|
+
if(typeof(network)==="number") return network.toString(10);
|
|
10
|
+
if(typeof(network)==="string") return network;
|
|
11
|
+
if(network instanceof Network) return network.name ?? network.chainId.toString(10);
|
|
12
|
+
return network.name ?? network.chainId?.toString(10) ?? "UNKNOWN";
|
|
13
|
+
}
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
16
|
* WebSocket RPC provider with automatic reconnect, heartbeat ping and connection timeout handling.
|
|
@@ -24,8 +31,11 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
24
31
|
wsCtor: () => WebSocketLike;
|
|
25
32
|
websocket: null | WebSocketLike & {onclose?: (...args: any[]) => void, ping?: () => void} = null;
|
|
26
33
|
|
|
34
|
+
readonly logger: LoggerType;
|
|
35
|
+
|
|
27
36
|
constructor(url: string | (() => WebSocketLike), network?: Networkish, options?: JsonRpcApiProviderOptions) {
|
|
28
37
|
super(network, options);
|
|
38
|
+
this.logger = getLogger("ReconnectingWebSocketProvider("+getChainIdentifier(network)+"): ");
|
|
29
39
|
this.wsCtor = typeof(url)==="string" ? () => new WebSocket(url) : url;
|
|
30
40
|
this.connect();
|
|
31
41
|
}
|
|
@@ -43,7 +53,7 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
43
53
|
this._send({method: "eth_chainId", params: [], id: 1_000_000_000, jsonrpc: "2.0"}).catch(e => {
|
|
44
54
|
//Error
|
|
45
55
|
if(e.code==="NETWORK_ERROR") {
|
|
46
|
-
logger.error("connect(): pingInterval: Websocket ping error: ", e);
|
|
56
|
+
this.logger.error("connect(): pingInterval: Websocket ping error: ", e);
|
|
47
57
|
if(this.websocket!=null) {
|
|
48
58
|
this.websocket.close();
|
|
49
59
|
this.disconnectedAndScheduleReconnect();
|
|
@@ -52,11 +62,11 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
52
62
|
});
|
|
53
63
|
}, this.pingIntervalSeconds * 1000);
|
|
54
64
|
|
|
55
|
-
logger.info("connect(): Websocket connected!");
|
|
65
|
+
this.logger.info("connect(): Websocket connected!");
|
|
56
66
|
};
|
|
57
67
|
|
|
58
68
|
this.websocket.onerror = (err) => {
|
|
59
|
-
logger.error(`connect(): onerror: Websocket connection error: `, err.error ?? err);
|
|
69
|
+
this.logger.error(`connect(): onerror: Websocket connection error: `, err.error ?? err);
|
|
60
70
|
this.disconnectedAndScheduleReconnect();
|
|
61
71
|
};
|
|
62
72
|
|
|
@@ -65,12 +75,12 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
65
75
|
};
|
|
66
76
|
|
|
67
77
|
this.websocket.onclose = (event) => {
|
|
68
|
-
logger.error(`connect(): onclose: Websocket connection closed: `, event);
|
|
78
|
+
this.logger.error(`connect(): onclose: Websocket connection closed: `, event);
|
|
69
79
|
this.disconnectedAndScheduleReconnect();
|
|
70
80
|
};
|
|
71
81
|
|
|
72
82
|
this.connectTimer = setTimeout(() => {
|
|
73
|
-
logger.warn("connect(): Websocket connection taking too long, (above "+this.connectionTimeout+" seconds!), closing and re-attempting connection");
|
|
83
|
+
this.logger.warn("connect(): Websocket connection taking too long, (above "+this.connectionTimeout+" seconds!), closing and re-attempting connection");
|
|
74
84
|
this.websocket!.close();
|
|
75
85
|
this.disconnectedAndScheduleReconnect();
|
|
76
86
|
}, this.connectionTimeout * 1000);
|
|
@@ -81,7 +91,7 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
81
91
|
if(this.websocket==null) return;
|
|
82
92
|
this.websocket.onclose = undefined;
|
|
83
93
|
//Register dummy handler, otherwise we get unhandled `error` event which crashes the whole thing
|
|
84
|
-
this.websocket.onerror = (err) => logger.error("disconnectedAndScheduleReconnect(): Post-close onerror: ", err.error ?? err);
|
|
94
|
+
this.websocket.onerror = (err) => this.logger.error("disconnectedAndScheduleReconnect(): Post-close onerror: ", err.error ?? err);
|
|
85
95
|
this.websocket.onmessage = null;
|
|
86
96
|
this.websocket.onopen = null;
|
|
87
97
|
this.websocket = null;
|
|
@@ -90,7 +100,7 @@ export class ReconnectingWebSocketProvider extends SocketProvider {
|
|
|
90
100
|
|
|
91
101
|
this._disconnected();
|
|
92
102
|
|
|
93
|
-
logger.info(`disconnectedAndScheduleReconnect(): Retrying in ${this.reconnectSeconds} seconds...`);
|
|
103
|
+
this.logger.info(`disconnectedAndScheduleReconnect(): Retrying in ${this.reconnectSeconds} seconds...`);
|
|
94
104
|
this.reconnectTimer = setTimeout(() => this.connect(), this.reconnectSeconds * 1000);
|
|
95
105
|
}
|
|
96
106
|
|
|
@@ -20,7 +20,7 @@ import {EVMSigner} from "../wallet/EVMSigner";
|
|
|
20
20
|
import {SpvVaultContractAbi} from "./SpvVaultContractAbi";
|
|
21
21
|
import {SpvVaultManager, SpvVaultParametersStructOutput} from "./SpvVaultContractTypechain";
|
|
22
22
|
import {EVMBtcRelay} from "../btcrelay/EVMBtcRelay";
|
|
23
|
-
import {getLogger} from "../../utils/Utils";
|
|
23
|
+
import {getLogger, LoggerType} from "../../utils/Utils";
|
|
24
24
|
import {EVMChainInterface} from "../chain/EVMChainInterface";
|
|
25
25
|
import {AbiCoder, getAddress, hexlify, keccak256, TransactionRequest, ZeroAddress, ZeroHash} from "ethers";
|
|
26
26
|
import {EVMAddresses} from "../chain/modules/EVMAddresses";
|
|
@@ -96,7 +96,7 @@ export class EVMSpvVaultContract<ChainId extends string>
|
|
|
96
96
|
private readonly btcRelay: EVMBtcRelay<any>;
|
|
97
97
|
private readonly bitcoinRpc: BitcoinRpc<any>;
|
|
98
98
|
|
|
99
|
-
private readonly logger
|
|
99
|
+
private readonly logger: LoggerType;
|
|
100
100
|
|
|
101
101
|
constructor(
|
|
102
102
|
chainInterface: EVMChainInterface<ChainId>,
|
|
@@ -106,6 +106,7 @@ export class EVMSpvVaultContract<ChainId extends string>
|
|
|
106
106
|
contractDeploymentHeight?: number
|
|
107
107
|
) {
|
|
108
108
|
super(chainInterface, contractAddress, SpvVaultContractAbi, contractDeploymentHeight);
|
|
109
|
+
this.logger = getLogger("EVMSpvVaultContract("+chainInterface.chainId+"): ");
|
|
109
110
|
this.chainId = chainInterface.chainId;
|
|
110
111
|
this.btcRelay = btcRelay;
|
|
111
112
|
this.bitcoinRpc = bitcoinRpc;
|
|
@@ -27,14 +27,12 @@ import {EVMPreFetchVerification, EVMSwapInit} from "./modules/EVMSwapInit";
|
|
|
27
27
|
import { EVMSwapRefund } from "./modules/EVMSwapRefund";
|
|
28
28
|
import {EVMSwapClaim} from "./modules/EVMSwapClaim";
|
|
29
29
|
import {TypedEventLog} from "../typechain/common";
|
|
30
|
-
import {getLogger} from "../../utils/Utils";
|
|
30
|
+
import {getLogger, LoggerType} from "../../utils/Utils";
|
|
31
31
|
|
|
32
32
|
const ESCROW_STATE_COMMITTED = 1;
|
|
33
33
|
const ESCROW_STATE_CLAIMED = 2;
|
|
34
34
|
const ESCROW_STATE_REFUNDED = 3;
|
|
35
35
|
|
|
36
|
-
const logger = getLogger("EVMSwapContract: ");
|
|
37
|
-
|
|
38
36
|
/**
|
|
39
37
|
* EVM swap contract (escrow manager) representation handling PrTLC (on-chain) and HTLC (lightning)
|
|
40
38
|
* based swaps.
|
|
@@ -52,6 +50,8 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
52
50
|
ChainId
|
|
53
51
|
> {
|
|
54
52
|
|
|
53
|
+
private readonly logger: LoggerType;
|
|
54
|
+
|
|
55
55
|
readonly supportsInitWithoutClaimer = true;
|
|
56
56
|
|
|
57
57
|
////////////////////////
|
|
@@ -145,6 +145,8 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
145
145
|
|
|
146
146
|
this._timelockRefundHandler = new TimelockRefundHandler(handlerAddresses.refund.timelock);
|
|
147
147
|
this._refundHandlersByAddress[this._timelockRefundHandler.address.toLowerCase()] = this._timelockRefundHandler;
|
|
148
|
+
|
|
149
|
+
this.logger = getLogger("EVMSwapContract("+this.chainId+"): ");
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/**
|
|
@@ -485,14 +487,14 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
485
487
|
|
|
486
488
|
const claimHandler = this._claimHandlersByAddress[claimHandlerHex.toLowerCase()];
|
|
487
489
|
if(claimHandler==null) {
|
|
488
|
-
logger.warn(`getHistoricalSwaps(): Unknown claim handler in tx ${event.transactionHash} with claim handler: `+claimHandlerHex);
|
|
490
|
+
this.logger.warn(`getHistoricalSwaps(): Unknown claim handler in tx ${event.transactionHash} with claim handler: `+claimHandlerHex);
|
|
489
491
|
return null;
|
|
490
492
|
}
|
|
491
493
|
|
|
492
494
|
const txTrace = await this.Chain.Transactions.traceTransaction(event.transactionHash);
|
|
493
495
|
const data = this.findInitSwapData(txTrace, event.args.escrowHash, claimHandler);
|
|
494
496
|
if(data==null) {
|
|
495
|
-
logger.warn(`getHistoricalSwaps(): Cannot parse swap data from tx ${event.transactionHash} with escrow hash: `+escrowHash);
|
|
497
|
+
this.logger.warn(`getHistoricalSwaps(): Cannot parse swap data from tx ${event.transactionHash} with escrow hash: `+escrowHash);
|
|
496
498
|
return null;
|
|
497
499
|
}
|
|
498
500
|
|
|
@@ -563,8 +565,8 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
563
565
|
startBlockheight
|
|
564
566
|
);
|
|
565
567
|
|
|
566
|
-
logger.debug(`getHistoricalSwaps(): Found ${Object.keys(resultingSwaps).length} settled swaps!`);
|
|
567
|
-
logger.debug(`getHistoricalSwaps(): Found ${Object.keys(swapsOpened).length} unsettled swaps!`);
|
|
568
|
+
this.logger.debug(`getHistoricalSwaps(): Found ${Object.keys(resultingSwaps).length} settled swaps!`);
|
|
569
|
+
this.logger.debug(`getHistoricalSwaps(): Found ${Object.keys(swapsOpened).length} unsettled swaps!`);
|
|
568
570
|
|
|
569
571
|
for(let escrowHash in swapsOpened) {
|
|
570
572
|
const foundSwapData = swapsOpened[escrowHash];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {ChainSwapType} from "@atomiqlabs/base";
|
|
2
|
-
import {getLogger} from "../../../../../utils/Utils";
|
|
3
2
|
import {BitcoinCommitmentData, BitcoinWitnessData, IBitcoinClaimHandler} from "./IBitcoinClaimHandler";
|
|
4
3
|
import {Buffer} from "buffer";
|
|
5
4
|
import {EVMSwapData} from "../../../EVMSwapData";
|
|
@@ -31,7 +31,7 @@ export type BitcoinWitnessData = {
|
|
|
31
31
|
synchronizer?: RelaySynchronizer<EVMBtcStoredHeader, EVMTx, any>
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const logger = getLogger("IBitcoinClaimHandler
|
|
34
|
+
const logger = getLogger("IBitcoinClaimHandler");
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Shared base implementation for bitcoin-backed claim handlers.
|
|
@@ -85,7 +85,7 @@ export abstract class IBitcoinClaimHandler<C, W extends BitcoinWitnessData> impl
|
|
|
85
85
|
|
|
86
86
|
const merkleProof = await btcRelay._bitcoinRpc.getMerkleProof(tx.txid, tx.blockhash);
|
|
87
87
|
if(merkleProof==null) throw new Error(`Failed to generate merkle proof for tx: ${tx.txid}!`);
|
|
88
|
-
logger.debug("getWitness(): merkle proof computed: ", merkleProof);
|
|
88
|
+
logger.debug("("+btcRelay.chainId+"): getWitness(): merkle proof computed: ", merkleProof);
|
|
89
89
|
|
|
90
90
|
const txs: EVMTx[] = [];
|
|
91
91
|
if(commitedHeader==null) {
|
|
@@ -65,7 +65,7 @@ export class EVMPersistentSigner extends EVMSigner {
|
|
|
65
65
|
this.minFeeIncreasePpm = minFeeIncreasePpm ?? MIN_FEE_INCREASE_PPM;
|
|
66
66
|
this.waitBeforeBump = waitBeforeBumpMillis ?? WAIT_BEFORE_BUMP;
|
|
67
67
|
this.safeBlockTag = chainInterface._config.safeBlockTag;
|
|
68
|
-
this.logger = getLogger("EVMPersistentSigner("+address+"): ");
|
|
68
|
+
this.logger = getLogger("EVMPersistentSigner("+this.chainInterface.chainId+","+address+"): ");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
private async load() {
|