Skip to content

Commit

Permalink
feat(ckerc20): Use EVM-RPC canister to call eth_getBlockByNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorydemay committed Jul 1, 2024
1 parent 995fadb commit 1978a07
Show file tree
Hide file tree
Showing 20 changed files with 886 additions and 187 deletions.
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,16 @@ http_file(
url = "https://download.dfinity.systems/ic/300dc603a92b5f70dae79229793c902f346af3cc/canisters/ic-icrc1-ledger-u256.wasm.gz",
)

# XC artifacts for testing

# EVM RPC canister

http_file(
name = "evm_rpc.wasm.gz",
sha256 = "ccce0d8e3210db42ff12b03360c20246855ad8529da0f844faa343bf8b393529",
url = "https://github.com/internet-computer-protocol/evm-rpc-canister/releases/download/release-2024-05-23/evm_rpc.wasm.gz",
)

# Haskell toolchain for spec_compliance tests

http_archive(
Expand Down
87 changes: 49 additions & 38 deletions rs/ethereum/cketh/minter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rust_library(
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/crypto/ecdsa_secp256k1",
"//rs/crypto/sha3",
"//rs/ethereum/evm-rpc-client",
"//rs/ethereum/types",
"//rs/phantom_newtype",
"//rs/types/management_canister_types",
Expand Down Expand Up @@ -173,44 +174,54 @@ rust_binary(
],
)

rust_ic_test_suite(
name = "integration_tests",
srcs = glob(["tests/**/*.rs"]),
data = [
":cketh_minter_debug.wasm",
"//rs/ethereum/ledger-suite-orchestrator:ledger_suite_orchestrator_canister.wasm",
"//rs/rosetta-api/icrc1/archive:archive_canister_u256.wasm.gz",
"//rs/rosetta-api/icrc1/index-ng:index_ng_canister_u256.wasm.gz",
"//rs/rosetta-api/icrc1/ledger:ledger_canister_u256.wasm.gz",
],
env = {
"CARGO_MANIFEST_DIR": "rs/ethereum/cketh/minter",
"CKETH_MINTER_WASM_PATH": "$(rootpath :cketh_minter_debug.wasm)",
"LEDGER_SUITE_ORCHESTRATOR_WASM_PATH": "$(rootpath //rs/ethereum/ledger-suite-orchestrator:ledger_suite_orchestrator_canister.wasm)",
"LEDGER_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/ledger:ledger_canister_u256.wasm.gz)",
"INDEX_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/index-ng:index_ng_canister_u256.wasm.gz)",
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/archive:archive_canister_u256.wasm.gz)",
},
proc_macro_deps = [],
deps = [
":minter",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/ethereum/cketh/test_utils",
"//rs/ethereum/ledger-suite-orchestrator/test_utils",
"//rs/ethereum/types",
"//rs/state_machine_tests",
"//rs/types/base_types",
"@crate_index//:assert_matches",
"@crate_index//:candid",
"@crate_index//:ethers-core",
"@crate_index//:hex",
"@crate_index//:num-bigint",
"@crate_index//:num-traits",
"@crate_index//:serde",
"@crate_index//:serde_bytes",
"@crate_index//:serde_json",
],
)
[
rust_ic_test_suite(
name = "integration_tests" + name_suffix,
srcs = glob(["tests/**/*.rs"]),
data = [
":cketh_minter_debug.wasm",
"//rs/ethereum/ledger-suite-orchestrator:ledger_suite_orchestrator_canister.wasm",
"//rs/rosetta-api/icrc1/archive:archive_canister_u256.wasm.gz",
"//rs/rosetta-api/icrc1/index-ng:index_ng_canister_u256.wasm.gz",
"//rs/rosetta-api/icrc1/ledger:ledger_canister_u256.wasm.gz",
] + extra_data,
env = {
"CARGO_MANIFEST_DIR": "rs/ethereum/cketh/minter",
"CKETH_MINTER_WASM_PATH": "$(rootpath :cketh_minter_debug.wasm)",
"LEDGER_SUITE_ORCHESTRATOR_WASM_PATH": "$(rootpath //rs/ethereum/ledger-suite-orchestrator:ledger_suite_orchestrator_canister.wasm)",
"LEDGER_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/ledger:ledger_canister_u256.wasm.gz)",
"INDEX_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/index-ng:index_ng_canister_u256.wasm.gz)",
"LEDGER_ARCHIVE_NODE_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icrc1/archive:archive_canister_u256.wasm.gz)",
} | extra_env,
proc_macro_deps = [],
deps = [
":minter",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/ethereum/cketh/test_utils",
"//rs/ethereum/ledger-suite-orchestrator/test_utils",
"//rs/ethereum/types",
"//rs/state_machine_tests",
"//rs/types/base_types",
"@crate_index//:assert_matches",
"@crate_index//:candid",
"@crate_index//:ethers-core",
"@crate_index//:hex",
"@crate_index//:num-bigint",
"@crate_index//:num-traits",
"@crate_index//:serde",
"@crate_index//:serde_bytes",
"@crate_index//:serde_json",
],
)
for (name_suffix, extra_data, extra_env) in [
("", [], {}),
(
"_evm_rpc",
["@evm_rpc.wasm.gz//file"],
{"EVM_RPC_CANISTER_WASM_PATH": "$(rootpath @evm_rpc.wasm.gz//file)"},
),
]
]

closure_js_library(
name = "principal_to_bytes",
Expand Down
1 change: 1 addition & 0 deletions rs/ethereum/cketh/minter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ path = "bin/principal_to_hex.rs"
askama = { workspace = true }
candid = { workspace = true }
ethnum = { workspace = true }
evm-rpc-client = { path = "../../evm-rpc-client" }
futures = { workspace = true }
hex = { workspace = true }
hex-literal = "0.4.1"
Expand Down
18 changes: 18 additions & 0 deletions rs/ethereum/cketh/minter/src/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::numeric::{BlockNumber, LogIndex, TransactionCount, Wei, WeiPerGas};
use crate::state::{mutate_state, State};
use candid::{candid_method, CandidType, Principal};
use ethnum;
use evm_rpc_client::types::candid::HttpOutcallError as EvmHttpOutcallError;
use ic_canister_log::log;
use ic_cdk::api::call::{call_with_payment128, RejectionCode};
use ic_cdk::api::management_canister::http_request::{
Expand Down Expand Up @@ -558,6 +559,23 @@ pub enum HttpOutcallError {
},
}

impl From<EvmHttpOutcallError> for HttpOutcallError {
fn from(value: EvmHttpOutcallError) -> Self {
match value {
EvmHttpOutcallError::IcError { code, message } => Self::IcError { code, message },
EvmHttpOutcallError::InvalidHttpJsonRpcResponse {
status,
body,
parsing_error,
} => Self::InvalidHttpJsonRpcResponse {
status,
body,
parsing_error,
},
}
}
}

impl HttpOutcallError {
pub fn is_response_too_large(&self) -> bool {
match self {
Expand Down
Loading

0 comments on commit 1978a07

Please sign in to comment.