Add script to verify that configured validators for an environment are consistent (#1400)
parent
fb197930b4
commit
935750fff9
@ -1,53 +0,0 @@ |
|||||||
import { ethers } from 'ethers'; |
|
||||||
import yargs from 'yargs'; |
|
||||||
|
|
||||||
import { |
|
||||||
AllChains, |
|
||||||
ChainNameToDomainId, |
|
||||||
hyperlaneCoreAddresses, |
|
||||||
} from '@hyperlane-xyz/sdk'; |
|
||||||
|
|
||||||
import { S3Validator } from '../src/agents/aws/validator'; |
|
||||||
|
|
||||||
function getArgs() { |
|
||||||
return yargs(process.argv.slice(2)) |
|
||||||
.describe('chain', 'chain of the validator to inspect') |
|
||||||
.choices('chain', AllChains) |
|
||||||
.demandOption('chain') |
|
||||||
.describe('address', 'address of the validator to inspect') |
|
||||||
.demandOption('address') |
|
||||||
.string('address') |
|
||||||
.describe('prospective', 'S3 bucket URL of the prospective validator') |
|
||||||
.demandOption('prospective') |
|
||||||
.string('prospective') |
|
||||||
.describe('control', 'S3 bucket URL of the the known (control) validator') |
|
||||||
.demandOption('control') |
|
||||||
.string('control').argv; |
|
||||||
} |
|
||||||
|
|
||||||
async function main() { |
|
||||||
const { address, prospective, control, chain } = await getArgs(); |
|
||||||
|
|
||||||
const localDomain = ChainNameToDomainId[chain]; |
|
||||||
const mailbox = hyperlaneCoreAddresses[chain].mailbox; |
|
||||||
|
|
||||||
const controlValidator = new S3Validator( |
|
||||||
ethers.constants.AddressZero, |
|
||||||
localDomain, |
|
||||||
mailbox, |
|
||||||
control, |
|
||||||
); |
|
||||||
|
|
||||||
const prospectiveValidator = new S3Validator( |
|
||||||
address, |
|
||||||
localDomain, |
|
||||||
mailbox, |
|
||||||
prospective, |
|
||||||
); |
|
||||||
|
|
||||||
const metrics = await prospectiveValidator.compare(controlValidator); |
|
||||||
|
|
||||||
console.log(JSON.stringify(metrics, null, 2)); |
|
||||||
} |
|
||||||
|
|
||||||
main().catch(console.error); |
|
@ -0,0 +1,53 @@ |
|||||||
|
import { |
||||||
|
ChainNameToDomainId, |
||||||
|
hyperlaneCoreAddresses, |
||||||
|
objMap, |
||||||
|
} from '@hyperlane-xyz/sdk'; |
||||||
|
|
||||||
|
import { CheckpointStatus, S3Validator } from '../src/agents/aws/validator'; |
||||||
|
import { CheckpointSyncerType } from '../src/config/agent'; |
||||||
|
|
||||||
|
import { getContext, getCoreEnvironmentConfig, getEnvironment } from './utils'; |
||||||
|
|
||||||
|
async function main() { |
||||||
|
const environment = await getEnvironment(); |
||||||
|
const coreConfig = getCoreEnvironmentConfig(environment); |
||||||
|
const context = await getContext(); |
||||||
|
const validatorSets = coreConfig.agents[context]?.validatorSets; |
||||||
|
if (!validatorSets) |
||||||
|
throw Error(`No validator sets found for ${environment}:${context}`); |
||||||
|
objMap(validatorSets, async (chain, validatorSet) => { |
||||||
|
const domainId = ChainNameToDomainId[chain]; |
||||||
|
const mailbox = hyperlaneCoreAddresses[chain].mailbox; |
||||||
|
const validators = validatorSet.validators.map((validator) => { |
||||||
|
const checkpointSyncer = validator.checkpointSyncer; |
||||||
|
if (checkpointSyncer.type == CheckpointSyncerType.S3) { |
||||||
|
return new S3Validator( |
||||||
|
validator.address, |
||||||
|
domainId, |
||||||
|
mailbox, |
||||||
|
checkpointSyncer.bucket, |
||||||
|
checkpointSyncer.region, |
||||||
|
); |
||||||
|
} |
||||||
|
throw new Error('Cannot check non-s3 validator type'); |
||||||
|
}); |
||||||
|
const controlValidator = validators[0]; |
||||||
|
for (let i = 1; i < validators.length; i++) { |
||||||
|
const prospectiveValidator = validators[i]; |
||||||
|
const metrics = await prospectiveValidator.compare(controlValidator); |
||||||
|
const valid = |
||||||
|
metrics.filter((metric) => metric.status !== CheckpointStatus.VALID) |
||||||
|
.length === 0; |
||||||
|
const name = validatorSet.validators[i].name; |
||||||
|
if (!valid) { |
||||||
|
console.log(`${name} has >=1 non-valid checkpoints for ${chain}`); |
||||||
|
console.log(JSON.stringify(metrics, null, 2)); |
||||||
|
} else { |
||||||
|
console.log(`${name} has valid checkpoints for ${chain}`); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
main().catch(console.error); |
Loading…
Reference in new issue