Skip to content

Commit

Permalink
Fix top contract invocation hook and auth interaction (stellar#1231)
Browse files Browse the repository at this point in the history
### What
Trigger top contract invocation finish hook after storing the auth
manager.

### Why
So that hook implementations can access the auth state that occurred
during the run.

### Merging
Intended to be merged to `main` after:
- stellar#1230
  • Loading branch information
leighmcculloch authored Nov 18, 2023
1 parent cfd2df9 commit 8e593ab
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions soroban-env-host/src/host/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ impl Host {
}
#[cfg(any(test, feature = "testutils"))]
if end_depth == 0 {
// Empty call stack in tests means that some contract function call
// has been finished and hence the authorization manager can be reset.
// In non-test scenarios, there should be no need to ever reset
// the authorization manager as the host instance shouldn't be
// shared between the contract invocations.
*self.try_borrow_previous_authorization_manager_mut()? =
Some(self.try_borrow_authorization_manager()?.clone());
self.try_borrow_authorization_manager_mut()?.reset();

// Call the contract invocation hook for contract invocations only.
if is_top_contract_invocation {
if let Some(top_contract_invocation_hook) =
Expand All @@ -477,14 +486,6 @@ impl Host {
);
}
}
// Empty call stack in tests means that some contract function call
// has been finished and hence the authorization manager can be reset.
// In non-test scenarios, there should be no need to ever reset
// the authorization manager as the host instance shouldn't be
// shared between the contract invocations.
*self.try_borrow_previous_authorization_manager_mut()? =
Some(self.try_borrow_authorization_manager()?.clone());
self.try_borrow_authorization_manager_mut()?.reset();
}
res
}
Expand Down

0 comments on commit 8e593ab

Please sign in to comment.