-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
There was a problem hiding this 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!
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍈
There was a problem hiding this comment.
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.
77e8c75
to
965acb6
Compare
data_structures/src/error.rs
Outdated
display = "Data Request Transactions weight: {}, exceed the maximum weight: {}", | ||
weight, max_weight | ||
)] | ||
DataRequestWeightOverflow { weight: u32, max_weight: u32 }, |
There was a problem hiding this comment.
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.
data_structures/src/transaction.rs
Outdated
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
Outdated
pub fn weight(&self) -> u32 { | ||
// Time lock: 8 bytes | ||
|
||
let mut retrieves_weight: u32 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut retrieves_weight: u32 = 0; | |
let mut retrievals_weight: u32 = 0; |
data_structures/src/error.rs
Outdated
ValueTransferWeightLimitExceeded { weight: u32, max_weight: u32 }, | ||
/// Data Request weight limit exceeded | ||
#[fail( | ||
display = "Data Request Transactions weight: {}, exceed the maximum weight: {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
display = "Data Request Transactions weight: {}, exceed the maximum weight: {}", | |
display = "Total weight of Data Request Transactions in a block ({}) exceeds the limit ({})", |
f080652
to
8b4140a
Compare
…ons and DRTransactions
…ons and DRTransactions
Close #1298
Close #1299