diff --git a/.gitignore b/.gitignore index 9765f8d0c7..3fafab658f 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,8 @@ starknet-e2e-test/contracts/build # vscode settings .vscode/settings.json +# script files +output_deoxys.json +output_pathfinder.json + tmp/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c18579816..51a1483d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ git # Madara Changelog ## Next release +- feat(script): added CI scripts for starting Deoxys and comparing JSON RPC + calls - perf(verify_l2): parallelized l2 state root update - perf(state_commitment): parallelized state commitment hash computations - fix(L1): fix l1 thread with battle tested implementation + removed l1-l2 diff --git a/Cargo.toml b/Cargo.toml index 17bdaf323d..7b2e7e3f93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -294,7 +294,7 @@ cairo-lang-utils = { git = "https://github.com/keep-starknet-strange/cairo.git", ] } # Ethers: using the same versions as in Anvil -ethers = { git = "https://github.com/gakonst/ethers-rs"} +ethers = { git = "https://github.com/gakonst/ethers-rs" } # Zaun starknet-core-contract-client = { git = "https://github.com/keep-starknet-strange/zaun" } diff --git a/crates/client/db/Cargo.toml b/crates/client/db/Cargo.toml index 4afd997f16..259b96404d 100644 --- a/crates/client/db/Cargo.toml +++ b/crates/client/db/Cargo.toml @@ -16,7 +16,9 @@ repository = "https://github.com/keep-starknet-strange/madara" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +bonsai-trie = { workspace = true } ethers = { workspace = true } +kvdb = "0.13.0" kvdb-rocksdb = { version = "0.19.0", optional = true } log = { workspace = true, default-features = true } parity-db = { version = "0.4.12", optional = true } @@ -32,8 +34,6 @@ starknet_api = { workspace = true, default-features = true, features = [ ] } thiserror = { workspace = true } uuid = "1.4.1" -bonsai-trie = { workspace = true } -kvdb = "0.13.0" [features] default = ["kvdb-rocksdb", "parity-db"] diff --git a/crates/client/deoxys/Cargo.toml b/crates/client/deoxys/Cargo.toml index de23a0951c..748fa11511 100644 --- a/crates/client/deoxys/Cargo.toml +++ b/crates/client/deoxys/Cargo.toml @@ -18,16 +18,17 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] anyhow = "1.0.75" +ethers = { workspace = true } lazy_static = "1.4.0" reqwest = "0.11" serde_json = "1" tokio-tungstenite = "0.20.1" -ethers = { workspace = true } blockifier = { workspace = true, default-features = false, features = [ "testing", ] } +crossbeam-skiplist = { workspace = true } env_logger = "0.10.0" futures = { workspace = true, default-features = true } hex = "0.4" @@ -35,14 +36,13 @@ indexmap = { workspace = true } itertools = { workspace = true } log = { version = "0.4.14" } mockito = { workspace = true } +primitive-types = { version = "0.12.2" } rand = { version = "0.8.5" } -primitive-types = { version = "0.12.2"} rodio = { version = "0.17", optional = true } serde = { workspace = true, default-features = true } tokio = { workspace = true, features = ["macros", "parking_lot", "test-util"] } url = { workspace = true } validator = { workspace = true, features = ["derive"] } -crossbeam-skiplist ={ workspace = true } madara-runtime = { workspace = true } parity-scale-codec = { workspace = true, features = ["derive"] } @@ -60,7 +60,10 @@ sc-service = { workspace = true } sp-core = { workspace = true, features = ["std"] } sp-runtime = { workspace = true } +bitvec = "1.0.1" +bonsai-trie = { workspace = true } mc-commitment-state-diff = { workspace = true } +mc-db = { workspace = true } mc-rpc-core = { workspace = true } mc-storage = { workspace = true } mp-block = { workspace = true } @@ -70,13 +73,10 @@ mp-felt = { workspace = true } mp-hashers = { workspace = true } mp-storage = { workspace = true, default-features = true } mp-transactions = { workspace = true, features = ["client"] } -mc-db = { workspace = true } -bonsai-trie = { workspace = true } starknet-types-core = { workspace = true, default-features = false, features = [ - "hash", - "parity-scale-codec", + "hash", + "parity-scale-codec", ] } -bitvec = "1.0.1" [dev-dependencies] # test_utils = { path = "./test_utils" } diff --git a/crates/client/rpc/Cargo.toml b/crates/client/rpc/Cargo.toml index 64a77c80d7..b3476875d0 100644 --- a/crates/client/rpc/Cargo.toml +++ b/crates/client/rpc/Cargo.toml @@ -12,8 +12,8 @@ publish = false repository = "https://github.com/keep-starknet-strange/madara" version.workspace = true - [package.metadata.docs.rs] - targets = ["x86_64-unknown-linux-gnu"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] # Madara utils diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index d14692da2c..c8e00140ef 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -14,8 +14,8 @@ publish = false repository = "https://github.com/kasarlabs/deoxys" version.workspace = true - [package.metadata.docs.rs] - targets = ["x86_64-unknown-linux-gnu"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [[bin]] name = "deoxys" diff --git a/crates/pallets/starknet/Cargo.toml b/crates/pallets/starknet/Cargo.toml index f8a2a2ce03..19285fdc00 100644 --- a/crates/pallets/starknet/Cargo.toml +++ b/crates/pallets/starknet/Cargo.toml @@ -9,8 +9,8 @@ publish = false repository = "https://github.com/keep-starknet-strange/madara" version.workspace = true - [package.metadata.docs.rs] - targets = ["x86_64-unknown-linux-gnu"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] # Madara primitives diff --git a/crates/primitives/block/Cargo.toml b/crates/primitives/block/Cargo.toml index f4b3c6ef4a..c95461184c 100644 --- a/crates/primitives/block/Cargo.toml +++ b/crates/primitives/block/Cargo.toml @@ -7,8 +7,8 @@ name = "mp-block" repository = { workspace = true } version.workspace = true - [package.metadata.docs.rs] - targets = ["x86_64-unknown-linux-gnu"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] blockifier = { workspace = true } diff --git a/crates/primitives/contract/Cargo.toml b/crates/primitives/contract/Cargo.toml index f84763d25a..98c1d2d041 100644 --- a/crates/primitives/contract/Cargo.toml +++ b/crates/primitives/contract/Cargo.toml @@ -7,15 +7,15 @@ name = "mp-contract" repository.workspace = true version.workspace = true - [package.metadata.docs.rs] - targets = ["x86_64-unknown-linux-gnu"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] blockifier = { workspace = true } mp-fee = { workspace = true, features = [ - "parity-scale-codec", - "scale-info", - "serde", + "parity-scale-codec", + "scale-info", + "serde", ] } mp-felt = { workspace = true } mp-hashers = { workspace = true } @@ -30,38 +30,38 @@ starknet_api = { workspace = true } anyhow = { workspace = true, optional = true } mp-convert = { workspace = true, optional = true } parity-scale-codec = { workspace = true, features = [ - "derive", + "derive", ], optional = true } scale-info = { workspace = true, features = ["derive"], optional = true } [features] default = ["std"] parity-scale-codec = [ - "blockifier/parity-scale-codec", - "dep:parity-scale-codec", - "mp-fee/parity-scale-codec", - "mp-felt/parity-scale-codec", - "mp-transactions/parity-scale-codec", - "starknet_api/parity-scale-codec", + "blockifier/parity-scale-codec", + "dep:parity-scale-codec", + "mp-fee/parity-scale-codec", + "mp-felt/parity-scale-codec", + "mp-transactions/parity-scale-codec", + "starknet_api/parity-scale-codec", ] scale-info = [ - "blockifier/scale-info", - "dep:scale-info", - "mp-felt/scale-info", - "starknet_api/scale-info", + "blockifier/scale-info", + "dep:scale-info", + "mp-felt/scale-info", + "starknet_api/scale-info", ] std = [ - "blockifier/std", - "mp-fee/std", - "mp-felt/std", - "mp-hashers/std", - "mp-transactions/std", - "serde/std", - "sp-core/std", - "starknet_api/std", - # Optionals - "anyhow/std", - "mp-convert/std", - "parity-scale-codec?/std", - "scale-info?/std", + "blockifier/std", + "mp-fee/std", + "mp-felt/std", + "mp-hashers/std", + "mp-transactions/std", + "serde/std", + "sp-core/std", + "starknet_api/std", + # Optionals + "anyhow/std", + "mp-convert/std", + "parity-scale-codec?/std", + "scale-info?/std", ] diff --git a/crates/primitives/felt/Cargo.toml b/crates/primitives/felt/Cargo.toml index ce8e02f3c5..29048607ed 100644 --- a/crates/primitives/felt/Cargo.toml +++ b/crates/primitives/felt/Cargo.toml @@ -15,8 +15,8 @@ cairo-vm = { workspace = true } sp-core = { workspace = true } starknet-core = { workspace = true } starknet-ff = { workspace = true } -starknet_api = { workspace = true } starknet-types-core = { workspace = true } +starknet_api = { workspace = true } thiserror-no-std = { workspace = true } # Optional diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index 3776bdb952..00febdcf17 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -12,8 +12,8 @@ publish = false repository = "https://github.com/keep-starknet-strange/madara" version.workspace = true - [package.metadata.docs.rs] - targets = ["x86_64-unknown-linux-gnu"] +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] parity-scale-codec = { workspace = true, features = [] } diff --git a/deoxys b/deoxys new file mode 100755 index 0000000000..bc653b453d --- /dev/null +++ b/deoxys @@ -0,0 +1,85 @@ +#!/bin/bash + +if [ "$#" -lt 1 ]; then + echo "Usage: $0 [start|reset|reboot|lint|help] [KEY for start/reboot]" + exit 1 +fi + +start_deoxys(){ + local key=$1 + echo "๐Ÿš€ start deoxys..." + cargo run \ + --release \ + -- \ + --deoxys \ + --rpc-port 9944 \ + --network main \ + --rpc-cors all \ + --pruning archive \ + --cache \ + --l1-endpoint="$key" +} + +clear_db(){ + echo "๐Ÿ› ๏ธ clear end rebuild DB..." + read -p "Are you sure? [y/N] " -n 1 -r + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + exit 1 + fi + rm -rf /tmp/deoxys +} + +lint(){ + echo "๐Ÿ“ Running linters..." + read -p "Are you sure? [y/N] " -n 1 -r + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + exit 1 + fi + npx @taplo/cli@0.5.2 fmt --config ./taplo/taplo.toml + npx prettier --write . +} + +ACTION=$1 + +case $ACTION in + start) + if [ "$#" -ne 2 ]; then + echo "Usage for start: $0 start [KEY]" + exit 1 + fi + start_deoxys "$2" + ;; + reset) + if [ "$#" -ne 1 ]; then + echo "Usage for reset: $0 reset" + exit 1 + fi + clear_db + ;; + reboot) + if [ "$#" -ne 2 ]; then + echo "Usage for reboot: $0 reboot [KEY]" + exit 1 + fi + clear_db + start_deoxys "$2" + ;; + lint) + lint + ;; + help) + echo "Usage: $0 [start|reset|reboot|lint|help] [KEY for start/reboot]" + echo "start: start deoxys with KEY" + echo "reset: clear and rebuild DB" + echo "reboot: clear and rebuild DB, then start deoxys with KEY" + echo "lint: run CI linter on project" + ;; + *) + echo "Invalid argument: $ACTION" + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/rpc_cmp b/rpc_cmp new file mode 100755 index 0000000000..58453a255f --- /dev/null +++ b/rpc_cmp @@ -0,0 +1,192 @@ +#!/bin/bash + +help() { + echo "Usage: [--deoxys=\"http://127.0.0.1:9944\"] [--pathfinder...] command args..." +} + +# ================= # +# PARSING ARGUMENTS # +# ================= # + +if [ $# -lt 2 ]; then + help + exit 1 +fi + +OPTIONS=$(getopt -o '' -l deoxys:,pathfinder: -- "$@") +if [ $? != 0 ]; then + help + exit 1 +fi + +eval set -- "$OPTIONS" + +PROVIDER_DEOXYS="http://127.0.0.1:9944" +PROVIDER_PATHFINDER="" + +while true; do + case "$1" in + --deoxys) + PROVIDER_DEOXYS="$2" + shift 2 + ;; + --pathfinder) + PROVIDER_PATHFINDER="$2" + shift 2 + ;; + --) + shift 1 + break + ;; + *) + break + ;; + esac +done + +# ================= # +# RPC METHODS # +# ================= # + +rpc_call(){ + local provider=$1 + local method=$2 + local params=$3 + + curl -s \ + --request POST \ + --url "$provider" \ + --header 'accept: application/json' \ + --header 'content-type: application/json' \ + --data " + { + \"id\": 1, + \"jsonrpc\": \"2.0\", + \"method\": \"$method\", + \"params\": $params + } + " | jq --sort-keys +} + +get_class(){ + local provider=$1 + local class_hash=$2 + local output=$3 + + rpc_call "$provider" "starknet_getClass" "[ + \"latest\", + \"$class_hash\" + ]" | jq 'del(.result.program)' > "$output" +} + +get_class_at(){ + local provider=$1 + local contract_address=$2 + local output=$3 + + rpc_call "$provider" "starknet_getClassAt" "[ + \"latest\", + \"$contract_address\" + ]" | jq 'del(.result.program)' > "$output" +} + +get_class_hash_at(){ + local provider=$1 + local contract_address=$2 + local output=$3 + + rpc_call "$provider" "starknet_getClassHashAt" "[ + \"latest\", + \"$contract_address\" + ]" > "$output" +} + +get_storage_at(){ + local provider=$1 + local contract_addr=$2 + local key=$3 + local output=$4 + + rpc_call "$provider" "starknet_getStorageAt" "[ + \"$contract_addr\", + \"$key\", + \"latest\" + ]" > "$output" +} + +get_block_with_tx(){ + local provider=$1 + local block_number=$2 + local output=$3 + + rpc_call "$provider" "starknet_getBlockWithTxs" "[ + { + \"block_number\": $block_number + } + ]" > "$output" +} + +# ================= # +# PROGRAM # +# ================= # + +OUTPUT_DEOXYS="output_deoxys.json" +OUTPUT_PATHFINDER="output_pathfinder.json" + +COMMAND=$1 +shift 1 + +validate_args(){ + local arg_count=$1 + local target=$2 + + if [ $arg_count -ne $target ]; then + echo "โŒ Invalid RPC argument count" + exit 1 + fi +} + +case $COMMAND in + getClass) + echo "๐Ÿงช Testing starknet_getClass" + validate_args $# 1 + get_class "$PROVIDER_DEOXYS" "$1" "$OUTPUT_DEOXYS" + get_class "$PROVIDER_PATHFINDER" "$1" "$OUTPUT_PATHFINDER" + ;; + getClassAt) + echo "๐Ÿงช Testing starknet_getClassAt" + validate_args $# 1 + get_class_at "$PROVIDER_DEOXYS" "$1" "$OUTPUT_DEOXYS" + get_class_at "$PROVIDER_PATHFINDER" "$1" "$OUTPUT_PATHFINDER" + ;; + getClassHashAt) + echo "๐Ÿงช Testing starknet_getClassHashAt" + validate_args $# 2 + get_class_hash_at "$PROVIDER_DEOXYS" "$1" "$2" "$OUTPUT_DEOXYS" + get_class_hash_at "$PROVIDER_PATHFINDER" "$1" "$2" "$OUTPUT_PATHFINDER" + ;; + getBlockWithTxs) + echo "๐Ÿงช Testing starknet_getBlockWithTxs" + validate_args $# 2 + get_block_with_tx "$PROVIDER_DEOXYS" "$1" "$OUTPUT_DEOXYS" + get_block_with_tx "$PROVIDER_PATHFINDER" "$1" "$OUTPUT_PATHFINDER" + ;; + *) + echo "Invalid argument: $COMMAND" + exit 1 + ;; +esac + +diff output_deoxys.json output_pathfinder.json + +if [ $? -eq 0 ]; then + if [ -s "$OUTPUT_DEOXYS" ]; then + echo "โœ… RPC results match" + exit 0 + fi + echo "โŒ Ouput files are empty" + exit 1 +else + echo "โŒ RPC results don't match" + exit 1 +fi \ No newline at end of file