Skip to content

Commit

Permalink
Add one-sided coinbase
Browse files Browse the repository at this point in the history
Added one-sided and stealth coinbase transactions. Coinbases can now only be paid to a
nominated wallet address other than self.
  • Loading branch information
hansieodendaal committed Nov 10, 2023
1 parent 27f78de commit 11d089d
Show file tree
Hide file tree
Showing 20 changed files with 667 additions and 76 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ message GetCoinbaseRequest {
uint64 fee = 2;
uint64 height = 3;
bytes extra = 4;
bytes wallet_payment_address = 5;
bool stealth_payment = 6;
}

message GetCoinbaseResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,18 @@ impl wallet_server::Wallet for WalletGrpcServer {
) -> Result<Response<GetCoinbaseResponse>, Status> {
let request = request.into_inner();
let mut tx_service = self.get_transaction_service();
let wallet_payment_address =
TariAddress::from_bytes(&request.wallet_payment_address).map_err(|e| Status::invalid_argument(e.to_string()))?;

let coinbase = tx_service
.generate_coinbase_transaction(request.reward.into(), request.fee.into(), request.height, request.extra)
.generate_coinbase_transaction(
wallet_payment_address,
request.stealth_payment,
request.reward.into(),
request.fee.into(),
request.height,
request.extra,
)
.await
.map_err(|err| Status::unknown(err.to_string()))?;

Expand Down
1 change: 1 addition & 0 deletions applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ default = []

[dependencies]
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"] }
minotari_app_utilities = { path = "../minotari_app_utilities" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
use std::{cmp, sync::Arc};

use log::*;
use tari_utilities::ByteArray;
use tari_utilities::hex::Hex;
use minotari_node_grpc_client::{grpc, BaseNodeGrpcClient};
use minotari_wallet_grpc_client::WalletGrpcClient;
use tari_common_types::tari_address::TariAddress;
use tari_common_types::types::PublicKey;
use tari_core::proof_of_work::{monero_rx, monero_rx::FixedByteArray, Difficulty};

use crate::{
Expand Down Expand Up @@ -185,6 +189,9 @@ impl BlockTemplateProtocol<'_> {
let block_reward = miner_data.reward;
let total_fees = miner_data.total_fees;
let extra = self.config.coinbase_extra.as_bytes().to_vec();
let wallet_payment_address = TariAddress::from_hex(&self.config.wallet_payment_address)
.map_err(|e| MmProxyError::ConversionError(e.to_string()))?
.to_vec();

let coinbase_response = self
.wallet_client
Expand All @@ -193,6 +200,8 @@ impl BlockTemplateProtocol<'_> {
fee: total_fees,
height: tari_height,
extra,
wallet_payment_address,
stealth_payment: self.config.stealth_payment,
})
.await
.map_err(|status| MmProxyError::GrpcRequestError {
Expand Down
8 changes: 8 additions & 0 deletions applications/minotari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use tari_common::{
configuration::{Network, StringList},
SubConfigPath,
};
use tari_common_types::tari_address::TariAddress;
use tari_comms::multiaddr::Multiaddr;

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -69,6 +70,11 @@ pub struct MergeMiningProxyConfig {
pub coinbase_extra: String,
/// Selected network
pub network: Network,
/// The Tari wallet address where the mining funds will be sent to (must be different wallet from the one used for
/// the wallet_grpc_address)
pub wallet_payment_address: String,
/// Stealth payment yes or no
pub stealth_payment: bool,
}

impl Default for MergeMiningProxyConfig {
Expand All @@ -89,6 +95,8 @@ impl Default for MergeMiningProxyConfig {
max_randomx_vms: 5,
coinbase_extra: "tari_merge_mining_proxy".to_string(),
network: Default::default(),
wallet_payment_address: TariAddress::default().to_hex(),
stealth_payment: true,
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion applications/minotari_miner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use std::time::Duration;
use minotari_app_grpc::tari_rpc::{pow_algo::PowAlgos, NewBlockTemplateRequest, PowAlgo};
use serde::{Deserialize, Serialize};
use tari_common::{configuration::Network, SubConfigPath};
use tari_common_types::grpc_authentication::GrpcAuthentication;
use tari_common_types::{grpc_authentication::GrpcAuthentication, tari_address::TariAddress};
use tari_comms::multiaddr::Multiaddr;

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -77,6 +77,11 @@ pub struct MinerConfig {
pub network: Network,
/// Base node reconnect timeout after any GRPC or miner error
pub wait_timeout_on_error: u64,
/// The Tari wallet address where the mining funds will be sent to (must be different wallet from the one used for
/// the wallet_grpc_address)
pub wallet_payment_address: String,
/// Stealth payment yes or no
pub stealth_payment: bool,
}

/// The proof of work data structure that is included in the block header. For the Minotari miner only `Sha3x` is
Expand Down Expand Up @@ -109,6 +114,8 @@ impl Default for MinerConfig {
coinbase_extra: "minotari_miner".to_string(),
network: Default::default(),
wait_timeout_on_error: 10,
wallet_payment_address: TariAddress::default().to_hex(),
stealth_payment: true,
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use tonic::{
codegen::InterceptedService,
transport::{Channel, Endpoint},
};
use tari_common_types::tari_address::TariAddress;
use tari_common_types::types::PublicKey;

use crate::{
cli::Cli,
Expand Down Expand Up @@ -245,7 +247,13 @@ async fn mining_cycle(
}

debug!(target: LOG_TARGET, "Getting coinbase");
let request = coinbase_request(&template, config.coinbase_extra.as_bytes().to_vec())?;
let request = coinbase_request(
&template,
config.coinbase_extra.as_bytes().to_vec(),
&TariAddress::from_hex(&config.wallet_payment_address)
.map_err(|e| MinerError::Conversion(e.to_string()))?,
config.stealth_payment,
)?;
let coinbase = wallet_conn.get_coinbase(request).await?.into_inner();
let (output, kernel) = extract_outputs_and_kernels(coinbase)?;
let body = block_template
Expand Down
24 changes: 16 additions & 8 deletions applications/minotari_miner/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
use minotari_app_grpc::tari_rpc::{
GetCoinbaseRequest,
GetCoinbaseResponse,
NewBlockTemplateResponse,
TransactionKernel,
TransactionOutput,
};
use tari_common_types::types::PublicKey;
use tari_utilities::ByteArray;
use tari_common_types::tari_address::TariAddress;

use crate::errors::{err_empty, MinerError};

/// Convert NewBlockTemplateResponse to GetCoinbaseRequest
pub fn coinbase_request(
template_response: &NewBlockTemplateResponse,
extra: Vec<u8>,
wallet_payment_address: &TariAddress,
stealth_payment: bool,
) -> Result<GetCoinbaseRequest, MinerError> {
let template = template_response
.new_block_template
Expand All @@ -50,11 +55,14 @@ pub fn coinbase_request(
.as_ref()
.ok_or_else(|| err_empty("template.header"))?
.height;
let wallet_payment_address = wallet_payment_address.as_bytes().to_vec();
Ok(GetCoinbaseRequest {
reward,
fee,
height,
extra,
wallet_payment_address,
stealth_payment,
})
}

Expand Down
Loading

0 comments on commit 11d089d

Please sign in to comment.