- Extract data from LevelDB managed by loopchain
- Extract data from LevelDB managed by ICON Service
- Execute ICON Service with block extracted from loopchain LevelDB
- Synchronize ICON Service statedb with confirmed_transaction_list of block db
- Execute IconServiceEngine.invoke() with confirmed transactions extracted from block db
- Compare commit_state in block with state_root_hash created from IconServiceEngine
- Compare transaction result in block with the one generated by IconServiceEngine
- If 'start' options is not defined, icondbtools tries to start to sync from the next height of the committed block in statedb automatically
(venv) $ icondbtools sync --help
usage: icondbtools sync [-h] --db DB [-s START] [--end END] [-c COUNT]
[-o BUILTIN_SCORE_OWNER] [--stop-on-error]
[--no-commit] [--write-precommit-data] [--no-fee]
[--no-audit] [--deployer-whitelist]
[--score-package-validator] [--channel CHANNEL]
[--backup-period BACKUP_PERIOD]
[--is-config IS_CONFIG]
[--print-block-height PRINT_BLOCK_HEIGHT]
optional arguments:
-h, --help show this help message and exit
--db DB
-s START, --start START
start height to sync
--end END end height to sync, inclusive
-c COUNT, --count COUNT
The number of blocks to sync
-o BUILTIN_SCORE_OWNER, --owner BUILTIN_SCORE_OWNER
BuiltinScoreOwner
--stop-on-error stop running when commit_state is different from
state_root_hash
--no-commit Do not commit
--write-precommit-data
Write precommit data to file
--no-fee Disable fee
--no-audit Diable audit
--deployer-whitelist Enable deployer whitelist
--score-package-validator
Enable score package validator
--channel CHANNEL channel name used as a key of commit_state in block
data
--backup-period BACKUP_PERIOD
Backup statedb every this period blocks
--is-config IS_CONFIG
iconservice_config.json filepath
--print-block-height PRINT_BLOCK_HEIGHT
Print every this block height
(venv) $ icondbtools sync --db ./db_13.125.135.114:7100_icon_dex --stop-on-error
key | value | desc |
---|---|---|
--db | string | the path of loopchain db ex) --db ./db_13.125.135.114:7100_icon_dex |
-s, --start | int | start block height to sync ex) --start 1234 |
-c, --count | int | the number of blocks to sync ex) --count 100 |
-o, --owner | string | Set buitinScoreOwner address |
--stop-on-error | - | If an error happens, sync is stopped |
--no-commit | - | Do not write changed states to stateDB |
--write-precommit-data | - | Write updated states (key:value pairs) to file for debugging |
Print the last block in block db
(venv) $ icondbtools lastblock --help
usage: icondbtools lastblock [-h] --db DB
optional arguments:
-h, --help show this help message and exit
--db DB
(venv) $ icondbtools lastblock --db ./db_13.125.135.114:7100_icon_dex
Namespace(db='../db_data/mainnet/db', func=<function print_last_block at 0x7f8ff76b8c80>)
{'version': '0.1a', 'prev_block_hash': 'dbedbc1d62b1ce2948b90a1bc5f15f921bdb84442465757a1b72563d43b0dc56', 'merkle_tree_root_hash': '2248fa6e966f7d13ac091914a92453df017be1fa8552c115fa0ca574bd30cd81', 'time_stamp': 1538705882749492, 'confirmed_transaction_list': [{'version': '0x3', 'nid': '0x1', 'from': 'hx522bff55a62e0c75a1b51855b0802cfec6a92e84', 'to': 'hx11de4e28be4845de3ea392fd8d758655bf766ca7', 'value': '0xe35fa931a0000', 'stepLimit': '0xf4240', 'timestamp': '0x57771e1850109', 'signature': 'zekHL22qcFJA3HheIFeyRIaxQ/hqn3ZDeGNPmCN0GepDyzbKcejaDp9i5pJuam9ooxL47SV9Si1me4FmWHUeCQE=', 'txHash': '2248fa6e966f7d13ac091914a92453df017be1fa8552c115fa0ca574bd30cd81'}], 'block_hash': '7fde929247ff78639560b633172b730cb63be91cfd10acc59aca777ba0c7f774', 'height': 67720, 'peer_id': 'hxe5eae2613e8b6c19302335676c3c04866e7c6298', 'signature': '/22IPWX7EdmT8DDTeTg+ATufqReCjKnfJLFsqo42W+wi3M3DAYDxQjO6goXFcM2GkytlLRDOZpiO4u2Q5k1G8QE=', 'commit_state': {'icon_dex': '48e288616311a7a8de8e3fc23e573c4f364a086fffbfabe48ab7d15c001510ee'}}
Print the block indicated by block height
(venv) $ icondbtools block --help
usage: icondbtools block [-h] --db DB --height HEIGHT
optional arguments:
-h, --help show this help message and exit
--db DB
--height HEIGHT start height to sync
(venv) $ icondbtools block --db ./db_13.125.135.114:7100_icon_dex --height 2
{'version': '0.1a', 'prev_block_hash': 'd5629fe006104df557570ce2613c8df1901d8f6f322b9f251645c201fa1d1e9e', 'merkle_tree_root_hash': '935e69a1937292e8de171e3c796c555e23d16e680ede6086a7583937d7ca703e', 'time_stamp': 1519289605629115, 'confirmed_transaction_list': [{'from': 'hx5a05b58a25a1e5ea0f1d5715e1f655dffc1fb30a', 'to': 'hxdbc9f726ad776d9a43d5bad387eff01325178fa3', 'value': '0x845951614014880000000', 'fee': '0x2386f26fc10000', 'timestamp': '1519289605344996', 'tx_hash': '935e69a1937292e8de171e3c796c555e23d16e680ede6086a7583937d7ca703e', 'signature': 'kF5b/l709ikHJwbGH8MvlwsWNjGbtmzZu4agizhVAGYQaIwInuBxw36P4jvFGY0DzmOVQ5SwB02zAn1/G8g1OQA=', 'method': 'icx_sendTransaction'}], 'block_hash': '8304cc79c8788cea92d3f25d1ce1e59ad66f8b6b03465d23128e6c8229467ee0', 'height': 2, 'peer_id': 'hx1fe2dfae9a5439bb1d4e193a3b7c6e5df6c6650e', 'signature': '0lUIA1mbiCDUyTcK6L0WfYWXMiD6TDCsCK01LWWOSvgqFp7rD+tgVBm0kbfp8DvpJNZPDV+dkNqj5EcYid0sHgA=', 'commit_state': {'icon_dex': '7b230ee5138e8b5a5faed4b5f59c032c8ad23b00991f263a05a3f41409de9237'}}
Remove .score/ and .statedb/ in a working directory
(venv) $ icondbtools clear --help
usage: icondbtools clear [-h]
optional arguments:
-h, --help show this help message and exit
(venv) $ icondbtools clear
Extract the transaction result indicated by transaction hash from block db and print it
(venv) $ icondbtools txresult --help
usage: icondbtools txresult [-h] --db DB --hash TX_HASH
optional arguments:
-h, --help show this help message and exit
--db DB
--hash TX_HASH tx hash without "0x" prefix
(venv) $ icondbtools txresult --db ../db_data/testnet/db --hash 7c1358eeaaa354d3ffa00f734d69038a4d3989a7d623857165244ab19cbe0ebd
{'block_hash': '8b6b7f6a208052d82c9f9f66050b22d24af2ecd511a0d2a49135b7f94e25e7b8', 'block_height': 32304, 'tx_index': '0x0', 'transaction': {'data': {'method': 'airdrop', 'params': {'amount': '0xde0b6b3a7640000', 'accounts': 'hxda034f6d8baae7ffb85ac827d91bbf0678719361'}}, 'stepLimit': '0x87000000', 'signature': 't1ZkT7ug4sDwimQ6eFlZ73DSVPvsfOFUcNkZYrNTQjYabT4f7+vpVgOIUxQ1co4fIZ56ixbgw3iV8QORh6n1CAE=', 'dataType': 'call', 'nid': '0x2', 'from': 'hx53dffc3b22a79845208f7f5fbd47f2e357162937', 'to': 'cx9de0c8e7266406df184b07f1c886c2eac804abef', 'version': '0x3', 'timestamp': '0x57771a5bf3e28'}, 'result': {'txHash': '7c1358eeaaa354d3ffa00f734d69038a4d3989a7d623857165244ab19cbe0ebd', 'blockHeight': '0x7e30', 'blockHash': '8b6b7f6a208052d82c9f9f66050b22d24af2ecd511a0d2a49135b7f94e25e7b8', 'txIndex': '0x0', 'to': 'cx9de0c8e7266406df184b07f1c886c2eac804abef', 'stepUsed': '0x32cd0', 'stepPrice': '0x2540be400', 'cumulativeStepUsed': '0x32cd0', 'eventLogs': [{'scoreAddress': 'cx4fd2ddde487072f4465b23fa40660db2676f5d94', 'indexed': ['Transfer(Address,Address,int,bytes)', 'cx9de0c8e7266406df184b07f1c886c2eac804abef', 'hxda034f6d8baae7ffb85ac827d91bbf0678719361', '0xde0b6b3a7640000'], 'data': ['0x61697264726f70706564']}, {'scoreAddress': 'cx9de0c8e7266406df184b07f1c886c2eac804abef', 'indexed': ['EventAirdropped(Address,int,int)', 'hxda034f6d8baae7ffb85ac827d91bbf0678719361'], 'data': ['0xde0b6b3a7640000', '0x2']}], 'logsBloom': '0x000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002300000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000081000000000000000000000000000000000000000000000000000000000000008600000000000000000000000000000000000000000000000000020000000000180000000000000000000000000000000000000000000000000000000000000208000000000000', 'status': '0x1'}}
- Generate the sha3_256 hash value from key and value data of leveldb
- Used to verify whether statedbs are the same
(venv) $ icondbtools statehash --help
usage: icondbtools statehash [-h] --db DB
optional arguments:
-h, --help show this help message and exit
--db DB
(venv) $ icondbtools statehash --db .statedb/icon_dex/
Namespace(db='.statedb/icon_dex/', func=<function run_command_state_hash at 0x7ff5daec4620>)
hash: 314fe6be51eac2b1e788f763041cbd6b0288dcaeeb300636aa5eecd7ebb03283
rows: 63791
total_key_size: 3976664
total_value_size: 7227054
elapsedTime: 0.09267663955688477 seconds
- Print the information of last block commited to statedb
(venv) $ icondbtools statelastblock --help
usage: icondbtools statelastblock [-h] --db DB
optional arguments:
-h, --help show this help message and exit
--db DB
(venv) goldworm@goldworm-vbox:~/work/icon/db_test$ icondbtools statelastblock --db .statedb/icon_dex/
Namespace(db='.statedb/icon_dex/', func=<function run_command_state_last_block at 0x7f793448f6a8>)
height: 32304
timestamp: 1538704880230341 (2018-10-05 11:01:20.230341)
prev_hash: 0x55d7cf9f52fd7a621d46afa66ee7efea7b0af328d1818ed4f8df501f65a29948
block_hash: 0x8b6b7f6a208052d82c9f9f66050b22d24af2ecd511a0d2a49135b7f94e25e7b8
- Print the information of the account indicated by an address
(venv) $ icondbtools account --help
usage: icondbtools account [-h] --db DB --address ADDRESS
optional arguments:
-h, --help show this help message and exit
--db DB
--address ADDRESS EOA or SCORE address. ex)
hx21a0f22e65ad8cd76c282b8b7fb35ba0368aa9bd
(venv) $ icondbtools account --db ../db_data/mainnet/20181018/.score_data/db/icon_dex/ --address hx677133298ed5319607a321a38169031a8867085c
address: hx677133298ed5319607a321a38169031a8867085c
amount: 11.5856642 in icx
is_c_rep: False
is_locked: False
- Calculate tps based on confirmed transactions that a specific range of blocks contain.
- The term "tps" means "transactions per second"
- db: loopchain database
usage: icondbtools tps [-h] --db DB [--start START] [--end END]
optional arguments:
-h, --help show this help message and exit
--db DB
--start START
--end END
(venv) $ icondbtools tps --db ../db_data/mainnet/20181018/.score_data/db/icon_dex/ --start 2
height | txs | total txs | period_s
---------------------------------------------------
2 | 5 | 5 | 0.0
3 | 2 | 7 | 0.347491
4 | 1 | 8 | 0.332745
5 | 1 | 9 | 0.440178
6 | 1 | 10 | 0.433037
7 | 1 | 11 | 0.636413
8 | 1 | 12 | 0.581929
9 | 1 | 13 | 0.643707
...
49 | 9 | 3414 | 0.421763
50 | 36 | 3450 | 0.36228
51 | 546 | 3996 | 1.237751
52 | 546 | 4542 | 2.229265
53 | 546 | 5088 | 1.354028
54 | 433 | 5521 | 1.229462
55 | 36 | 5557 | 8.596111
56 | 69 | 5626 | 0.418352
57 | 80 | 5706 | 0.418352
tps: 79.93847007350809
transactions: 5706
blocks: 56
period: 71.3799 seconds, 71379900 microseconds
---------------------------------------------------
- Read a token balance from IRC2 Standard Token SCORE
- Write a new balance to StateDB for IRC2 Standard Token SCORE
- Refer to ICON Token Standard RI
(venv) $ icondbtools token --help
usage: icondbtools token [-h] --db DB --score SCORE --user USER
[--balance BALANCE]
optional arguments:
-h, --help show this help message and exit
--db DB
--score SCORE score address ex)
cx63af7f2e073985a9e9965765e809f66da3b0f238
--user USER user address ex)
hxd7cf2f6bcbbfa542a08e9cd0e48bf848018a2ec7
--balance BALANCE token balance to write. ex) 100
# Read a token balance from StateDB.
(venv) $ icondbtools token --db ./icon_dex/ --score cx63af7f2e073985a9e9965765e809f66da3b0f238 --user hxd7cf2f6bcbbfa542a08e9cd0e48bf848018a2ec7
token balance: 100
elapsedTime: 0.03488469123840332 seconds
# Write a token balance to StateDB.
(venv) $ icondbtools token --db ./icon_dex/ --score cx63af7f2e073985a9e9965765e809f66da3b0f238 --user hxd7cf2f6bcbbfa542a08e9cd0e48bf848018a2ec7 --balance 1234
elapsedTime: 0.019192934036254883 seconds
# Read a token balance from StateDB.
(venv) $ icondbtools token --db ./icon_dex/ --score cx63af7f2e073985a9e9965765e809f66da3b0f238 --user hxd7cf2f6bcbbfa542a08e9cd0e48bf848018a2ec7
token balance: 1234
elapsedTime: 0.03488469123840332 seconds
- Copy LevelDB into the file path
(venv) $ icondbtools copy -h
usage: icondbtools copy [-h] --db DB [-s START] [--end END] [--count COUNT]
[--new-db NEW_DB]
optional arguments:
-h, --help show this help message and exit
--db DB
-s START, --start START
start block height to be copied
--end END end block height to be copied, inclusive
--count COUNT block count to be copied
--new-db NEW_DB new DB path for blocks to be copied
# Copy part of LevelDB from block height 0 to 100 into new DB path
(venv) $ icondbtools copy --db ./db_13.125.135.114:7100_icon_dex --start 0 --end 100 --new-db ./newdb
- Print information of the block and period the block belongs to
- It is only for MainNet
(venv) $ icondbtools term -h
usage: icondbtools term [-h] [--height HEIGHT]
optional arguments:
-h, --help show this help message and exit
--height HEIGHT target block height
# Get general info about prevote and decentralization
(venv) $ icondbtools term
Pre-vote
- start BH: 7597282
- end BH: 10362082
- term period: 43200
Decentralization
- start BH: 10362083
- term period: 43120
# Get decentralization info of the block and period the block belongs to
(venv) $ icondbtools term --height 10362083
Decentralization info of the block and period the block belongs to for only MainNet
- seq: 1 (start at 1)
- term period: 43120
- start BH: 10362083
- end BH: 10405202
- 1 block from start BH-10362083
- Prune Block DB to optimize storage.
- Remains Block (default 86400)
(venv) $ icondbtools prune -h
usage: icondbtools prune [-h] --db DB [-d] [-b REMAIN_BLOCKS] --dest DEST
optional arguments:
-h, --help show this help message and exit
--db DB
-b REMAIN_BLOCKS Prune LastBlock - remain_blocks (default 86400)
--dest DEST Dest new database path
# example
(venv) $ icondbtools prune --db ./db_icon_dex --dest ./new_icon_dex -b 86400