stellar / soroban-examples

Example Soroban Contracts
Apache License 2.0
65 stars 68 forks source link

unexpected environment interface version(soroban events contract) #237

Closed Julian-dev28 closed 1 year ago

Julian-dev28 commented 1 year ago

Bug Report:

Summary: The user is attempting to invoke a contract called "soroban_events_contract" but encounters an error while executing the command. The error message states that there is an issue with the input arguments provided to the host function, which results in a "HostError". The debug events indicate that an unexpected environment interface version was encountered, and a backtrace is provided. Additionally, to fix the issue, the user made some changes to the cargo.toml file of the project.

Steps to Reproduce:

Build the "soroban_events_contract" using cargo build --target wasm32-unknown-unknown --release. Invoke the "soroban_events_contract" using soroban contract invoke with the following arguments: a. --wasm pointing to the path of the built wasm file. b. --id argument set to 1. c. -- followed by the function name "increment".

soroban contract invoke --wasm target/wasm32-unknown-unknown/release/soroban_events_contract.wasm --id 1 -- increment

Expected Results: The contract should be successfully invoked, and the function increment should be executed. Event should be displayed in terminal

soroban contract invoke \                                 
    --wasm target/wasm32-unknown-unknown/release/soroban_events_contract.wasm \
    --id 1 \
    -- \
    increment
#0: event: {"ext":"v0","contract_id":"0000000000000000000000000000000000000000000000000000000000000001","type_":"contract","body":{"v0":{"topics":[{"symbol":"COUNTER"},{"symbol":"increment"}],"data":{"u32":1}}}}
1

Actual Results: Upon executing the soroban contract invoke command, the following error is encountered:

error: HostError
Value: Status(HostFunctionError(InputArgsInvalid))

Debug events (newest first):
   0: "Debug unexpected environment interface version"

Backtrace (newest first):
   0: backtrace::capture::Backtrace::new_unresolved
   1: soroban_env_host::host::err_helper::<impl soroban_env_host::host::Host>::err
   2: soroban_env_host::host::err_helper::<impl soroban_env_host::host::Host>::err_status_msg
   3: soroban_env_host::vm::Vm::new
   4: soroban_env_host::host::Host::call_n_internal
   5: soroban_env_host::host::Host::invoke_function
   6: soroban_cli::commands::contract::invoke::Cmd::run_in_sandbox
   7: soroban_cli::commands::contract::Cmd::run::{{closure}}
   8: soroban_cli::commands::Root::run::{{closure}}
   9: tokio::runtime::park::CachedParkThread::block_on
  10: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
  11: tokio::runtime::runtime::Runtime::block_on
  12: soroban::main

The debug events indicate that there was an unexpected environment interface version, and the backtrace suggests that there was an error with the host function.

Environment: The error occurred on a MacBook Pro. The user attempted invoking the contract using both soroban version 0.7.0 and soroban version 0.7.1.

Additional Information: To solve the issue, the user made changes to the cargo.toml file of the project and then used cargo build --target wasm32-unknown-unknown --release to rebuild the .wasm file for the increment contract. Specifically, they removed the git and rev fields from the soroban-sdk dependencies, which were pointing to a specific commit on the Stellar Soroban SDK repository. Instead, they included only the version field.

old cargo.toml:

[package]
name = "soroban-events-contract"
version = "0.0.0"
authors = ["Stellar Development Foundation <info@stellar.org>"]
license = "Apache-2.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { version = "0.7.0", git = "https://github.com/stellar/rs-soroban-sdk", rev = "9bbac60c25cee9aa995025db5af828c243d15690"}

[dev_dependencies]
soroban-sdk = { version = "0.7.0", git = "https://github.com/stellar/rs-soroban-sdk", rev = "9bbac60c25cee9aa995025db5af828c243d15690", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true

new cargo.toml

[package]
name = "soroban-events-contract"
version = "0.0.0"
authors = ["Stellar Development Foundation <info@stellar.org>"]
license = "Apache-2.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { version = "0.7.0" }

[dev_dependencies]
soroban-sdk = { version = "0.7.0", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true
Julian-dev28 commented 1 year ago

Error might occur due to an incorrect rev value

The main issue seems to be resolved by updating the rev value to 8abd3353c728f09ee1c8a2544f67a853e915afc2, which is the commit hash for rs-soroban-sdk version 0.7.0.

[dependencies]
soroban-sdk = { version = "0.7.0", git = "https://github.com/stellar/rs-soroban-sdk", rev = "8abd3353c728f09ee1c8a2544f67a853e915afc2"}

[dev_dependencies]
soroban-sdk = { version = "0.7.0", git = "https://github.com/stellar/rs-soroban-sdk", rev = "8abd3353c728f09ee1c8a2544f67a853e915afc2", features = ["testutils"] }
Julian-dev28 commented 1 year ago

This error occurs consistently in all examples when running locally, but it can be fixed by making a change to the cargo.toml file. On the other hand, the examples appear to work without any issues in GitPod.

leighmcculloch commented 1 year ago

This likely means you're running a version of soroban-cli that is not compatible with the contracts on the main branch. You'll need to figure out which soroban-cli (if one exists) that is using the same soroban-sdk and soroban-env as the examples in here. This is not always trivial, as you might need to look through the cli's history and install it from source at the right commit. The soroban-cli source can be found at https://github.com/stellar/soroban-tools.

Note that when folks typically use this example repo, they do so at a specific tag that corresponds to a specific soroban-cli, soroban-sdk, etc, which have all been aligned for a release.

Julian-dev28 commented 1 year ago

Thanks for the response @leighmcculloch I appreciate it.

I have re-cloned the repo and used soroban 0.7.0 and it its working fine

It was my error by cloning the soroban/examples from gh and then working from there instead of cloning the specific version as the tutorial states

Julian-dev28 commented 1 year ago

@leighmcculloch although it doesn't affect the current workflow for users if they follow the example tutorials in their current state, if we update the docs to use the main branch, the dependencies may cause errors for users.

leighmcculloch commented 1 year ago

Are we planning to update the docs to point to the main branch? (The main branch of this repo is at the moment always a work-in-progress, using unreleased development versions of the sdk and env that are probably not compatible with any deployed environment, or even quickstart, and not really ready for use.)

Julian-dev28 commented 1 year ago

Understood

It's possible that my assumption is incorrect. However, I based it on the reference to a layout where the target directory is included in each example's directory, rather than being at the top level. Currently, this implementation is only present in the main branch.

Are we planning to implement this change into the soroban v0.7.0 examples?

leighmcculloch commented 1 year ago

Ah. So those changes shouldn't be published to the docs until the v0.8.0 examples are released.

What we've done in the past is push changes that need to be scheduled with the release to the docs to a dev branch and them merged the dev branch to main at release. But this process might have changed recently. @sisuresh did this process change?

sisuresh commented 1 year ago

We said that we would create a docs branch for the upcoming release (so something like release-v0.8.0) and merge into that. This hasn't been done yet, but I or someone else can create it now since docs are being worked on. The dev branch should be deprecated.

Julian-dev28 commented 1 year ago

Thanks for the clarification everyone

Sorry if I caused any confusion. It sounds like there are a lot of moving pieces and I began working on this prematurely. Please ping me when the changes are pushed and I can get those target directories changed asap!

sisuresh commented 1 year ago

I created a release-preview-9 branch in soroban-docs that can be used to stage docs changes for the next release.