-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add expiration policy #871
base: master
Are you sure you want to change the base?
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.
About time we added the expiration :) Both maturity and expiration are important for predicate writing.
We might want to beef up the tests around da_compression.rs to cover policy compression/decompression, as right now it is only testing randomly generated txs without any policies. cc @Dentosal |
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.
LGTM!
Co-authored-by: Andrea Cerone <[email protected]>
fuel-tx/src/transaction/policies.rs
Outdated
@@ -305,6 +328,11 @@ impl Distribution<Policies> for Standard { | |||
policies.set(PolicyType::Maturity, Some(maturity as u64)); | |||
} | |||
|
|||
if policies.get(PolicyType::Expiration).is_some() { |
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.
nit: I think we can use is_set()
instead of get(...).is_some()
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.
Nice. Changed it and for Maturity above also.
let rng = &mut StdRng::seed_from_u64(2322u64); | ||
|
||
// Given | ||
const EXPIRATION: BlockHeight = BlockHeight::new(2); |
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.
const EXPIRATION: BlockHeight = BlockHeight::new(2); | |
const EXPIRATION: BlockHeight = BlockHeight::new(1); |
to clearly show that transactions expire only when the current block height is higher than the specified expiry block (if the match, the transaction is still ok).
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.
For the record, I'd also add a similar test fn transaction__execution__doesn_not_work_after_expiration()
and use, for example:
const EXPIRATION: BlockHeight = BlockHeight::new(9);
const BLOCK_HEIGHT: BlockHeight = BlockHeight::new(10);
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 added a new test to test the current height. However it seems that for maturiy we only test correct case here (failed cases are test elsewhere) but I tried to make one here but finalize_checked
is panicking on error.
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 think we can also update the into_ready
function to verify the expiration policy as well. Because this function exists to verify stuff that can change after verification.
// Given | ||
let err = Transaction::script( | ||
Default::default(), | ||
vec![], | ||
vec![], | ||
Policies::new().with_expiration(999.into()).with_max_fee(0), | ||
vec![], | ||
vec![], | ||
vec![], | ||
) | ||
// When | ||
.check(block_height, &test_params()) | ||
.expect_err("Expected erroneous transaction"); |
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.
// Given | |
let err = Transaction::script( | |
Default::default(), | |
vec![], | |
vec![], | |
Policies::new().with_expiration(999.into()).with_max_fee(0), | |
vec![], | |
vec![], | |
vec![], | |
) | |
// When | |
.check(block_height, &test_params()) | |
.expect_err("Expected erroneous transaction"); | |
// Given | |
let old_block_height = 999u32.into(); | |
let err = Transaction::script( | |
Default::default(), | |
vec![], | |
vec![], | |
Policies::new().with_expiration(old_block_height).with_max_fee(0), | |
vec![], | |
vec![], | |
vec![], | |
) | |
// When | |
.check(block_height, &test_params()) | |
.expect_err("Expected erroneous transaction"); |
} | ||
|
||
#[test] | ||
fn script__check__invalid_expiration_policy() { |
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.
Why we can't use the same pattern like in
TransactionBuilder::create(rng.gen(), rng.gen(), vec![])
// Given
.expiration(block_height)
.add_fee_input()
.add_contract_created()
.finalize()
// When
.check(block_height, &test_params())
// Then
.expect("Failed to validate tx create");
?
The same about Create
transaction
@@ -358,6 +361,10 @@ where | |||
Err(ValidityError::TransactionMaturity)?; | |||
} | |||
|
|||
if tx.expiration() < block_height { |
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.
@dmihal @bajpai244 What do we expect when tx.expiration == block_height
? Should it fail or should it pass?
FuelLabs/fuel-specs#593
Spec PR : FuelLabs/fuel-specs#616
Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]