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

fix max seat number computation #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use color_eyre::eyre::{Context, ContextCompat};
use near_cli_rs::types::near_token::NearToken;
use near_jsonrpc_client::methods::EXPERIMENTAL_protocol_config::RpcProtocolConfigResponse;
use near_primitives::types::NumSeats;
use num_rational::Rational32;

/// This implementation is ported from near-api-js:
Expand All @@ -16,6 +18,19 @@ pub fn find_seat_price(
find_seat_price_for_protocol_after_49(stakes, max_number_of_seats, minimum_stake_ratio)
}

/// With statelessnet feature enabled, we need to take into account `num_chunk_only_producer_seats`.
pub fn find_max_number_of_seats(protocol_config: &RpcProtocolConfigResponse) -> NumSeats {
let seats_before_statelessnet = protocol_config.num_block_producer_seats
+ protocol_config
.avg_hidden_validator_seats_per_shard
.iter()
.sum::<u64>();
std::cmp::max(
seats_before_statelessnet,
protocol_config.num_chunk_only_producer_seats,
)
Copy link
Author

@telezhnaya telezhnaya Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should sum up these numbers or taking the maximum. Current value is for sure smaller than we need.

current <= maximum <= sum

For Statelessnet, the values are 20, 300, 320.

Instead of spending hours on the investigation, I suggest starting using maximum and fix it later again if we see the other issues here.

}

/// This implementation is ported from near-api-js:
/// https://github.com/near/near-api-js/blob/bdbf839f54fbc399d7299da8cf9966bbdc426238/packages/utils/src/validators.ts#L24-L50
fn find_seat_price_for_protocol_before_49(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think we don't need to check protocol version for the current change because protocol_config.num_chunk_only_producer_seats will be zero for older protocol versions, so it will not affect the result.

Expand Down
6 changes: 1 addition & 5 deletions src/proposals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ pub fn display_proposals_info(
})
.wrap_err("Failed to get protocol config.")?;

let max_number_of_seats = protocol_config.num_block_producer_seats
+ protocol_config
.avg_hidden_validator_seats_per_shard
.iter()
.sum::<u64>();
let max_number_of_seats = crate::common::find_max_number_of_seats(&protocol_config);

let expected_seat_price = crate::common::find_seat_price(
combine_validators_and_proposals_table
Expand Down
6 changes: 1 addition & 5 deletions src/validators/block_id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ pub fn display_current_validators_info(
.blocking_call(&RpcProtocolConfigRequest { block_reference })
.wrap_err("Failed to get protocol config.")?;

let max_number_of_seats = protocol_config.num_block_producer_seats
+ protocol_config
.avg_hidden_validator_seats_per_shard
.iter()
.sum::<u64>();
let max_number_of_seats = crate::common::find_max_number_of_seats(&protocol_config);
eprintln!(
"Validators (total: {}, seat price: {})",
current_validators.len(),
Expand Down
6 changes: 1 addition & 5 deletions src/validators/epoch_id/next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ fn display_next_validators_info(
})
.wrap_err("Failed to get protocol config.")?;

let max_number_of_seats = protocol_config.num_block_producer_seats
+ protocol_config
.avg_hidden_validator_seats_per_shard
.iter()
.sum::<u64>();
let max_number_of_seats = crate::common::find_max_number_of_seats(&protocol_config);
let seat_price = crate::common::find_seat_price(
next_validators
.iter()
Expand Down
Loading