Skip to content

Commit

Permalink
chore: remove metadata references (#5035)
Browse files Browse the repository at this point in the history
* rename metadata

* remove coinbase_extra from convenant

* remove zip
  • Loading branch information
SWvheerden authored Dec 14, 2022
1 parent 3dd10bd commit 75eabc8
Show file tree
Hide file tree
Showing 30 changed files with 194 additions and 172 deletions.
2 changes: 1 addition & 1 deletion applications/tari_app_grpc/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ message OutputFeatures {
// 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 = 3;
bytes metadata = 4;
bytes coinbase_extra = 4;
SideChainFeature sidechain_feature = 5;
}

Expand Down
2 changes: 1 addition & 1 deletion applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ message WeightParams {
uint64 kernel_weight = 1;
uint64 input_weight = 2;
uint64 output_weight = 3;
uint64 metadata_bytes_per_gram = 4;
uint64 features_and_scripts_bytes_per_gram = 4;
}

/// Output version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ impl From<ConsensusConstants> for grpc::ConsensusConstants {
max: u64::from(valid_blockchain_version_range.1),
};
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 features_and_scripts_bytes_per_gram =
if let Some(val) = transaction_weight.params().features_and_scripts_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,
features_and_scripts_bytes_per_gram,
};
let output_version_range = cc.output_version_range();
let outputs = grpc::Range {
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_app_grpc/src/conversions/output_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TryFrom<grpc::OutputFeatures> for OutputFeatures {
)?,
OutputType::from_byte(output_type).ok_or_else(|| "Invalid or unrecognised output type".to_string())?,
features.maturity,
features.metadata,
features.coinbase_extra,
sidechain_feature,
))
}
Expand All @@ -64,7 +64,7 @@ impl From<OutputFeatures> for grpc::OutputFeatures {
version: features.version as u32,
output_type: u32::from(features.output_type.as_byte()),
maturity: features.maturity,
metadata: features.coinbase_extra,
coinbase_extra: features.coinbase_extra,
sidechain_feature: features.sidechain_feature.map(Into::into),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ impl CommandContext {
}
} else {
println!(
" {} Fee: {}, Outputs: {}, Kernels: {}, Inputs: {}, metadata: {} bytes",
" {} Fee: {}, Outputs: {}, Kernels: {}, Inputs: {}, features_and_scripts: {} bytes",
tx_sig,
tx.body.get_total_fee(),
tx.body.outputs().len(),
tx.body.kernels().len(),
tx.body.inputs().len(),
tx.body.sum_metadata_size(),
tx.body.sum_features_and_scripts_size(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_merge_mining_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl InnerService {
.metadata
.as_ref()
.map(|meta| meta.height_of_longest_chain)
.ok_or(MmProxyError::GrpcResponseMissingField("metadata"))?;
.ok_or(MmProxyError::GrpcResponseMissingField("base node metadata"))?;
if result.get_ref().initial_sync_achieved != self.initial_sync_achieved.load(Ordering::Relaxed) {
self.initial_sync_achieved
.store(result.get_ref().initial_sync_achieved, Ordering::Relaxed);
Expand Down
2 changes: 0 additions & 2 deletions base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ fn get_igor_genesis_block_raw() -> Block {
script!(Nop),
// Script offset never checked for coinbase, thus can use default
PublicKey::from_hex("88c4d5dafaeb529d70d594cdb43a0fad2842a6cfdc47ac579b09b2e6478d3a4f").unwrap(),
// For genesis block: Metadata signature will never be checked
coinbase_meta_sig,
Covenant::default(),
EncryptedValue::default(),
Expand Down Expand Up @@ -303,7 +302,6 @@ fn get_esmeralda_genesis_block_raw() -> Block {
script!(Nop),
// The Sender offset public key is not checked for coinbase outputs
PublicKey::from_hex("0ad98e0eab0d736a52b607c1136bed6c4c0a6b47331b6dee22fadf8b6fa41011").unwrap(),
// For genesis block: Metadata signature will never be checked
coinbase_meta_sig,
// Covenant
Covenant::default(),
Expand Down
8 changes: 4 additions & 4 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ impl ConsensusConstants {
pub fn coinbase_weight(&self) -> u64 {
// TODO: We do not know what script, features etc a coinbase has - this should be max coinbase size?
let output_features = OutputFeatures { ..Default::default() };
let metadata_size = self
.transaction_weight
.round_up_metadata_size(output_features.get_serialized_size() + script![Nop].get_serialized_size());
self.transaction_weight.calculate(1, 0, 1, metadata_size)
let features_and_scripts_size = self.transaction_weight.round_up_features_and_scripts_size(
output_features.get_serialized_size() + script![Nop].get_serialized_size(),
);
self.transaction_weight.calculate(1, 0, 1, features_and_scripts_size)
}

pub fn coinbase_output_features_extra_max_length(&self) -> u32 {
Expand Down
1 change: 0 additions & 1 deletion base_layer/core/src/covenants/byte_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ pub const FIELD_COVENANT: u8 = 0x03;
pub const FIELD_FEATURES: u8 = 0x04;
pub const FIELD_FEATURES_OUTPUT_TYPE: u8 = 0x05;
pub const FIELD_FEATURES_MATURITY: u8 = 0x06;
pub const FIELD_FEATURES_COINBASE_EXTRA: u8 = 0x07;
pub const FIELD_FEATURES_SIDE_CHAIN_FEATURES: u8 = 0x08;

#[cfg(test)]
Expand Down
6 changes: 2 additions & 4 deletions base_layer/core/src/covenants/covenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ mod test {
input.set_maturity(42).unwrap();
let covenant = covenant!(fields_preserved(@fields(
@field::features_output_type,
@field::features_maturity,
@field::features_metadata))
@field::features_maturity))
);
let num_matching_outputs = covenant.execute(0, &input, &outputs).unwrap();
assert_eq!(num_matching_outputs, 3);
Expand All @@ -198,8 +197,7 @@ mod test {
input.set_maturity(42).unwrap();
let covenant = covenant!(fields_preserved(@fields(
@field::features_output_type,
@field::features_maturity,
@field::features_metadata))
@field::features_maturity))
);
let mut buf = Vec::new();
covenant.serialize(&mut buf).unwrap();
Expand Down
7 changes: 2 additions & 5 deletions base_layer/core/src/covenants/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod test {
let hash = FixedHash::from_hex("53563b674ba8e5166adb57afa8355bcf2ee759941eef8f8959b802367c2558bd").unwrap();
let mut bytes = Vec::new();
covenant!(fields_hashed_eq(
@fields(@field::commitment, @field::features_metadata),
@fields(@field::commitment),
@hash(hash),
))
.write_to(&mut bytes)
Expand All @@ -183,10 +183,7 @@ mod test {
));
let token = decoder.next().unwrap().unwrap();
unpack_enum!(CovenantArg::OutputFields(fields) = token.as_arg().unwrap());
assert_eq!(fields.fields(), &[
OutputField::Commitment,
OutputField::FeaturesCoinbaseExtra
]);
assert_eq!(fields.fields(), &[OutputField::Commitment]);

let token = decoder.next().unwrap().unwrap();
unpack_enum!(CovenantArg::Hash(hash) = token.as_arg().unwrap());
Expand Down
20 changes: 0 additions & 20 deletions base_layer/core/src/covenants/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub enum OutputField {
Features = byte_codes::FIELD_FEATURES,
FeaturesOutputType = byte_codes::FIELD_FEATURES_OUTPUT_TYPE,
FeaturesMaturity = byte_codes::FIELD_FEATURES_MATURITY,
FeaturesCoinbaseExtra = byte_codes::FIELD_FEATURES_COINBASE_EXTRA,
FeaturesSideChainFeatures = byte_codes::FIELD_FEATURES_SIDE_CHAIN_FEATURES,
}

Expand All @@ -71,7 +70,6 @@ impl OutputField {
FIELD_FEATURES_OUTPUT_TYPE => Ok(FeaturesOutputType),
FIELD_FEATURES_MATURITY => Ok(FeaturesMaturity),
FIELD_FEATURES_SIDE_CHAIN_FEATURES => Ok(FeaturesSideChainFeatures),
FIELD_FEATURES_COINBASE_EXTRA => Ok(FeaturesCoinbaseExtra),

_ => Err(CovenantDecodeError::UnknownByteCode { code: byte }),
}
Expand All @@ -93,7 +91,6 @@ impl OutputField {
FeaturesOutputType => &output.features.output_type as &dyn Any,
FeaturesMaturity => &output.features.maturity as &dyn Any,
FeaturesSideChainFeatures => &output.features.sidechain_feature as &dyn Any,
FeaturesCoinbaseExtra => &output.features.coinbase_extra as &dyn Any,
};
val.downcast_ref::<T>()
}
Expand All @@ -112,7 +109,6 @@ impl OutputField {
FeaturesOutputType => BorshSerialize::serialize(&output.features.output_type, &mut writer),
FeaturesMaturity => BorshSerialize::serialize(&output.features.maturity, &mut writer),
FeaturesSideChainFeatures => BorshSerialize::serialize(&output.features.sidechain_feature, &mut writer),
FeaturesCoinbaseExtra => BorshSerialize::serialize(&output.features.coinbase_extra, &mut writer),
}
.unwrap();
writer
Expand Down Expand Up @@ -151,10 +147,6 @@ impl OutputField {
.features()
.map(|features| features.sidechain_feature == output.features.sidechain_feature)
.unwrap_or(false),
FeaturesCoinbaseExtra => input
.features()
.map(|features| features.coinbase_extra == output.features.coinbase_extra)
.unwrap_or(false),
}
}

Expand Down Expand Up @@ -235,11 +227,6 @@ impl OutputField {
pub fn features_sidechain_feature() -> Self {
OutputField::FeaturesSideChainFeatures
}

#[allow(dead_code)]
pub fn features_metadata() -> Self {
OutputField::FeaturesCoinbaseExtra
}
}

impl Display for OutputField {
Expand All @@ -254,7 +241,6 @@ impl Display for OutputField {
Features => write!(f, "field::features"),
FeaturesOutputType => write!(f, "field::features_flags"),
FeaturesSideChainFeatures => write!(f, "field::features_sidechain_feature"),
FeaturesCoinbaseExtra => write!(f, "field::features_metadata"),
FeaturesMaturity => write!(f, "field::features_maturity"),
}
}
Expand Down Expand Up @@ -386,9 +372,6 @@ mod test {
assert!(OutputField::FeaturesSideChainFeatures
.is_eq(&output, output.features.sidechain_feature.as_ref().unwrap())
.unwrap());
assert!(OutputField::FeaturesCoinbaseExtra
.is_eq(&output, &output.features.coinbase_extra)
.unwrap());
assert!(OutputField::SenderOffsetPublicKey
.is_eq(&output, &output.sender_offset_public_key)
.unwrap());
Expand Down Expand Up @@ -419,7 +402,6 @@ mod test {
assert!(!OutputField::FeaturesOutputType
.is_eq(&output, &OutputType::Coinbase)
.unwrap());
assert!(!OutputField::FeaturesCoinbaseExtra.is_eq(&output, &vec![123u8]).unwrap());
assert!(!OutputField::SenderOffsetPublicKey
.is_eq(&output, &PublicKey::default())
.unwrap());
Expand Down Expand Up @@ -464,7 +446,6 @@ mod test {
assert!(OutputField::FeaturesMaturity.is_eq_input(&input, &output));
assert!(OutputField::FeaturesOutputType.is_eq_input(&input, &output));
assert!(OutputField::FeaturesSideChainFeatures.is_eq_input(&input, &output));
assert!(OutputField::FeaturesCoinbaseExtra.is_eq_input(&input, &output));
assert!(OutputField::SenderOffsetPublicKey.is_eq_input(&input, &output));
}
}
Expand All @@ -476,7 +457,6 @@ mod test {
OutputField::Features,
OutputField::FeaturesOutputType,
OutputField::FeaturesSideChainFeatures,
OutputField::FeaturesCoinbaseExtra,
OutputField::FeaturesMaturity,
OutputField::SenderOffsetPublicKey,
OutputField::Script,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ mod test {
1,
1,
1,
test_params.get_size_for_default_metadata(1),
test_params.get_size_for_default_features_and_scripts(1),
);

let utxo = test_params.create_unblinded_output(UtxoTestParams {
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/transactions/aggregated_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ impl AggregateBody {
transaction_weight.calculate_body(self)
}

pub fn sum_metadata_size(&self) -> usize {
self.outputs.iter().map(|o| o.get_metadata_size()).sum()
pub fn sum_features_and_scripts_size(&self) -> usize {
self.outputs.iter().map(|o| o.get_features_and_scripts_size()).sum()
}

pub fn is_sorted(&self) -> bool {
Expand Down
15 changes: 9 additions & 6 deletions base_layer/core/src/transactions/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ impl Fee {
num_kernels: usize,
num_inputs: usize,
num_outputs: usize,
rounded_metadata_byte_size: usize,
rounded_features_and_scripts_byte_size: usize,
) -> MicroTari {
let weight = self
.weighting()
.calculate(num_kernels, num_inputs, num_outputs, rounded_metadata_byte_size);
let weight = self.weighting().calculate(
num_kernels,
num_inputs,
num_outputs,
rounded_features_and_scripts_byte_size,
);
MicroTari::from(weight) * fee_per_gram
}

Expand Down Expand Up @@ -100,8 +103,8 @@ mod test {
f1.weighting().params().output_weight
);
assert_eq!(
f0.weighting().params().metadata_bytes_per_gram,
f1.weighting().params().metadata_bytes_per_gram
f0.weighting().params().features_and_scripts_bytes_per_gram,
f1.weighting().params().features_and_scripts_bytes_per_gram
);
}

Expand Down
19 changes: 12 additions & 7 deletions base_layer/core/src/transactions/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,11 @@ impl TestParams {
(input, unblinded)
}

pub fn get_size_for_default_metadata(&self, num_outputs: usize) -> usize {
pub fn get_size_for_default_features_and_scripts(&self, num_outputs: usize) -> usize {
let output_features = OutputFeatures { ..Default::default() };
self.fee()
.weighting()
.round_up_metadata_size(script![Nop].get_serialized_size() + output_features.get_serialized_size()) *
num_outputs
self.fee().weighting().round_up_features_and_scripts_size(
script![Nop].get_serialized_size() + output_features.get_serialized_size(),
) * num_outputs
}

pub fn commit_value(&self, value: MicroTari) -> Commitment {
Expand Down Expand Up @@ -517,12 +516,18 @@ pub fn create_unblinded_txos(
) -> (Vec<UnblindedOutput>, Vec<(UnblindedOutput, PrivateKey)>) {
let weighting = TransactionWeight::latest();
// This is a best guess to not underestimate metadata size
let output_metadata_size = weighting.round_up_metadata_size(
let output_features_and_scripts_size = weighting.round_up_features_and_scripts_size(
output_features.get_serialized_size() +
output_script.get_serialized_size() +
output_covenant.get_serialized_size(),
) * output_count;
let estimated_fee = Fee::new(weighting).calculate(fee_per_gram, 1, input_count, output_count, output_metadata_size);
let estimated_fee = Fee::new(weighting).calculate(
fee_per_gram,
1,
input_count,
output_count,
output_features_and_scripts_size,
);
let amount_per_output = (amount - estimated_fee) / output_count as u64;
let amount_for_last_output = (amount - estimated_fee) - amount_per_output * (output_count as u64 - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,29 @@ impl OutputFeatures {
version: OutputFeaturesVersion,
output_type: OutputType,
maturity: u64,
metadata: Vec<u8>,
coinbase_extra: Vec<u8>,
sidechain_feature: Option<SideChainFeature>,
) -> OutputFeatures {
OutputFeatures {
version,
output_type,
maturity,
coinbase_extra: metadata,
coinbase_extra,
sidechain_feature,
}
}

pub fn new_current_version(
flags: OutputType,
maturity: u64,
metadata: Vec<u8>,
coinbase_extra: Vec<u8>,
sidechain_feature: Option<SideChainFeature>,
) -> OutputFeatures {
OutputFeatures::new(
OutputFeaturesVersion::get_current_version(),
flags,
maturity,
metadata,
coinbase_extra,
sidechain_feature,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl TransactionOutput {
.into()
}

pub fn get_metadata_size(&self) -> usize {
pub fn get_features_and_scripts_size(&self) -> usize {
self.features.get_serialized_size() + self.script.get_serialized_size() + self.covenant.get_serialized_size()
}
}
Expand Down
Loading

0 comments on commit 75eabc8

Please sign in to comment.