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(transactions): add transaction weight for ValueTransferTransacti… #1301

Merged
merged 1 commit into from
Jun 16, 2020

Conversation

lrubiorod
Copy link
Contributor

…ons and DRTransactions

Close #1298
Close #1299

Copy link
Contributor

@mariocao mariocao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to say apart from what @tmpolaczyk and @girazoki commented! Great PR!

data_structures/src/transaction.rs Show resolved Hide resolved
validations/src/validations.rs Show resolved Hide resolved
data_structures/src/chain.rs Outdated Show resolved Hide resolved
data_structures/src/chain.rs Outdated Show resolved Hide resolved
data_structures/src/error.rs Outdated Show resolved Hide resolved
data_structures/src/error.rs Outdated Show resolved Hide resolved
data_structures/src/transaction.rs Outdated Show resolved Hide resolved
data_structures/src/transaction.rs Outdated Show resolved Hide resolved
let vt_body =
VTTransactionBody::new(vec![Input::default()], vec![ValueTransferOutput::default()]);
let vt_tx = VTTransaction::new(vt_body, vec![KeyedSignature::default()]);
assert_eq!(INPUT_SIZE + OUTPUT_SIZE * GAMMA, vt_tx.weight());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of mistrust tests that re-implement the logic of the computations. I can't see how one piece of code would not conform with another that has been written by the same person using the same programming language.

Moreover, I think that any breaking change in ValueTransferTransaction::weight would go unnoticed — these tests would simply pass.

Using static numbers here is also more useful IMO because they can be used as test vectors for other implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍈

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have both, simply add a line checking the actual value.

data_structures/src/error.rs Outdated Show resolved Hide resolved
Comment on lines 368 to 371
display = "Data Request Transactions weight: {}, exceed the maximum weight: {}",
weight, max_weight
)]
DataRequestWeightOverflow { weight: u32, max_weight: u32 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions from previous block also apply here.

let inputs_len = u32::try_from(self.body.inputs.len()).unwrap_or(u32::MAX);
let outputs_len = u32::try_from(self.body.outputs.len()).unwrap_or(u32::MAX);
let inputs_weight = inputs_len.saturating_mul(INPUT_SIZE);
let outputs_weight = outputs_len.saturating_mul(OUTPUT_SIZE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be changed after #1306, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, later it would be only OUTPUT_SIZE

}

if new_block_weight == max_block_weight {
if new_vt_weight == max_vt_weight {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we know the weight of the lighter possible VTT, we can add that to the left operand in the equality and save a crazy amount of iterations here.

dr_weight += transaction_weight;
}

if new_dr_weight == max_dr_weight {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

data_structures/src/chain.rs Show resolved Hide resolved
pub fn weight(&self) -> u32 {
// Time lock: 8 bytes

let mut retrieves_weight: u32 = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut retrieves_weight: u32 = 0;
let mut retrievals_weight: u32 = 0;

ValueTransferWeightLimitExceeded { weight: u32, max_weight: u32 },
/// Data Request weight limit exceeded
#[fail(
display = "Data Request Transactions weight: {}, exceed the maximum weight: {}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
display = "Data Request Transactions weight: {}, exceed the maximum weight: {}",
display = "Total weight of Data Request Transactions in a block ({}) exceeds the limit ({})",

@lrubiorod lrubiorod force-pushed the tx_weight branch 2 times, most recently from f080652 to 8b4140a Compare June 16, 2020 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate block weights Implement block weights while building a block
5 participants