-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
264 lines (203 loc) · 9.66 KB
/
script.js
File metadata and controls
264 lines (203 loc) · 9.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// call the trace_transaction method using the node and hash from the input
async function trace() {
//retrieve the users inputs
const node_url = document.getElementById("erigon").value;
const txHash = document.getElementById("hash").value;
// connect to the node and log getBlockNumber to verify the connection is successful
const provider = new ethers.providers.JsonRpcProvider(node_url);
const blockNum = await provider.getBlockNumber();
console.log(`The latest block is: ${blockNum}`);
console.log('Tracing...')
// update info label
document.getElementById("info").innerHTML = "Tracing..."
// call and measure the excecution time of the callTrace function
const start = Date.now();
const traceResult = await callTrace(txHash, provider);
const end = Date.now();
document.getElementById("SpeedEri").innerHTML = `${end - start} ms`
//console.log(traceTx);
console.log('done')
// Display the JSON response.
const jsonResponse = JSON.stringify(traceResult, null, 4)
document.getElementById("result").innerHTML = jsonResponse
// update info label
document.getElementById("info").innerHTML = "Done retrieving"
// calculate the aproximate size of the object, trace is usually small and getSizeKb returns a value in kB
const size = getSizeKb(traceResult)
//const megaBytes = size / 1024;
document.getElementById("dataEri").innerHTML = `${size} kB`
// call getLines to count how many lines are present in the JSON
const lines = getLines(traceResult)
document.getElementById("linesEri").innerHTML = lines
}
// call the debug_traceTransaction method using the Erigon URL and hash from the input
async function debugErigon() {
//retrieve the users inputs
const node_url = document.getElementById("erigon").value;
const txHash = document.getElementById("hash").value;
// connect to the node and log getBlockNumber to verify the connection is successful
const provider = new ethers.providers.JsonRpcProvider(node_url);
const blockNum = await provider.getBlockNumber();
console.log(`The latest block is: ${blockNum}`);
console.log('Debugging...')
// update info label
document.getElementById("info").innerHTML = "Debugging..."
// call and measure the excecution time of the callDebugErigon function
const start = Date.now();
const debugResult = await callDebugErigon(txHash, provider);
const end = Date.now();
document.getElementById("SpeedEri").innerHTML = `${end - start} ms`
// display Json response
const jsonResponse = JSON.stringify(debugResult, null, 4)
document.getElementById("result").innerHTML = jsonResponse
// update info label
document.getElementById("info").innerHTML = "Done retrieving"
// calculate the aproximate size of the object, trace is usually small and getSizeKb returns a value in kB
const size = getSizeKb(debugResult)
const megaBytes = size / 1024;
document.getElementById("dataEri").innerHTML = `${megaBytes.toFixed(2)} MB`
// call getLines to count how many lines are present in the JSON
const lines = getLines(debugResult)
document.getElementById("linesEri").innerHTML = lines
}
// call the debug_traceTransaction method using the Geth URL and hash from the input
async function debugGeth() {
//retrieve the users inputs
const node_url = document.getElementById("geth").value;
const txHash = document.getElementById("hash").value;
// connect to the node and log getBlockNumber to verify the connection is successful
const provider = new ethers.providers.JsonRpcProvider(node_url);
const blockNum = await provider.getBlockNumber();
console.log(`The latest block is: ${blockNum}`);
console.log('Debugging...')
// update info label
document.getElementById("info").innerHTML = "Debugging..."
// call and measure the excecution time of the callDebugGeth function
const start = Date.now();
const debugResult = await callDebugGeth(txHash, provider);
const end = Date.now();
document.getElementById("SpeedGeth").innerHTML = `${end - start} ms`
// update info label
document.getElementById("info").innerHTML = "Done retrieving"
// display Json response
const jsonResponse = JSON.stringify(debugResult, null, 4)
document.getElementById("result").innerHTML = jsonResponse
// calculate the aproximate size of the object, getSizeKb returns a value in kB
const size = getSizeKb(debugResult)
const megaBytes = size / 1024;
document.getElementById("dataGeth").innerHTML = `${megaBytes.toFixed(2)} MB`
// call getLines to count how many lines are present in the JSON
const lines = getLines(debugResult)
document.getElementById("linesGeth").innerHTML = lines
}
// call the trace_transaction method
async function callTrace(hash, provider) {
// try/catch to give an error alert
try {
// call trace_transaction using the transaction hash from the user (Erigon node only)
const traceTx = await provider.send("trace_transaction", [hash, ]);
return traceTx
} catch (err) {
console.log(err)
alert("Something went wrong - possible reasons: Not an Erigon node, Trace module not active on your node, Transaction hash not valid.")
}
}
// call the debug_traceTransaction method using Erigon
async function callDebugErigon(hash, provider) {
// try/catch for error handling
try {
// call debug_traceTransaction using the transaction hash from the user
const debugTx = await provider.send("debug_traceTransaction", [hash, ]);
return debugTx
} catch (err) {
console.log(err)
alert("Something went wrong - possible reasons: Not an Erigon node, Trace module not active on your node, Transaction hash not valid.")
}
}
// call the debug_traceTransaction method using Geth
async function callDebugGeth(hash, provider) {
// try/catch for error handling
try {
// call debug_traceTransaction using the transaction hash from the user
const debugTx = await provider.send("debug_traceTransaction", [hash, ]);
return debugTx
} catch (err) {
console.log(err)
alert("Something went wrong - possible reasons: Not an Erigon node, Trace module not active on your node, Transaction hash not valid.")
}
}
// compare the 2 nodes by calling the same method on the same hash at the same time.
async function compareNodes() {
//retrieve the users inputs
const eri_url = document.getElementById("erigon").value;
const geth_url = document.getElementById("geth").value;
const txHash = document.getElementById("hash").value;
// Create nodes instances
const eriProvider = new ethers.providers.JsonRpcProvider(eri_url);
const gethProvider = new ethers.providers.JsonRpcProvider(geth_url);
console.log("Comparing...")
// measure the time to complete the 2 functions, callDebugErigon and callDebugGeth
const startEri = Date.now();
const traceResult = await callDebugErigon(txHash, eriProvider);
const endEri = Date.now();
document.getElementById("SpeedEri").innerHTML = `${endEri - startEri} ms`
console.log("Done Erigon")
const start = Date.now();
const debugResult = await callDebugGeth(txHash, gethProvider);
const end = Date.now();
document.getElementById("SpeedGeth").innerHTML = `${end - start} ms`
console.log("Done Geth")
// calculate the approximate size of the responses
const sizeEri = getSizeKb(traceResult)
const megaBytesEri = sizeEri / 1024;
document.getElementById("dataEri").innerHTML = `${megaBytesEri.toFixed(2)} MB`
const sizeGeth = getSizeKb(debugResult)
const megaBytesGeth = sizeGeth / 1024;
document.getElementById("dataGeth").innerHTML = `${megaBytesGeth.toFixed(2)} MB`
// call getLines to count how many lines are present in the JSON
const linesEri = getLines(traceResult)
document.getElementById("linesEri").innerHTML = linesEri
// call getLines to count how many lines are present in the JSON
const linesGeth = getLines(debugResult)
document.getElementById("linesGeth").innerHTML = linesGeth
console.log("Done comparing")
}
// return the approximate sie of the stringified JSON object
function getSizeKb(object) {
const parsed = JSON.stringify(object, null, )
const bytes = new TextEncoder().encode(parsed).length
const kb = (bytes / 1024).toFixed(2);
return kb
}
// count the lines retrieved
function getLines(object) {
const parsed = JSON.stringify(object, null, 4)
const lines = parsed.split("\n")
let length = 0;
for (let i = 0; i < lines.length; ++i)
length++;
console.log("lines:" + length)
return length
}
// clear the screen from the previous result
function clean() {
let div = document.getElementById('result');
let info = document.getElementById('info');
div.innerHTML = "";
info.innerHTML = "";
}
// clear the screen from the data stats
function cleanStats() {
let timeEri = document.getElementById("SpeedEri")
let timeGeth = document.getElementById("SpeedGeth")
let sizeEri = document.getElementById("dataEri")
let sizeGeth = document.getElementById("dataGeth")
let linesEri = document.getElementById("linesEri")
let linesGeth = document.getElementById("linesGeth")
timeEri.innerHTML = "";
timeGeth.innerHTML = "";
sizeEri.innerHTML = "";
sizeGeth.innerHTML = "";
linesEri.innerHTML = "";
linesGeth.innerHTML = "";
}