-
Notifications
You must be signed in to change notification settings - Fork 8
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(coinbase-extra): add coinbase extra field #67
Merged
stringhandler
merged 7 commits into
tari-project:development
from
ksrichard:feture/coinbase-extra
Sep 24, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
904bd23
implementation done
ksrichard 7b9a2af
fixed small problems
ksrichard 37da1c8
removed unneeded logging
ksrichard f1bf478
update cargo toml
ksrichard 5b3f91d
rename tribe to squad everywhere + using separate coinbase extra cach…
ksrichard 609afad
removed unnecessary iteration over block levels
ksrichard ba5f4d9
removed unneeded info log
ksrichard 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use std::{collections::HashMap, sync::Arc, time::Instant}; | ||
use std::{collections::HashMap, str::FromStr, sync::Arc, time::Instant}; | ||
|
||
use log::{debug, error, info, warn}; | ||
use minotari_app_grpc::tari_rpc::{ | ||
|
@@ -16,7 +16,7 @@ use minotari_app_grpc::tari_rpc::{ | |
SubmitBlockResponse, | ||
}; | ||
use num_format::{Locale, ToFormattedString}; | ||
use tari_common_types::types::FixedHash; | ||
use tari_common_types::{tari_address::TariAddress, types::FixedHash}; | ||
use tari_core::{ | ||
consensus::ConsensusManager, | ||
proof_of_work::{randomx_difficulty, randomx_factory::RandomXFactory, sha3x_difficulty, Difficulty, PowAlgorithm}, | ||
|
@@ -37,6 +37,7 @@ use crate::{ | |
P2POOL_STAT_REJECTED_BLOCKS_COUNT, | ||
}, | ||
p2p, | ||
p2p::Tribe, | ||
stats_store::StatsStore, | ||
}, | ||
sharechain::{block::Block, BlockValidationParams, ShareChain, SHARE_COUNT}, | ||
|
@@ -77,6 +78,8 @@ where S: ShareChain | |
stats_max_difficulty_since_last_success: Arc<RwLock<Difficulty>>, | ||
consensus_manager: ConsensusManager, | ||
submit_block_semaphore: Arc<Semaphore>, | ||
tribe: Tribe, | ||
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. Let's change this to Squad and replace all instances of 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. done |
||
coinbase_extras: Arc<RwLock<HashMap<String, Vec<u8>>>>, | ||
} | ||
|
||
impl<S> ShaP2PoolGrpc<S> | ||
|
@@ -92,6 +95,8 @@ where S: ShareChain | |
random_x_factory: RandomXFactory, | ||
consensus_manager: ConsensusManager, | ||
genesis_block_hash: FixedHash, | ||
tribe: Tribe, | ||
coinbase_extras: Arc<RwLock<HashMap<String, Vec<u8>>>>, | ||
) -> Result<Self, Error> { | ||
Ok(Self { | ||
client: Arc::new(RwLock::new( | ||
|
@@ -111,6 +116,8 @@ where S: ShareChain | |
stats_max_difficulty_since_last_success: Arc::new(RwLock::new(Difficulty::min())), | ||
consensus_manager, | ||
submit_block_semaphore: Arc::new(Semaphore::new(1)), | ||
tribe, | ||
coinbase_extras: coinbase_extras.clone(), | ||
}) | ||
} | ||
|
||
|
@@ -158,11 +165,10 @@ where S: ShareChain | |
request: Request<GetNewBlockRequest>, | ||
) -> Result<Response<GetNewBlockResponse>, Status> { | ||
let timer = Instant::now(); | ||
let grpc_req = request.into_inner(); | ||
|
||
// extract pow algo | ||
let grpc_block_header_pow = request | ||
.into_inner() | ||
.pow | ||
.ok_or(Status::invalid_argument("missing pow in request"))?; | ||
let grpc_block_header_pow = grpc_req.pow.ok_or(Status::invalid_argument("missing pow in request"))?; | ||
let grpc_pow_algo = PowAlgos::from_i32(grpc_block_header_pow.pow_algo) | ||
.ok_or_else(|| Status::internal("invalid block header pow algo in request"))?; | ||
let pow_algo = match grpc_pow_algo { | ||
|
@@ -187,12 +193,23 @@ where S: ShareChain | |
.ok_or_else(|| Status::internal("missing miner data"))?; | ||
// let reward = miner_data.reward; | ||
|
||
// update coinbase extras cache | ||
let wallet_payment_address = TariAddress::from_str(grpc_req.wallet_payment_address.as_str()) | ||
.map_err(|error| Status::failed_precondition(format!("Invalid wallet payment address: {}", error)))?; | ||
let mut coinbase_extras_lock = self.coinbase_extras.write().await; | ||
coinbase_extras_lock.insert( | ||
wallet_payment_address.to_base58(), | ||
util::convert_coinbase_extra(self.tribe.clone(), grpc_req.coinbase_extra) | ||
.map_err(|error| Status::internal(format!("failed to convert coinbase extra {error:?}")))?, | ||
); | ||
drop(coinbase_extras_lock); | ||
|
||
// request new block template with shares as coinbases | ||
let share_chain = match pow_algo { | ||
PowAlgorithm::RandomX => self.share_chain_random_x.clone(), | ||
PowAlgorithm::Sha3x => self.share_chain_sha3x.clone(), | ||
}; | ||
let shares = share_chain.generate_shares().await; | ||
let shares = share_chain.generate_shares(self.tribe.clone()).await; | ||
|
||
let mut response = self | ||
.client | ||
|
@@ -257,6 +274,7 @@ where S: ShareChain | |
if timer.elapsed() > MAX_ACCEPTABLE_GRPC_TIMEOUT { | ||
warn!(target: LOG_TARGET, "get_new_block took {}ms", timer.elapsed().as_millis()); | ||
} | ||
|
||
Ok(Response::new(GetNewBlockResponse { | ||
block: Some(response), | ||
target_difficulty: target_difficulty.as_u64(), | ||
|
@@ -307,7 +325,7 @@ where S: ShareChain | |
PowAlgorithm::Sha3x => self.share_chain_sha3x.clone(), | ||
}; | ||
let mut block = share_chain | ||
.new_block(grpc_block) | ||
.new_block(grpc_block, self.tribe.clone()) | ||
.await | ||
.map_err(|error| Status::internal(error.to_string()))?; | ||
|
||
|
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
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
Oops, something went wrong.
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.
These should be two different hashmaps
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.
okay, makes sense let me update
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.
updated