mirror of
https://github.com/stronk-dev/OrchestratorTracker.git
synced 2025-07-06 11:25:11 +02:00
Compare commits
No commits in common. "5bac6c996d337fa5cc2c39377d8f90718672f8d8" and "d3afd739aec9892cf86b7c24e15f2fdf4749d435" have entirely different histories.
5bac6c996d
...
d3afd739ae
@ -15,7 +15,7 @@
|
||||
"author": "Marco van Dijk",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"ethers": "5.7.2",
|
||||
"ethers": "^6.8.1",
|
||||
"express": "^4.17.1",
|
||||
"node-persist": "^3.1.3",
|
||||
"npm": "^8.5.2",
|
||||
|
@ -18,7 +18,7 @@ const {
|
||||
|
||||
*/
|
||||
|
||||
const l1provider = new ethers.providers.JsonRpcProvider(
|
||||
const l1provider = new ethers.JsonRpcProvider(
|
||||
CONF_API_L1_HTTP + CONF_API_L1_KEY
|
||||
);
|
||||
const masterRouter = express.Router();
|
||||
@ -104,7 +104,8 @@ const getEnsDomain = async function (addr) {
|
||||
return cached.domain ? cached.domain : cached.address;
|
||||
}
|
||||
// Refresh cause not cached or stale
|
||||
const ensDomain = await l1provider.lookupAddress(addr);
|
||||
const address = ethers.getAddress(addr);
|
||||
const ensDomain = await l1provider.lookupAddress(address);
|
||||
let ensObj;
|
||||
if (!ensDomain) {
|
||||
let domain = null;
|
||||
@ -133,18 +134,7 @@ const getEnsDomain = async function (addr) {
|
||||
);
|
||||
ensDomainCache[addr] = ensObj;
|
||||
await storage.setItem("ensDomainCache", ensDomainCache);
|
||||
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;
|
||||
}
|
||||
}
|
||||
return ensObj.domain ? ensObj.domain : ensObj.address;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.log("Error looking up ENS info, retrying...");
|
||||
@ -159,7 +149,7 @@ const getEnsDomain = async function (addr) {
|
||||
|
||||
*/
|
||||
|
||||
const updatePrometheus = async function (tag, instance, orchInfo) {
|
||||
const updatePrometheus = async function (tag, id, instance, orchInfo) {
|
||||
const thisInstance = orchInfo.instances[instance];
|
||||
const regionInfo = orchInfo.regionalStats[tag];
|
||||
if (regionInfo.latestDiscoveryTime) {
|
||||
@ -210,13 +200,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.toLowerCase());
|
||||
ensDomain = await getEnsDomain(id);
|
||||
}
|
||||
// Retrieve entry to update or init it
|
||||
let newObj = orchCache[id.toLowerCase()];
|
||||
if (!newObj) {
|
||||
newObj = {
|
||||
name: ensDomain,
|
||||
name: obj.name,
|
||||
regionalStats: {},
|
||||
instances: {},
|
||||
leaderboardResults: { lastTime: now },
|
||||
@ -301,48 +291,21 @@ const onOrchUpdate = async function (id, obj, tag, region, livepeer_regions) {
|
||||
}
|
||||
|
||||
// Remove expired stuff
|
||||
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.probedFrom)) {
|
||||
if (now - obj.lastTime > CONF_KEY_EXPIRY) {
|
||||
newInstance.probedFrom[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.regions)) {
|
||||
if (now - obj.lastTime > CONF_KEY_EXPIRY) {
|
||||
newInstance.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];
|
||||
}
|
||||
for (const [id, obj] of Object.entries(newInstance.livepeer_regions)) {
|
||||
if (now - obj.lastTime > CONF_KEY_EXPIRY) {
|
||||
newInstance.livepeer_regions[id] = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Set last times for instance info
|
||||
newInstance.probedFrom[tag] = {
|
||||
@ -368,6 +331,9 @@ 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;
|
||||
@ -375,8 +341,8 @@ const onOrchUpdate = async function (id, obj, tag, region, livepeer_regions) {
|
||||
await storage.setItem("orchCache", orchCache);
|
||||
|
||||
// Update prometheus stats
|
||||
updatePrometheus(tag, obj.resolv.resolvedTarget, newObj);
|
||||
console.log("Handled results for " + newObj.name + " from prober " + tag);
|
||||
updatePrometheus(tag, id, obj.resolv.resolvedTarget, newObj);
|
||||
console.log("Handled results for " + id + " from prober " + tag);
|
||||
};
|
||||
|
||||
const updateCache = async function (
|
||||
@ -470,9 +436,7 @@ 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;
|
||||
@ -504,18 +468,6 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -549,60 +501,6 @@ 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