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

Conversation

stringhandler
Copy link
Collaborator

Adds merge mining support for p2pool

@ghpbot-tari-project ghpbot-tari-project added the CR-insufficient_context Your PRs commit messages don't provide enough context to justify accepting the change. label Aug 16, 2024
Copy link

github-actions bot commented Aug 16, 2024

Test Results (Integration tests)

36 tests   36 ✅  16m 3s ⏱️
11 suites   0 💤
 2 files     0 ❌

Results for commit 650f6dc.

♻️ This comment has been updated with latest results.

@ghpbot-tari-project ghpbot-tari-project added P-acks_required Process - Requires more ACKs or utACKs P-reviews_required Process - Requires a review from a lead maintainer to be merged labels Aug 16, 2024
Copy link

github-actions bot commented Aug 16, 2024

Test Results (CI)

    2 files     86 suites   24m 11s ⏱️
1 302 tests 1 301 ✅ 0 💤 1 ❌
2 601 runs  2 600 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit 650f6dc.

♻️ This comment has been updated with latest results.

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

SWvheerden
SWvheerden previously approved these changes Aug 20, 2024
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.

Just 2 nits

Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

Hi there, I am a bit concerned that this PR is doing too much. My proposal would be to only add support for pool mining and then do condensing/refactoring in a next PR.

},
);
b
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We are missing handing this error

Suggested change
},
},
Err(MmProxyError::FailedPreconditionBlockLostRetry) => {
debug!(
target: LOG_TARGET,
"Chain tip has progressed past template height {}. Fetching a new block template (try {}).",
height, loop_count
);
continue;
},

None => {
let new_template = match self.get_new_block_template().await {
Ok(val) => val,
let (_new_template, block_template_with_coinbase, height) = self
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let (_new_template, block_template_with_coinbase, height) = self
let (new_template, block_template_with_coinbase, height) = self

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this field is not used, but I have removed it now

.cloned()
.ok_or_else(|| MmProxyError::GrpcResponseMissingField("miner_data"))?;

(add_monero_data(block, monero_mining_data.clone(), miner_data)?, height)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should new_template as calculated earlier not be used for non-pools? I am not sure if miner data pulled form the block will be the same. In fn add_monero_data( parameter template_data: NewBlockTemplateData is fed in and not pulled from tari_block_result: grpc::GetNewBlockResult. With the suggestion below we know the code will behave the same.

Suggested change
(add_monero_data(block, monero_mining_data.clone(), miner_data)?, height)
match self.p2pool_client.as_mut() {
Some(p2pool_client) => {
(add_monero_data(block, monero_mining_data.clone(), miner_data)?, height)
},
None => {
(add_monero_data(block, monero_mining_data.clone(), new_template)?, height)
},
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I understand what you mean here. I think the mmproxy caching can be simplified even for non pools, but I unfortunately don't have the time to do this now

Comment on lines 224 to 225
// TODO: I don't know why this is so complicated, but I've extracted it into it's own method to hide the ugliness
async fn get_block_template_in_unnecessarily_complicated_manner(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO: I don't know why this is so complicated, but I've extracted it into it's own method to hide the ugliness
async fn get_block_template_in_unnecessarily_complicated_manner(
async fn get_block_template_from_cache_or_new(

let new_template = match self.get_new_block_template().await {
Ok(val) => val,
let (_new_template, block_template_with_coinbase, height) = self
.get_block_template_in_unnecessarily_complicated_manner(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.get_block_template_in_unnecessarily_complicated_manner(
.get_block_template_from_cache_or_new(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Comment on lines +131 to +134
let block_result = client.get_new_block(GetNewBlockRequest::default()).await?.into_inner();
block_result
.block
.ok_or_else(|| MmProxyError::FailedToGetBlockTemplate("block result".to_string()))?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think pool mining could also benefit using the cached templates

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pool mining has a new template every second, so I don't think that is true

Comment on lines -107 to -115
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()
})
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

@@ -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.

Co-authored-by: SW van Heerden <swvheerden@gmail.com>
…otocol.rs

Co-authored-by: SW van Heerden <swvheerden@gmail.com>
stringhandler added a commit to tari-project/universe that referenced this pull request Aug 28, 2024
Description
---
Sha-P2Pool must be integrated into universe to help users earn more by
mining in a pool.
P2pool should be able to enable/disable from the app.

Motivation and Context
---

How Has This Been Tested?
---



https://github.com/user-attachments/assets/7fa09375-d5e3-4e3f-b990-497dc38612c0



What process can a PR reviewer use to test or verify this change?
---
See tests

Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

**NOTE:** 
This PR must wait for the following changes to be merged:
- tari-project/sha-p2pool#31
- tari-project/tari#6474
- tari-project/sha-p2pool#32

---------

Co-authored-by: stringhandler <stringhandler@protonmail.com>
Co-authored-by: C.Lee Taylor <47312074+leet4tari@users.noreply.github.com>
Co-authored-by: shan <47271333+shanimal08@users.noreply.github.com>
Co-authored-by: Marcin Papież <mmpapiez@gmail.com>
Co-authored-by: Misieq01 <38589417+Misieq01@users.noreply.github.com>
Co-authored-by: Erika <87762061+NovaT82@users.noreply.github.com>
Co-authored-by: stringhandler <stringhandler@gmail.com>
Co-authored-by: Bertok Richard <richardb@Bertok-MacBook-Pro.local>
@SWvheerden SWvheerden merged commit bed32d5 into tari-project:development Aug 30, 2024
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CR-insufficient_context Your PRs commit messages don't provide enough context to justify accepting the change. P-acks_required Process - Requires more ACKs or utACKs P-reviews_required Process - Requires a review from a lead maintainer to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants