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

Refactor soroban-simulation to use the e2e_invoke #1354

Merged
merged 12 commits into from
Feb 28, 2024

Conversation

dmkozh
Copy link
Contributor

@dmkozh dmkozh commented Feb 24, 2024

What

Refactor soroban-simulation to use the e2e_invoke and also to be more modular/reusable.

  • Use e2e_invoke for invoking host functions in recording mode
  • Separate network config and adjustment config into separate structs for easier testing/caching etc.
  • Clean up the storage logic to clearly distinguish between snapshots with and without archive access
  • Added some documentation for public functions/structs
  • Added some basic test coverage. I didn't try to verify the math for every number, but I did sanity-check them. The host function simulation accuracy is mostly covered on e2e_invoke side.
  • Reuse host code for common test and non-test utilities

Why

Improving simulation quality, as well as maintainability.

Known limitations

N/A

- Simplify `SnapshotSource` interface
- Expose some useful functions as public and decoupled from `Host`
- Expose most of the test utils for e2e testing
@dmkozh dmkozh requested review from graydon, sisuresh and a team as code owners February 24, 2024 01:53
…re modular/reusable.

- Use e2e_invoke for invoking host functions in recording mode
- Separate network config and adjustment config into separate structs for easier testing/caching etc.
- Clean up the storage logic to clearly distinguish between snapshots with and without archive access
- Added some documentation for public functions/structs
- Added some basic test coverage. I didn't try to verify the math for every number, but I did sanity-check them. The host function simulation accuracy is mostly covered on `e2e_invoke` side.
@2opremio
Copy link
Contributor

2opremio commented Feb 28, 2024

@dmkozh Nice! I see that the public API has changed. Did you take into consideration the impact at https://github.com/stellar/soroban-rpc/blob/main/cmd/soroban-rpc/lib/preflight/src/lib.rs and whether it satisfies all the current functionality?

@2opremio
Copy link
Contributor

@dmkozh I would like to make sure that all integration tests of soroban-rpc pass after these changes. Could you take a stab at adapting the rpc code?

@2opremio
Copy link
Contributor

Another option is to do this in a two-step process, keeping an externally-compatible layer at first.

@dmkozh
Copy link
Contributor Author

dmkozh commented Feb 28, 2024

Did you take into consideration the impact at https://github.com/stellar/soroban-rpc/blob/main/cmd/soroban-rpc/lib/preflight/src/lib.rs and whether it satisfies all the current functionality?

Of course, these changes are meant to be functionally no-op (besides the additional capabilities, like ledger diffs we've discussed before - but there is no need to use them immediately). I'll definitely help with the migration, but this PR has to be finalized first.

@dmkozh dmkozh added this pull request to the merge queue Feb 28, 2024
Merged via the queue into stellar:main with commit 0ceb08b Feb 28, 2024
13 checks passed
@dmkozh dmkozh deleted the sim_refactor branch February 28, 2024 22:56
Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

A couple asks are inline. At minimum can we fix the docs issue before this is released?

Comment on lines +102 to +105
# These changes may be used by the 'Soroban-owned' crates, such as
# stellar-core, soroban-simulation, and soroban-sdk.
# When bumping the major version of soroban-env-host all the code guarded
# by this feature should be enabled unconditionally.
Copy link
Member

@leighmcculloch leighmcculloch Feb 28, 2024

Choose a reason for hiding this comment

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

It feels odd to say this functionality can only be used by certain crates. Realistically anyone can use this functionality. What we should communicate about is who can safely use this functionality without big surprises or breaking builds.

Suggested change
# These changes may be used by the 'Soroban-owned' crates, such as
# stellar-core, soroban-simulation, and soroban-sdk.
# When bumping the major version of soroban-env-host all the code guarded
# by this feature should be enabled unconditionally.
# These changes should only be used by importers who depend on
# an exact patch version of the crates in this repo, because breaking
# changes may be introduced into any version in any code gated by
# this feature. When bumping the major version of any crates in this
# repo all the code guarded by this feature should be enabled
# unconditionally.

Comment on lines +83 to +84
#[cfg(any(test, feature = "unstable-next-api"))]
pub contract_events_and_return_value_size: u32,
Copy link
Member

Choose a reason for hiding this comment

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

This field will show up in the docs on docs.rs without any disclaimer it is only available with a certain feature. We have a couple options:

  1. Mark any unstable-next-api using the doc attribute so that docs.rs knows that it is only available with certain features and will display so.

    This is what we do for testutils in the sdk. It requires more work. It's good for things we want people to use.

    See this example for how to do it:
    https://github.com/stellar/rs-soroban-sdk/blob/9d802fc8ab82ff571e71b85c790b397b680a00bf/soroban-sdk/src/testutils.rs#L2

  2. Tell docs.rs not to enable the unstable-next-api feature at all when building docs so that none of these features show up in the docs at all.

    This is the simpler approach. It's a single line in a toml file. We need to change:

    [package.metadata.docs.rs]
    all-features = true

My gut feel is we should do (2), because we don't see a ton of value in people using this features asap.

Comment on lines +163 to +166
#[cfg(any(test, feature = "unstable-next-api"))]
let entry_with_live_until = init_storage_snapshot.get(key)?;
#[cfg(not(any(test, feature = "unstable-next-api")))]
let entry_with_live_until = if init_storage_snapshot.has(key)? {
Copy link
Member

Choose a reason for hiding this comment

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

The fact that test is included in here as an any condition suggests that the non-unstable code is not tested. How can we still test it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there is anything to test in this particular case. SnapshotSource is not really covered directly. The new field is covered in the tests as well and I don't see much value in covering not returning this field.

dmkozh added a commit to dmkozh/rs-soroban-env that referenced this pull request Feb 28, 2024
github-merge-queue bot pushed a commit that referenced this pull request Feb 29, 2024
### What

This is a small followup/cleanup after
#1354. Updated comments
and exclude some features from the generated docs.

### Why

Cleanup

### Known limitations

N/A

---------

Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com>
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