Created
November 27, 2022 17:12
-
-
Save dapplion/da3f58f2693c30b9ec419c0f1e407d62 to your computer and use it in GitHub Desktop.
Print Gnosis fork bellatrix readiness, with data from https://nodewatch.chainsafe.io/query
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
import { execSync } from "node:child_process"; | |
const URL = "https://nodewatch.chainsafe.io/query"; | |
// From https://github.com/gnosischain/configs/blob/main/mainnet/config.yaml | |
const known_versions = { | |
"0x00000064": "gnosis-phase0", | |
"0x01000064": "gnosis-altair", | |
"0x02000064": "gnosis-bellatrix", | |
}; | |
const ready_fork_key = next_fork_key("0x02000064", 385536); | |
// the query should be a one-liner, without newlines | |
const script = `query { | |
aggregateByHardforkSchedule { | |
version | |
epoch | |
count | |
} | |
}`.replaceAll("\n", "\\n"); | |
// Where do version and epoch came from? | |
// ``` | |
// Epoch: peer.NextForkEpoch.String(), | |
// Version: peer.NextForkVersion.String(), | |
// ``` | |
// https://github.com/mandrigin/eth2-crawler/blob/6e07276b71dee7a709dd8cb7a993016ee8753804/graph/model/helpers.go#L30 | |
// | |
// ``` | |
// NextForkVersion: eth2Data.NextForkVersion, | |
// NextForkEpoch: Epoch(eth2Data.NextForkEpoch), | |
// ``` | |
// https://github.com/ChainSafe/nodewatch-api/blob/7caa71fc133327d403dfbe38483f3fe36b43ee79/models/peer.go#L195 | |
// How to understand next_fork_version field? | |
// - It shows the next fork version if already scheduled (declared in config) or the current version otherwise | |
// - For Ethereum mainnet (bellatrix already happened) 0x02000000 + FAR_FUTURE_EPOCH = capella fork not known | |
// - For Gnosis (bellatrix not happened) 0x02000064 + FAR_FUTURE_EPOCH = bellatrix fork known, but not scheduled yet | |
// - For Gnosis (current fork is altair) 0x01000064 + FAR_FUTURE_EPOCH = bellatrix fork not known to the codebase | |
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/p2p-interface.md#eth2-field | |
function next_fork_key(version, epoch) { | |
return `${version}-${epoch}` | |
} | |
// { | |
// "data": { | |
// "aggregateByHardforkSchedule": [ | |
// {"version":"0x02000000","epoch":"18446744073709551615","count":7779} | |
// ] | |
// } | |
// } | |
const resTxt = execSync( | |
`curl -s -X POST -H 'Content-Type: application/json' -d '{ "query": "${script}"}' ${URL}`, | |
{ encoding: "utf8" } | |
); | |
const res = JSON.parse(resTxt); | |
let readyCount = 0; | |
let totalCount = 0; | |
for (const { version, epoch, count } of res.data.aggregateByHardforkSchedule) { | |
if (known_versions[version]) { | |
console.log(`count: ${count} \tnext_fork_version: ${version} \tnext_fork_epoch: ${epoch}`); | |
if (next_fork_key(version, epoch) === ready_fork_key) { | |
readyCount += count | |
} | |
totalCount += count | |
} | |
} | |
console.log(`Ready nodes ${(100*readyCount/totalCount).toFixed(1)}% ${readyCount}/${totalCount}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment