-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-debug.mjs
More file actions
109 lines (86 loc) · 3.29 KB
/
test-debug.mjs
File metadata and controls
109 lines (86 loc) · 3.29 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
/**
* Debug the history lookup issue
*/
import axios from "axios";
const NEXUS_API = "https://nexus.oasis.io/v1";
const VALIDATOR = "oasis1qq3xrq0urs8qcffhvmhfhz4p0mu7ewc8rscnlwxe";
const START_EPOCH = 28809;
const END_EPOCH = 37689;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const paginatedFetch = async (url, params, itemsKey, limit = 1000) => {
let items = [];
let offset = 0;
while (true) {
const response = await axios.get(url, {
params: { ...params, limit, offset },
});
const pageItems = response.data[itemsKey] || [];
items = [...items, ...pageItems];
console.log(` Page: offset=${offset}, got ${pageItems.length} items, total_count=${response.data.total_count}, clipped=${response.data.is_total_count_clipped}`);
// Break if we got fewer than the limit (last page)
// Note: When is_total_count_clipped is true, total_count is capped (often at 1000),
// so we can't rely on offset >= total_count to know we're done.
if (pageItems.length < limit) {
break;
}
offset += pageItems.length;
await sleep(100);
}
return { items };
};
const findHistoryEntryForEpoch = (history, targetEpoch) => {
if (!history || history.length === 0) return null;
let low = 0;
let high = history.length - 1;
let result = null;
while (low <= high) {
const mid = Math.floor((low + high) / 2);
if (history[mid].epoch <= targetEpoch) {
result = history[mid];
low = mid + 1;
} else {
high = mid - 1;
}
}
return result;
};
async function main() {
console.log("=== Debug: Checking validator history fetch ===\n");
// This is what the implementation does
console.log(`Fetching history from epoch ${Math.max(1, START_EPOCH - 100)} to ${END_EPOCH}...`);
const { items: history } = await paginatedFetch(
`${NEXUS_API}/consensus/validators/${VALIDATOR}/history`,
{ from: Math.max(1, START_EPOCH - 100), to: END_EPOCH },
"history"
);
console.log(`Fetched ${history.length} history entries`);
if (history.length > 0) {
history.sort((a, b) => a.epoch - b.epoch);
console.log(`First epoch: ${history[0].epoch}`);
console.log(`Last epoch: ${history[history.length - 1].epoch}`);
}
// Check what epochs we can find
const epochsToCheck = [28809, 29549, 30289, 31029, 31769, 32509, 33249, 33989, 34729, 35469, 36209, 36949, 37689];
console.log("\nChecking findHistoryEntryForEpoch for each monthly epoch:");
for (const epoch of epochsToCheck) {
const entry = findHistoryEntryForEpoch(history, epoch);
if (entry) {
console.log(` Epoch ${epoch}: found entry at epoch ${entry.epoch}`);
} else {
console.log(` Epoch ${epoch}: NOT FOUND!`);
}
}
// Show what epochs are actually in the history
console.log("\n=== Sample of history entries ===");
const epochs = history.map(h => h.epoch);
console.log(`Total entries: ${epochs.length}`);
console.log(`Min epoch: ${Math.min(...epochs)}`);
console.log(`Max epoch: ${Math.max(...epochs)}`);
// Check if our target epochs exist in history
console.log("\n=== Checking if target epochs exist in history ===");
for (const epoch of epochsToCheck) {
const exists = epochs.includes(epoch);
console.log(` Epoch ${epoch}: ${exists ? "EXISTS" : "DOES NOT EXIST"}`);
}
}
main().catch(console.error);