• Stars
    star
    187
  • Rank 206,464 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Celer state channel network

Celer State Channel Network

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.

Run Local Manual Tests

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.

Run OSP on Ethereum Mainnet

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.

Requirements

  • 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.

Get prebuilt binaries and config files

  1. 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
  2. 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.

Prepare OSP account

  1. Run geth account new --keystore . --lightkdf to generate a new keystore file, and move it to your OSP server $HOME folder as ks.json. Then fund your newly generated OSP account address some mainnet ETH.

  2. 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.

  3. 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 node B, node A will make channel deposit from its account balance, while node B 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.

Run OSP server

Option 1: run OSP using SQLite as storage backend (easier setup)

  1. Choose a store path (e.g., $HOME/celerdb), your OSP data will be located at $HOME/celerdb/[ospAddr].

  2. 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.

Option 2: run OSP using CockroachDB as storage backend (higher performance)

  1. 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.

  2. 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 is localhost: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.

Open channel with peer OSP

  1. 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 a peerservers file with lines of addr 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.

  2. 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.

  3. 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.

  4. 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.

Apply other OSP operations

Use OSP CLI Commands to operate the OSP. See local manual tests for example.

Close channel and withdraw fund

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.

TLS Certificate for serving Internet traffic

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 [email protected] and we'll email you a unique cert for requested IP address.

Start Web Proxy for Celer web client

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

More Repositories

1

sgn-v2-contracts

Smart Contracts for Celer State Guardian Network (SGN) V2 and cBridge V2
Solidity
132
star
2

zk-benchmark

Benchmark of multiple zk implementations.
Go
82
star
3

cChannel-eth

CelerPay contracts on Ethereum
JavaScript
65
star
4

cBridge-node

Celer cBridge relay node implementation in Golang
Go
62
star
5

layer2-finance-contracts

Contracts for the Layer 2 Finance DeFi aggregator, powered by optimistic rollup.
Solidity
53
star
6

celer-light-client

TypeScript implementation of a Celer client
JavaScript
31
star
7

celer-web-sdk

JavaScript library to interact with a local Celer node
JavaScript
25
star
8

sgn

Official Go implementation of the Celer State Guardian Network (SGN)
Go
24
star
9

cApps-eth

Ethereum contracts of sample CelerX dApps
Go
19
star
10

brevis-contracts-deprecated

Solidity
16
star
11

pb3-gen-sol

Generate solidity decoders from proto3 files
Go
16
star
12

brevis-circuits

Go
16
star
13

celer-client

Prebuilt Celer client binary to interact with Celer Network
13
star
14

cChannel-substrate

Substrate Runtime Module of cChannel
Rust
13
star
15

cBridge-contracts

Contracts for cBridge, cross-chain liquidity solution powered by Hashed-Timelock Transfers
TypeScript
12
star
16

cBridge-typescript-client

cBridge gateway typescript
JavaScript
12
star
17

layer2-finance-v2-contracts

Contracts for the Layer 2 Finance DeFi aggregator V2, powered by optimistic rollup.
Solidity
11
star
18

sgn-v2-networks

Celer State Guardian Network (SGN) V2 binaries, operational instructions, genesis files, and config templates.
11
star
19

sgn-contract

Mainchain smart contracts for Celer State Guardian Network (SGN)
Go
7
star
20

sgn-networks

Celer State Guardian Network (SGN) operational instructions, genesis files, and config templates.
7
star
21

nft-bridge-contracts

Open source NFT bridge contracts using Celer IM
Solidity
6
star
22

celerx-example-go-celer

This is an example HTML5 game that can be easily integrated with CelerX eSport Gaming SDK
JavaScript
6
star
23

rollup-contracts

Go
6
star
24

celerx-example-gomoku

CelerX Gomoku
JavaScript
5
star
25

cBridge-transfer-widget

TypeScript
5
star
26

im-executor

Example Executor for Celer IM
Go
4
star
27

cApps-substrate

Rust
4
star
28

goutils

Go packages for common utilities
Go
4
star
29

celerx-js

the Javascript library of CelerX eSport Gaming SDK
JavaScript
4
star
30

CelerPod

Objective-C
3
star
31

osp-explorer

JavaScript
3
star
32

contract_addresses

3
star
33

go-rollup

Go implementation of the Celer Optimistic Rollup
Go
3
star
34

peti-rfq-mm

Market Maker of RFQ system.
Go
2
star
35

tofu-contracts

Solidity
2
star
36

Liquidity-Backing

Celer cryptoeconomics to meet the state channel network liquidity challenge
JavaScript
2
star
37

eth-services

Ethereum subscription and transaction services
Go
2
star
38

celercore-docs

Documentation of Celer Network Core Architecture
HTML
1
star
39

layer2-finance-bugs

1
star
40

cbridge-cowa

CosmWasm Rust smart contracts for cbridge
Rust
1
star
41

nano-plugin-cbridge

ledger nano plugin of cBridge
C
1
star
42

sgn-explorer

Explorer web UI for the Celer State Guardian Network (SGN)
JavaScript
1
star
43

endpoint-proxy

Used for some chain which can not support ethclient
Go
1
star
44

Interface_automation-Robot_framework

Python
1
star