-
Notifications
You must be signed in to change notification settings - Fork 123
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
add(mining): Restore internal miner #9311
Open
arya2
wants to merge
2
commits into
update-ecc-deps
Choose a base branch
from
restore-internal-testnet-miner
base: update-ecc-deps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−15
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -133,21 +133,92 @@ impl Solution { | |||||||||
#[allow(clippy::unwrap_in_result)] | ||||||||||
pub fn solve<F>( | ||||||||||
mut header: Header, | ||||||||||
mut _cancel_fn: F, | ||||||||||
mut cancel_fn: F, | ||||||||||
) -> Result<AtLeastOne<Header>, SolverCancelled> | ||||||||||
where | ||||||||||
F: FnMut() -> Result<(), SolverCancelled>, | ||||||||||
{ | ||||||||||
// TODO: Function code was removed as part of https://github.com/ZcashFoundation/zebra/issues/8180 | ||||||||||
// Find the removed code at https://github.com/ZcashFoundation/zebra/blob/v1.5.1/zebra-chain/src/work/equihash.rs#L115-L166 | ||||||||||
// Restore the code when conditions are met. https://github.com/ZcashFoundation/zebra/issues/8183 | ||||||||||
header.solution = Solution::for_proposal(); | ||||||||||
Ok(AtLeastOne::from_one(header)) | ||||||||||
use crate::shutdown::is_shutting_down; | ||||||||||
|
||||||||||
let mut input = Vec::new(); | ||||||||||
header | ||||||||||
.zcash_serialize(&mut input) | ||||||||||
.expect("serialization into a vec can't fail"); | ||||||||||
// Take the part of the header before the nonce and solution. | ||||||||||
// This data is kept constant for this solver run. | ||||||||||
let input = &input[0..Solution::INPUT_LENGTH]; | ||||||||||
|
||||||||||
while !is_shutting_down() { | ||||||||||
// Don't run the solver if we'd just cancel it anyway. | ||||||||||
cancel_fn()?; | ||||||||||
|
||||||||||
let solutions = equihash::tromp::solve_200_9(input, || { | ||||||||||
// Cancel the solver if we have a new template. | ||||||||||
if cancel_fn().is_err() { | ||||||||||
return None; | ||||||||||
} | ||||||||||
|
||||||||||
// This skips the first nonce, which doesn't matter in practice. | ||||||||||
Self::next_nonce(&mut header.nonce); | ||||||||||
Some(*header.nonce) | ||||||||||
}); | ||||||||||
|
||||||||||
let mut valid_solutions = Vec::new(); | ||||||||||
|
||||||||||
// If we got any solutions, try submitting them, because the new template might just | ||||||||||
// contain some extra transactions. Mining extra transactions is optional. | ||||||||||
for solution in &solutions { | ||||||||||
header.solution = Self::from_bytes(solution) | ||||||||||
.expect("unexpected invalid solution: incorrect length"); | ||||||||||
|
||||||||||
// TODO: work out why we sometimes get invalid solutions here | ||||||||||
if let Err(error) = header.solution.check(&header) { | ||||||||||
info!(?error, "found invalid solution for header"); | ||||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
if Self::difficulty_is_valid(&header) { | ||||||||||
valid_solutions.push(header); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
match valid_solutions.try_into() { | ||||||||||
Ok(at_least_one_solution) => return Ok(at_least_one_solution), | ||||||||||
Err(_is_empty_error) => debug!( | ||||||||||
solutions = ?solutions.len(), | ||||||||||
"found valid solutions which did not pass the validity or difficulty checks" | ||||||||||
), | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
Err(SolverCancelled) | ||||||||||
} | ||||||||||
|
||||||||||
// TODO: Some methods were removed as part of https://github.com/ZcashFoundation/zebra/issues/8180 | ||||||||||
// Find the removed code at https://github.com/ZcashFoundation/zebra/blob/v1.5.1/zebra-chain/src/work/equihash.rs#L171-L196 | ||||||||||
// Restore the code when conditions are met. https://github.com/ZcashFoundation/zebra/issues/8183 | ||||||||||
/// Returns `true` if the `nonce` and `solution` in `header` meet the difficulty threshold. | ||||||||||
/// | ||||||||||
/// Assumes that the difficulty threshold in the header is valid. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
#[cfg(feature = "internal-miner")] | ||||||||||
fn difficulty_is_valid(header: &Header) -> bool { | ||||||||||
// Simplified from zebra_consensus::block::check::difficulty_is_valid(). | ||||||||||
let difficulty_threshold = header | ||||||||||
.difficulty_threshold | ||||||||||
.to_expanded() | ||||||||||
.expect("unexpected invalid header template: invalid difficulty threshold"); | ||||||||||
|
||||||||||
// TODO: avoid calculating this hash multiple times | ||||||||||
let hash = header.hash(); | ||||||||||
|
||||||||||
// Note: this comparison is a u256 integer comparison, like zcashd and bitcoin. Greater | ||||||||||
// values represent *less* work. | ||||||||||
hash <= difficulty_threshold | ||||||||||
} | ||||||||||
|
||||||||||
/// Modifies `nonce` to be the next integer in big-endian order. | ||||||||||
/// Wraps to zero if the next nonce would overflow. | ||||||||||
#[cfg(feature = "internal-miner")] | ||||||||||
fn next_nonce(nonce: &mut [u8; 32]) { | ||||||||||
let _ignore_overflow = crate::primitives::byte_array::increment_big_endian(&mut nonce[..]); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
impl PartialEq<Solution> for Solution { | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Default configuration for zebrad. | ||
# | ||
# This file can be used as a skeleton for custom configs. | ||
# | ||
# Unspecified fields use default values. Optional fields are Some(field) if the | ||
# field is present and None if it is absent. | ||
# | ||
# This file is generated as an example using zebrad's current defaults. | ||
# You should set only the config options you want to keep, and delete the rest. | ||
# Only a subset of fields are present in the skeleton, since optional values | ||
# whose default is None are omitted. | ||
# | ||
# The config format (including a complete list of sections and fields) is | ||
# documented here: | ||
# https://docs.rs/zebrad/latest/zebrad/config/struct.ZebradConfig.html | ||
# | ||
# zebrad attempts to load configs in the following order: | ||
# | ||
# 1. The -c flag on the command line, e.g., `zebrad -c myconfig.toml start`; | ||
# 2. The file `zebrad.toml` in the users's preference directory (platform-dependent); | ||
# 3. The default config. | ||
# | ||
# The user's preference directory and the default path to the `zebrad` config are platform dependent, | ||
# based on `dirs::preference_dir`, see https://docs.rs/dirs/latest/dirs/fn.preference_dir.html : | ||
# | ||
# | Platform | Value | Example | | ||
# | -------- | ------------------------------------- | ---------------------------------------------- | | ||
# | Linux | `$XDG_CONFIG_HOME` or `$HOME/.config` | `/home/alice/.config/zebrad.toml` | | ||
# | macOS | `$HOME/Library/Preferences` | `/Users/Alice/Library/Preferences/zebrad.toml` | | ||
# | Windows | `{FOLDERID_RoamingAppData}` | `C:\Users\Alice\AppData\Local\zebrad.toml` | | ||
|
||
[consensus] | ||
checkpoint_sync = true | ||
|
||
[mempool] | ||
eviction_memory_time = "1h" | ||
tx_cost_limit = 80000000 | ||
debug_enable_at_height = 0 | ||
|
||
[metrics] | ||
|
||
[mining] | ||
miner_address = 't27eWDgjFYJGVXmzrXeVjnb5J3uXDM9xH9v' | ||
internal_miner = true | ||
|
||
[network] | ||
cache_dir = true | ||
crawl_new_peer_interval = "1m 1s" | ||
initial_mainnet_peers = [ | ||
"dnsseed.z.cash:8233", | ||
"dnsseed.str4d.xyz:8233", | ||
"mainnet.seeder.zfnd.org:8233", | ||
"mainnet.is.yolo.money:8233", | ||
] | ||
initial_testnet_peers = [ | ||
"dnsseed.testnet.z.cash:18233", | ||
"testnet.seeder.zfnd.org:18233", | ||
"testnet.is.yolo.money:18233", | ||
] | ||
listen_addr = "0.0.0.0:8233" | ||
max_connections_per_ip = 1 | ||
network = "Testnet" | ||
peerset_initial_target_size = 25 | ||
|
||
[rpc] | ||
debug_force_finished_sync = false | ||
parallel_cpu_threads = 0 | ||
|
||
[state] | ||
cache_dir = "cache_dir" | ||
delete_old_database = true | ||
ephemeral = false | ||
|
||
[sync] | ||
checkpoint_verify_concurrency_limit = 1000 | ||
download_concurrency_limit = 50 | ||
full_verify_concurrency_limit = 20 | ||
parallel_cpu_threads = 0 | ||
|
||
[tracing] | ||
buffer_limit = 128000 | ||
force_use_color = false | ||
use_color = true | ||
use_journald = false |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment related to the code?