From fa380636857ec0e0bce15255b2eabfeee6335fde Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Thu, 21 Apr 2022 21:19:41 +0200 Subject: [PATCH] fixes, seems stable enough for now --- backend/src/routes/livepeer.js | 5 ++- src/components/OrchAddressViewer.js | 2 +- src/components/WinnerMonth.js | 43 ++++++++++++++++++++------ src/components/WinnerStat.js | 8 ++--- src/components/eventButtonAddress.js | 4 +-- src/reducers/livepeer/livepeerstate.js | 2 -- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/backend/src/routes/livepeer.js b/backend/src/routes/livepeer.js index f88364e..5f0a205 100644 --- a/backend/src/routes/livepeer.js +++ b/backend/src/routes/livepeer.js @@ -1889,6 +1889,8 @@ const parseOrchestrator = async function (reqAddr) { orchestratorObj = orchestratorObj.transcoder; // Not found if (!orchestratorObj) { + console.log("Pushing null orchestrator " + reqAddr + " @ " + now); + orchestratorCache.push({id: reqAddr, lastGet: now }); return {}; } orchestratorObj.lastGet = now; @@ -2537,7 +2539,7 @@ const getScoreAtMonthYear = async function (month, year) { // Else get it and cache it const url = "https://leaderboard-serverless.vercel.app/api/aggregated_stats?since=" + startTime + "&until=" + endTime; console.log("Getting new Orchestrator scores for " + year + "-" + month + " @ " + url); - await https.get(url, (res) => { + return https.get(url, (res) => { let body = ""; res.on("data", (chunk) => { body += chunk; @@ -2565,6 +2567,7 @@ const getScoreAtMonthYear = async function (month, year) { } // Also update monthly stats mutateTestScoresToDB(scoreObj, month, year); + return scoreObj; } catch (error) { console.error(error.message); }; diff --git a/src/components/OrchAddressViewer.js b/src/components/OrchAddressViewer.js index bc2370e..6e32f9c 100644 --- a/src/components/OrchAddressViewer.js +++ b/src/components/OrchAddressViewer.js @@ -40,7 +40,7 @@ const Address = (obj) => { thisInfo = thisAddr; hasENS = true; // Check timeout - if (now - thisAddr.timestamp < 86400000) { + if (now - thisAddr.timestamp < 3600000) { break; } // Is outdated diff --git a/src/components/WinnerMonth.js b/src/components/WinnerMonth.js index 4105c38..d7e8bd8 100644 --- a/src/components/WinnerMonth.js +++ b/src/components/WinnerMonth.js @@ -10,15 +10,18 @@ const WinnerMonth = (obj) => { const livepeer = useSelector((state) => state.livepeerstate); const [thisScores, setThisScores] = useState(null); - useEffect(async () => { - if (!obj.data.testScores) { - const freshScore = await getOrchestratorScores(obj.data.year, obj.data.month); - if (freshScore) { - setThisScores(freshScore); + useEffect(() => { + const setScore = async() => { + if (!obj.data.testScores) { + const freshScore = await getOrchestratorScores(obj.data.year, obj.data.month); + if (freshScore) { + setThisScores(freshScore); + } + } else { + setThisScores(obj.data.testScores); } - } else { - setThisScores(obj.data.testScores); } + setScore(); }, [obj.data.testScores]); const getName = (address) => { @@ -137,16 +140,38 @@ const WinnerMonth = (obj) => { let ticketIdx2 = orchList.length - 1; let largestIdx = 0; let largestValue = 0; + let thisVal = null; // Find current O with most ticket wins in Eth while (ticketIdx2 >= 0) { const currentOrch = orchList[ticketIdx2]; - const thisVal = (currentOrch.sum || currentOrch.totalStake); + thisVal = currentOrch.sum; + if (!thisVal) { + ticketIdx2 -= 1; + continue; + } if (thisVal > largestValue) { largestIdx = ticketIdx2; largestValue = thisVal; } ticketIdx2 -= 1; } + // Else try to sort by stake + if (!thisVal) { + ticketIdx2 = orchList.length - 1; + while (ticketIdx2 >= 0) { + const currentOrch = orchList[ticketIdx2]; + thisVal = currentOrch.totalStake; + if (!thisVal) { + ticketIdx2 -= 1; + continue; + } + if (thisVal > largestValue) { + largestIdx = ticketIdx2; + largestValue = thisVal; + } + ticketIdx2 -= 1; + } + } // Push current biggest list sortedList.push(orchList[largestIdx]); // Remove from list @@ -165,7 +190,7 @@ const WinnerMonth = (obj) => { while (ticketIdx >= 0) { const thisTicket = obj.data.winningTicketsReceived[ticketIdx]; ticketIdx -= 1; - if ((thisTicket.sum / obj.data.winningTicketsReceivedSum) < 0.04) { + if ((thisTicket.sum / obj.data.winningTicketsReceivedSum) < 0.03) { otherSum += thisTicket.sum; } else { pieList.push({ diff --git a/src/components/WinnerStat.js b/src/components/WinnerStat.js index 235e510..93283c5 100644 --- a/src/components/WinnerStat.js +++ b/src/components/WinnerStat.js @@ -101,8 +101,8 @@ const Winner = (obj) => {

Fees

-
-

{obj.thisEarnings.sum.toFixed(4)} Eth

+
+ {obj.thisEarnings.sum.toFixed(4)} Eth
({((obj.thisEarnings.sum / obj.totalEarnings) * 100).toFixed(2)} %) @@ -114,8 +114,8 @@ const Winner = (obj) => {

Stake

-
-

{obj.thisStake.totalStake.toFixed(4)} LPT

+
+ {obj.thisStake.totalStake.toFixed(2)} LPT
({((obj.thisStake.totalStake / obj.totalStake) * 100).toFixed(2)} %) diff --git a/src/components/eventButtonAddress.js b/src/components/eventButtonAddress.js index 47ef310..6f1b515 100644 --- a/src/components/eventButtonAddress.js +++ b/src/components/eventButtonAddress.js @@ -43,13 +43,13 @@ const EventButtonAddress = (obj) => { } } // Lookup current info in cache only if this addr has a mapped ENS domain - if (thisDomain && thisDomain.domain && !hasRefreshed) { + if (livepeer.ensInfoMapping && thisDomain && thisDomain.domain && !hasRefreshed) { for (const thisAddr of livepeer.ensInfoMapping) { if (thisAddr.domain === thisDomain.domain) { thisInfo = thisAddr; hasENS = true; // Check timeout - if (now - thisAddr.timestamp < 86400000) { + if (now - thisAddr.timestamp < 3600000) { break; } // Is outdated diff --git a/src/reducers/livepeer/livepeerstate.js b/src/reducers/livepeer/livepeerstate.js index 1baa854..5f8bb97 100644 --- a/src/reducers/livepeer/livepeerstate.js +++ b/src/reducers/livepeer/livepeerstate.js @@ -32,8 +32,6 @@ export default (state = { blockchains: [], thisOrchestrator: null, selectedOrchestrator: null, - ensInfoMapping: [], - ensDomainMapping: [], winningTickets: [], orchScores: [], monthlyStats: [],