mirror of
https://github.com/stronk-dev/OrchestratorTracker.git
synced 2025-07-05 19:05:10 +02:00
Compare commits
10 Commits
d3afd739ae
...
5bac6c996d
Author | SHA1 | Date | |
---|---|---|---|
5bac6c996d | |||
51255de9d8 | |||
903a9b85c2 | |||
17cc8e8e7f | |||
46305d97e8 | |||
bff8b714d9 | |||
12d42a72bb | |||
ff2b4ec16f | |||
aa1d1e942f | |||
67781976cc |
@ -15,7 +15,7 @@
|
||||
"author": "Marco van Dijk",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"ethers": "^6.8.1",
|
||||
"ethers": "5.7.2",
|
||||
"express": "^4.17.1",
|
||||
"node-persist": "^3.1.3",
|
||||
"npm": "^8.5.2",
|
||||
|
@ -18,7 +18,7 @@ const {
|
||||
|
||||
*/
|
||||
|
||||
const l1provider = new ethers.JsonRpcProvider(
|
||||
const l1provider = new ethers.providers.JsonRpcProvider(
|
||||
CONF_API_L1_HTTP + CONF_API_L1_KEY
|
||||
);
|
||||
const masterRouter = express.Router();
|
||||
@ -104,8 +104,7 @@ const getEnsDomain = async function (addr) {
|
||||
return cached.domain ? cached.domain : cached.address;
|
||||
}
|
||||
// Refresh cause not cached or stale
|
||||
const address = ethers.getAddress(addr);
|
||||
const ensDomain = await l1provider.lookupAddress(address);
|
||||
const ensDomain = await l1provider.lookupAddress(addr);
|
||||
let ensObj;
|
||||
if (!ensDomain) {
|
||||
let domain = null;
|
||||
@ -134,7 +133,18 @@ const getEnsDomain = async function (addr) {
|
||||
);
|
||||
ensDomainCache[addr] = ensObj;
|
||||
await storage.setItem("ensDomainCache", ensDomainCache);
|
||||
return ensObj.domain ? ensObj.domain : ensObj.address;
|
||||
if (ensObj.domain) {
|
||||
// Update domain name
|
||||
return ensObj.domain;
|
||||
} else {
|
||||
if (cached.domain) {
|
||||
// Reuse last cached domain
|
||||
return cached.domain;
|
||||
} else {
|
||||
// Return ETH addr
|
||||
return ensObj.address;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.log("Error looking up ENS info, retrying...");
|
||||
@ -149,7 +159,7 @@ const getEnsDomain = async function (addr) {
|
||||
|
||||
*/
|
||||
|
||||
const updatePrometheus = async function (tag, id, instance, orchInfo) {
|
||||
const updatePrometheus = async function (tag, instance, orchInfo) {
|
||||
const thisInstance = orchInfo.instances[instance];
|
||||
const regionInfo = orchInfo.regionalStats[tag];
|
||||
if (regionInfo.latestDiscoveryTime) {
|
||||
@ -200,13 +210,13 @@ const onOrchUpdate = async function (id, obj, tag, region, livepeer_regions) {
|
||||
// Overwrite name with ENS domain if set
|
||||
let ensDomain = null;
|
||||
while (!ensDomain) {
|
||||
ensDomain = await getEnsDomain(id);
|
||||
ensDomain = await getEnsDomain(id.toLowerCase());
|
||||
}
|
||||
// Retrieve entry to update or init it
|
||||
let newObj = orchCache[id.toLowerCase()];
|
||||
if (!newObj) {
|
||||
newObj = {
|
||||
name: obj.name,
|
||||
name: ensDomain,
|
||||
regionalStats: {},
|
||||
instances: {},
|
||||
leaderboardResults: { lastTime: now },
|
||||
@ -291,21 +301,48 @@ const onOrchUpdate = async function (id, obj, tag, region, livepeer_regions) {
|
||||
}
|
||||
|
||||
// Remove expired stuff
|
||||
for (const [id, obj] of Object.entries(newInstance.probedFrom)) {
|
||||
if (now - obj.lastTime > CONF_KEY_EXPIRY) {
|
||||
newInstance.probedFrom[id] = null;
|
||||
Object.keys(newInstance.probedFrom).forEach((key) => {
|
||||
if (
|
||||
!newInstance.probedFrom[key] ||
|
||||
!newInstance.probedFrom[key].lastTime ||
|
||||
now - newInstance.probedFrom[key].lastTime > CONF_KEY_EXPIRY
|
||||
) {
|
||||
console.log(
|
||||
"Removing expired key " +
|
||||
key +
|
||||
" from the probed-from cache for orch " +
|
||||
id
|
||||
);
|
||||
delete newInstance.probedFrom[key];
|
||||
}
|
||||
}
|
||||
for (const [id, obj] of Object.entries(newInstance.regions)) {
|
||||
if (now - obj.lastTime > CONF_KEY_EXPIRY) {
|
||||
newInstance.regions[id] = null;
|
||||
});
|
||||
Object.keys(newInstance.regions).forEach((key) => {
|
||||
if (
|
||||
!newInstance.regions[key] ||
|
||||
!newInstance.regions[key].lastTime ||
|
||||
now - newInstance.regions[key].lastTime > CONF_KEY_EXPIRY
|
||||
) {
|
||||
console.log(
|
||||
"Removing expired key " + key + " from the regions cache for orch " + id
|
||||
);
|
||||
delete newInstance.regions[key];
|
||||
}
|
||||
}
|
||||
for (const [id, obj] of Object.entries(newInstance.livepeer_regions)) {
|
||||
if (now - obj.lastTime > CONF_KEY_EXPIRY) {
|
||||
newInstance.livepeer_regions[id] = null;
|
||||
});
|
||||
Object.keys(newInstance.livepeer_regions).forEach((key) => {
|
||||
if (
|
||||
!newInstance.livepeer_regions[key] ||
|
||||
!newInstance.livepeer_regions[key].lastTime ||
|
||||
now - newInstance.livepeer_regions[key].lastTime > CONF_KEY_EXPIRY
|
||||
) {
|
||||
console.log(
|
||||
"Removing expired key " +
|
||||
key +
|
||||
" from the livepeer regions cache for orch " +
|
||||
id
|
||||
);
|
||||
delete newInstance.livepeer_regions[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Set last times for instance info
|
||||
newInstance.probedFrom[tag] = {
|
||||
@ -331,9 +368,6 @@ const onOrchUpdate = async function (id, obj, tag, region, livepeer_regions) {
|
||||
newInstance.longitude = obj.resolv.geoLookup.longitude;
|
||||
}
|
||||
|
||||
// Update name
|
||||
newObj.name = obj.name;
|
||||
|
||||
// Finished updating
|
||||
newObj.instances[obj.resolv.resolvedTarget] = newInstance;
|
||||
newObj.regionalStats[tag] = newRegion;
|
||||
@ -341,8 +375,8 @@ const onOrchUpdate = async function (id, obj, tag, region, livepeer_regions) {
|
||||
await storage.setItem("orchCache", orchCache);
|
||||
|
||||
// Update prometheus stats
|
||||
updatePrometheus(tag, id, obj.resolv.resolvedTarget, newObj);
|
||||
console.log("Handled results for " + id + " from prober " + tag);
|
||||
updatePrometheus(tag, obj.resolv.resolvedTarget, newObj);
|
||||
console.log("Handled results for " + newObj.name + " from prober " + tag);
|
||||
};
|
||||
|
||||
const updateCache = async function (
|
||||
@ -436,7 +470,9 @@ const updateScore = async function (address) {
|
||||
const newRTR = instance.round_trip_time / instance.seg_duration;
|
||||
let latitude = null;
|
||||
let longitude = null;
|
||||
for (const [resolvedTarget, instance] of Object.entries(thisInstances)) {
|
||||
for (const [resolvedTarget, instance] of Object.entries(
|
||||
thisInstances
|
||||
)) {
|
||||
if (instance.livepeer_regions[region]) {
|
||||
latitude = instance.latitude;
|
||||
longitude = instance.longitude;
|
||||
@ -468,6 +504,18 @@ const updateScore = async function (address) {
|
||||
},
|
||||
newSR
|
||||
);
|
||||
if (
|
||||
!orchCache[address.toLowerCase()].leaderboardResults[instance.region]
|
||||
) {
|
||||
orchCache[address.toLowerCase()].leaderboardResults[instance.region] =
|
||||
{};
|
||||
}
|
||||
orchCache[address.toLowerCase()].leaderboardResults[
|
||||
instance.region
|
||||
].latestRTR = newRTR;
|
||||
orchCache[address.toLowerCase()].leaderboardResults[
|
||||
instance.region
|
||||
].latestSR = newSR;
|
||||
hasEdited = true;
|
||||
}
|
||||
}
|
||||
@ -501,6 +549,60 @@ const recoverStorage = async function () {
|
||||
if (storedOrchs) {
|
||||
orchCache = storedOrchs;
|
||||
}
|
||||
|
||||
// Re-init from storage
|
||||
for (const [id, obj] of Object.entries(orchCache)) {
|
||||
const thisName = obj.name;
|
||||
const thisInstances = obj.instances;
|
||||
|
||||
// Latest leaderboard results observed
|
||||
if (obj.leaderboardResults) {
|
||||
for (const [region, res] of Object.entries(obj.leaderboardResults)) {
|
||||
// Skip the lastTime accessor - only use last observed regional stats
|
||||
if (res.latestRTR == null || res.latestSR == null) {
|
||||
continue;
|
||||
}
|
||||
console.log(
|
||||
"Re-init leaderboard scores for orch=" +
|
||||
id +
|
||||
", RTR=" +
|
||||
res.latestRTR +
|
||||
" and success rate of " +
|
||||
res.latestSR * 100 +
|
||||
"%, livepeer region " +
|
||||
region
|
||||
);
|
||||
let latitude = null;
|
||||
let longitude = null;
|
||||
for (const [resolvedTarget, instance] of Object.entries(
|
||||
thisInstances
|
||||
)) {
|
||||
if (instance.livepeer_regions[region]) {
|
||||
latitude = instance.latitude;
|
||||
longitude = instance.longitude;
|
||||
}
|
||||
}
|
||||
promLatestRTR.set(
|
||||
{
|
||||
livepeer_region: region,
|
||||
orchestrator: thisName,
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
},
|
||||
res.latestRTR
|
||||
);
|
||||
promLatestSuccessRate.set(
|
||||
{
|
||||
livepeer_region: region,
|
||||
orchestrator: thisName,
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
},
|
||||
res.latestSR
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
isSynced = true;
|
||||
};
|
||||
recoverStorage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user