-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
f: calc start and end epoch (moved logging to estimate script)
- Loading branch information
Showing
1 changed file
with
57 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,72 @@ | ||
"use strict"; | ||
|
||
/** @typedef {Number} Float64 */ | ||
/** @typedef {Number} Uint53 */ | ||
let DashGov = require("../"); | ||
//let Logger = require("../scripts/estimate.js"); | ||
|
||
let GObj = require("../"); | ||
function check2024Aug1() { | ||
let currentBlockHeight = 2114623; | ||
let currentBlockTime = "2024-08-01T22:01:00Z"; | ||
let currentBlockMs = Date.parse(currentBlockTime); | ||
|
||
const MS_PER_DAY = 24 * 60 * 60 * 1000; | ||
let cycleCount = 2; | ||
let estimates = DashGov.estimateProposalCycles(cycleCount, { | ||
ms: currentBlockMs, | ||
block: currentBlockHeight, | ||
}); | ||
|
||
function logEstimates(estimates) { | ||
console.log(`Until next...`); | ||
if (!estimates.last?.voteDeltaMs) { | ||
throw new Error(`missing 'estimates.last'`); | ||
} | ||
if (estimates.lameduck?.voteDeltaMs) { | ||
throw new Error( | ||
`has 'estimates.lameduck' during an active proposal period`, | ||
); | ||
} | ||
if (estimates.upcoming?.length !== cycleCount) { | ||
throw new Error( | ||
`expected '${cycleCount}' upcoming cycles but only got '${estimates.upcoming.length}'`, | ||
); | ||
} | ||
|
||
let voteDeltaDays = estimates.voteDeltaMs / MS_PER_DAY; | ||
console.log(` Vote (${estimates.voteHeight}):`); | ||
console.log(" Blocks:", estimates.voteDelta); | ||
console.log(" Days:", voteDeltaDays); | ||
console.log(" Date:", estimates.voteIso); | ||
//Logger.logEstimates(estimates); | ||
} | ||
|
||
let superblockDeltaDays = estimates.superblockDeltaMs / MS_PER_DAY; | ||
console.log(` Superblock (${estimates.superblockHeight}):`); | ||
console.log(" Blocks:", estimates.superblockDelta); | ||
console.log(" Days:", superblockDeltaDays); | ||
console.log(" Date:", estimates.superblockIso); | ||
function checkLameduck() { | ||
let secondsBefore = 3 * 24 * 60 * 60; | ||
let blocksBefore = secondsBefore / DashGov._AVG_SECS_PER_BLOCK; | ||
blocksBefore = Math.round(blocksBefore); | ||
|
||
console.log(""); | ||
} | ||
let voteDeadlineHeight = 2108570; | ||
let voteDeadlineTime = "2024-07-19T02:56:54.552Z"; | ||
|
||
function check2024Aug1() { | ||
// let currentBlockHeight = 2114626; | ||
// let currentBlockMs = new Date("2024-08-01T22:09:01Z"); | ||
let currentBlockHeight = 2114623; | ||
let currentBlockMs = new Date("2024-08-01 22:01:00"); | ||
let lameDuckHeight = voteDeadlineHeight - blocksBefore; | ||
// '2024-07-22T02:56:54.552Z' - 3 days | ||
let lameDuckMs = Date.parse(voteDeadlineTime); | ||
|
||
let estimates = GObj.estimateFutureBlocks(currentBlockMs, currentBlockHeight); | ||
console.log("Measured Seconds per Block", estimates[0].secondsPerBlock); | ||
console.log(""); | ||
console.log(estimates); | ||
let cycleCount = 3; | ||
let snapshot = { | ||
ms: lameDuckMs, | ||
block: lameDuckHeight, | ||
}; | ||
let estimates = DashGov.estimateProposalCycles(cycleCount, snapshot); | ||
|
||
for (let estimate of estimates) { | ||
// TODO test outputs for rough legitimacy | ||
logEstimates(estimate); | ||
if (!estimates.last?.voteDeltaMs) { | ||
throw new Error(`missing 'estimates.last'`); | ||
} | ||
if (!estimates.lameduck?.voteDeltaMs) { | ||
throw new Error(`missing 'estimates.lameduck' on lame duck period`); | ||
} | ||
if (estimates.upcoming?.length !== cycleCount) { | ||
throw new Error( | ||
`expected '${cycleCount}' upcoming cycles but only got '${estimates.upcoming.length}'`, | ||
); | ||
} | ||
|
||
//Logger.logEstimates(estimates); | ||
} | ||
|
||
check2024Aug1(); | ||
checkLameduck(); | ||
|
||
console.info("PASS: DashGov.estimateProposalCycles(count, snapshot)"); | ||
console.info(" - correctly categorizes last, lameduck, and upcoming"); |