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.git
Build the node
cargo build --release
Cache 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.ts
If you wanna run echo
sample
cd examples/simple_echo
rm deno.lock
deno cache --reload ./main.ts
If you wanna run imaginator
(AIGC) sample
cd examples/imaginator
rm deno.lock
deno cache --reload ./main.ts
Run and configure local test network
Start the local test network
target/release/cybros-node --dev
Once 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)
attestationMethod
ChooseOptOut
means 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)
implId
fill101
(we got theimplId
from previous extrinsic)version
can fill1
(it accepts any number larger than 0)magicBytes
keepNone
(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)
implId
fill101
createJobEnabled
chooseYes
or the pool will not allow to create new jobautoDestroyProcessedJobEnabled
can 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)
poolId
fill101
(we got thepoolId
from previous extrinsic)applicableScope
can choosePublic
which means anyone could use the policystartBlock
andendBlock
can keepNone
which 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:9944
After the program launches, you can see the worker's address from the output:
Worker address: 5CmLkeupoN7tSthSD6hFj9wHYc9RyMRAWb38uo5BD6LEViGw
Wait for few seconds, then you should see events on the Network -> Explorer
page:
offchainComputingInfra.WorkerRegistered
offchainComputingInfra.WorkerOnline
Add the worker to the pool
Use Alice to send the extrinsic offchainComputingPool.authorizeWorker(poolId, worker)
poolId
fill101
worker
fill5CmLkeupoN7tSthSD6hFj9wHYc9RyMRAWb38uo5BD6LEViGw
(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)
poolId
fill101
policyId
fill1
implSpecVersion
fill1
input
you can fillHello World !!!
softExpiresIn
can 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.JobAssigned
offchainComputingPool.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: true
when creating the pool
Send the extrinsic use the job's creator account offchainComputingPool.destroyJob(poolId, jobId)
poolId
fill101
jobId
fill1
Submit the extrinsic, then you should see the success event on the Network -> Explorer
page:
offchainComputingPool.JobDestroyed { poolId: 101, jobId: 1 }