Skip to content

Commit

Permalink
New seat price formula used (#897)
Browse files Browse the repository at this point in the history
* new seat price logic
* naj v0.44.1
  • Loading branch information
volovyks committed Dec 9, 2021
1 parent 6931906 commit 00a0bf1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"jest-environment-node": "^27.0.6",
"mixpanel": "^0.13.0",
"ncp": "^2.0.0",
"near-api-js": "^0.43.1",
"near-api-js": "^0.44.1",
"near-seed-phrase": "^0.2.0",
"open": "^8.0.7",
"rimraf": "^3.0.0",
Expand Down
24 changes: 19 additions & 5 deletions utils/validators-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ async function validatorsInfo(near, blockNumberOrHash) {
blockNumberOrHash = Number(blockNumberOrHash);
}
const genesisConfig = await near.connection.provider.sendJsonRpc('EXPERIMENTAL_genesis_config', {});
const protocolConfig = await near.connection.provider.sendJsonRpc('EXPERIMENTAL_protocol_config', { 'finality': 'final' });
const result = await near.connection.provider.sendJsonRpc('validators', [blockNumberOrHash]);
result.genesisConfig = genesisConfig;
result.protocolConfig = protocolConfig;
result.numSeats = genesisConfig.num_block_producer_seats + genesisConfig.avg_hidden_validator_seats_per_shard.reduce((a, b) => a + b);
return result;
}

async function showValidatorsTable(near, blockNumberOrHash) {
const result = await validatorsInfo(near, blockNumberOrHash);
const seatPrice = validators.findSeatPrice(result.current_validators, result.numSeats);
const seatPrice = validators.findSeatPrice(
result.current_validators,
result.numSeats,
result.genesisConfig.minimum_stake_ratio,
result.protocolConfig.protocol_version);
result.current_validators = result.current_validators.sort((a, b) => -new BN(a.stake).cmp(new BN(b.stake)));
var validatorsTable = new AsciiTable();
validatorsTable.setHeading('Validator Id', 'Stake', '# Seats', '% Online', 'Blocks produced', 'Blocks expected');
Expand All @@ -35,7 +41,11 @@ async function showValidatorsTable(near, blockNumberOrHash) {

async function showNextValidatorsTable(near) {
const result = await validatorsInfo(near, null);
const nextSeatPrice = validators.findSeatPrice(result.next_validators, result.numSeats);
const nextSeatPrice = validators.findSeatPrice(
result.next_validators,
result.numSeats,
result.genesisConfig.minimum_stake_ratio,
result.protocolConfig.protocol_version);
result.next_validators = result.next_validators.sort((a, b) => -new BN(a.stake).cmp(new BN(b.stake)));
const diff = validators.diffEpochValidators(result.current_validators, result.next_validators);
console.log(`\nNext validators (total: ${result.next_validators.length}, seat price: ${utils.format.formatNearAmount(nextSeatPrice, 0)}):`);
Expand All @@ -47,8 +57,8 @@ async function showNextValidatorsTable(near) {
utils.format.formatNearAmount(validator.stake, 0),
new BN(validator.stake).div(nextSeatPrice)));
diff.changedValidators.forEach((changeValidator) => nextValidatorsTable.addRow(
'Rewarded',
changeValidator.next.account_id,
'Rewarded',
changeValidator.next.account_id,
`${utils.format.formatNearAmount(changeValidator.current.stake, 0)} -> ${utils.format.formatNearAmount(changeValidator.next.stake, 0)}`,
new BN(changeValidator.next.stake).div(nextSeatPrice)));
diff.removedValidators.forEach((validator) => nextValidatorsTable.addRow('Kicked out', validator.account_id, '-', '-'));
Expand All @@ -68,7 +78,11 @@ async function showProposalsTable(near) {
let proposals = new Map();
result.current_proposals.forEach((p) => proposals.set(p.account_id, p));
const combinedProposals = combineValidatorsAndProposals(result.current_validators, proposals);
const expectedSeatPrice = validators.findSeatPrice(combinedProposals, result.numSeats);
const expectedSeatPrice = validators.findSeatPrice(
combinedProposals,
result.numSeats,
result.genesisConfig.minimum_stake_ratio,
result.protocolConfig.protocol_version);
const combinedPassingProposals = combinedProposals.filter((p) => new BN(p.stake).gte(expectedSeatPrice));
console.log(`Proposals for the epoch after next (new: ${proposals.size}, passing: ${combinedPassingProposals.length}, expected seat price = ${utils.format.formatNearAmount(expectedSeatPrice, 0)})`);
const proposalsTable = new AsciiTable();
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 00a0bf1

Please sign in to comment.