Skip to content

Commit

Permalink
Merge pull request #137 from RetricSu/chaos-reorg
Browse files Browse the repository at this point in the history
feat: enable ckb reorgs for chaos test
  • Loading branch information
RetricSu authored Dec 24, 2021
2 parents ee7dbc3 + 7f20ecd commit 47e3a57
Show file tree
Hide file tree
Showing 30 changed files with 4,168 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ workspace/*
!workspace/.gitkeep
cache/activity/*
cache/build/*

plugins/*/node_modules
plugins/*/*.log

*.log
58 changes: 57 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ifndef VERBOSE
endif


.PHONY: ckb
.PHONY: ckb ckb2 ckb3 connect-ckb chaos
###### command list ########

### 1. utils
Expand Down Expand Up @@ -99,8 +99,20 @@ install:
make rebuild-poa-scripts ; \
else make copy-poa-scripts-from-docker ;\
fi
# if multi ckb nodes, install deps for plugins
# todo: maybe use prebuild image here
if [ "$(ENABLE_MULTI_CKB_NODES)" = true ] ; then \
cd plugins/chaos && yarn ;\
fi

start: SHELL:=/bin/bash
start:
if [ "$(ENABLE_MULTI_CKB_NODES)" = true ] ; then \
source ./gw_util.sh && wait_to_connect_ckb > connect-ckb.log 2>&1 & \
fi
if [ "$(WATCH_CKB_REORG)" = true ] ; then \
source ./gw_util.sh && watch_ckb_reorg > chain-reorg.log 2>&1 & \
fi
cd docker && FORCE_GODWOKEN_REDEPLOY=false docker-compose --env-file .build.mode.env up -d --build > /dev/null
make show_wait_tips

Expand Down Expand Up @@ -146,6 +158,13 @@ web3:
# show ckb
ckb:
cd docker && docker-compose logs -f --tail 200 ckb
# show ckb2
ckb2:
cd docker && docker-compose logs -f --tail 200 ckb2

# show ckb3
ckb3:
cd docker && docker-compose logs -f --tail 200 ckb3
# show call-polyman
call-polyman:
cd docker && docker-compose logs -f call-polyman
Expand Down Expand Up @@ -179,9 +198,21 @@ stop-web3:
start-ckb:
cd docker && docker-compose start ckb

start-ckb2:
cd docker && docker-compose start ckb2

start-ckb3:
cd docker && docker-compose start ckb3

stop-ckb:
cd docker && docker-compose stop ckb

stop-ckb2:
cd docker && docker-compose stop ckb2

stop-ckb3:
cd docker && docker-compose stop ckb3

start-db:
cd docker && docker-compose start postgres

Expand Down Expand Up @@ -213,6 +244,12 @@ enter-web3:
enter-ckb:
cd docker && docker-compose exec ckb bash

enter-ckb2:
cd docker && docker-compose exec ckb2 bash

enter-ckb3:
cd docker && docker-compose exec ckb3 bash

enter-db:
cd docker && docker-compose exec postgres bash

Expand Down Expand Up @@ -324,6 +361,9 @@ install-web3-node-modules-if-empty:
install-polyman-node-modules-if-empty:
cd `pwd`/packages/godwoken-polyman && yarn check --verify-tree && cd .. || yarn install

patch-lumos-indexer-for-polyman:
cp `pwd`/patches/lumos-indexer-linux/index.node `pwd`/packages/godwoken-polyman/node_modules/@ckb-lumos/indexer/native/index.node

### 7. godwoken gen schema helper command
gen-schema:
make clean-schema
Expand All @@ -343,3 +383,19 @@ prepare-schema-for-web3:
mv ./godwoken-web3/packages/godwoken/godwoken.esm.js ./packages/godwoken-web3/packages/godwoken/schemas/index.esm.js
mv ./godwoken-web3/packages/godwoken/godwoken.js ./packages/godwoken-web3/packages/godwoken/schemas/index.js
mv ./godwoken-web3/packages/godwoken/godwoken.json ./packages/godwoken-web3/packages/godwoken/schemas/index.json

########### helper function #############
connect-ckb:
cd plugins/chaos && yarn connect

watch-reorg:
cd plugins/chaos && yarn watch

delay-ckb:
pumba -v && echo "ready to delay ckb network..." || echo "you need to install Pumba, https://github.com/alexei-led/pumba";
pumba netem --duration 50s --tc-image gaiadocker/iproute2 delay --time 3000 docker_ckb3_1 & pumba netem --duration 50s --tc-image gaiadocker/iproute2 delay --time 3000 docker_ckb2_1

chaos: SHELL:=/bin/bash
chaos:
source gw_util.sh && start_chaos > chaos.log 2>&1 &

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ one line command to start godwoken-polyjuice chain for devnet.
- develop branch: for newest development, might be broken. most of time, only support custom-mode.
```

test feature: [ckb reorg for chaos test](/docs/chaos-test.md)

----

Expand Down
5 changes: 3 additions & 2 deletions ckb/ckb-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ poll_interval = 1_000_000_000_000

[[miner.workers]]
worker_type = "Dummy"
delay_type = "Constant"
value = 5000
delay_type = "Uniform"
low = 3500
high = 5000
41 changes: 41 additions & 0 deletions ckb2/ckb-miner.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Config generated by `ckb init --chain dev`

data_dir = "/usr/local/ckb-chain-data"

[chain]
# Choose the kind of chains to run, possible values:
# - { file = "specs/dev.toml" }
# - { bundled = "specs/testnet.toml" }
# - { bundled = "specs/mainnet.toml" }
spec = { file = "specs/dev.toml" }

[logger]
filter = "info"
color = true
log_to_file = true
log_to_stdout = true

[sentry]
# set to blank to disable sentry error collection
dsn = ""
# if you are willing to help us to improve,
# please leave a way to contact you when we have troubles to reproduce the errors.
# org_contact = ""

# # **Experimental** Monitor memory changes.
# [memory_tracker]
# # Seconds between checking the process, 0 is disable, default is 0.
# interval = 600

[miner.client]
rpc_url = "http://0.0.0.0:8117/"
block_on_submit = true

# block template polling interval in milliseconds
poll_interval = 1_000_000_000_000

[[miner.workers]]
worker_type = "Dummy"
delay_type = "Uniform"
low = 3500
high = 5000
152 changes: 152 additions & 0 deletions ckb2/ckb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Config generated by `ckb init --chain dev`

data_dir = "/usr/local/ckb2-chain-data"

[chain]
# Choose the kind of chains to run, possible values:
# - { file = "specs/dev.toml" }
# - { bundled = "specs/testnet.toml" }
# - { bundled = "specs/mainnet.toml" }
spec = { file = "specs/dev.toml" }

[logger]
filter = "info"
color = true
log_to_file = true
log_to_stdout = true

[sentry]
# set to blank to disable sentry error collection
dsn = ""
# if you are willing to help us to improve,
# please leave a way to contact you when we have troubles to reproduce the errors.
# org_contact = ""

# # **Experimental** Monitor memory changes.
# [memory_tracker]
# # Seconds between checking the process, 0 is disable, default is 0.
# interval = 600

[db]
# The capacity of RocksDB cache, which caches uncompressed data blocks, indexes and filters, default is 128MB.
# Rocksdb will automatically create and use an 8MB internal cache if you set this value to 0.
# To turning off cache, you need to set this value to 0 and set `no_block_cache = true` in the options_file,
# however, we strongly discourage this setting, it may lead to severe performance degradation.
cache_size = 134217728

# Provide an options file to tune RocksDB for your workload and your system configuration.
# More details can be found in [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide).
options_file = "default.db-options"

[network]
listen_addresses = ["/ip4/0.0.0.0/tcp/8118"]
### Specify the public and routable network addresses
# public_addresses = []

# Node connects to nodes listed here to discovery other peers when there's no local stored peers.
# When chain.spec is changed, this usually should also be changed to the bootnodes in the new chain.
bootnodes = []

### Whitelist-only mode
# whitelist_only = false
### Whitelist peers connecting from the given IP addresses
# whitelist_peers = []
### Enable `SO_REUSEPORT` feature to reuse port on Linux, not supported on other OS yet
# reuse_port_on_linux = true

max_peers = 125
max_outbound_peers = 8
# 2 minutes
ping_interval_secs = 120
# 20 minutes
ping_timeout_secs = 1200
connect_outbound_interval_secs = 15
# If set to true, try to register upnp
upnp = false
# If set to true, network service will add discovered local address to peer store, it's helpful for private net development
discovery_local_address = true
# If set to true, random cleanup when there are too many inbound nodes
# Ensure that itself can continue to serve as a bootnode node
bootnode_mode = false

[rpc]
# By default RPC only binds to localhost, thus it only allows accessing from the same machine.
#
# Allowing arbitrary machines to access the JSON-RPC port is dangerous and strongly discouraged.
# Please strictly limit the access to only trusted machines.
listen_address = "0.0.0.0:8117"

# Default is 10MiB = 10 * 1024 * 1024
max_request_body_size = 10485760

# List of API modules: ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug"]
modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug"]

# By default RPC only binds to HTTP service, you can bind it to TCP and WebSocket.
# tcp_listen_address = "127.0.0.1:18117"
ws_listen_address = "0.0.0.0:28117"
reject_ill_transactions = true

# By default deprecated rpc methods are disabled.
enable_deprecated_rpc = false

[tx_pool]
max_mem_size = 20_000_000 # 20mb
max_cycles = 200_000_000_000
min_fee_rate = 1_000 # shannons/KB
max_tx_verify_cycles = 70_000_000
max_ancestors_count = 25

[store]
header_cache_size = 4096
cell_data_cache_size = 128
block_proposals_cache_size = 30
block_tx_hashes_cache_size = 30
block_uncles_cache_size = 30

# [notifier]
# # Execute command when the new tip block changes, first arg is block hash.
# new_block_notify_script = "your_new_block_notify_script.sh"
# # Execute command when node received an network alert, first arg is alert message string.
# network_alert_notify_script = "your_network_alert_notify_script.sh"

# Set the lock script to protect mined CKB.
#
# CKB uses CS architecture for miner. Miner process (ckb miner) gets block
# template from the Node process (ckb run) via RPC. Thus the lock script is
# configured in ckb.toml instead of ckb-miner.toml, and the config takes effect
# after restarting Node process.
#
# The `code_hash` identifies different cryptography algorithm. Read the manual
# of the lock script provider about how to generate this config.
#
# CKB provides an secp256k1 implementation, it requires a hash on the
# compressed public key. The hash algorithm is blake2b, with personal
# "ckb-default-hash". The first 160 bits (20 bytes) are used as the only arg.
#
# You can use any tool you trust to generate a Bitcoin private key and public
# key pair, which can be used in CKB as well. CKB CLI provides the function for
# you to convert the public key into block assembler configuration parameters.
#
# Here is an example using ckb-cli to generate an account, this command will
# print the block assembler args(lock_arg) to screen:
#
# ckb-cli account new
#
# If you already have a raw secp256k1 private key, you can get the lock_arg by:
#
# ckb-cli util key-info --privkey-path <privkey-path>
#
# The command `ckb init` also accepts options to generate the block assembler
# directly. See `ckb init --help` for details.
#
# ckb init <lock_arg>
#
# secp256k1_blake160_sighash_all example:
[block_assembler]
code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
args = "0xc48a45e11c66b2c8b5c61f6036486ad4d9d2fd29"
hash_type = "type"
message = "0x1234"
# # CKB will prepend the binary version to message, to identify the block miner client. (default true, false to disable it)
# use_binary_version_as_message_prefix = true
23 changes: 23 additions & 0 deletions ckb2/default.db-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is a RocksDB option file.
#
# For detailed file format spec, please refer to the official documents
# in https://rocksdb.org/docs/
#

[DBOptions]
bytes_per_sync=1048576
max_background_compactions=4
max_background_flushes=2
max_total_wal_size=134217728
keep_log_file_num=32

[CFOptions "default"]
level_compaction_dynamic_level_bytes=true
write_buffer_size=8388608
min_write_buffer_number_to_merge=1
max_write_buffer_number=2
max_write_buffer_size_to_maintain=-1

[TableOptions/BlockBasedTable "default"]
cache_index_and_filter_blocks=true
pin_l0_filter_and_index_blocks_in_cache=true
Loading

0 comments on commit 47e3a57

Please sign in to comment.