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 missing fields to grpc consensus constants interface #4845

79 changes: 78 additions & 1 deletion applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,67 @@ message ComSignature {
bytes signature_v = 3;
}

/// PoW Algorithm constants
message PowAlgorithmConstants {
uint64 max_target_time = 1;
uint64 min_difficulty = 2;
uint64 max_difficulty = 3;
uint64 target_time = 4;
}

/// Weight params
message WeightParams {
uint64 kernel_weight = 1;
uint64 input_weight = 2;
uint64 output_weight = 3;
uint64 metadata_bytes_per_gram = 4;
}

/// Transaction input version
enum TransactionInputVersion {
TRANSACTION_INPUT_V0 = 0;
TRANSACTION_INPUT_V1 = 1;
}

/// Transaction output version
enum TransactionOutputVersion {
TRANSACTION_OUTPUT_V0 = 0;
TRANSACTION_OUTPUT_V1 = 1;
}

/// Output features version
enum OutputFeaturesVersion {
OUTPUT_FEATURES_V0 = 0;
OUTPUT_FEATURES_V1 = 1;
}

/// Output version
message OutputsVersion {
repeated TransactionOutputVersion outputs = 1;
repeated OutputFeaturesVersion features = 2;
}

/// Kernel version
enum KernelVersion {
KERNEL_V0 = 0;
}

/// Output types
enum OutputType {
STANDARD = 0;
COINBASE = 1;
BURN = 2;
VALIDATOR_NODE_REGISTRATION = 3;
CODE_TEMPLATE_REGISTRATION = 4;
}

/// Consensus Constants response
message ConsensusConstants {
/// The min height maturity a coinbase utxo must have
uint64 coinbase_lock_height = 1;
/// Current version of the blockchain
uint32 blockchain_version = 2;
/// The Future Time Limit (FTL) of the blockchain in seconds. This is the max allowable timestamp that is excepted.
/// The Future Time Limit (FTL) of the blockchain in seconds. Thfis is the max allowable timestamp that is excepted.
/// We use TxN/20 where T = target time = 60 seconds, and N = block_window = 150
uint64 future_time_limit = 3;

Expand Down Expand Up @@ -76,4 +129,28 @@ message ConsensusConstants {
uint64 block_weight_outputs = 15;
/// Block weight for kernels
uint64 block_weight_kernels = 16;
/// This is to keep track of the value inside of the genesis block
uint64 faucet_value = 17;
/// Maximum byte size of TariScript
uint64 max_script_byte_size = 18;
/// How long does it take to timeout validator node registration
uint64 validator_node_timeout = 19;
/// The height at which these constants become effective
uint64 effective_from_height = 20;
/// Current version of the blockchain
repeated uint64 valid_blockchain_version_range = 21;
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
/// This is the maximum age a monero merge mined seed can be reused
uint64 max_randomx_seed_height = 22;
/// This keeps track of the block split targets and which algo is accepted
repeated PowAlgorithmConstants proof_of_work = 23;
/// Transaction Weight params
WeightParams transaction_weight = 24;
/// Range of valid transaction input versions
repeated TransactionInputVersion input_version_range = 26;
/// Range of valid transaction output (and features) versions
OutputsVersion output_version_range = 27;
/// Range of valid transaction kernel versions
repeated KernelVersion kernel_version_range = 28;
/// An allowlist of output types
repeated OutputType permitted_output_types = 29;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,93 @@

use std::convert::TryFrom;

use tari_core::{consensus::ConsensusConstants, proof_of_work::PowAlgorithm};
use tari_core::{
consensus::ConsensusConstants,
proof_of_work::PowAlgorithm,
};

use crate::tari_rpc as grpc;

impl From<ConsensusConstants> for grpc::ConsensusConstants {
fn from(cc: ConsensusConstants) -> Self {
let (emission_initial, emission_decay, emission_tail) = cc.emission_amounts();
let weight_params = cc.transaction_weight().params();
let input_version_range = cc.input_version_range().clone().into_inner();
let input_version_range = if input_version_range.0 != input_version_range.1 {
vec![
input_version_range.0.as_u8() as i32,
input_version_range.1.as_u8() as i32,
]
} else {
vec![input_version_range.0.as_u8() as i32]
};
let kernel_version_range = cc.kernel_version_range().clone().into_inner();
let kernel_version_range = if kernel_version_range.0 != kernel_version_range.1 {
vec![
kernel_version_range.0.as_u8() as i32,
kernel_version_range.1.as_u8() as i32,
]
} else {
vec![kernel_version_range.0.as_u8() as i32]
};
let valid_blockchain_version_range = cc.valid_blockchain_version_range().clone().into_inner();
let valid_blockchain_version_range = if valid_blockchain_version_range.0 != valid_blockchain_version_range.1 {
vec![
valid_blockchain_version_range.0 as u64,
valid_blockchain_version_range.1 as u64,
]
} else {
vec![valid_blockchain_version_range.0 as u64]
};
let transaction_weight = cc.transaction_weight();
let metadata_bytes_per_gram = if let Some(val) = transaction_weight.params().metadata_bytes_per_gram {
u64::from(val)
} else {
0u64
};
let transaction_weight = grpc::WeightParams {
kernel_weight: cc.transaction_weight().params().kernel_weight,
input_weight: cc.transaction_weight().params().input_weight,
output_weight: cc.transaction_weight().params().output_weight,
metadata_bytes_per_gram,
};
let output_version_range = cc.output_version_range();
let outputs = vec![
output_version_range.outputs.start().as_u8() as i32,
output_version_range.outputs.end().as_u8() as i32,
];
let features = vec![
output_version_range.features.start().as_u8() as i32,
output_version_range.features.end().as_u8() as i32,
];

let output_version_range = grpc::OutputsVersion { outputs, features };

let permitted_output_types = cc.permitted_output_types();
let permitted_output_types = permitted_output_types
.iter()
.map(|ot| ot.as_byte() as i32)
.collect::<Vec<i32>>();

let monero_pow = PowAlgorithm::Monero;
let sha3_pow = PowAlgorithm::Sha3;

let monero_pow = grpc::PowAlgorithmConstants {
max_target_time: cc.get_difficulty_max_block_interval(monero_pow),
max_difficulty: cc.max_pow_difficulty(monero_pow).as_u64(),
min_difficulty: cc.min_pow_difficulty(monero_pow).as_u64(),
target_time: cc.get_diff_target_block_interval(monero_pow),
};

let sha3_pow = grpc::PowAlgorithmConstants {
max_target_time: cc.get_difficulty_max_block_interval(sha3_pow),
max_difficulty: cc.max_pow_difficulty(sha3_pow).as_u64(),
min_difficulty: cc.min_pow_difficulty(sha3_pow).as_u64(),
target_time: cc.get_diff_target_block_interval(sha3_pow),
};

let proof_of_work = vec![monero_pow, sha3_pow];

Self {
coinbase_lock_height: cc.coinbase_lock_height(),
blockchain_version: cc.blockchain_version().into(),
Expand All @@ -46,6 +125,18 @@ impl From<ConsensusConstants> for grpc::ConsensusConstants {
block_weight_inputs: weight_params.input_weight,
block_weight_outputs: weight_params.output_weight,
block_weight_kernels: weight_params.kernel_weight,
validator_node_timeout: cc.validator_node_timeout(),
max_script_byte_size: cc.get_max_script_byte_size() as u64,
faucet_value: cc.faucet_value().as_u64(),
effective_from_height: cc.effective_from_height(),
input_version_range,
kernel_version_range,
valid_blockchain_version_range,
proof_of_work,
transaction_weight: Some(transaction_weight),
max_randomx_seed_height: cc.max_randomx_seed_height(),
output_version_range: Some(output_version_range),
permitted_output_types,
}
}
}
5 changes: 3 additions & 2 deletions applications/tari_base_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,9 +1675,10 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
let sidechain_outputs = utxos
.into_iter()
.filter(|u| u.features.output_type.is_sidechain_type())
.collect::<Vec<_>>();
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>();

match sidechain_outputs.into_iter().map(TryInto::try_into).collect() {
match sidechain_outputs {
Ok(outputs) => {
let resp = tari_rpc::GetSideChainUtxosResponse {
block_info: Some(tari_rpc::BlockInfo {
Expand Down