Fix testutils incompatibility with soroban-ledger-snapshot#1476
Conversation
I would argue that dependency reduction is a side effect, and the primary point of 'features' is to conditionally compile, well, features, as the name suggests. And in case of While I don't mind this PR, I don't quite understand the motivation behind not enabling testutils in snapshot, specifically this part:
Isn't the snapshot a test utility as a whole? Also, I can't imagine a scenario where host doesn't run in testutils mode and the snapshot is used. Getting the intermediate stored entries is not something that |
|
Rust features are ideally additive, they're really designed around being additive. The compiler can enable them even for crates that don't request them, so the assumption in the tooling is that they're additive. That becomes a problem when the testutils feature permeating across so many crates, and traits also change depending on the feature. The stellar-cli workspace includes the soroban-sdk without testutils, and the soroban-ledger-snapshot without needing the Host functionality. That's why I've removed the unconditional inclusion of testutils on soroban-legder-snapshot, because we can't enable the soroban-sdk with testutils in its use cases in the stellar-cli workspace. |
Sorry, I'm not sure I understand the sentiment here. I agree that changing the traits is not ideal and we need to break them down instead. But otherwise, I don't see what's wrong with passing the feature around for crates that actually need it. If that's about the name, then we could name it 'dev_mode' or something like that in order to not imply just the testing use cases.
The CLI->SDK dependency doesn't seem necessary at all, I can only see the SDK crate itself being used for the XDR dependencies, which is actually wrong. As for the snapshot dependency, doesn't that mean that snapshot should have a feature for the host functionality? (in case if we care about reducing the amount of dependencies, that is). |
What
Add a
testutilsfeature tosoroban-ledger-snapshot, and use it to gate the functionality in ledger snapshots that uses thesoroban-env-host'stestutilsfeatures.Why
In #1467 the
soroban-ledger-snapshotcrate dependency onsoroban-env-hostwas changed to include an always-enabled dependency on thetestutilsfeature. This appears to have been done because the functionget_stored_entriesof theHostwas changed from being always available, to only available intestutilsmode. Thesoroban-ledger-snapshotcrate uses theget_stored_entriesfunction.A side-effect of of always pulling in the
soroban-env-hostis that thesoroban-ledger-snapshotcrate became incompatible with any project that also depends on thesoroban-sdkwithout itstestutilfeature enabled. This is because thesoroban_env_host::EnvBasetrait type, which is implemented by thesoroban-sdkcrate, has functions that are required when thetestutilfeature is enabled.To resolve the above challenges with only changes to this repository the most straight-forward thing to do is to move the functionality in
soroban-ledger-snapshotthat now needstestutilsinsoroban-env-hostbehind atestutilsfeature as well, whichsoroban-sdkenables when it usessoroban-ledger-snapshot.Known Limitations
Features on traits, like
EnvBase, inherently create situations where dependencies can get stuck in situations where they are incompatible because another dep might be dependent on the trait in the opposite state. We should probably revisitEnvBase's liberal use of features, breaking it up into separate traits. Rust features should always be, where possible, additively compatible. I've opened the following issue for us to explore that sometime:We may also want to revisit whether some simple getters like
get_stored_entriestruly need to be gated behind a testutils flag. Features in general come at a cost in maintenance and rigidity. Typically features in Rust projects are used to reduce dependencies, but insoroban-env-hostwe are using it to limit features in different use cases.After #1467 and the change in this PR, some of the functionality in
soroban-ledger-snapshotcrate is unusable with theHost, unless theHostis being used intestutilsmode. Today the only uses of the library that use that functionality is when thesoroban-sdkis also being used withtestutilsenabled, but it is feasible that we may want to use the functionality in situations where it doesn't make sense to run theHostintestutilsmode. This would probably mean changing the function insoroban-env-hostthat became testutils only, to be available withouttestutilsagain. We don't need it today, so I'm not proposing it today.cc @stellar/devx @stellar/contract-committers @fnando