Official go/grpc implementation of the off-chain modules of Celer state channel network.
Celer state channel network is a generic framework of state channels with deeply optimized on-chain contracts and off-chain messaging protocols. Please checkout the overview of our system architecture and design principles. This repo implements the off-chain CelerNodes.
One who plans to run a full Off-chain Service Provider (OSP) node should start by following the instructions on local manual tests to play with the code and essential tools, and to get familiar with the operaton process.
Please walk through the local manual tests before moving forward to Mainnet deployment. Steps to operate OSPs on Mainnet are very similar to local manual tests. Note that running the local manual tests require a bit more steps and system dependencies than directly using the prebuilt binaries to run an OSP on mainnet as instructed below.
Current running OSPs can be found at https://explorer.celer.network.
Here we only show how to operate ETH channels as examples. ERC20 channels are also fully supported by adding -token
arg in related commands.
- Get TLS certificate ready for serving Internet traffic.
- There are two storage options: SQLite3 and CockroachDB. Install CockroachDB if you plan to use it.
- Hardware requirements are minimal (e.g., 1 core CPU, <1GB memory), as the full-stack software is running smoothly on many iOS and Android devices every day.
-
Download prebuit binaries from https://github.com/celer-network/goCeler-oss/releases. Then run
tar xzf goceler-v0.16.16-linux-amd64.tar.gz export PATH=$PATH:$PWD/goceler
-
Download the profile.json, rt_config.json and channels_xxx.json files from deploy/mainnet to your
$HOME
folder, which is the base location for instructions below. Replace$HOME
with your preferred local path if needed.
-
Run
geth account new --keystore . --lightkdf
to generate a new keystore file, and move it to your OSP server$HOME
folder asks.json
. Then fund your newly generated OSP account address some mainnet ETH. -
Update the profile.json
gateway
field to your Mainnet API gateway URL (eg. https://mainnet.infura.io/v3/xxxxx),host
filed to the OSP public RPC hostname:port (default rpc port is 10000),address
field to the OSP ETH address. -
Setup OSP: Run
osp-cli -profile $HOME/profile.json -ks $HOME/ks.json -ethpooldeposit -amount [ETH amount] -register -blkdelay 2
to deposit OSP's ETH into the EthPool contract, and register the OSP as a state channel network router.- EthPool is used by OSP to accept ETH open channel requests from peers. For example, when node
A
initiates an ETH open channel request with nodeB
, nodeA
will make channel deposit from its account balance, while nodeB
will make deposit from its EthPool balance. - As noted in the CLI Command Reference,
amount
is float assuming 18 token decimals. - Unused ETH in the EthPool can be withdrawn through
osp-cli -profile $HOME/profile.json -ks $HOME/ks.json -ethpoolwithdraw -amount [ETH amount]
. -blkdelay
specifies how many blocks to wait to confirm the on-chain transactions.
- EthPool is used by OSP to accept ETH open channel requests from peers. For example, when node
-
Choose a store path (e.g.,
$HOME/celerdb
), your OSP data will be located at$HOME/celerdb/[ospAddr]
. -
Start OSP:
server -profile $HOME/profile.json -ks $HOME/ks.json -svrname s0 -storedir $HOME/celerdb -rtc $HOME/rt_config.json -routedata $HOME/channels_2020_05_08.json
.
-
First install CockroachDB. Then checkout tools/scripts/cockroachdb.sh, update
STOREPATH
to your preferred storage location, and run./cockroachdb.sh start
to start the cockroachDB process and create tables. -
Start OSP:
server -profile $HOME/profile.json -ks $HOME/ks.json -svrname s0 -storesql postgresql://celer@localhost:26257/celer?sslmode=disable -rtc $HOME/rt_config.json -routedata $HOME/channels_2020_05_08.json
.
Notes (for both options):
- Use
-routedata
only when starting OSP from scracth for the first time. - Use log args as needed, e.g.,
-logdir $HOME/logs -logrotate
. - The default rpc port is
10000
, default admin http endpoint islocalhost:8090
, use-port
and-adminweb
to change those values (example) if needed. - Your OSP should be shown on the Explorer within 15 minutes after the server started.
-
Connect with another OSP through grpc stream:
osp-cli -adminhostport localhost:8090 -registerstream -peer [peerOspAddr] -peerhostport [peerOspHostPort]
.If you want to quickly connect to multiple peer OSPs (e.g., reconnect after restart), you can use the
-file
option. Create apeerservers
file with lines ofaddr host:port
you want to connect, for example:00290a43e5b2b151d530845b2d5a818240bc7c70 a.b.net:10000 003ea363bccfd7d14285a34a6b1deb862df0bc84 x.y.com:10000 00495b55a68b5d5d1b0860b2c9eeb839e7d3a362 m.n.network:10000
Then run
osp-cli -adminhostport localhost:8090 -registerstream -file peerservers
. -
Open channel with another OSP:
osp-cli -adminhostport localhost:8090 -openchannel -peer [peerOspAddr] -selfdeposit [ETH amount] -peerdeposit [ETH amount]
.Make sure you have enough balance in your ETH account, and the peer you want to open channel with has enough balance in the EthPool contract. If you get an error response from the peer for any reason (e.g., due to policy violation), wait for 10 minutes before trying to open channel with the same peer. As always for CLI commands,
amount
is float assuming 18 token decimals. -
Query channel from database:
osp-cli -profile $HOME/profile.json -storedir $HOME/celerdb/[ospAddr] -dbview channel -peer [peerOspAddr]
. If using CockroachDB, replace-storedir $HOME/celerdb/[ospAddr]
with-storesql postgresql://celer@localhost:26257/celer?sslmode=disable
. -
Query channel from blockchain:
osp-cli -profile $HOME/profile.json -onchainview channel -cid [channel ID]
. You can see the channel ID from the output of step 10 above.
Use OSP CLI Commands to operate the OSP. See local manual tests for example.
You can close a channel and withdraw all tokens to the OSP ETH address through unilateral settle.
- First, submit
intentSettle
transaction:osp-cli -profile $HOME/profile.json -ks $HOME/ks.json -storedir $HOME/celerdb -intendsettle -cid [channel ID]
- Then, submit
confirmSettle
transaction after the channel dispute timeout (10000 blocks by default):osp-cli -profile $HOME/profile.json -ks $HOME/ks.json -storedir $HOME/celerdb -confirmsettle -cid [channel ID]
.
Cooperative withdrawal is currently supported only for Client-to-OSP channels. We will release new version to support cooperative settle and cooperative withdrawal for both OSP-to-OSP and Client-to-OSP channels soon.
OSP needs to have a valid TLS certificate for Celer connections over the Internet. If you already have a domain name, you can get one from Let's Encrypt. Then run OSP with flags -tlscert mysvr.crt -tlskey mysvr.key
.
Otherwise, the builtin cert supports DDNS with the following domain names:
*.dynu.com
*.mooo.com
*.us.to
*.hopto.org
*.zapto.org
*.sytes.net
*.ddns.net
and all domains in 1st and 2nd pages at https://freedns.afraid.org/domain/registry/. You can register free account with the DDNS provider, eg. mycelernode.ddns.net, update host field in profile.json to it, and run OSP, no need to specify tlscert or tlskey flag.
If you prefer using IP address directly, please contact cert@celer.network and we'll email you a unique cert for requested IP address.
go run webproxy/cmd/main.go -server localhost:10000
assume OSP runs on default 10000 port
Then clone https://github.com/celer-network/celer-light-client repo, update demo/mainnet_config.json ospEthAddress
to your OSP account address and ospNetworkAddress
to http://[webproxy DNS or IP]:29980