Tips for CKB Development
Nervos CKB is the layer 1 of Nervos Network, a public/permissionless blockchain, which is an open source project on github. There are some tips for ckb development below, hope it will be useful for you.
Molecule
We have developed a particular serialization format called Molecule. It is recommended to check the molecule github repo for more details.
Well-known Hashes
The command ckb list-hashes prints the well-known hashes for current
effective chain spec.
The file docs/hashes.toml in ckb release package and source code repository
contains the well-known hashes for all the bundled chain specs. The file is
generated by:
cargo run list-hashes -b > docs/hashes.toml
Running Test
Install dependencies
rustup component add rustfmt
rustup component add clippy
Run tests
make ci
Run acceptance integration tests
make integration
Debug CKB
Note: Only support linux system.
Track Memory Usage in Logs
Add the follow configuration into ckb.toml:
[logger]
filter = "error,ckb-memory-tracker=trace"
[memory_tracker]
# Seconds between checking the process, 0 is disable, default is 0.
interval = 600
Profile Memory
Compile
ckbwith featureprofiling.make build-for-profilingAfter compiling, a script named
jeprofwill be generated intargetdirectory.find target/ -name "jeprof"Enable RPC module
Debuginckb.toml.[rpc]
modules = ["Debug"]Run
ckb.Dump memory usage to a file via call RPC
jemalloc_profiling_dump.curl -H 'content-type: application/json' -d '{ "id": 2, "jsonrpc": "2.0", "method": "jemalloc_profiling_dump", "params": [] }' http://localhost:8114Then, a file named
ckb-jeprof.$TIMESTAMP.heapwill be generated in the working directory of the runningckb.Generate a PDF of the call graph.
Required: graphviz and ghostscript
jeprof --show_bytes --pdf target/debug/ckb ckb-jeprof.$TIMESTAMP.heap > call-graph.pdf