Contract deployment in local stack

I’m trying to deploy simple flipper contract example on local stack.

Based on this doc I have compiled and started node, pruntime and pherry (master branch of phala-blockchain).

[1]. However I notices issues in pherry - every processed block I get logs (pherry):

[2022-09-16T15:59:30.043698Z INFO  pherry] try to sync blocks. next required: (body=501, header=501), finalized tip: 320, buffered: 0
[2022-09-16T15:59:30.063247Z INFO  phactory_api::pruntime_client] Response: 404 Not Found
[2022-09-16T15:59:30.063269Z ERROR pherry] FailedToCallBindWorkerEndpoint: Method Not Found
[2022-09-16T15:59:30.078479Z INFO  phactory_api::pruntime_client] Response: 200 OK

and in pruntime:

[INFO  phactory::prpc_service] Dispatching request: PhactoryAPI.GetEndpointInfo
[ERROR phactory::prpc_service] Rpc error: NotFound

It didn’t crashed so I assume it is not big deal.

Dev node is not prepared for contracts deployment so I’m configuring it in those steps:

  1. get worker public key from http://localhost:8000/get_info
  2. sudo
    phalaFatContracts.addCluster(alice.address, 'Public', [ workerPublicKey ]) as Alice

Now based on this doc I’m deploying contract in few steps:

  1. build with cargo +nightly contract build
  2. get JSON contract info from ./target/ink/flipper.contract
  3. execute
phalaFatContracts.clusterUploadResource(
    0,
    'InkCode',
    contract.source.wasm
)
  1. execute
phalaFatContracts.instantiateContract(
    { WasmCode: contract.source.hash },
    '0xed4b9d1b',
    randomHex,
    0
)

[2] BTW how to instantiate contract with contructor which request some args? I suppose it is required to somehow encode args with contructor signature.

[3] However I only get one event - phalaFatContracts.Instantiating. It is never finalized.

I’ve noticed there is no entires when queried with phalaFatContracts.clusterContracts(0) and phalaFatContracts.clusterWorkers(0)

But phalaFatContracts.clusters(0) gives nice result

{
  owner: 45R2pfjQUW2s9PQRHU48HQKLKHVMaDja7N3wpBtmF28UYDs2
  permission: Public
  workers: [
    0x3a3d45dc55b57bf542f4c6ff41af080ec675317f4ed50ae1d2713bf9f892692d
  ]
}

and phalaFatContracts.contracts(contractHash) gives

{
  deployer: 45R2pfjQUW2s9PQRHU48HQKLKHVMaDja7N3wpBtmF28UYDs2
  codeIndex: {
    WasmCode: 0xfc7dc6a1272105e32e748310dcee0485cfe6a5219b7cdf2687d734703cfba0cf
  }
  salt: 1b74c95d6
  clusterId: 0x0000000000000000000000000000000000000000000000000000000000000000
  instantiateData: 0xed4b9d1b
}

Here I have pushed my sandbox repo.
Steps to reproduce (with running local stack on default ports)

cargo +nightly contract build
yarn install
yarn deploy

UPDATE1:
e2e tests seems nice source of knowledge :) I will return with update.

UPDATE2:
[4] Sadly both in repo docs and e2e tests seems outdated (on master branch)

The e2e tests should not be outdated. It runs against each commit on master in Github Action.
For example:

I’ll try to reproduce it.

I haven’t be able to reproduce it.
I followed your steps using phala-blockchain at git commit 7a1c92141d73d3452e488a0078772326698850aa. And use your sandbox repo to deploy the contract. Finnally, I got the following outputs:

1 Like

I tried commit 7a1c92141d73d3452e488a0078772326698850aa but I get compilation errors

error[E0046]: not all trait items implemented, missing: `http_fetch`
   --> crates/phactory/src/prpc_service.rs:898:1

After cleaning blockchain repo (commit ab00cfe7c2e6e466edd6cab2bd77d19502003b79) and building everything from scratch is still see that issue [3].
However error in pherry is gone now - so at least [1] is done.

About outdated tests you are partially right.
I mean less changes are required to make it working.

  1. Point 2 in docs/test.md seems cargo build --release is required instead of make as there is no makefile.
  2. In fullstack.js it is required to update pathPRuntime cuz there is no app in
    standalone/pruntime/bin/pruntime
    it is only in
    standalone/pruntime/target/release/pruntime
  3. No --port argument for pruntime - it is not accepted anymore
  4. No Rocket.toml exist in pruntime directory - so I skip this file in filesMustCopy

After those changes I was able to execute tests by yarn test

I change those in my fork so you can check.

My stack:

$ uname -a
Linux xxx 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ rustup --version
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.59.0 (9d1b2106e 2022-02-23)`

$ cargo --version
cargo 1.59.0 (49d8809dc 2022-02-10)

$ echo $SGX_SDK
/opt/intel/sgxsdk

$ clang --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ node --version
v16.15.1

$ yarn --version
1.22.19

My steps to build:

get clone --recursive https://github.com/Phala-Network/phala-blockchain.git .
cargo build --release
cd standalone/pruntime
cargo build --release

And steps to run

# node
./target/release/phala-node --dev --rpc-methods=Unsafe

# pruntime
cd ./standalone/pruntime/bin
rm -r data
mkdir -p data
../target/release/pruntime --cores=0

# pherry
./target/release/pherry --dev

I tried commit 7a1c92141d73d3452e488a0078772326698850aa but I get compilation errors

If you checked out from newer commit to a older commit, you should also update the git submodules with git submodule update.

I mean less changes are required to make it working.

  1. Point 2 in docs/test.md seems cargo build --release is required instead of make as there is no makefile.
  2. In fullstack.js it is required to update pathPRuntime cuz there is no app in
    standalone/pruntime/bin/pruntime
    it is only in
    standalone/pruntime/target/release/pruntime
  3. No --port argument for pruntime - it is not accepted anymore
  4. No Rocket.toml exist in pruntime directory - so I skip this file in filesMustCopy

The path where to run the make in the doc is outdated, it should be run in standalone/pruntime/gramine-build/. This should solves the 1,2 and 4. However, it requires to install the gramine toolchain to build it in this way. Maybe we add a Makefile to make things easier.
The --port has never been removed. How was it rejected?

1 Like

I’ve added a Makefile there to extend the old docs’s life.

1 Like

Shit! you are right! I didn’t updated submodules. But phactory (origin of error) isn’t in main repo? Nvm.

That makes sense now.

pruntime binary was not accepting that arg - was configurable only by ROCKET_PORT env. But now works fine.

Finally - thank you for you time!