Skip to content

Instantly share code, notes, and snippets.

@JokerCatz
Last active March 19, 2022 12:20
Show Gist options
  • Save JokerCatz/85ce67a595f142c6d899c4f8d5d57fec to your computer and use it in GitHub Desktop.
Save JokerCatz/85ce67a595f142c6d899c4f8d5d57fec to your computer and use it in GitHub Desktop.
Chia (XCH) build local private chain (regtest / self testnet) for testing
// chia node need ssl keys when connection , it auto gen ssl keys at init , so no offical open node or endpoint
// need build node , testnet no node to sync , so ... build regtest by self : )
// ============== chia mainnet just need
git clone --depth=1 https://github.com/Chia-Network/chia-blockchain
cd chia-blockchain
sh install.sh
. ./activate
chia init
chia start farmer
// then use RPC to watch sync status
// ============== chia mainnet is very easy right ?
// ============== start create chia regtest node (testnet , please use this for test only)
// first , you may want move ~/.chia to outside , like use `ln -s`
// then add this to `~/.profile` to change default network path
export CHIA_ROOT="~/.chia/regtest"
// remember use `source ~/.profile` to use new profile or just re-login
git clone --depth=1 https://github.com/Chia-Network/chia-blockchain
cd chia-blockchain
sh install.sh
// enable evn
. ./activate
// if you want mine genesis block (height 1) , you must install timelord , it only support linux / macos(with dorcker)
sh install-timelord.sh
// test timelord is work or not
./vdf_bench square_asm 400000
// init config
chia init
// plz remember main walllet , it start `xch`
// copy paste main wallet to `https://www.chiaexplorer.com/tools/address-puzzlehash-converter`
// `Enter a receive address below to convert it to a puzzle hash` convert to puzzle hash
// like {wallet} xch1l95ygggqn23veg0dk0hp2u9m0x3xcqejfykgjzk3cugz9kucad9seg7mr3
// to {puzzle_hash} 0xf9684421009aa2cca1edb3ee1570bb79a26c0332492c890ad1c71022db98eb4b
// if no gen key at init , you can use command `chia keys generate`
// if you forget main walet , you can use `chia keys show`
// but `chia keys show` will not show wallet's {puzzle_hash} , so you need to the website to convert it
// start fix config.yaml
vim ~/.chia/regtest/config/config.yaml
// remove all farmer.network_overrides.config & farmer.network_overrides.constants all contrant
// // MIN_PLOT_SIZE // min = 25 & it is `K` (ref)
// // GENESIS_CHALLENGE // what you want
// // GENESIS_PRE_FARM_FARMER_PUZZLE_HASH // your {puzzle_hash} without 0x
// // GENESIS_PRE_FARM_POOL_PUZZLE_HASH // your {puzzle_hash} without 0x
// and change to like this :
// =========================
config:
regtest:
address_prefix: xch
constants:
regtest:
BLOCKS_CACHE_SIZE: 490
COST_PER_BYTE: 1337
DIFFICULTY_CONSTANT_FACTOR: 33554432
DIFFICULTY_STARTING: 1
DISCRIMINANT_SIZE_BITS: 16
EPOCH_BLOCKS: 340
GENESIS_CHALLENGE: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
GENESIS_PRE_FARM_FARMER_PUZZLE_HASH: f9684421009aa2cca1edb3ee1570bb79a26c0332492c890ad1c71022db98eb4b
GENESIS_PRE_FARM_POOL_PUZZLE_HASH: f9684421009aa2cca1edb3ee1570bb79a26c0332492c890ad1c71022db98eb4b
MAX_SUB_SLOT_BLOCKS: 50
MEMPOOL_BLOCK_BUFFER: 6
MIN_BLOCKS_PER_CHALLENGE_BLOCK: 12
MIN_PLOT_SIZE: 18
NETWORK_TYPE: 1
NUMBER_ZERO_BITS_PLOT_FILTER: 1
NUM_SPS_SUB_SLOT: 16
SUB_EPOCH_BLOCKS: 170
SUB_SLOT_ITERS_STARTING: 1024
SUB_SLOT_TIME_TARGET: 600
WEIGHT_PROOF_RECENT_BLOCKS: 380
WEIGHT_PROOF_THRESHOLD: 2
// ===========================
// then fix another settings
// fix `full_node.send_uncompact_interval` = 300
// fix `min_mainnet_k_size` = 25
// fix `farmer.logging.log_level` = INFO
// fix `full_node.dns_servers[0] & full_node.introducer_peer` = localhost
// fix `full_node.enable_profiler & full_node.enable_upnp` = false
// fix `wallet.introducer_peer.host` = localhost
// fix `timelord_launcher.process_count` = 1
// fix `self_hostname` = 0.0.0.0 // if you want connect from another IP
// save ~/.chia/regtest/config/config.yaml
// start build plots , it will create to ~/.chia/regtest/config/plots
// please don't use like =~/.. it will make a "~" folder at ~/.chia/regtest/config/
// make {n = 1} x {K = 25} plots
chia plots create --override-k -k 25 -n 1 --tmp_dir=plots/tmp --final_dir=plots/final
/*
[[processing]]
Starting phase 1/4: // very slow , if K != 25 will very very slow (ref : K)
Computing table 1~7
Bucket 0~127
Starting phase 2/4: // fast
Starting phase 3/4: // slow
Compressing tables 1 => 7
Bucket 0~127
Starting phase 4/4: // fast
// success , create one 638M plot file
*/
// check plots status
chia plots check
// start chia node, if you want disable timelord , you can change `all` to `farmer`
// please use this command to start chia node (-r restart , make sure all service restart)
chia start all -r
// and use this command to stop , (-d deamon , make sure deamon is stop)
chia stop all -d
// use command like `top` you can watch `vdf_client` is burning CPU
// if height > 10 , you may change this config (not yet tested)
// fix `timelord.sanitizer_mode` from `false` to `true`
// it may mine block when mempool has transcations , but it not work at height = 0
// and if you need confirm block > N , it not good , and it will not auto mine to get coinbase money
// ============ RPC command to check status , all need use ssl key (please mind keys path)
curl --insecure --cert ~/.chia/regtest/config/ssl/full_node/private_full_node.crt --key ~/.chia/regtest/config/ssl/full_node/private_full_node.key -d '{"":""}' -H "Content-Type: application/json" -X POST https://localhost:8555/get_blockchain_state
curl --insecure --cert ~/.chia/regtest/config/ssl/full_node/private_full_node.crt --key ~/.chia/regtest/config/ssl/full_node/private_full_node.key -d '{"":""}' -H "Content-Type: application/json" -X POST https://localhost:8555/get_initial_freeze_period
curl --insecure --cert ~/.chia/regtest/config/ssl/full_node/private_full_node.crt --key ~/.chia/regtest/config/ssl/full_node/private_full_node.key -d '{"":""}' -H "Content-Type: application/json" -X POST https://localhost:8555/get_network_info
curl --insecure --cert ~/.chia/mainnet/config/ssl/full_node/private_full_node.crt --key ~/.chia/mainnet/config/ssl/full_node/private_full_node.key -d '{"height":"520"}' -H "Content-Type: application/json" -X POST https://localhost:8555/get_block_record_by_height
// ========= ref
// https://github.com/Chia-Network/chia-blockchain/blob/main/BUILD_TIMELORD.md
// https://github.com/Chia-Network/chia-blockchain/wiki/Timelords
// https://github.com/Chia-Network/chia-blockchain/wiki/k-sizes
// https://github.com/Flax-Network/flax-blockchain/blob/b61980cee6da1cb49c040318b5ce62b55b108a09/flax/consensus/default_constants.py
// https://github.com/Chia-Network/chia-blockchain/blob/1.1.7/chia/util/block_tools.py#L78
// (old version for blockchain testing , but without INITIAL_FREEZE_END_TIMESTAMP , it look like removed at new version)
// have fun : )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment