Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsutil: dump more about slash status #2795

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 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 @@ -277,6 +278,11 @@ async function getSlashCount() {
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 +291,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
Loading