Skip to content

Commit

Permalink
Revert "add "set" tag as default for serialization"
Browse files Browse the repository at this point in the history
This reverts commit c7682ab.
  • Loading branch information
lisicky committed Sep 3, 2024
1 parent bf3137e commit b8d771c
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 85 deletions.
38 changes: 2 additions & 36 deletions rust/src/builders/batch_tools/cbor_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ impl CborCalculator {
}
}

pub(super) fn get_wrapped_struct_size(items_count: u64) -> usize {
//wrapped struct is a struct of 2 elements, tag and value
let tag_size = CborCalculator::get_tag_size(258);
let value_size = CborCalculator::get_struct_size(items_count);
tag_size + value_size
}

pub(super) fn get_tag_size(tag: u64) -> usize {
Self::get_struct_size(tag)
}

pub(super) fn get_coin_size(coin: &Coin) -> usize {
Self::get_struct_size(coin.clone().into())
}
Expand Down Expand Up @@ -82,35 +71,12 @@ impl CborCalculator {
pub(super) fn get_bare_tx_body_size(body_fields: &HashSet<TxBodyNames>) -> usize {
let mut size = CborCalculator::get_struct_size(body_fields.len() as u64);
for field in body_fields {
let wrapped = match field {
TxBodyNames::Inputs => true,
TxBodyNames::Outputs => false,
TxBodyNames::Fee => false,
TxBodyNames::Ttl => false,
TxBodyNames::Certs => true,
TxBodyNames::Withdrawals => false,
TxBodyNames::Update => false,
TxBodyNames::AuxiliaryDataHash => false,
TxBodyNames::ValidityStartInterval => false,
TxBodyNames::Mint => false,
TxBodyNames::ScriptDataHash => false,
TxBodyNames::Collateral => true,
TxBodyNames::RequiredSigners => true,
TxBodyNames::NetworkId => false,
TxBodyNames::CollateralReturn => false,
TxBodyNames::TotalCollateral => false,
TxBodyNames::ReferenceInputs => true,
};
if wrapped {
size += CborCalculator::get_wrapped_struct_size(field.to_u64().unwrap());
} else {
size += CborCalculator::get_struct_size(field.to_u64().unwrap());
}
size += CborCalculator::get_struct_size(field.to_u64().unwrap());
}
size
}

pub(super) fn get_witnesses_set_struct_size(
pub(super) fn get_wintnesses_set_struct_size(
witnesses_fields: &HashSet<WitnessSetNames>,
) -> usize {
let mut size = CborCalculator::get_struct_size(witnesses_fields.len() as u64);
Expand Down
16 changes: 8 additions & 8 deletions rust/src/builders/batch_tools/witnesses_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ impl WitnessesCalculator {
if self.vkeys_count == 0 {
if self.used_fields.len() > 0 {
self.total_size -=
CborCalculator::get_witnesses_set_struct_size(&self.used_fields);
CborCalculator::get_wintnesses_set_struct_size(&self.used_fields);
}

self.used_fields.insert(WitnessSetNames::Vkeys);
self.total_size += CborCalculator::get_witnesses_set_struct_size(&self.used_fields);
self.total_size += CborCalculator::get_wintnesses_set_struct_size(&self.used_fields);
}

if self.vkeys_count != 0 {
self.total_size -= CborCalculator::get_wrapped_struct_size(self.vkeys_count);
self.total_size -= CborCalculator::get_struct_size(self.vkeys_count);
}
self.vkeys_count += 1;
self.total_size += CborCalculator::get_wrapped_struct_size(self.vkeys_count);
self.total_size += CborCalculator::get_struct_size(self.vkeys_count);
self.total_size += CborCalculator::get_fake_vkey_size();
}

Expand All @@ -164,18 +164,18 @@ impl WitnessesCalculator {
if self.boostrap_count == 0 {
if self.used_fields.len() > 0 {
self.total_size -=
CborCalculator::get_witnesses_set_struct_size(&self.used_fields);
CborCalculator::get_wintnesses_set_struct_size(&self.used_fields);
}

self.used_fields.insert(WitnessSetNames::Bootstraps);
self.total_size += CborCalculator::get_witnesses_set_struct_size(&self.used_fields);
self.total_size += CborCalculator::get_wintnesses_set_struct_size(&self.used_fields);
}

if self.boostrap_count != 0 {
self.total_size -= CborCalculator::get_wrapped_struct_size(self.boostrap_count);
self.total_size -= CborCalculator::get_struct_size(self.boostrap_count);
}
self.boostrap_count += 1;
self.total_size += CborCalculator::get_wrapped_struct_size(self.boostrap_count);
self.total_size += CborCalculator::get_struct_size(self.boostrap_count);
self.total_size += CborCalculator::get_boostrap_witness_size(address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ impl Serialize for Certificates {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(Len::Len(self.len() as u64))?;
for element in &self.certs {
element.serialize(serializer)?;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ impl cbor_event::se::Serialize for Credentials {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(cbor_event::Len::Len(self.len() as u64))?;
for element in self.to_vec() {
element.serialize(serializer)?;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/ed25519_key_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ impl Serialize for Ed25519KeyHashes {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(cbor_event::Len::Len(self.len() as u64))?;
for element in self.to_vec() {
element.serialize(serializer)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ impl cbor_event::se::Serialize for VotingProposals {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(cbor_event::Len::Len(self.len() as u64))?;
for element in &self.proposals {
element.serialize(serializer)?;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/native_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ impl NativeScripts {
need_deduplication: bool,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
if need_deduplication {
let view = self.deduplicated_view();
serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/plutus/plutus_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ impl PlutusList {
need_deduplication: bool,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
let use_definite_encoding = match self.definite_encoding {
Some(definite) => definite,
None => self.elems.is_empty(),
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/plutus/plutus_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl PlutusScripts {
version: &Language,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
let view = match need_deduplication {
true => self.deduplicated_view(Some(version)),
false => self.view(version),
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/tx_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ impl cbor_event::se::Serialize for TransactionInputs {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(cbor_event::Len::Len(self.len() as u64))?;
for element in &self.inputs {
element.serialize(serializer)?;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/witnesses/bootstrap_witnesses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ impl cbor_event::se::Serialize for BootstrapWitnesses {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(cbor_event::Len::Len(self.get_vec_wits().len() as u64))?;
for element in self.get_vec_wits() {
element.serialize(serializer)?;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/serialization/witnesses/vkeywitnesses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ impl cbor_event::se::Serialize for Vkeywitnesses {
&self,
serializer: &'se mut Serializer<W>,
) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_tag(258)?;
//TODO: uncomment this line when we conway ero will come
//serializer.write_tag(258)?;
serializer.write_array(cbor_event::Len::Len(self.witnesses.len() as u64))?;
for element in &self.witnesses {
element.serialize(serializer)?;
Expand Down
28 changes: 14 additions & 14 deletions rust/src/tests/builders/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn build_tx_with_change() {
.checked_add(&Value::new(&tx_builder.get_fee_if_set().unwrap()))
.unwrap()
);
assert_eq!(tx_builder.full_size().unwrap(), 291);
assert_eq!(tx_builder.full_size().unwrap(), 285);
assert_eq!(tx_builder.output_sizes(), vec![62, 65]);
let _final_tx = tx_builder.build(); // just test that it doesn't throw
}
Expand Down Expand Up @@ -172,7 +172,7 @@ fn build_tx_with_change_with_datum() {
.checked_add(&Value::new(&tx_builder.get_fee_if_set().unwrap()))
.unwrap()
);
assert_eq!(tx_builder.full_size().unwrap(), 325);
assert_eq!(tx_builder.full_size().unwrap(), 319);
assert_eq!(tx_builder.output_sizes(), vec![62, 99]);
let _final_tx = tx_builder.build(); // just test that it doesn't throw
}
Expand Down Expand Up @@ -304,8 +304,8 @@ fn build_tx_with_certs() {
)
.to_address();
tx_builder.add_change_if_needed(&change_addr).unwrap();
assert_eq!(tx_builder.min_fee().unwrap().to_str(), "218502");
assert_eq!(tx_builder.get_fee_if_set().unwrap().to_str(), "218502");
assert_eq!(tx_builder.min_fee().unwrap().to_str(), "214002");
assert_eq!(tx_builder.get_fee_if_set().unwrap().to_str(), "214002");
assert_eq!(tx_builder.get_deposit().unwrap().to_str(), "1000000");
assert_eq!(tx_builder.outputs.len(), 1);
assert_eq!(
Expand Down Expand Up @@ -559,7 +559,7 @@ fn build_tx_with_inputs() {
)
.unwrap()
.to_str(),
"71000"
"69500"
);
tx_builder.add_regular_input(
&EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred)
Expand Down Expand Up @@ -1592,7 +1592,7 @@ fn build_tx_with_native_assets_change_and_no_purification_cuz_not_enough_pure_co
);
// The single change output contains more Coin then minimal utxo value
// But not enough to cover the additional fee for a separate output
assert_eq!(final_tx.outputs().get(1).amount().coin(), BigNum(493));
assert_eq!(final_tx.outputs().get(1).amount().coin(), BigNum(499));
}

#[test]
Expand Down Expand Up @@ -2512,15 +2512,15 @@ fn tx_builder_cip2_random_improve_adds_enough_for_fees() {
.unwrap(),
)
.unwrap();
assert_eq!(tx_builder.min_fee().unwrap(), BigNum(56));
assert_eq!(tx_builder.min_fee().unwrap(), BigNum(53));
let mut available_inputs = TransactionUnspentOutputs::new();
available_inputs.add(&make_input(1u8, Value::new(&BigNum(150))));
available_inputs.add(&make_input(2u8, Value::new(&BigNum(150))));
available_inputs.add(&make_input(3u8, Value::new(&BigNum(150))));
let add_inputs_res =
tx_builder.add_inputs_from(&available_inputs, CoinSelectionStrategyCIP2::RandomImprove);
assert!(add_inputs_res.is_ok(), "{:?}", add_inputs_res.err());
assert_eq!(tx_builder.min_fee().unwrap(), BigNum(270));
assert_eq!(tx_builder.min_fee().unwrap(), BigNum(264));
let change_addr =
ByronAddress::from_base58("Ae2tdPwUPEZGUEsuMAhvDcy94LKsZxDjCbgaiBBMgYpR8sKf96xJmit7Eho")
.unwrap()
Expand Down Expand Up @@ -3529,7 +3529,7 @@ fn add_mint_includes_witnesses_into_fee_estimation() {

// Original tx fee now assumes two VKey signatures for two inputs
let original_tx_fee = tx_builder.min_fee().unwrap();
assert_eq!(original_tx_fee, BigNum(168625));
assert_eq!(original_tx_fee, BigNum(168361));

// Add minting four assets from three different policies
tx_builder.add_mint_asset(&mint_script1, &name1, &amount).expect("Failed to add mint asset");
Expand All @@ -3555,7 +3555,7 @@ fn add_mint_includes_witnesses_into_fee_estimation() {
.unwrap();

assert_eq!(raw_mint_fee, BigNum(5544));
assert_eq!(raw_mint_script_fee, BigNum(4444));
assert_eq!(raw_mint_script_fee, BigNum(4312));

let new_tx_fee = tx_builder.min_fee().unwrap();

Expand Down Expand Up @@ -4364,10 +4364,10 @@ fn test_ex_unit_costs_are_added_to_the_fees() {
tx_builder.get_fee_if_set().unwrap()
}

assert_eq!(calc_fee_with_ex_units(0, 0), BigNum(174169));
assert_eq!(calc_fee_with_ex_units(10000, 0), BigNum(174834));
assert_eq!(calc_fee_with_ex_units(0, 10000000), BigNum(175066));
assert_eq!(calc_fee_with_ex_units(10000, 10000000), BigNum(175731));
assert_eq!(calc_fee_with_ex_units(0, 0), BigNum(173509));
assert_eq!(calc_fee_with_ex_units(10000, 0), BigNum(174174));
assert_eq!(calc_fee_with_ex_units(0, 10000000), BigNum(174406));
assert_eq!(calc_fee_with_ex_units(10000, 10000000), BigNum(175071));
}

#[test]
Expand Down
Loading

0 comments on commit b8d771c

Please sign in to comment.