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

fix: make block number in txe make sense #11807

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sklppy88
Copy link
Contributor

@sklppy88 sklppy88 commented Feb 7, 2025

Right now env.block_number() returns the block number that is currently being built, as per an arbitrary choice when creating the TXe.

But this has a strange side effect of the current block (from the header) and env.block_number() not matching up. The current header has env.block_number() - 1 because the current header reflects the state of the last committed block.

Before this mattered less because we couldn't do historical proofs, and because we had less of a notion of "correctness" in blocks but now due to the changes this makes sense to change.

Copy link
Contributor Author

sklppy88 commented Feb 7, 2025

@sklppy88 sklppy88 changed the title init fix: make block number in txe make sense Feb 7, 2025
@sklppy88 sklppy88 marked this pull request as ready for review February 7, 2025 13:04
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch 2 times, most recently from 3bb2506 to 57bee7d Compare February 7, 2025 16:35
@@ -54,7 +54,7 @@ unconstrained fn test_get_scheduled_value_in_public() {

let (scheduled, block_of_change) = state_var.get_scheduled_value();
assert_eq(scheduled, new_value);
assert_eq(block_of_change, env.block_number() + TEST_INITIAL_DELAY);
assert_eq(block_of_change, env.block_number() + 1 + TEST_INITIAL_DELAY);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because now env.block_number() to the most recent committed block, the initial delay needs to be added the block that this tx will be committed in (which is env.block_number() + 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nobody reading the test would have any clue why this is the case. We need better naming here.

@@ -120,7 +120,7 @@ unconstrained fn test_get_scheduled_delay_in_public() {
let (scheduled, block_of_change) = state_var.get_scheduled_delay();
assert_eq(scheduled, new_delay);
// The new delay is smaller, therefore we need to wait for the difference between current and new
assert_eq(block_of_change, env.block_number() + TEST_INITIAL_DELAY - new_delay);
assert_eq(block_of_change, env.block_number() + 1 + TEST_INITIAL_DELAY - new_delay);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above

@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch 3 times, most recently from 35cc0c4 to cd72a0e Compare February 10, 2025 14:19
@sklppy88 sklppy88 force-pushed the ek/fix/make-block-number-in-txe-make-sense branch from cd72a0e to 69c913c Compare February 10, 2025 15:18
@@ -22,7 +22,7 @@ impl TestEnvironment {
}

pub unconstrained fn block_number(_self: Self) -> u32 {
get_block_number()
get_block_number() - 1
Copy link
Contributor

@benesjan benesjan Feb 11, 2025

Choose a reason for hiding this comment

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

This function needs to be documented. It's also just weird that we have a env.block_number() function and it returns different thing from get_block_number() oracle.

I think we should rename TestEnvironment::block_number to TestEnvironment::committed_block_number or smt. Or alternatively to historical_block_number since we call it like that here.

Also do you know what block number would be used in private calls and what be used in public calls? Would it be the case that in private we would have output of env.block_number() and in public it would be incremented by 1?

@@ -54,7 +54,7 @@ unconstrained fn test_get_scheduled_value_in_public() {

let (scheduled, block_of_change) = state_var.get_scheduled_value();
assert_eq(scheduled, new_value);
assert_eq(block_of_change, env.block_number() + TEST_INITIAL_DELAY);
assert_eq(block_of_change, env.block_number() + 1 + TEST_INITIAL_DELAY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nobody reading the test would have any clue why this is the case. We need better naming here.

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.

2 participants