Calindra / cartesi-application-templates

Templates for Cartesi CLI
MIT License
1 stars 1 forks source link

[Co-Processor/Lambada] Run the js/ts example #1

Open fabiooshiro opened 3 months ago

fabiooshiro commented 3 months ago

https://github.com/stskeeps/cartesi-application-templates/tree/lambada

Record a video using OBS

https://github.com/Calindra/cartesi-concepts/blob/main/lambada-co-processors.md

I got this error:

 => exporting to image                                                                                                                                                                                 0.3s 
 => => exporting layers                                                                                                                                                                                0.3s 
 => => writing image sha256:11f680e9447c095a5c90ec70185ed4615b944c004c607f49e8464d357621d6ae                                                                                                           0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/nakodn8lxyygao8q73zgbcu0m

 2 warnings found (use --debug to expand):
 - FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 9)
 - FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/riscv64" (line 20)
 ›   Warning: sdk version is not a valid semver
    Error: Command failed with exit code 1: docker container create --volume ./.cartesi/image.tar:/tmp/input cartesi/sdk:devel /usr/bin/env bash -c cat /tmp/input | crane export - - | bsdtar -cf 
    /tmp/output --format=gnutar @/dev/stdin
    Unable to find image 'cartesi/sdk:devel' locally
    Error response from daemon: manifest for cartesi/sdk:devel not found: manifest unknown: manifest unknown

After updating the cartesi cli to:

cartesi --version
@cartesi/cli/0.16.0 darwin-arm64 node-v18.20.0

it worked

cartesi build
[+] Building 147.5s (19/19) FINISHED                                                                                                                                                   docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.2s
 => => transferring dockerfile: 1.89kB                                                                                                                                                                 0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                                                                                                                              3.3s
 => docker-image://docker.io/docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28                                                                               2.3s
 => => resolve docker.io/docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28                                                                                   0.0s
 => => sha256:d312885c06a18797ed74920104cd51acf2fc014e0965c529f4d94cd57bc3085a 482B / 482B                                                                                                             0.0s
 => => sha256:93fef1a67bbd936949d6c31a15186599e6af59975a876d4ffa71d03e684a8429 1.25kB / 1.25kB                                                                                                         0.0s
 => => sha256:a6501617884b82b0497fa03d77efdbdb89ad1b17b6ee026da31fcc000695ebf8 11.72MB / 11.72MB                                                                                                       2.2s
 => => sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28 8.40kB / 8.40kB                                                                                                         0.0s
 => => extracting sha256:a6501617884b82b0497fa03d77efdbdb89ad1b17b6ee026da31fcc000695ebf8                                                                                                              0.1s
 => [internal] load metadata for docker.io/library/node:20.8.0-bookworm                                                                                                                                1.5s
 => [internal] load metadata for docker.io/cartesi/node:20.8.0-jammy-slim                                                                                                                              1.6s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 69B                                                                                                                                                                       0.0s
 => [stage-1 1/6] FROM docker.io/cartesi/node:20.8.0-jammy-slim@sha256:47b872074fd14b8ff23452a7e2886ff91675671f00d0ca8b9943edc7f6cf3198                                                                0.0s
 => => resolve docker.io/cartesi/node:20.8.0-jammy-slim@sha256:47b872074fd14b8ff23452a7e2886ff91675671f00d0ca8b9943edc7f6cf3198                                                                        0.0s
 => => sha256:d0b8014fddda7a9d2aebfa90f785a751d55eaaad84bb1f1ca8175fc605f51529 5.87kB / 5.87kB                                                                                                         0.0s
 => => sha256:47b872074fd14b8ff23452a7e2886ff91675671f00d0ca8b9943edc7f6cf3198 858B / 858B                                                                                                             0.0s
 => => sha256:797ca13233dcf47253a24b6822e1c403a89be6b5b615b5ee2c6a8e0aa0b310b4 1.24kB / 1.24kB                                                                                                         0.0s
 => [stage-1 3/6] ADD https://github.com/zippiehq/cartesi-lambada-guest-tools/releases/download/v0.15.7/machine-emulator-tools-v0.15.7.deb /                                                          11.7s
 => [build-stage 1/4] FROM docker.io/library/node:20.8.0-bookworm@sha256:21505ae2f9f4b29ad9091e6dfc6c56ef9e890a16fc38fe6f6cd9ba3e979ef37c                                                             83.2s
 => => resolve docker.io/library/node:20.8.0-bookworm@sha256:21505ae2f9f4b29ad9091e6dfc6c56ef9e890a16fc38fe6f6cd9ba3e979ef37c                                                                          0.0s
 => => sha256:e720f94321d63ecb6efa873b294dce7eaa1c3a5ddcd5bf7daddf375b955669a4 49.61MB / 49.61MB                                                                                                      35.2s
 => => sha256:5b7541d83e7b8c0f5f6cacacddfcf5fdd942793f13418bc4645203b4ab4f3de3 23.59MB / 23.59MB                                                                                                      13.6s
 => => sha256:21505ae2f9f4b29ad9091e6dfc6c56ef9e890a16fc38fe6f6cd9ba3e979ef37c 1.21kB / 1.21kB                                                                                                         0.0s
 => => sha256:2ca01bc05a29b0e860f39db285e77844a7e3461eff8ada00d0aa27100b45dc8a 2.00kB / 2.00kB                                                                                                         0.0s
 => => sha256:4a3ba4ac08185a17760aa22471960245fdd08ae345be064f54241f7526773d98 7.30kB / 7.30kB                                                                                                         0.0s
 => => sha256:b1a653d69b7b96df6835b157d043d7b926f776531e96c9263f4c7dae0033514d 63.99MB / 63.99MB                                                                                                      38.4s
 => => sha256:c02d5d50082e4632f070b715dfd5d3a3680e35e0434a1281edbcfdc3cdff52dc 202.45MB / 202.45MB                                                                                                    77.2s
 => => sha256:fea96a5cf6f247278509ffaaf40ccdf2ee13c076315fe2807e32b0e12cc61aab 3.37kB / 3.37kB                                                                                                        35.8s
 => => extracting sha256:e720f94321d63ecb6efa873b294dce7eaa1c3a5ddcd5bf7daddf375b955669a4                                                                                                              1.5s
 => => sha256:adb6acfb502d53dd3f3536c2929350174679e13541ea265dcd3bf452e7c9dcfc 47.89MB / 47.89MB                                                                                                      56.2s
 => => extracting sha256:5b7541d83e7b8c0f5f6cacacddfcf5fdd942793f13418bc4645203b4ab4f3de3                                                                                                              0.4s
 => => extracting sha256:b1a653d69b7b96df6835b157d043d7b926f776531e96c9263f4c7dae0033514d                                                                                                              1.6s
 => => sha256:16f676f0e4bda40e0503895a2526d6fd7037d5176bcd81ffe92d040c94390d98 2.28MB / 2.28MB                                                                                                        40.3s
 => => sha256:6a120ed4c39eb29141c7361b4d0e2704359a551cf0f8afeb9fdf6eda07f3b0dc 452B / 452B                                                                                                            40.5s
 => => extracting sha256:c02d5d50082e4632f070b715dfd5d3a3680e35e0434a1281edbcfdc3cdff52dc                                                                                                              4.1s
 => => extracting sha256:fea96a5cf6f247278509ffaaf40ccdf2ee13c076315fe2807e32b0e12cc61aab                                                                                                              0.0s
 => => extracting sha256:adb6acfb502d53dd3f3536c2929350174679e13541ea265dcd3bf452e7c9dcfc                                                                                                              1.5s
 => => extracting sha256:16f676f0e4bda40e0503895a2526d6fd7037d5176bcd81ffe92d040c94390d98                                                                                                              0.0s
 => => extracting sha256:6a120ed4c39eb29141c7361b4d0e2704359a551cf0f8afeb9fdf6eda07f3b0dc                                                                                                              0.0s
 => [internal] load build context                                                                                                                                                                      0.0s
 => => transferring context: 410.10kB                                                                                                                                                                  0.0s
 => [stage-1 2/6] RUN <<EOF (set -e...)                                                                                                                                                               84.8s
 => [build-stage 2/4] WORKDIR /opt/cartesi/dapp                                                                                                                                                        0.4s
 => [build-stage 3/4] COPY . .                                                                                                                                                                         0.0s
 => [build-stage 4/4] RUN yarn install && yarn build                                                                                                                                                  55.9s
 => [stage-1 3/6] ADD https://github.com/zippiehq/cartesi-lambada-guest-tools/releases/download/v0.15.7/machine-emulator-tools-v0.15.7.deb /                                                           0.0s
 => [stage-1 4/6] RUN dpkg -i /machine-emulator-tools-v0.15.7.deb   && rm /machine-emulator-tools-v0.15.7.deb                                                                                          5.1s
 => [stage-1 5/6] WORKDIR /opt/cartesi/dapp                                                                                                                                                            0.0s
 => [stage-1 6/6] COPY --from=build-stage /opt/cartesi/dapp/dist .                                                                                                                                     0.0s 
 => exporting to image                                                                                                                                                                                 0.2s 
 => => exporting layers                                                                                                                                                                                0.1s
 => => writing image sha256:71d1e536319e634040a5cce36f8b872dd8420f7aee3a089a4fab1c2b09cf8828                                                                                                           0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/wwsqokmsd96ncmviiz8euq3ms

 2 warnings found (use docker --debug to expand):
 - FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 9)
 - FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/riscv64" (line 20)

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
 ›   Warning: sdk version is not a valid semver
copying from tar archive /tmp/input
Making machine snapshot for Lambada
0: c4fcd4ead39168a639f461f70a50c9fce4301cf7cd0e65da567f9cb9a40463e8
Storing machine: please wait
generating ED25519 keypair...done
peer identity: 12D3KooWKCbNmdLyfX1Ssf25nQdLFdXjtAYrACeWKYaZYaBQmcfp
initializing IPFS node at /data/ipfs

My result:

taskInputHash: 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad
Next Batch Index: 0
TaskBatchRegistered: 0 19 0xfc8fee276d1d9079d2f2e07e74927716cfa6b4218909b565002616f584c21f9d
[
  '0x01701220fb04e6de21b8466d4a5bec2854820639159779037809c291b1574a985a74bf93',
  '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',
  resultCID: '0x01701220fb04e6de21b8466d4a5bec2854820639159779037809c291b1574a985a74bf93',
  outputHash: '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
]
Task Responded: {
  batchIndex: 0,
  outputHash: '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',
  resultCID: '0x01701220fb04e6de21b8466d4a5bec2854820639159779037809c291b1574a985a74bf93'
}
Ethereum Block Number: 19
Ethereum Block Hash: 0xfc8fee276d1d9079d2f2e07e74927716cfa6b4218909b565002616f584c21f9d
{
  metadata: {
    'ja62BU8gb23hXMVivcJog65z9/7tTcS2YxLgtQy5TTo=': 'pFjb5KvjYDW0RbBGsMwOAnhz1G7fEiD675bd0AOVDa8=',
    '8WDSbTPNI+IOj4tkz9WNQt7Ya4l1EIwIIIeGFEMoXj4=': 'AAAAAAAAABM=',
    'nA22OtVjDhZqtMnr7KwhbIiOXh14fhCBkCm8p6bxPyA=': '/I/uJ20dkHnS8uB+dJJ3Fs+mtCGJCbVlACYW9YTCH50='
  },
  payload: 'aGVsbG8gd29ybGQ='
}
{ cid: 'bafybeih3attn4inyizwuuw7mfbkiebrzcwlxsa3ybhbjdmkxjkmfu5f7sm' }
Local compute job matches output of co-processor, result CID bafybeih3attn4inyizwuuw7mfbkiebrzcwlxsa3ybhbjdmkxjkmfu5f7sm output file hash: b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
output file contents: hello world
fabiooshiro commented 3 months ago

cheat sheet

fabiooshiro commented 3 months ago

I got an error running the js template:

 => => writing image sha256:7baaec9b4e3bb2201249805325c286c9031a8256188294a0193fac671a3f7caa                                            0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/rrw2tm1uvrv3cy3mkz3esfz1r

 2 warnings found (use docker --debug to expand):
 - FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 9)
 - FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/riscv64" (line 20)

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
    Error: Unsupported sdk version: 0.6.0 (used) < 0.9.0 (minimum).
    Update your application Dockerfile using one of the templates at https://github.com/cartesi/application-templates/tree/sdk-0.9
fabiooshiro commented 3 months ago

Probably the error on javascript example is somehow related to:

lambada-coprocessor-operator1   | {"level":"error","ts":1723144340.8908122,"caller":"operator/operator.go:336","msg":"failed to request echo from lambada service -invalid cid: cid too short, faking result - bafybeif5liyov4oltxvc34qh3uyyxy5znisbmarsorxrp4nr3o7ywjuo5u, \ufffd\ufffd\ufffdD\ufffd\\\ufffd\ufffd{\ufffd\ufffd","stacktrace":"github.com/zippiehq/cartesi-lambada-coprocessor/operator.(*Operator).processTaskBatch\n\t/usr/src/app/operator/operator.go:336\ngithub.com/zippiehq/cartesi-lambada-coprocessor/operator.(*Operator).Start\n\t/usr/src/app/operator/operator.go:307\nmain.operatorMain\n\t/usr/src/app/operator/cmd/main.go:80\ngithub.com/urfave/cli.HandleAction\n\t/go/pkg/mod/github.com/urfave/cli@v1.22.14/app.go:524\ngithub.com/urfave/cli.(*App).Run\n\t/go/pkg/mod/github.com/urfave/cli@v1.22.14/app.go:286\nmain.main\n\t/usr/src/app/operator/cmd/main.go:48\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:267"}
fabiooshiro commented 3 months ago

Carsten updated the JavaScript example, and now it's working like a charm.

javascript git:(lambada) PROGRAM_CID=`cat .cartesi/image/sample.car.cid` PROGRAM_INPUT="hello world" node ~/coprocessor-demo/coprocessor/demo/demo.mjs
taskInputHash: 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad
Next Batch Index: 0
TaskBatchRegistered: 0 19 0x9c04c6f09fda572a5b4d93c15dc18827ad129a3fedf36702db30c5dc2e5b98e7
[
  '0x0170122049fbff13510d5f8f8daae8b5bda6db83d9366131b3d4d4209f1dda5133642f96',
  '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',
  resultCID: '0x0170122049fbff13510d5f8f8daae8b5bda6db83d9366131b3d4d4209f1dda5133642f96',
  outputHash: '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
]
Task Responded: {
  batchIndex: 0,
  outputHash: '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',
  resultCID: '0x0170122049fbff13510d5f8f8daae8b5bda6db83d9366131b3d4d4209f1dda5133642f96'
}
Ethereum Block Number: 19
Ethereum Block Hash: 0x9c04c6f09fda572a5b4d93c15dc18827ad129a3fedf36702db30c5dc2e5b98e7
{
  metadata: {
    'ja62BU8gb23hXMVivcJog65z9/7tTcS2YxLgtQy5TTo=': 'pFjb5KvjYDW0RbBGsMwOAnhz1G7fEiD675bd0AOVDa8=',
    '8WDSbTPNI+IOj4tkz9WNQt7Ya4l1EIwIIIeGFEMoXj4=': 'AAAAAAAAABM=',
    'nA22OtVjDhZqtMnr7KwhbIiOXh14fhCBkCm8p6bxPyA=': 'nATG8J/aVypbTZPBXcGIJ60Smj/t82cC2zDF3C5bmOc='
  },
  payload: 'aGVsbG8gd29ybGQ='
}
{ cid: 'bafybeicj7p7rguinl6hy3kxiww62nw4d3e3gcmnt2tkcbhy53jitgzbpsy' }
Local compute job matches output of co-processor, result CID bafybeicj7p7rguinl6hy3kxiww62nw4d3e3gcmnt2tkcbhy53jitgzbpsy output file hash: b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
output file contents: hello world