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: mining ffi add coinbase add #6183

Merged
merged 9 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion base_layer/core/src/blocks/new_block_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use std::fmt::{Display, Formatter};

use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -36,7 +37,7 @@ use crate::{

/// The new block template is used constructing a new partial block, allowing a miner to added the coinbase utxo and as
/// a final step the Base node to add the MMR roots to the header.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
pub struct NewBlockTemplate {
/// The NewBlockHeaderTemplate is used for the construction of a new mineable block. It contains all the metadata
/// for the block that the Base Node is able to complete on behalf of a Miner.
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/blocks/new_blockheader_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

use std::fmt::{Display, Error, Formatter};

use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use tari_common_types::types::{BlockHash, PrivateKey};
use tari_utilities::hex::Hex;

use crate::{blocks::block_header::BlockHeader, proof_of_work::ProofOfWork};

/// The NewBlockHeaderTemplate is used for the construction of a new mineable block. It contains all the metadata for
/// the block that the Base Node is able to complete on behalf of a Miner.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, BorshSerialize, BorshDeserialize)]
pub struct NewBlockHeaderTemplate {
/// Version of the block
pub version: u16,
Expand Down
5 changes: 4 additions & 1 deletion base_layer/core/src/proof_of_work/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use std::fmt;

use borsh::{BorshDeserialize, BorshSerialize};
use num_format::{Locale, ToFormattedString};
use primitive_types::U256;
use serde::{Deserialize, Serialize};
Expand All @@ -34,7 +35,9 @@ use crate::proof_of_work::{error::DifficultyError, DifficultyAdjustmentError};
pub const MIN_DIFFICULTY: u64 = 1;

/// The difficulty is defined as the maximum target divided by the block hash.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Deserialize, Serialize)]
#[derive(
Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Deserialize, Serialize, BorshSerialize, BorshDeserialize,
)]
pub struct Difficulty(u64);

impl Difficulty {
Expand Down
4 changes: 3 additions & 1 deletion base_layer/tari_mining_helper_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ tari_comms = { path = "../../comms/core" }
tari_crypto = { version = "0.20" }
tari_common = { path = "../../common" }
tari_core = { path = "../core", default-features = false, features = ["transactions", "base_node_proto", "base_node"] }
tari_common_types = { path = "../../base_layer/common_types", version = "1.0.0-pre.9" }
tari_utilities = { version = "0.7" }
libc = "0.2.65"
thiserror = "1.0.26"
borsh = "1.2"
hex = "0.4.2"
tokio = { version = "1.36", features = ["rt"] }

[dev-dependencies]
tari_core = { path = "../core", features = ["transactions", "base_node"] }
Expand All @@ -25,4 +27,4 @@ rand = "0.8"
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }

[lib]
crate-type = ["staticlib","cdylib"]
crate-type = ["cdylib"]
24 changes: 24 additions & 0 deletions base_layer/tari_mining_helper_ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ pub enum InterfaceError {
AllocationError,
#[error("An error because the supplied position was out of range")]
PositionInvalidError,
#[error("An error has occurred when trying to create the tokio runtime: `{0}`")]
TokioError(String),
#[error("An error has occurred when trying to create the a coinbase: `{0}`")]
CoinbaseBuildError(String),
#[error("An invalid address was passed in: `{0}`")]
InvalidAddress(String),
#[error("An invalid network was passed in: `{0}`")]
InvalidNetwork(String),
}

/// This struct is meant to hold an error for use by Miningcore. The error has an integer code and string
Expand Down Expand Up @@ -73,6 +81,22 @@ impl From<InterfaceError> for MiningHelperError {
code: 6,
message: format!("{:?}", v),
},
InterfaceError::TokioError(_) => Self {
code: 7,
message: format!("{:?}", v),
},
InterfaceError::CoinbaseBuildError(_) => Self {
code: 8,
message: format!("{:?}", v),
},
InterfaceError::InvalidAddress(_) => Self {
code: 9,
message: format!("{:?}", v),
},
InterfaceError::InvalidNetwork(_) => Self {
code: 10,
message: format!("{:?}", v),
},
}
}
}
Expand Down
Loading
Loading