Skip to content

Conversation

@pkhry
Copy link

@pkhry pkhry commented Nov 21, 2025

Description

see title.

alexggh and others added 30 commits October 2, 2025 12:34
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
call_after_invariant: bool,
identified_contracts: Option<&ContractsByAddress>,
) -> TestResult {
self.executor.strategy.runner.rollback_transaction(self.executor.strategy.context.as_ref());
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to rollback transaction before run?

Copy link
Author

Choose a reason for hiding this comment

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

just in case if i missed it anywhere, ie table tests or else

Copy link
Author

Choose a reason for hiding this comment

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

but given that setup happens outside a transaction it's changes are not being rolled back

Self(self.0.clone())
}

pub fn start_snapshotting(&mut self) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why you have not decided to just copy backend like this:

pub fn save_revive_snapshot(snapshot_id: U256) {
    TEST_EXTERNALITIES.with_borrow_mut(|test_ext| {
        let backend = test_ext.as_backend();
        REVIVE_SNAPSHOTS.with_borrow_mut(|snapshots| {
            snapshots.insert(snapshot_id, backend);
        });
    });
}

And revert it like this

pub fn revert_revive_snapshot(snapshot_id: U256) -> bool {
    REVIVE_SNAPSHOTS.with_borrow_mut(|snapshots| {
        if let Some(backend) = snapshots.get(&snapshot_id).cloned() {
            let mut test_externalities = ExtBuilder::default().build();
            let mut backend_copy = backend;
            std::mem::swap(&mut test_externalities.backend, &mut backend_copy);
            TEST_EXTERNALITIES.set(test_externalities);
            true
        } else {
            false
        }
    })
}

Of course this implementation is based on old code base, but when I have implemented it the changes were very minimal.

Copy link
Author

Choose a reason for hiding this comment

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

transaction commit and rollback are much more faster

Copy link
Collaborator

@smiasojed smiasojed Nov 24, 2025

Choose a reason for hiding this comment

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

why? It is mem swap/copy, Rollbacks you are doing in loops. Do you have any numbers?
I see that as_backend could be slow, is there an option to use into_raw_snapshot

Copy link
Author

Choose a reason for hiding this comment

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

yeah, i'll post the comparative changes today. for fuzz tests for example executor.clone was very much noticeable in the .trace output compared to transaction_start and transaction_rollback

Copy link
Author

Choose a reason for hiding this comment

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

why? It is mem swap/copy, Rollbacks you are doing in loops. Do you have any numbers?
I see that as_backend could be slow, is there an option to use into_raw_snapshot

it was even slower than as_backend(), in the thread local impl but i'll add benches today to an issue and tag you so that it's more visible

@pkhry pkhry force-pushed the pkhry/snapshotting_cheats branch from ecd69f2 to 70e30d9 Compare November 24, 2025 17:27
Base automatically changed from pkhry/refactor_externalities_usage to master November 25, 2025 15:02
@pkhry pkhry requested a review from smiasojed November 25, 2025 23:01
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.

4 participants