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

Request PoW target difficulty for miner from the base node #1085

Conversation

neonknight64
Copy link
Contributor

Description

  • Introduced the difficulty adjustment manager that keeps track of the chain state to calculate the target difficulty of the different PoW algorithms.
  • Added the GetTargetDifficulty comms request and TargetDifficulty comms response to the BaseNodeService allowing miners to request the target difficulty from a Base node.
  • Added proto conversions for the GetTargetDifficulty request and TargetDifficulty response.
  • Added the difficulty adjustment manager to the tari base node and existing tests.
  • Fixed 0 difficulty issue in Lwma_diff and change it to make use of the correct target time. Changed it to make the target time configurable.

Motivation and Context

Enables miners to query a Base node to determine the target difficulty for a specified PoW algorithm.

How Has This Been Tested?

Added a test for testing the the get target difficulty request and response system and tests for the DiffAdjManager system.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Feature refactor (No new feature or functional changes, but performance or technical debt improvements)
  • New Tests
  • Documentation

Checklist:

  • I'm merging against the development branch
  • I ran cargo-fmt --all before pushing
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@neonknight64 neonknight64 force-pushed the yuko-#1067-request_target_difficulty_for_miner_from_basenode branch from 42ece20 to fd34167 Compare December 2, 2019 11:32
Copy link
Collaborator

@SWvheerden SWvheerden left a comment

Choose a reason for hiding this comment

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

Looks good.
I checked the target window, it should be 90.

There is also some dbg! code left to be taken out

base_layer/core/src/proof_of_work/lwma_diff.rs Outdated Show resolved Hide resolved
base_layer/core/src/proof_of_work/lwma_diff.rs Outdated Show resolved Hide resolved
base_layer/transactions/src/consensus.rs Outdated Show resolved Hide resolved
@neonknight64 neonknight64 force-pushed the yuko-#1067-request_target_difficulty_for_miner_from_basenode branch from fd34167 to 323bd1e Compare December 2, 2019 12:31
…e chain state to calculate the target difficulty of the different PoW algorithms.

- Added the GetTargetDifficulty comms request and TargetDifficulty comms response to the BaseNodeService allowing miners to request the target difficulty from a Base node.
- Added proto conversions for the GetTargetDifficulty request and TargetDifficulty response.
- Added the difficulty adjustment manager to the tari base node and existing tests.
- Fixed 0 difficulty issue in Lwma_diff and change it to make use of the correct target time. Changed it to make the target time configurable.
- Added a test for testing the the get target difficulty request and response system and tests for the DiffAdjManager system.
@neonknight64 neonknight64 force-pushed the yuko-#1067-request_target_difficulty_for_miner_from_basenode branch from 323bd1e to d1c5041 Compare December 2, 2019 13:47
Copy link
Collaborator

@CjS77 CjS77 left a comment

Choose a reason for hiding this comment

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

I had some comments, but it's ok to merge as is.

DifficultyAdjustmentError(DifficultyAdjustmentError),
ChainStorageError(ChainStorageError),
EmptyBlockchain,
PoisonedAccess,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I've mentioned this before, but I'd rather not lift RWLock errors to the caller -- there's no real action they can take, right; it's usually a sign of a bug? I'd just bundle this in with the general error case with a suitable message.


/// DiffAdjManager makes use of DiffAdjStorage to provide thread save access to its LinearWeightedMovingAverages for
/// each PoW algorithm.
pub struct DiffAdjStorage<T>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a lot of code for a "keep a running list of the last N block data"-- it works, so we'll leave it as is, but did you consider any other strategies?:

  • Use VecDequeues and just update from the DB every time? i.e. assume we're always in SyncToTip but you pop off the front and push to the back until you have enough data
  • Or make it someone else's job to keep the Queues up to date (like a subscriber to a newBlock message)

CjS77 added a commit that referenced this pull request Dec 3, 2019
Merge pull request #1085

- Introduced the difficulty adjustment manager that keeps track of the chain state to calculate the target difficulty of the different PoW algorithms.

- Added the GetTargetDifficulty comms request and TargetDifficulty comms response to the BaseNodeService allowing miners to request the target difficulty from a Base node.

- Added proto conversions for the GetTargetDifficulty request and TargetDifficulty response.

- Added the difficulty adjustment manager to the tari base node and existing tests.

- Fixed 0 difficulty issue in Lwma_diff and change it to make use of the correct target time. Changed it to make the target time configurable.

- Added a test for testing the the get target difficulty request and response system and tests for the DiffAdjManager system. (#1085)
@CjS77 CjS77 merged commit d1c5041 into development Dec 3, 2019
@CjS77 CjS77 deleted the yuko-#1067-request_target_difficulty_for_miner_from_basenode branch December 3, 2019 10:22
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.

3 participants