Skip to content

Instantly share code, notes, and snippets.

@dapplion
Created November 27, 2022 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dapplion/da3f58f2693c30b9ec419c0f1e407d62 to your computer and use it in GitHub Desktop.
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
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