How to fork mainnet L1 into a devnet?

Do you mean run a devchain using existing mainnet data?

Run a local CKB dev chain using existing testnet/mainnet data

  1. Copy the data directory to a new directory. The following steps will be done in this new directory.

  2. Download the corresponding chain spec file based on testnet or mainnet

    1. testnet https://github.com/nervosnetwork/ckb/blob/develop/resource/specs/testnet.toml
    2. mainnet https://github.com/nervosnetwork/ckb/blob/develop/resource/specs/mainnet.toml
  3. Initialize dev chain and import testnet or mainnet chain spec, taking mainnet as an example

    ckb init -c dev --import-spec /path/to/downloaded/mainnet.toml --force
    
  4. Modify the imported specs/dev.toml

    [params]
    genesis_epoch_length = 1743
    # params can add the following options for configuration, keep genesis_epoch_length the same as original file
    initial_primary_epoch_reward = 1_917_808_21917808
    secondary_epoch_reward = 613_698_63013698
    max_block_cycles = 10_000_000_000
    cellbase_maturity = 0
    primary_epoch_reward_halving_interval = 8760
    epoch_duration_target = 14400
    # For development and testing purposes only.
    # Keep difficulty be permanent if the pow is Dummy. (default: false)
    permanent_difficulty_in_dummy = true
    
    # Change pow.func to Dummy
    [pow]
    func = "Dummy"
    
  5. Now CKB can be started, need to add parameters -skip-spec-check --overwrite-spec for the first run

    ckb run --skip-spec-check --overwrite-spec
    

I previously suggesting change the spec name to ckb_dev:

# change name in the first line to ckb_dev
name = "ckb_dev"

However, this will use the softfork and hardfork configurations for dev chain, to follow the mainnet or testnet forks configurations, just keep the original values.

2 Likes