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

feat: add merge mining proxy support for p2pool #6474

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ members = [
"applications/minotari_ledger_wallet/comms",
"applications/minotari_ledger_wallet/common",
"integration_tests",
"hashing",
"hashing"
]

# Add here until we move to edition=2021
Expand Down
17 changes: 12 additions & 5 deletions applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ default = []

[dependencies]
minotari_app_grpc = { path = "../minotari_app_grpc" }
minotari_app_utilities = { path = "../minotari_app_utilities", features = ["miner_input"] }
minotari_app_utilities = { path = "../minotari_app_utilities", features = [
"miner_input",
] }
minotari_node_grpc_client = { path = "../../clients/rust/base_node_grpc_client" }
minotari_wallet_grpc_client = { path = "../../clients/rust/wallet_grpc_client" }
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
tari_key_manager = { path = "../../base_layer/key_manager", features = ["key_manager_service"] }
tari_core = { path = "../../base_layer/core", default-features = false, features = [
"transactions",
] }
tari_key_manager = { path = "../../base_layer/key_manager", features = [
"key_manager_service",
] }
tari_utilities = { version = "0.7" }

anyhow = "1.0.53"
Expand All @@ -35,6 +41,7 @@ hex = "0.4.2"
hyper = "0.14.12"
jsonrpc = "0.12.0"
log = { version = "0.4.8", features = ["std"] }
# log4rs = "1.3.0"
stringhandler marked this conversation as resolved.
Show resolved Hide resolved
monero = { version = "0.21.0" }
reqwest = { version = "0.11.4", features = ["json"] }
serde = { version = "1.0.136", features = ["derive"] }
Expand All @@ -47,7 +54,7 @@ url = "2.1.1"
scraper = "0.19.0"

[build-dependencies]
tari_features = { path = "../../common/tari_features", version = "1.2.0-pre.0"}
tari_features = { path = "../../common/tari_features", version = "1.2.0-pre.0" }

[dev-dependencies]
markup5ever = "0.11.0"
markup5ever = "0.11.0"
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@ impl BlockTemplateRepository {
/// Return [BlockTemplateData] with the associated hash. None if the hash is not stored.
pub async fn get_final_template<T: AsRef<[u8]>>(&self, merge_mining_hash: T) -> Option<FinalBlockTemplateData> {
let b = self.blocks.read().await;
b.get(merge_mining_hash.as_ref()).map(|item| {
trace!(
target: LOG_TARGET,
"Retrieving block template at height #{} with merge mining hash: {:?}",
item.data.clone().template.new_block_template.header.unwrap_or_default().height,
hex::encode(merge_mining_hash.as_ref())
);
item.data.clone()
})
Comment on lines -107 to -115
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave in the the trace log please

b.get(merge_mining_hash.as_ref()).map(|item| item.data.clone())
}

/// Return [BlockTemplateData] with the associated hash. None if the hash is not stored.
Expand Down Expand Up @@ -165,7 +157,7 @@ impl BlockTemplateRepository {
let b = self.blocks.read().await;
b.values()
.find(|item| {
let header = item.data.template.new_block_template.header.clone().unwrap_or_default();
let header = item.data.template.tari_block.header.clone().unwrap_or_default();
FixedHash::try_from(header.prev_hash).unwrap_or(FixedHash::default()) == current_best_block_hash
})
.map(|val| val.data.clone())
Expand Down Expand Up @@ -223,7 +215,6 @@ pub struct BlockTemplateData {
pub tari_merge_mining_hash: FixedHash,
#[allow(dead_code)]
pub aux_chain_hashes: Vec<monero::Hash>,
pub new_block_template: grpc::NewBlockTemplate,
}

impl BlockTemplateData {}
Expand All @@ -238,7 +229,6 @@ pub struct BlockTemplateDataBuilder {
tari_difficulty: Option<u64>,
tari_merge_mining_hash: Option<FixedHash>,
aux_chain_hashes: Vec<monero::Hash>,
new_block_template: Option<grpc::NewBlockTemplate>,
}

impl BlockTemplateDataBuilder {
Expand Down Expand Up @@ -281,11 +271,6 @@ impl BlockTemplateDataBuilder {
self
}

pub fn new_block_template(mut self, template: grpc::NewBlockTemplate) -> Self {
self.new_block_template = Some(template);
self
}

/// Build a new [BlockTemplateData], all the values have to be set.
///
/// # Errors
Expand Down Expand Up @@ -313,9 +298,6 @@ impl BlockTemplateDataBuilder {
if self.aux_chain_hashes.is_empty() {
return Err(MmProxyError::MissingDataError("aux chain hashes are empty".to_string()));
};
let new_block_template = self
.new_block_template
.ok_or_else(|| MmProxyError::MissingDataError("new_block_template not provided".to_string()))?;

Ok(BlockTemplateData {
monero_seed,
Expand All @@ -325,7 +307,6 @@ impl BlockTemplateDataBuilder {
tari_difficulty,
tari_merge_mining_hash,
aux_chain_hashes: self.aux_chain_hashes,
new_block_template,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave refactoring this (removing new_block_template and using tari_block instead) for a next PR when we can do ample tests to verify that the change is good. We had very-hard-to-find sync issues between when the template is requested from the base node and when the block is finally populated by the base node, of state changing midway.

})
}
}
Expand Down Expand Up @@ -354,16 +335,14 @@ pub mod test {
total_fees: 100,
algo: Some(grpc::PowAlgo { pow_algo: 0 }),
};
let new_block_template = grpc::NewBlockTemplate::default();
let btdb = BlockTemplateDataBuilder::new()
.monero_seed(FixedByteArray::new())
.tari_block(block.try_into().unwrap())
.tari_miner_data(miner_data)
.monero_difficulty(123456)
.tari_difficulty(12345)
.tari_merge_mining_hash(hash)
.aux_hashes(vec![monero::Hash::from_slice(hash.as_slice())])
.new_block_template(new_block_template);
.aux_hashes(vec![monero::Hash::from_slice(hash.as_slice())]);
let block_template_data = btdb.build().unwrap();
FinalBlockTemplateData {
template: block_template_data,
Expand Down
Loading
Loading