fixes, seems stable enough for now

This commit is contained in:
Marco van Dijk 2022-04-21 21:19:41 +02:00
parent 31c41b2673
commit fa38063685
6 changed files with 45 additions and 19 deletions

View File

@ -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);
};

View File

@ -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

View File

@ -10,7 +10,8 @@ const WinnerMonth = (obj) => {
const livepeer = useSelector((state) => state.livepeerstate);
const [thisScores, setThisScores] = useState(null);
useEffect(async () => {
useEffect(() => {
const setScore = async() => {
if (!obj.data.testScores) {
const freshScore = await getOrchestratorScores(obj.data.year, obj.data.month);
if (freshScore) {
@ -19,6 +20,8 @@ const WinnerMonth = (obj) => {
} 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({

View File

@ -101,8 +101,8 @@ const Winner = (obj) => {
<div className="rowAlignLeft" >
<h3>Fees</h3>
</div>
<div className="rowAlignLeft" >
<h4>{obj.thisEarnings.sum.toFixed(4)} Eth</h4>
<div className="rowAlignRight" >
<span>{obj.thisEarnings.sum.toFixed(4)} Eth</span>
</div>
<div className="rowAlignRight" >
<span>({((obj.thisEarnings.sum / obj.totalEarnings) * 100).toFixed(2)} %)</span>
@ -114,8 +114,8 @@ const Winner = (obj) => {
<div className="rowAlignLeft" >
<h3>Stake</h3>
</div>
<div className="rowAlignLeft" >
<h4>{obj.thisStake.totalStake.toFixed(4)} LPT</h4>
<div className="rowAlignRight" >
<span>{obj.thisStake.totalStake.toFixed(2)} LPT</span>
</div>
<div className="rowAlignRight" >
<span>({((obj.thisStake.totalStake / obj.totalStake) * 100).toFixed(2)} %)</span>

View File

@ -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

View File

@ -32,8 +32,6 @@ export default (state = {
blockchains: [],
thisOrchestrator: null,
selectedOrchestrator: null,
ensInfoMapping: [],
ensDomainMapping: [],
winningTickets: [],
orchScores: [],
monthlyStats: [],