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: estimated hashrate calculation is incorrect #3996

Merged

Conversation

mrnaveira
Copy link
Contributor

Description

  • Created new fields in the base_node grpc api for sha3 and monero hash rates, using an independent moving average for each one
  • Kept the estimated_hash_rate field but now it corresponds to the sum of the sha3 and monero hash rates, so existing clients (i.e. web explorer) will not break
  • Modified the text explorer to show the estimated hash rates

Motivation and Context

The current hash rate calculation is incorrect, we want to use a separated moving average for each PoW algo independently

How Has This Been Tested?

Unit testing for the moving average hash rate calculation

@mrnaveira mrnaveira changed the title fix: Estimated hashrate calculation is incorrect fix: estimated hashrate calculation is incorrect Apr 4, 2022
@mrnaveira mrnaveira marked this pull request as ready for review April 4, 2022 08:43
Copy link
Collaborator

@stringhandler stringhandler left a comment

Choose a reason for hiding this comment

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

Nice work. Happy to merge if you keep the protobuf numbers in NetworkDifficultyResponse

uint64 height = 3;
uint64 timestamp = 4;
uint64 pow_algo = 5;
uint64 sha3_estimated_hash_rate = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather add these fields at the end. numbers in protobuf should not change.

Suggested change
uint64 sha3_estimated_hash_rate = 3;
uint64 sha3_estimated_hash_rate = 6;
uint64 height =3;


/// The number of past blocks to be used on moving averages for (smooth) estimated hashrate
/// The hash rate is calculated as the difficulty divided by the target block time
const SHA3_HASH_RATE_MOVING_AVERAGE_WINDOW: usize = 12;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need a comment here for why these values are different

/// Adds a new hash rate entry in the moving average and recalculates the average
pub fn add(&mut self, height: u64, difficulty: Difficulty) {
// target block time for the current block is provided by the consensus rules
let target_time = self
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice

sum / count
}

pub fn get_average(&self) -> u64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub fn get_average(&self) -> u64 {
pub fn average(&self) -> u64 {

@mrnaveira
Copy link
Contributor Author

Implemented all suggested changes

@aviator-app aviator-app bot merged commit 4587fc0 into tari-project:development Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants