Skip to content

Commit

Permalink
jsutil: dump more about slash status
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzckck committed Dec 10, 2024
1 parent f485aff commit a622b0c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cmd/jsutils/getchainstatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const addrSlash = '0x0000000000000000000000000000000000001001';
const addrStakeHub = '0x0000000000000000000000000000000000002002';

const validatorSetAbi = [
"function validatorExtraSet(uint256 offset) external view returns (uint256, bool, bytes)",
"function getLivingValidators() external view returns (address[], bytes[])",
"function numOfCabinets() external view returns (uint256)",
"function maxNumOfCandidates() external view returns (uint256)",
Expand Down Expand Up @@ -272,11 +273,17 @@ async function getValidatorMoniker(consensusAddr, blockNum) {
return moniker
}


async function getSlashCount() {
let blockNum = ethers.getNumber(program.blockNum)
if (blockNum === 0) {
blockNum = await provider.getBlockNumber()
}
let slashScale = await validatorSet.maintainSlashScale({blockTag:blockNum})
let maxElected = await stakeHub.maxElectedValidators({blockTag:blockNum})
const maintainThreshold = BigInt(50) // governable, hardcode to avoid one RPC call
const felonyThreshold = BigInt(150) // governable, hardcode to avoid one RPC call

let block = await provider.getBlock(blockNum)
console.log("At block", blockNum, "time", block.date)
const data = await validatorSet.getLivingValidators({blockTag:blockNum})
Expand All @@ -285,9 +292,22 @@ async function getSlashCount() {
let addr = data[0][i];
var moniker = await getValidatorMoniker(addr, blockNum)
let info = await slashIndicator.getSlashIndicator(addr, {blockTag:blockNum})
let count = ethers.toNumber(info[1])
totalSlash += count
console.log("Slash:", count, addr, moniker)
let slashHeight = ethers.toNumber(info[0])
let slashCount = ethers.toNumber(info[1])
totalSlash += slashCount
console.log("Slash:", slashCount, addr, moniker, slashHeight)
if (slashCount >= maintainThreshold) {
let validatorExtra = await validatorSet.validatorExtraSet(i, {blockTag:blockNum})
let enterMaintenanceHeight = validatorExtra[0]
let isMaintaining = validatorExtra[1]
// let voteAddress = validatorExtra[2]
if (isMaintaining) {
let jailHeight = (felonyThreshold - slashCount) * slashScale * maxElected + BigInt(enterMaintenanceHeight)
console.log(" in maintenance mode since", enterMaintenanceHeight, "will jail after", ethers.toNumber(jailHeight))
} else {
console.log(" exited maintenance mode")
}
}
}
console.log("Total slash count", totalSlash)
};
Expand Down

0 comments on commit a622b0c

Please sign in to comment.