Quick start
This doc will use the local development node and the protocol_impl as a sample.
Preparation
You must install Rust and Deno to build the node and run the demo.
Clone the repo
git clone https://github.com/cybros-network/cybros-network.gitBuild the node
cargo build --releaseCache dependencies for the demo app
This is necessary.
cd protocol_impl
rm deno.lock # For unknown reason, esm.sh may change files' SHA which will break Deno's security check
deno cache --reload ./main.tsIf you wanna run echo sample
cd examples/simple_echo
rm deno.lock
deno cache --reload ./main.tsIf you wanna run imaginator (AIGC) sample
cd examples/imaginator
rm deno.lock
deno cache --reload ./main.tsRun and configure local test network
Start the local test network
target/release/cybros-node --devOnce the node started, you can connect it with Polkadot-JS Apps front-end to interact with the chain.
https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/extrinsics
Register an impl and an impl build
Use Alice to send the extrinsic offchainComputingInfra.registerImpl(attestationMethod)
attestationMethodChooseOptOutmeans the Impl doesn't support attestation
Submit the extrinsic, then you should get the success event on the Network -> Explorer page:
offchainComputingInfra.ImplRegistered { implId: 101 }
Use Alice to send the extrinsic offchainComputingInfra.registerImplBuild(implId, version, magicBytes)
implIdfill101(we got theimplIdfrom previous extrinsic)versioncan fill1(it accepts any number larger than 0)magicByteskeepNone(It uses for TEE)
Submit the extrinsic, then you should see the success event on the Network -> Explorer page:
offchainComputingInfra.ImplBuildRegistered
Create a pool
Use Alice to send the extrinsic offchainComputingPool.createPool(implId, createJobEnabled, autoDestroyProcessedJobEnabled)
implIdfill101createJobEnabledchooseYesor the pool will not allow to create new jobautoDestroyProcessedJobEnabledcan chooseYes
Submit the extrinsic, then you should see the success event on the Network -> Explorer page:
offchainComputingPool.PoolCreated { poolId: 101, ... }
Create a job policy
Use Alice to send the extrinsic offchainComputingPool.createJobPolicy(poolId, applicableScope, startBlock, endBlock)
poolIdfill101(we got thepoolIdfrom previous extrinsic)applicableScopecan choosePublicwhich means anyone could use the policystartBlockandendBlockcan keepNonewhich means the policy never expires
Submit the extrinsic, then you should see the success event on the Network -> Explorer page:
offchainComputingPool.JobPolicyCreated { policyId: 1, ... }
Start a worker
We use simple_echo as an example
cd protocol_impl
EXECUTOR_PATH="./examples/simple_echo" ./run.sh --owner-phrase "//Alice" --subscribe-pool 101 --impl 101 --rpcUrl ws://127.0.0.1:9944After the program launches, you can see the worker's address from the output:
Worker address: 5CmLkeupoN7tSthSD6hFj9wHYc9RyMRAWb38uo5BD6LEViGwWait for few seconds, then you should see events on the Network -> Explorer page:
offchainComputingInfra.WorkerRegisteredoffchainComputingInfra.WorkerOnline
Add the worker to the pool
Use Alice to send the extrinsic offchainComputingPool.authorizeWorker(poolId, worker)
poolIdfill101workerfill5CmLkeupoN7tSthSD6hFj9wHYc9RyMRAWb38uo5BD6LEViGw(we got the address from the worker starting)
Submit the extrinsic, then you should see the success event on the Network -> Explorer page:
offchainComputingPool.WorkerAuthorized
Wait for few seconds, then you should see the event:
offchainComputingPool.WorkerSubscribed
Create a job
Send the extrinsic offchainComputingPool.createJob(poolId, policyId, implSpecVersion, input, softExpiresIn)
poolIdfill101policyIdfill1implSpecVersionfill1inputyou can fillHello World !!!softExpiresIncan keepNone
Submit the extrinsic, then you should see the success event on the Network -> Explorer page:
offchainComputingPool.JobCreated { jobId: 1, ... }
Keep watching, you should see these events:
offchainComputingPool.JobAssignedoffchainComputingPool.JobStatusUpdated { status: Processing }offchainComputingPool.JobResultUpdated { result: Sucess, output: "Hello World !!!", ... }offchainComputingPool.JobStatusUpdated { status: Processed }
Destroy the processed job, releasing reserving tokens
You don't need to do this step if you set
autoDestroyProcessedJobEnabled: truewhen creating the pool
Send the extrinsic use the job's creator account offchainComputingPool.destroyJob(poolId, jobId)
poolIdfill101jobIdfill1
Submit the extrinsic, then you should see the success event on the Network -> Explorer page:
offchainComputingPool.JobDestroyed { poolId: 101, jobId: 1 }