Skip to content

V116 #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 15, 2024
Merged

V116 #45

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import requests
from tqdm import tqdm

versions = ['0.109.0', '0.110.2', '0.111.0', '0.112.1', '0.113.1', "0.114.0", "0.115.0"] # Replace with your versions

versions = ['0.109.0', '0.110.2', '0.111.0', '0.112.1', '0.113.1', "0.114.0", "0.115.0", "0.116.1"] # Replace with your versions

DOWNLOAD_DIR = "download"
SYSTEMS = {
Expand Down
106 changes: 105 additions & 1 deletion framework/helper/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,108 @@ def build_tx_info(tmp_tx_file):
witness = "0x5500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
tx_msg = tx['transaction']
tx_msg['witnesses'] = [witness]
return tx_msg
return tx_msg

def build_tx_info_err(tmp_tx_file):
with open(tmp_tx_file, "r") as file:
tx_info_str = file.read()
tx = json.loads(tx_info_str)
sign_keys = list(tx['signatures'].keys())[0]
witness = "0x0500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
tx_msg = tx['transaction']
tx_msg['witnesses'] = [witness]
return tx_msg

def build_tx_info_err2(tmp_tx_file):
with open(tmp_tx_file, "r") as file:
tx_info_str = file.read()
tx = json.loads(tx_info_str)
tx['transaction']['cell_deps'][0]['out_point']['index'] = '0x11'
sign_keys = list(tx['signatures'].keys())[0]
witness = "0x5500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
tx_msg = tx['transaction']
tx_msg['witnesses'] = [witness]
return tx_msg

def build_send_transfer_self_tx_with_input_err(input_tx_hash_list, input_tx_index_list, sign_private, data="0x",

fee=5000, output_count=1,
api_url="http://127.0.0.1:8114", dep_cells=[]):
# tx file init

tmp_tx_file = f"/tmp/demo{time.time()}-{random.randint(0, 100000000)}.json"
tx_init(tmp_tx_file, api_url)
account = util_key_info_by_private_key(sign_private)
account_address = account["address"]["testnet"]
tx_add_multisig_config(account_address, tmp_tx_file, api_url)
# add input
output_cell_capacity_total = 0
input_cell_template: any
for i in range(len(input_tx_hash_list)):
input_tx_index = input_tx_index_list[i]
input_tx_hash = input_tx_hash_list[i]
print(f"input_tx_index:{input_tx_index}")
tx_add_input(input_tx_hash, int(input_tx_index, 16), tmp_tx_file, api_url)
# add output
input_cell = RPCClient(api_url).get_transaction(input_tx_hash)["transaction"]["outputs"][
int(input_tx_index, 16)]
output_cell_capacity = int(int(input_cell["capacity"], 16) - fee)
output_cell_capacity_total += output_cell_capacity
input_cell_template = input_cell
min_output_count = min(int(output_cell_capacity_total / (100 * 100000000)), output_count)
min_output_count = max(min_output_count, 1)
output_cell_capacity = int(output_cell_capacity_total / min_output_count)
for i in range(min_output_count):
tx_add_type_out_put(input_cell_template["lock"]["code_hash"], input_cell_template["lock"]["hash_type"],
input_cell_template["lock"]["args"],
hex(output_cell_capacity), data, tmp_tx_file, False)
for i in range(len(dep_cells)):
tx_add_cell_dep(dep_cells[i]['tx_hash'],dep_cells[i]['index_hex'],tmp_tx_file)

# sign
sign_data = tx_sign_inputs(sign_private, tmp_tx_file, api_url)
tx_add_signature(sign_data[0]['lock-arg'], sign_data[0]['signature'], tmp_tx_file, api_url)
tx_info(tmp_tx_file, api_url)
# send tx return hash
return build_tx_info_err(tmp_tx_file)

def build_send_transfer_self_tx_with_input_err2(input_tx_hash_list, input_tx_index_list, sign_private, data="0x",
fee=5000, output_count=1,
api_url="http://127.0.0.1:8114", dep_cells=[]):
# tx file init

tmp_tx_file = f"/tmp/demo{time.time()}-{random.randint(0, 100000000)}.json"
tx_init(tmp_tx_file, api_url)
account = util_key_info_by_private_key(sign_private)
account_address = account["address"]["testnet"]
tx_add_multisig_config(account_address, tmp_tx_file, api_url)
# add input
output_cell_capacity_total = 0
input_cell_template: any
for i in range(len(input_tx_hash_list)):
input_tx_index = input_tx_index_list[i]
input_tx_hash = input_tx_hash_list[i]
print(f"input_tx_index:{input_tx_index}")
tx_add_input(input_tx_hash, int(input_tx_index, 16), tmp_tx_file, api_url)
# add output
input_cell = RPCClient(api_url).get_transaction(input_tx_hash)["transaction"]["outputs"][
int(input_tx_index, 16)]
output_cell_capacity = int(int(input_cell["capacity"], 16) - fee)
output_cell_capacity_total += output_cell_capacity
input_cell_template = input_cell
min_output_count = min(int(output_cell_capacity_total / (100 * 100000000)), output_count)
min_output_count = max(min_output_count, 1)
output_cell_capacity = int(output_cell_capacity_total / min_output_count)
for i in range(min_output_count):
tx_add_type_out_put(input_cell_template["lock"]["code_hash"], input_cell_template["lock"]["hash_type"],
input_cell_template["lock"]["args"],
hex(output_cell_capacity), data, tmp_tx_file, False)
for i in range(len(dep_cells)):
tx_add_cell_dep(dep_cells[i]['tx_hash'],dep_cells[i]['index_hex'],tmp_tx_file)

# sign
sign_data = tx_sign_inputs(sign_private, tmp_tx_file, api_url)
tx_add_signature(sign_data[0]['lock-arg'], sign_data[0]['signature'], tmp_tx_file, api_url)
tx_info(tmp_tx_file, api_url)
# send tx return hash
return build_tx_info_err2(tmp_tx_file)
30 changes: 30 additions & 0 deletions framework/rpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from typing import Union

import requests

Expand Down Expand Up @@ -177,7 +178,33 @@ def set_network_active(self, state):
def remove_transaction(self, tx_hash):
return self.call("remove_transaction", [tx_hash])

def get_live_cell_with_include_tx_pool(self, index, tx_hash, with_data=True, include_tx_pool: Union[bool, None] = None):
"""
over ckb v116.1 version
https://github.com/nervosnetwork/ckb/blob/bb677558efdc3e5f0759556720b62169469b555d/rpc/README.md#chain-get_live_cell
Args:
index:
tx_hash:
with_data:boolean
include_tx_pool:boolean | null

Returns:CellWithStatus

"""
return self.call("get_live_cell", [{"index": index, "tx_hash": tx_hash}, with_data, include_tx_pool])

def get_live_cell(self, index, tx_hash, with_data=True):
"""
under ckb v116.1 version
https://github.com/nervosnetwork/ckb/blob/bb677558efdc3e5f0759556720b62169469b555d/rpc/README.md#chain-get_live_cell
Args:
index:
tx_hash:
with_data:boolean

Returns:CellWithStatus

"""
return self.call("get_live_cell", [{"index": index, "tx_hash": tx_hash}, with_data])

def submit_block(self, work_id, block):
Expand All @@ -192,6 +219,9 @@ def get_cells_capacity(self, script):
def get_current_epoch(self):
return self.call("get_current_epoch", [])

def test_tx_pool_accept(self,tx, outputs_validator):
return self.call("test_tx_pool_accept",[tx, outputs_validator])

def call(self, method, params, try_count=15):

headers = {'content-type': 'application/json'}
Expand Down
19 changes: 12 additions & 7 deletions framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
class CkbNodeConfigPath(Enum):

CURRENT_TEST = (
"source/template/ckb/v115/ckb.toml.j2",
"source/template/ckb/v115/ckb-miner.toml.j2",
"source/template/ckb/v115/specs/dev.toml",
"download/0.115.0"
"source/template/ckb/v116/ckb.toml.j2",
"source/template/ckb/v116/ckb-miner.toml.j2",
"source/template/ckb/v116/specs/dev.toml",
"download/0.116.1"
)

CURRENT_MAIN = ("source/template/ckb/v115/ckb.toml.j2",
"source/template/ckb/v115/ckb-miner.toml.j2",
CURRENT_MAIN = ("source/template/ckb/v116/ckb.toml.j2",
"source/template/ckb/v116/ckb-miner.toml.j2",
"source/template/specs/mainnet.toml.j2",
"download/0.115.0")
"download/0.116.1")

v116 = ( "source/template/ckb/v116/ckb.toml.j2",
"source/template/ckb/v116/ckb-miner.toml.j2",
"source/template/ckb/v116/specs/dev.toml",
"download/0.116.1"
)
v115 = (
"source/template/ckb/v115/ckb.toml.j2",
"source/template/ckb/v115/ckb-miner.toml.j2",
Expand Down
2 changes: 1 addition & 1 deletion source/template/ckb/v114/ckb.toml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ block_uncles_cache_size = {{ ckb_store_block_uncles_cache_size | default("
# init_tip_hash = "0x8fbd0ec887159d2814cee475911600e3589849670f5ee1ed9798b38fdeef4e44"
#
# # CKB rich-indexer has its unique configuration.
[indexer_v2.rich_indexer]
#[indexer_v2.rich_indexer]
# # By default, it uses an embedded SQLite database.
# # Alternatively, you can set up a PostgreSQL database service and provide the connection parameters.
# db_type = "postgres"
Expand Down
45 changes: 45 additions & 0 deletions source/template/ckb/v116/ckb-miner.toml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Config generated by `ckb init --chain dev`

data_dir = "{{ ckb_miner_data_dir | default(ckb_data_dir) }}"

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


[logger]
filter = "{{ ckb_miner_logger_filter | default("info") }}"
color = {{ ckb_miner_logger_color | default("true") }}
log_to_file = {{ ckb_miner_logger_log_to_file | default("true") }}
log_to_stdout = {{ ckb_miner_logger_log_to_stdout | default("true") }}

[sentry]
# set to blank to disable sentry error collection
dsn = "{{ ckb_miner_sentry_dsn | default("") }}"
# 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 = "{{ ckb_miner_sentry_org_contact | default() }}"

[miner.client]
rpc_url = "http://{{ ckb_miner_rpc_url | default("127.0.0.1:8114") }}"
block_on_submit = {{ ckb_miner_block_on_submit | default("true") }}

# block template polling interval in milliseconds
poll_interval = {{ ckb_miner_poll_interval | default("1000") }}

#{% if ckb_miner_workers is defined %}
# {% for worker in ckb_miner_workers %}
# [[miner.workers]]
# worker_type = "{{ worker.worker_type }}"
# delay_type = "{{ worker.delay_type }}"
# value = {{ worker.value }}
# {% endfor %}
#{% else %}
[[miner.workers]]
worker_type = "Dummy"
delay_type = "Constant"
value = 1000
#{% endif %}
Loading
Loading