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

stellar tx build --meta creates multiple entries #1694

Open
Ifropc opened this issue Oct 31, 2024 · 14 comments
Open

stellar tx build --meta creates multiple entries #1694

Ifropc opened this issue Oct 31, 2024 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@Ifropc
Copy link
Contributor

Ifropc commented Oct 31, 2024

What version are you using?

Latest main

What did you do?

Run the same command multiple times:

stellar contract build --meta example-key=example-value --out-dir /tmp

What did you expect to see?

Only one meta with example-key: example-value is present in the contract

What did you see instead?

Every time command is executed new meta is appended:

[ifro@nixos:~/projects/soroban-examples/hello_world]$ stellar contract build --meta example-key=example-value --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.09s

[ifro@nixos:~/projects/soroban-examples/hello_world]$ stellar contract deploy --source-account alice --network testnet --wasm /tmp/soroban_hello_world_contract.wasm
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
ℹ️ Simulating install transaction…
🌎 Submitting install transaction…
ℹ️ Signing transaction: 54fb1841df752dcc278eea7408763d4cf1e2c7f061f6462542e27bf8c7e22fb1
ℹ️ Using wasm hash 51090ba2e814d119bccdd78e81f454aa694bff5c7ab15945cac65d8425369780
ℹ️ Simulating deploy transaction…
🌎 Submitting deploy transaction…
ℹ️ Transaction hash is 5005c2b7027f67a059c45e7e37feac8fffec2327f0197b2af42d5c6b18a35132
🔗 https://stellar.expert/explorer/testnet/tx/5005c2b7027f67a059c45e7e37feac8fffec2327f0197b2af42d5c6b18a35132
ℹ️ Signing transaction: 5005c2b7027f67a059c45e7e37feac8fffec2327f0197b2af42d5c6b18a35132
🔗 https://stellar.expert/explorer/testnet/contract/CDHJ7TEZPRB2QOOJFGUN32PRZAGGZSP7C2BMW5OFZCS6AYBP63RAPJ7H
✅ Deployed!
CDHJ7TEZPRB2QOOJFGUN32PRZAGGZSP7C2BMW5OFZCS6AYBP63RAPJ7H

[ifro@nixos:~/projects/soroban-examples/hello_world]$ stellar contract info meta --id CDHJ7TEZPRB2QOOJFGUN32PRZAGGZSP7C2BMW5OFZCS6AYBP63RAPJ7H --network testnet
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
Contract meta:
 • rsver: 1.82.0 (Rust version)
 • rssdkver: 21.4.0#d6f5639f643d76e758beecbb0ca391f8cd304c24 (Soroban SDK version and it's commit hash)
 • foo: bar
 • foo: bar
 • test-key: test-value
 • example-key: example-value

[ifro@nixos:~/projects/soroban-examples/hello_world]$ wasm-cs  /tmp/soroban_hello_world_contract.wasm ls
contractspecv0 (52 bytes)
contractenvmetav0 (12 bytes)
contractmetav0 (96 bytes)
contractmetav0 (20 bytes)
contractmetav0 (20 bytes)
contractmetav0 (32 bytes)
contractmetav0 (40 bytes)

(Here I ran the same command with the same out-dir 4 times: as you can see every time we append a new meta to the file, on top of an existing one)


The simplest solution would be to delete existing wasm file. Because we append new contractmetav0 to an existing file, if the file already exists we will do just that -- append it to a "dirty" WASM

@Ifropc Ifropc added the bug Something isn't working label Oct 31, 2024
@github-project-automation github-project-automation bot moved this to Backlog (Not Ready) in DevX Oct 31, 2024
@Ifropc
Copy link
Contributor Author

Ifropc commented Oct 31, 2024

cc @elizabethengelman

@leighmcculloch
Copy link
Member

I'm not able to reproduce the behaviour described above:

$ stellar contract build --out-dir out --meta a=b && stellar contract info meta --wasm out/test_account.wasm --network testnet
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.07s
Contract meta:
 • rsver: 1.81.0 (Rust version)
 • rssdkver: 22.0.0-rc.3#c621381cbd971eee4109866605537be9b298927c-dirty (Soroban SDK version and it's commit hash)
 • a: b

$ stellar contract build --out-dir out --meta a=b && stellar contract info meta --wasm out/test_account.wasm --network testnet
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.07s
Contract meta:
 • rsver: 1.81.0 (Rust version)
 • rssdkver: 22.0.0-rc.3#c621381cbd971eee4109866605537be9b298927c-dirty (Soroban SDK version and it's commit hash)
 • a: b

@leighmcculloch
Copy link
Member

@Ifropc Could you share a full set of commands you're running to reproduce the issue?

@Ifropc
Copy link
Contributor Author

Ifropc commented Nov 1, 2024

@leighmcculloch can you try running build command in the same setup multiple times?

@leighmcculloch
Copy link
Member

See above, the output is me running the build command multiple times. If that isn't what you were doing can you share an example?

@Ifropc
Copy link
Contributor Author

Ifropc commented Nov 1, 2024

[ ~/projects/soroban-examples/hello_world ] > ls /tmp | grep wasm                                                   
[ ~/projects/soroban-examples/hello_world ] > stellar contract build --meta example-key=example-value --out-dir /tmp
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Updating crates.io index
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
== trimmed output, compiling contract for the first time ==
    Finished `release` profile [optimized] target(s) in 19.69s
[ ~/projects/soroban-examples/hello_world ] > stellar contract build --meta example-key=example-value --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.06s
[ ~/projects/soroban-examples/hello_world ] > stellar contract build --meta example-key=example-value --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.05s
[ ~/projects/soroban-examples/hello_world ] > stellar contract build --meta example-key=example-value --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.06s
[ ~/projects/soroban-examples/hello_world ] > stellar contract info meta --wasm /tmp/soroban_hello_world_contract.wasm --network testnet 
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
Contract meta:
 • rsver: 1.82.0 (Rust version)
 • rssdkver: 21.7.4#f67b4bf2d2de04d87d28225a99027fd40b7da914 (Soroban SDK version and it's commit hash)
 • example-key: example-value
 • example-key: example-value
 • example-key: example-value
 • example-key: example-value

^ Tried on a different machine just in case

@Ifropc
Copy link
Contributor Author

Ifropc commented Nov 1, 2024

I can check on this issue when I have time especially if it's not reproducible 🤔

@elizabethengelman
Copy link
Contributor

Thanks for making an issue @Ifropc - I heard you mention something about this in the demo yesterday, and wanted to reach out to check on it.

I may be incorrect with this, but the way my mental model works is that each time we run stellar contract build it will re-compile the wasm binary, and overwrite the existing wasm file. In that case, I'm not sure how we would have multiple meta entries since the change to add meta on build is happening after the wasm is rebuilt, so it should just add what is passed in as args on build. 🤔

I can try to repro it as well, and am happy to dig into it a bit on Monday.

@elizabethengelman
Copy link
Contributor

I tried to reproduce this issue this morning, and wasn't able to. Here's what I did. @Ifropc lmk if you want another set of eyes while you dig into this - happy to help out!

➜ stellar contract build --meta example-key=example-value --meta hello=goodbye --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=contracts/hello-world/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.16s
➜ stellar contract build --meta example-key=example-value --meta hello=goodbye --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=contracts/hello-world/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.14s
➜ stellar contract build --meta example-key=example-value --meta hello=goodbye --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=contracts/hello-world/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.15s
➜ stellar contract build --meta example-key=example-value --meta hello=goodbye --meta hola=adios  --out-dir /tmp
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
cargo rustc --manifest-path=contracts/hello-world/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
    Finished `release` profile [optimized] target(s) in 0.17s
➜ stellar contract deploy --source alice --network testnet --wasm /tmp/hello_world.wasm
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
ℹ️ Simulating install transaction…
🌎 Submitting install transaction…
ℹ️ Signing transaction: 8d8cbb6f5aa1c2e2734fdaa10fe95bce653d7cf13bc7753797b929c3a6ff1502
ℹ️ Using wasm hash 804f2cdefc544178b9d3041bd6a0e7201a9a1a7c0c6216b480ac1d8466ff6314
ℹ️ Simulating deploy transaction…
🌎 Submitting deploy transaction…
ℹ️ Transaction hash is 27ca2fdecfcf680c244f3748d6d52f45b98d6683249b6fe2266d518a1794822d
🔗 https://stellar.expert/explorer/testnet/tx/27ca2fdecfcf680c244f3748d6d52f45b98d6683249b6fe2266d518a1794822d
ℹ️ Signing transaction: 27ca2fdecfcf680c244f3748d6d52f45b98d6683249b6fe2266d518a1794822d
🔗 https://stellar.expert/explorer/testnet/contract/CDM3XH2NHXHJDA3WYGMLK3J7BSLIDEW25SUASUG2LO3N2TUPKC32XUJE
✅ Deployed!
CDM3XH2NHXHJDA3WYGMLK3J7BSLIDEW25SUASUG2LO3N2TUPKC32XUJE
➜ stellar contract info meta --id CDM3XH2NHXHJDA3WYGMLK3J7BSLIDEW25SUASUG2LO3N2TUPKC32XUJE --network testnet
⚠️ A new release of stellar-cli is available: 21.5.0 -> 21.5.3
Contract meta:
 • rsver: 1.81.0 (Rust version)
 • rssdkver: 21.7.6#c6cca8f8cf75618c24ceb5d9ffdfe735486ae1e9 (Soroban SDK version and it's commit hash)
 • example-key: example-value
 • hello: goodbye
 • hola: adios

@Ifropc Ifropc self-assigned this Nov 4, 2024
@leighmcculloch
Copy link
Member

@Ifropc could you share a Dockerfile that demonstrates the issue?

@Ifropc
Copy link
Contributor Author

Ifropc commented Nov 5, 2024

@leighmcculloch I'll get back to this issue a bit later and will try to reproduce it locally again and dig a bit more into it. Will see if it can be reproduced in the docker

@elizabethengelman
Copy link
Contributor

@leighmcculloch @Ifropc I was able to reproduce this bug in a docker container.

FROM rust:1.81

# Set the working directory to /app
WORKDIR /app

RUN apt-get update && apt-get install -y curl libudev-dev jq
RUN git clone https://github.com/stellar/stellar-cli.git && cd stellar-cli && cargo build --release
RUN echo "alias stellar='/app/stellar-cli/target/release/stellar'" >> ~/.bashrc

# Set the default command to run when the container starts
CMD ["bash"]

and then to run:

docker build -t cli .
docker run -it cli

and once in the docker container:

stellar contract init ./test && cd test
stellar contract build --meta example-key=example-value --out-dir out
stellar contract build --meta example-key=example-value --out-dir out
stellar contract info meta --wasm out/hello_world.wasm --network testnet

@elizabethengelman
Copy link
Contributor

I think that I have a fix that should work, that I'll get pushed up today.

However, I am still uncertain why this behaves differently on MacOS vs Linux - I'll keep digging in on that today too, but would love another set of eyes on that.

@elizabethengelman
Copy link
Contributor

For some more context

  • I am seeing that when running stellar contract build for a second time, it seems to use the existing wasm, and build on/add to that. However in MacOS when running stellar contract build for a second time, building a fresh wasm.

  • When I run the underlying command directly on linux (outside of stellar build), i don't see the duplicate metas
    CARGO_BUILD_RUSTFLAGS=--remap-path-prefix=/root/.cargo/registry/src/= cargo rustc --manifest-path=contracts/hello-world/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release

leighmcculloch added a commit that referenced this issue Nov 25, 2024
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
bug Something isn't working
Projects
Status: Backlog (Not Ready)
Development

Successfully merging a pull request may close this issue.

3 participants