Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Zilliqa/zq2 into dependabot…
Browse files Browse the repository at this point in the history
…/cargo/alloy-revm-53e89ab0b1
  • Loading branch information
saeed-zil committed Dec 15, 2024
2 parents 1883eb3 + 4c76cf9 commit 82d6e71
Show file tree
Hide file tree
Showing 64 changed files with 177,816 additions and 62,448 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/base_benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ on:
push:
branches: main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
benchmark_base_branch:
name: Continuous Benchmarking
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
types:
- checks_requested

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

env:
CARGO_TERM_COLOR: always
# Run a decent number of samples for our randomized tests
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr_benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ on:
pull_request:
types: [opened, reopened, edited, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
benchmark_pr_branch:
name: Continuous Benchmarking PRs
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr_benchmarks_closed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: bencherdev/bencher@main
- name: Archive closed PR branch
continue-on-error: true # This will fail if the branch did not exist in bencher. This is fine.
run: |
bencher archive \
--project zq2 \
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ Pass the path to configuration files on the command line with `-c` or `--config-
If multiple configuration files are provided, they will be merged together.
If a configuration key occurs in more than one configuration file, the process will exit with an error.

By default, a node will not expose the JSON-RPC API.
To enable APIs, you must set `api_servers` under the [[nodes]] object in the configuration file.
Each item must be an object with keys `port` and `enabled_apis`.
Each item in `enabled_apis` must either be:

* A string such as `"eth"`, which enables all API methods under the `eth_` namespace.
* An object of the form `{ namespace = "eth", apis = ["blockNumber"] }`, which enables specific API methods.

Zilliqa APIs which don't have a namespace are implicitly grouped under the `zilliqa` namespace.

See `config-example.toml` for a configuration example.

## Testing

The tests can be run with `cargo test`.
Expand Down
10 changes: 6 additions & 4 deletions config-example.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
p2p_port = 0

[[nodes]]
json_rpc_port = 4201
api_servers = [
{ port = 4201, enabled_apis = [ "admin", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa" ] }
]
eth_chain_id = 0x8001
consensus.consensus_timeout = { secs = 5, nanos = 0 }
# These public keys correspond to the private keys of all four nodes in `docker-compose.yaml`.
Expand All @@ -28,7 +30,9 @@ consensus.eth_block_gas_limit = 84000000
consensus.gas_price = "4_761_904_800_000"

[[nodes]]
json_rpc_port = 4202
api_servers = [
{ port = 4202, enabled_apis = [ "admin", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa" ] }
]
eth_chain_id = 0x8002
[nodes.consensus]
consensus_timeout = { secs = 5, nanos = 0 }
Expand All @@ -54,5 +58,3 @@ consensus.minimum_stake = "10_000_000_000_000_000_000_000_000"
# Gas parameters
consensus.eth_block_gas_limit = 84000000
consensus.gas_price = "4_761_904_800_000"


4 changes: 3 additions & 1 deletion config-single-node.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
p2p_port = 0

[[nodes]]
json_rpc_port = 4201
api_servers = [
{ port = 4201, enabled_apis = [ "admin", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa" ] }
]
eth_chain_id = 0x8001
consensus.consensus_timeout = { secs = 5, nanos = 0 }
consensus.genesis_deposits = [
Expand Down
3 changes: 0 additions & 3 deletions docs/api/zilliqa/getblockchaininfo.doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ blockchain,info,get

Returns the current network statistics for the specified network. See [https://chainlist.org/?search=zilliqa&testnets=true](https://chainlist.org/?search=zilliqa&testnets=true) for details of deployed chains.

!!! note

`CHAIN_ID` from `2` to `9` are reserved for Zilliqa Core use.

# Curl

Expand Down
2 changes: 1 addition & 1 deletion eth-trie.rs/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait DB: Send + Sync {
pub struct MemoryDB {
// If "light" is true, the data is deleted from the database at the time of submission.
light: bool,
storage: Arc<RwLock<HashMap<Vec<u8>, Vec<u8>>>>,
pub storage: Arc<RwLock<HashMap<Vec<u8>, Vec<u8>>>>,
}

impl MemoryDB {
Expand Down
4 changes: 4 additions & 0 deletions infra/config_docker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ bootstrap_address = [
p2p_port = 5643

[[nodes]]
api_servers = [
{ port = 4201, enabled_apis = [ "admin", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa" ] },
]

# These (public key, peerId, stake, rewardAddress) tuples correspond to the private keys of all four nodes in `docker-compose.yaml`.
consensus.genesis_deposits = [
[
Expand Down
2 changes: 0 additions & 2 deletions infra/config_rpc_disabled.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ consensus.minimum_stake = "10_000_000_000_000_000_000_000_000"
# Gas parameters
consensus.eth_block_gas_limit = 84000000
consensus.gas_price = "4_761_904_800_000"

disable_rpc=true
23 changes: 19 additions & 4 deletions scripts/zilliqa_api_comparator/config_mainnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"urls": {
"ZQ2": "http://34.124.218.159:4201/",
"ZQ2": "https://api.zq2-protomainnet.zilliqa.com",
"ZQ1": "http://34.124.185.137:4201/"
},
"headers": {
Expand All @@ -15,7 +15,8 @@
"zil1ad7krn8lkvm2g40eyu0f0er96t54je0ka7yldp",
"zil1jj9gmttszflvnze4jg6nd7d4vau4akd0xjwpkj",
"zil1gy44tg8tcyqplyc2h2xuzpcz9gazhfyyn8qsxf",
"zil1ascnfxmlzl4z3l6ecavxcae5hc37gdzr23enz0"
"zil1ascnfxmlzl4z3l6ecavxcae5hc37gdzr23enz0",
"zil1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq9yf6pz"
]
},
"eth_getBalance": {
Expand All @@ -39,6 +40,10 @@
[
"0xec31349b7f17ea28ff59c7586c7734be23e43443",
"latest"
],
[
"0x0000000000000000000000000000000000000000",
"latest"
]
]
}
Expand All @@ -53,7 +58,9 @@
"0xc504cbb9a8fecb52d6da9f23c236e72c96d20e368c221943b6090ab92581b911",
"e7bb4c68d06e784ce9c358212f532825cabd5d9549d080d70f63fcef6035de8e",
"0x4964bf50c8f598f6deedaed6c34cc5d739f8a9a8aecf8eb548206af8594e6c89",
"b95dd8837550bfdbcbb983a2860a2d0cd3eaad7a8902db51352ac8c178486ccf"
"b95dd8837550bfdbcbb983a2860a2d0cd3eaad7a8902db51352ac8c178486ccf",
"0x7b9808f32fc6ce4fa4d591a33d4d4346f30dd1c7c76c280502f3df3431d18c5f",
"0x165779aad8d325db02a4f2ef0aaedc177c9b659f9de881490551d8a56a715046"
]
},
"eth_call": {
Expand Down Expand Up @@ -194,6 +201,12 @@
]
]
},
"GetTxnBodiesForTxBlock": {
"params": [
"3277414",
"3277415"
]
},
"GetTxBlock": {
"params": [
"3277414",
Expand All @@ -214,7 +227,9 @@
},
"DSBlockListing": {
"params": [
[1]
[
1
]
]
},
"GetCurrentDSEpoch": {
Expand Down
36 changes: 24 additions & 12 deletions scripts/zilliqa_api_comparator/validate_zq1_zq2.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def prompt_to_view_difference(mismatched_apis):
while True:
print("\nThe following APIs have mismatches:")
for i, api in enumerate(mismatched_apis):
print(f"{i + 1}. {api['method']} ({api['params'][0]})")
params = format_params(api["params"])
print(f"{i + 1}. {api['method']} ({params})")

choice = input("\nEnter the number of the API you'd like to view the difference for (or 0 to go back to method selection): ").strip()

Expand All @@ -310,7 +311,6 @@ def prompt_to_view_difference(mismatched_apis):
diff = compare_json_files(selected_api["local_file"], selected_api["zilliqa_file"])
display_key_differences(diff, selected_api["method"], selected_api["params"])

# Validate "y" or "n" input for viewing outputs
while True:
view_outputs = input(f"\nDo you want to view the outputs for {selected_api['method']} ({selected_api['params'][0]})? (y/n): ").strip().lower()
if view_outputs in {'y', 'n'}:
Expand All @@ -323,7 +323,6 @@ def prompt_to_view_difference(mismatched_apis):
print(f"\n ZQ1 Output ({selected_api['zilliqa_file']}):")
pretty_print_with_jq(selected_api["zilliqa_file"])

# Validate "y" or "n" input for continuing mismatches
while True:
more = input("\nDo you want to view another mismatch? (y/n): ").strip().lower()
if more in {'y', 'n'}:
Expand All @@ -345,14 +344,17 @@ def select_method_in_subset(subset):
print(f"\nAvailable methods in {subset.capitalize()}:")
for i, method in enumerate(methods, 1):
print(f"{i}. {method}")
print("0. Run all methods in this subset")
print("-1. Go back to Available API subsets")

method_choice = input(f"Select a method to run in {subset.capitalize()} (1-{len(methods)}) or press 0 to run all: ").strip()

if method_choice == "-1":
return None
elif method_choice == "0" or (method_choice.isdigit() and 1 <= int(method_choice) <= len(methods)):
method = methods[int(method_choice) - 1] if method_choice != "0" else None
return method
return None # User wants to go back to subset selection
elif method_choice == "0":
return "ALL" # New option to run all methods in the subset
elif method_choice.isdigit() and 1 <= int(method_choice) <= len(methods):
return methods[int(method_choice) - 1] # Return the selected method
else:
print(f"Invalid choice. Please enter a valid number (-1, 0-{len(methods)}).")

Expand Down Expand Up @@ -392,7 +394,9 @@ def main():
if method is None:
break

config, api_calls = load_config(subset=subset, method=method)
# Load configuration and API calls
config, api_calls = load_config(subset=subset, method=None if method == "ALL" else method)

headers = config["headers"]
results = []
mismatched_apis = []
Expand All @@ -402,25 +406,31 @@ def main():
params = api_call["params"]
output_file_prefix = api_call["output_file_prefix"]

local_file = f"{output_file_prefix}_ZQ2.json"
print(f"Making {method} API call to ZQ2 API - {config['urls']['ZQ2']} with param {params[0]}")
# Truncate parameters for logging
truncated_params = format_params(params)

# Make API calls to ZQ2
local_file = f"{output_file_prefix}_ZQ2.json"
print(f"Making {method} API call to ZQ2 API - {config['urls']['ZQ2']} with param {truncated_params}")
local_response_time, _ = make_api_call(
config["urls"]["ZQ2"], headers, method, params, f"{output_file_prefix}_ZQ2.txt", local_file
)

# Make API calls to ZQ1
zilliqa_file = f"{output_file_prefix}_ZQ1.json"
print(f"Making {method} API call to ZQ1 API - {config['urls']['ZQ1']} with param {params[0]}")
print(f"Making {method} API call to ZQ1 API - {config['urls']['ZQ1']} with param {truncated_params}")
zilliqa_response_time, _ = make_api_call(
config["urls"]["ZQ1"], headers, method, params, f"{output_file_prefix}_ZQ1.txt", zilliqa_file
)

# Compare results
diff = compare_json_files(local_file, zilliqa_file)
success = not bool(diff)
local_time_str, zilliqa_time_str = format_time(local_response_time, zilliqa_response_time)

# Append results
results.append([
f"{method} ({format_params(params)})",
f"{method} ({truncated_params})",
config["urls"]["ZQ2"],
config["urls"]["ZQ1"],
local_time_str,
Expand All @@ -438,9 +448,11 @@ def main():
"zilliqa_file": zilliqa_file
})

# Print results in a table
print("\nResults:")
print(tabulate(results, headers=["API Method", "ZQ2 URL", "ZQ1 URL", "ZQ2 Time", "ZQ1 Time", "Status", "ZQ2 File", "ZQ1 File"]))
prompt_to_view_difference(mismatched_apis)


if __name__ == "__main__":
main()
Loading

0 comments on commit 82d6e71

Please sign in to comment.