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(core)!: add side-chain features and constitution to UTXOs #4134

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
7 changes: 5 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions applications/tari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", t
chrono = { version = "0.4.19", default-features = false }
prost = "0.9"
prost-types = "0.9"
num-traits = "0.2.15"
tonic = "0.6.2"

[build-dependencies]
Expand Down
75 changes: 61 additions & 14 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -206,32 +206,79 @@ message TransactionOutput {

// Options for UTXOs
message OutputFeatures {
// Version
uint32 version = 1;
// Flags are the feature flags that differentiate between outputs, eg Coinbase all of which has different rules
uint32 flags = 1;
uint32 flags = 2;
// The maturity of the specific UTXO. This is the min lock height at which an UTXO can be spend. Coinbase UTXO
// require a min maturity of the Coinbase_lock_height, this should be checked on receiving new blocks.
uint64 maturity = 2;
uint64 maturity = 3;
bytes metadata = 4;
// The recovery byte - not consensus critical - can help reduce the bandwidth with wallet recovery or in other
// instances when a wallet needs to request the complete UTXO set from a base node.
uint32 recovery_byte = 5;
SideChainFeatures sidechain_features = 6;
bytes unique_id = 7;

// TODO: deprecated
AssetOutputFeatures asset = 8;
bytes parent_public_key = 9;
MintNonFungibleFeatures mint_non_fungible = 10;
SideChainCheckpointFeatures sidechain_checkpoint = 11;
CommitteeDefinitionFeatures committee_definition = 12;
}

bytes metadata= 3;
message SideChainFeatures {
bytes contract_id = 1;
// ContractDefinition definition = 2;
ContractConstitution constitution = 3;
}

message ContractConstitution {
CommitteeMembers validator_committee = 1;
ContractAcceptanceRequirements acceptance_requirements = 2;
SideChainConsensus consensus = 3;
CheckpointParameters checkpoint_params = 4;
ConstitutionChangeRules constitution_change_rules = 5;
uint64 initial_reward = 6;
}

AssetOutputFeatures asset = 4;
message ContractAcceptanceRequirements {
uint64 acceptance_period_expiry = 1;
uint32 minimum_quorum_required = 2;
}

bytes unique_id = 5;
message CommitteeMembers {
repeated bytes members = 1;
}

bytes parent_public_key = 6;
message CheckpointParameters {
uint64 abandoned_interval = 1;
uint32 minimum_quorum_required = 2;
}

MintNonFungibleFeatures mint_non_fungible = 7;
message ConstitutionChangeRules {
uint32 change_flags = 1;
RequirementsForConstitutionChange requirements_for_constitution_change = 2;
}

SideChainCheckpointFeatures sidechain_checkpoint = 8;
// Version
uint32 version = 9;
CommitteeDefinitionFeatures committee_definition = 10;
message RequirementsForConstitutionChange {
// The minimum required constitution committee signatures required for a constitution change proposal to pass.
uint32 minimum_constitution_committee_signatures = 1;
// An allowlist of keys that are able to accept and ratify the initial constitution and its amendments. If this is
// None, the constitution cannot be amended.
CommitteeMembers constitution_committee = 2;
}

// The recovery byte - not consensus critical - can help reduce the bandwidth with wallet recovery or in other
// instances when a wallet needs to request the complete UTXO set from a base node.
uint32 recovery_byte = 11;
enum SideChainConsensus {
UNSPECIFIED = 0;
BFT = 1;
PROOF_OF_WORK = 2;
MERKLE_ROOT = 3;
}

// TODO: DEPRECATED

message AssetOutputFeatures {
bytes public_key = 1;
repeated uint32 template_ids_implemented = 2;
Expand Down
1 change: 1 addition & 0 deletions applications/tari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod new_block_template;
mod output_features;
mod peer;
mod proof_of_work;
mod sidechain_features;
mod signature;
mod transaction;
mod transaction_input;
Expand Down
28 changes: 17 additions & 11 deletions applications/tari_app_grpc/src/conversions/output_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use tari_core::transactions::transaction_components::{
OutputFeaturesVersion,
OutputFlags,
SideChainCheckpointFeatures,
SideChainFeatures,
TemplateParameter,
};
use tari_utilities::ByteArray;
Expand All @@ -54,7 +55,12 @@ impl TryFrom<grpc::OutputFeatures> for OutputFeatures {
} else {
Some(PublicKey::from_bytes(features.parent_public_key.as_bytes()).map_err(|err| format!("{:?}", err))?)
};
let flags = u16::try_from(features.flags).map_err(|_| "Invalid output flags: overflowed u8")?;
let sidechain_features = features
.sidechain_features
.map(SideChainFeatures::try_from)
.transpose()?;

let flags = u16::try_from(features.flags).map_err(|_| "Invalid output flags: overflowed u16")?;

Ok(OutputFeatures::new(
OutputFeaturesVersion::try_from(
Expand All @@ -65,6 +71,7 @@ impl TryFrom<grpc::OutputFeatures> for OutputFeatures {
u8::try_from(features.recovery_byte).map_err(|_| "Invalid recovery byte: overflowed u8")?,
features.metadata,
unique_id,
sidechain_features,
parent_public_key,
features.asset.map(|a| a.try_into()).transpose()?,
features.mint_non_fungible.map(|m| m.try_into()).transpose()?,
Expand All @@ -77,24 +84,23 @@ impl TryFrom<grpc::OutputFeatures> for OutputFeatures {
impl From<OutputFeatures> for grpc::OutputFeatures {
fn from(features: OutputFeatures) -> Self {
Self {
version: features.version as u32,
flags: u32::from(features.flags.bits()),
maturity: features.maturity,
metadata: features.metadata,
unique_id: features.unique_id.unwrap_or_default(),
parent_public_key: features
.parent_public_key
.map(|a| a.as_bytes().to_vec())
.unwrap_or_default(),
asset: features.asset.map(|a| a.into()),
mint_non_fungible: features.mint_non_fungible.map(|m| m.into()),
sidechain_checkpoint: features.sidechain_checkpoint.map(|m| m.into()),
version: features.version as u32,
committee_definition: features.committee_definition.map(|c| c.into()),
recovery_byte: u32::from(features.recovery_byte),
sidechain_features: features.sidechain_features.map(Into::into),

// TODO: Deprecated
asset: None,
parent_public_key: vec![],
mint_non_fungible: None,
sidechain_checkpoint: None,
committee_definition: None,
}
}
}

impl TryFrom<grpc::AssetOutputFeatures> for AssetOutputFeatures {
type Error = String;

Expand Down
Loading