From ec054bceb10bcd918176f857f940d27bc871cd28 Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Mon, 18 Sep 2023 20:49:19 +0200 Subject: [PATCH] refactor: move common utilities into indexer-common crate --- Cargo.lock | 675 ++++++++++-------- Cargo.toml | 3 +- common/Cargo.toml | 32 + .../src/allocations/mod.rs | 11 +- .../src/allocations/monitor.rs | 23 +- common/src/attestations/mod.rs | 188 +++++ .../src/attestations/signer.rs | 32 +- .../src/attestations/signers.rs | 37 +- common/src/lib.rs | 23 + .../src/network_subgraph/mod.rs | 49 +- .../src/signature_verification.rs | 13 +- common/src/test_vectors.rs | 225 ++++++ {service/src/common => common/src}/types.rs | 25 +- native/Cargo.toml | 26 - native/src/lib.rs | 13 - service/Cargo.toml | 3 +- service/src/common/indexer_management/mod.rs | 7 +- service/src/common/mod.rs | 3 - service/src/escrow_monitor.rs | 11 +- service/src/main.rs | 16 +- service/src/query_processor.rs | 14 +- service/src/server/mod.rs | 7 +- service/src/server/routes/network.rs | 22 +- service/src/server/routes/subgraphs.rs | 4 +- service/src/tap_manager.rs | 13 +- service/src/test_vectors.rs | 223 +----- service/src/util.rs | 25 - 27 files changed, 980 insertions(+), 743 deletions(-) create mode 100644 common/Cargo.toml rename service/src/common/allocation.rs => common/src/allocations/mod.rs (97%) rename service/src/allocation_monitor.rs => common/src/allocations/monitor.rs (95%) create mode 100644 common/src/attestations/mod.rs rename native/src/attestation.rs => common/src/attestations/signer.rs (74%) rename service/src/attestation_signers.rs => common/src/attestations/signers.rs (84%) create mode 100644 common/src/lib.rs rename service/src/common/network_subgraph.rs => common/src/network_subgraph/mod.rs (79%) rename {native => common}/src/signature_verification.rs (81%) create mode 100644 common/src/test_vectors.rs rename {service/src/common => common/src}/types.rs (90%) delete mode 100644 native/Cargo.toml delete mode 100644 native/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 12726f4a..36c10a87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,7 +101,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f938f00332d63a5b0ac687bd6f46d03884638948921d9f8b50c59563d421ae25" dependencies = [ - "arrayvec 0.7.2", + "arrayvec", "bytes", "smol_str", ] @@ -199,9 +199,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.71" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "arc-swap" @@ -210,16 +210,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" [[package]] -name = "arrayref" -version = "0.3.7" +name = "array-init" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +checksum = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" +dependencies = [ + "nodrop", +] [[package]] -name = "arrayvec" -version = "0.5.2" +name = "arrayref" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" @@ -382,9 +385,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.72" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", @@ -607,9 +610,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" dependencies = [ "serde", ] @@ -723,12 +726,6 @@ version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" -[[package]] -name = "byte-slice-cast" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" - [[package]] name = "byte-slice-cast" version = "1.2.2" @@ -819,9 +816,9 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.15.4" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +checksum = "e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592" dependencies = [ "camino", "cargo-platform", @@ -938,7 +935,7 @@ dependencies = [ "k256", "lazy_static", "serde", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", ] @@ -955,7 +952,7 @@ dependencies = [ "once_cell", "pbkdf2 0.12.1", "rand 0.8.5", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", ] @@ -974,7 +971,7 @@ dependencies = [ "ripemd", "serde", "serde_derive", - "sha2 0.10.6", + "sha2 0.10.7", "sha3", "thiserror", ] @@ -1383,7 +1380,16 @@ version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" dependencies = [ - "dirs-sys", + "dirs-sys 0.3.7", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys 0.4.1", ] [[package]] @@ -1407,6 +1413,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1450,7 +1468,7 @@ version = "0.4.0" source = "git+https://github.com/graphprotocol/eip-712-derive#0ce4f89c98d0b56d9d67c16b732425e7f2fd14b3" dependencies = [ "clear_on_drop", - "keccak-hash 0.10.0", + "keccak-hash", "lazy_static", "libsecp256k1", ] @@ -1503,11 +1521,11 @@ dependencies = [ [[package]] name = "enr" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf56acd72bb22d2824e66ae8e9e5ada4d0de17a69c7fd35569dde2ada8ec9116" +checksum = "0be7b2ac146c1f99fe245c02d16af0696450d8e06c135db75e10eeb9e642c20d" dependencies = [ - "base64 0.13.1", + "base64 0.21.2", "bytes", "hex", "k256", @@ -1515,6 +1533,7 @@ dependencies = [ "rand 0.8.5", "rlp", "serde", + "serde-hex", "sha3", "zeroize", ] @@ -1586,7 +1605,7 @@ dependencies = [ "scrypt", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.7", "sha3", "thiserror", "uuid 0.8.2", @@ -1606,7 +1625,7 @@ dependencies = [ "serde_json", "sha3", "thiserror", - "uint 0.9.5", + "uint", ] [[package]] @@ -1616,8 +1635,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" dependencies = [ "crunchy", - "fixed-hash 0.8.0", - "impl-codec 0.6.0", + "fixed-hash", + "impl-codec", "impl-rlp", "impl-serde", "scale-info", @@ -1631,20 +1650,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" dependencies = [ "ethbloom", - "fixed-hash 0.8.0", - "impl-codec 0.6.0", + "fixed-hash", + "impl-codec", "impl-rlp", "impl-serde", - "primitive-types 0.12.1", + "primitive-types", "scale-info", - "uint 0.9.5", + "uint", ] [[package]] name = "ethers" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a58ce802c65cf3d0756dee5a61094a92cde53c1583b246e9ee5b37226c7fc15" +checksum = "1ad13497f6e0a24292fc7b408e30d22fe9dc262da1f40d7b542c3a44e7fc0476" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1658,9 +1677,9 @@ dependencies = [ [[package]] name = "ethers-addressbook" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b856b7b8ff5c961093cb8efe151fbcce724b451941ce20781de11a531ccd578" +checksum = "c6e9e8acd0ed348403cc73a670c24daba3226c40b98dc1a41903766b3ab6240a" dependencies = [ "ethers-core", "once_cell", @@ -1670,16 +1689,16 @@ dependencies = [ [[package]] name = "ethers-contract" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e066a0d9cfc70c454672bf16bb433b0243427420076dc5b2f49c448fb5a10628" +checksum = "d79269278125006bb0552349c03593ffa9702112ca88bc7046cc669f148fb47c" dependencies = [ + "const-hex", "ethers-contract-abigen", "ethers-contract-derive", "ethers-core", "ethers-providers", "futures-util", - "hex", "once_cell", "pin-project", "serde", @@ -1689,16 +1708,16 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c113e3e86b6bc16d98484b2c3bb2d01d6fed9f489fe2e592e5cc87c3024d616b" +checksum = "ce95a43c939b2e4e2f3191c5ad4a1f279780b8a39139c9905b43a7433531e2ab" dependencies = [ "Inflector", + "const-hex", "dunce", "ethers-core", "ethers-etherscan", "eyre", - "hex", "prettyplease", "proc-macro2", "quote", @@ -1713,14 +1732,14 @@ dependencies = [ [[package]] name = "ethers-contract-derive" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3fb5adee25701c79ec58fcf2c63594cd8829bc9ad6037ff862d5a111101ed2" +checksum = "8e9ce44906fc871b3ee8c69a695ca7ec7f70e50cb379c9b9cb5e532269e492f6" dependencies = [ "Inflector", + "const-hex", "ethers-contract-abigen", "ethers-core", - "hex", "proc-macro2", "quote", "serde_json", @@ -1729,18 +1748,18 @@ dependencies = [ [[package]] name = "ethers-core" -version = "2.0.8" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ca2514feb98918a0a31de7e1983c29f2267ebf61b2dc5d4294f91e5b866623" +checksum = "c0a17f0708692024db9956b31d7a20163607d2745953f5ae8125ab368ba280ad" dependencies = [ - "arrayvec 0.7.2", + "arrayvec", "bytes", "cargo_metadata", "chrono", + "const-hex", "elliptic-curve", "ethabi", "generic-array", - "hex", "k256", "num_enum", "once_cell", @@ -1759,9 +1778,9 @@ dependencies = [ [[package]] name = "ethers-etherscan" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ebb401ba97c6f5af278c2c9936c4546cad75dec464b439ae6df249906f4caa" +checksum = "0e53451ea4a8128fbce33966da71132cf9e1040dcfd2a2084fd7733ada7b2045" dependencies = [ "ethers-core", "reqwest", @@ -1774,9 +1793,9 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740f4a773c19dd6d6a68c8c2e0996c096488d38997d524e21dc612c55da3bd24" +checksum = "473f1ccd0c793871bbc248729fa8df7e6d2981d6226e4343e3bbaa9281074d5d" dependencies = [ "async-trait", "auto_impl", @@ -1801,23 +1820,24 @@ dependencies = [ [[package]] name = "ethers-providers" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56b498fd2a6c019d023e43e83488cd1fb0721f299055975aa6bac8dbf1e95f2c" +checksum = "6838fa110e57d572336178b7c79e94ff88ef976306852d8cb87d9e5b1fc7c0b5" dependencies = [ "async-trait", "auto_impl", "base64 0.21.2", "bytes", + "const-hex", "enr", "ethers-core", "futures-core", "futures-timer", "futures-util", "hashers", - "hex", "http", "instant", + "jsonwebtoken", "once_cell", "pin-project", "reqwest", @@ -1825,7 +1845,7 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tokio-tungstenite 0.19.0", + "tokio-tungstenite 0.20.0", "tracing", "tracing-futures", "url", @@ -1837,34 +1857,35 @@ dependencies = [ [[package]] name = "ethers-signers" -version = "2.0.8" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4864d387456a9c09a1157fa10e1528b29d90f1d859443acf06a1b23365fb518c" +checksum = "5ea44bec930f12292866166f9ddbea6aa76304850e4d8dcd66dc492b43d00ff1" dependencies = [ "async-trait", "coins-bip32", "coins-bip39", + "const-hex", "elliptic-curve", "eth-keystore", "ethers-core", - "hex", "rand 0.8.5", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", "tracing", ] [[package]] name = "ethers-solc" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81c89f121595cf8959e746045bb8b25a6a38d72588561e1a3b7992fc213f674" +checksum = "de34e484e7ae3cab99fbfd013d6c5dc7f9013676a4e0e414d8b12e1213e8b3ba" dependencies = [ "cfg-if", + "const-hex", + "dirs", "dunce", "ethers-core", "glob", - "hex", "home", "md-5", "num_cpus", @@ -1919,6 +1940,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" + [[package]] name = "faux" version = "0.1.10" @@ -1958,27 +1985,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" -[[package]] -name = "fixed-hash" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" -dependencies = [ - "static_assertions", -] - -[[package]] -name = "fixed-hash" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" -dependencies = [ - "byteorder", - "rand 0.8.5", - "rustc-hex", - "static_assertions", -] - [[package]] name = "fixed-hash" version = "0.8.0" @@ -2042,9 +2048,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" dependencies = [ "percent-encoding", ] @@ -2130,7 +2136,7 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ - "fastrand", + "fastrand 1.9.0", "futures-core", "futures-io", "memchr", @@ -2388,15 +2394,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.1" @@ -2550,7 +2547,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -2614,30 +2611,21 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ "unicode-bidi", "unicode-normalization", ] -[[package]] -name = "impl-codec" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" -dependencies = [ - "parity-scale-codec 1.3.7", -] - [[package]] name = "impl-codec" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" dependencies = [ - "parity-scale-codec 3.5.0", + "parity-scale-codec", ] [[package]] @@ -2675,6 +2663,32 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +[[package]] +name = "indexer-common" +version = "0.1.0" +dependencies = [ + "alloy-primitives", + "anyhow", + "arc-swap", + "bs58 0.5.0", + "eip-712-derive", + "env_logger", + "ethereum-types", + "ethers", + "ethers-core", + "faux", + "keccak-hash", + "lazy_static", + "log", + "reqwest", + "secp256k1 0.27.0", + "serde", + "serde_json", + "test-log", + "tokio", + "wiremock", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -2745,7 +2759,7 @@ checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", - "rustix", + "rustix 0.37.19", "windows-sys 0.48.0", ] @@ -2791,6 +2805,20 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "jsonwebtoken" +version = "8.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" +dependencies = [ + "base64 0.21.2", + "pem", + "ring", + "serde", + "serde_json", + "simple_asn1", +] + [[package]] name = "k256" version = "0.13.1" @@ -2801,7 +2829,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.6", + "sha2 0.10.7", "signature", ] @@ -2814,31 +2842,21 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "keccak-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f58a51ef3df9398cf2434bea8d4eb61fb748d0feb1571f87388579a120a4c8f" -dependencies = [ - "primitive-types 0.7.3", - "tiny-keccak", -] - [[package]] name = "keccak-hash" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b286e6b663fb926e1eeb68528e69cb70ed46c6d65871a21b2215ae8154c6d3c" dependencies = [ - "primitive-types 0.12.1", + "primitive-types", "tiny-keccak", ] [[package]] name = "lalrpop" -version = "0.19.12" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" +checksum = "da4081d44f4611b66c6dd725e6de3169f9f63905421e8626fcb86b6a898998b8" dependencies = [ "ascii-canvas", "bit-set", @@ -2849,7 +2867,7 @@ dependencies = [ "lalrpop-util", "petgraph", "regex", - "regex-syntax 0.6.29", + "regex-syntax 0.7.5", "string_cache", "term", "tiny-keccak", @@ -2858,9 +2876,9 @@ dependencies = [ [[package]] name = "lalrpop-util" -version = "0.19.12" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" +checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d" [[package]] name = "lazy_static" @@ -2948,6 +2966,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "linux-raw-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" + [[package]] name = "lock_api" version = "0.4.9" @@ -2960,9 +2984,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.18" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "mach" @@ -2979,7 +3003,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -2988,6 +3012,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + [[package]] name = "md-5" version = "0.10.5" @@ -2999,9 +3029,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memoffset" @@ -3120,20 +3150,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "native" -version = "0.1.0" -dependencies = [ - "arc-swap", - "eip-712-derive", - "hex", - "keccak-hash 0.5.1", - "lazy_static", - "never", - "primitive-types 0.8.0", - "secp256k1", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -3152,18 +3168,18 @@ dependencies = [ "tempfile", ] -[[package]] -name = "never" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" - [[package]] name = "new_debug_unreachable" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + [[package]] name = "nom" version = "7.1.3" @@ -3208,7 +3224,7 @@ dependencies = [ "num-iter", "num-traits", "rand 0.8.5", - "smallvec", + "smallvec 1.10.0", "zeroize", ] @@ -3245,28 +3261,28 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.1", "libc", ] [[package]] name = "num_enum" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +checksum = "70bf6736f74634d299d00086f02986875b3c2d924781a6a2cb6c201e73da0ceb" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -3301,7 +3317,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" dependencies = [ - "arrayvec 0.7.2", + "arrayvec", "auto_impl", "bytes", "ethereum-types", @@ -3422,22 +3438,16 @@ dependencies = [ ] [[package]] -name = "overload" -version = "0.1.1" +name = "option-ext" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] -name = "parity-scale-codec" -version = "1.3.7" +name = "overload" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4b26b16c7687c3075982af47719e481815df30bc544f7a6690763a25ca16e9d" -dependencies = [ - "arrayvec 0.5.2", - "bitvec 0.17.4", - "byte-slice-cast 0.3.5", - "serde", -] +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parity-scale-codec" @@ -3445,9 +3455,9 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ddb756ca205bd108aee3c62c6d3c994e1df84a59b9d6d4a5ea42ee1fd5a9a28" dependencies = [ - "arrayvec 0.7.2", + "arrayvec", "bitvec 1.0.1", - "byte-slice-cast 1.2.2", + "byte-slice-cast", "impl-trait-for-tuples", "parity-scale-codec-derive", "serde", @@ -3490,7 +3500,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall 0.2.16", - "smallvec", + "smallvec 1.10.0", "windows-sys 0.45.0", ] @@ -3526,7 +3536,7 @@ dependencies = [ "digest 0.10.7", "hmac 0.12.1", "password-hash", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] @@ -3539,6 +3549,15 @@ dependencies = [ "hmac 0.12.1", ] +[[package]] +name = "pem" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +dependencies = [ + "base64 0.13.1", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -3550,9 +3569,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pest" @@ -3657,9 +3676,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -3731,39 +3750,18 @@ dependencies = [ "syn 2.0.28", ] -[[package]] -name = "primitive-types" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd39dcacf71411ba488570da7bbc89b717225e46478b30ba99b92db6b149809" -dependencies = [ - "fixed-hash 0.6.1", - "uint 0.8.5", -] - -[[package]] -name = "primitive-types" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3824ae2c5e27160113b9e029a10ec9e3f0237bad8029f69c7724393c9fdefd8" -dependencies = [ - "fixed-hash 0.7.0", - "impl-codec 0.4.2", - "uint 0.9.5", -] - [[package]] name = "primitive-types" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" dependencies = [ - "fixed-hash 0.8.0", - "impl-codec 0.6.0", + "fixed-hash", + "impl-codec", "impl-rlp", "impl-serde", "scale-info", - "uint 0.9.5", + "uint", ] [[package]] @@ -4064,13 +4062,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.3" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.2", + "regex-automata 0.3.8", + "regex-syntax 0.7.5", ] [[package]] @@ -4082,6 +4081,17 @@ dependencies = [ "regex-syntax 0.6.29", ] +[[package]] +name = "regex-automata" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.5", +] + [[package]] name = "regex-syntax" version = "0.6.29" @@ -4090,9 +4100,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "rend" @@ -4105,9 +4115,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ "base64 0.21.2", "bytes", @@ -4141,7 +4151,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.22.6", + "webpki-roots 0.25.2", "winreg", ] @@ -4309,7 +4319,7 @@ version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4c4216490d5a413bc6d10fa4742bd7d4955941d062c0ef873141d6b0e7b30fd" dependencies = [ - "arrayvec 0.7.2", + "arrayvec", "borsh", "bytes", "num-traits", @@ -4350,19 +4360,32 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys 0.4.7", "windows-sys 0.48.0", ] [[package]] name = "rustls" -version = "0.21.1" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", - "rustls-webpki", + "rustls-webpki 0.101.5", "sct", ] @@ -4385,6 +4408,16 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustls-webpki" +version = "0.101.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a27e3b59326c16e23d30aeb7a36a24cc0d29e71d68ff611cdfb4a01d013bed" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -4435,7 +4468,7 @@ checksum = "b569c32c806ec3abdf3b5869fb8bf1e0d275a7c1c9b0b05603d9464632649edf" dependencies = [ "cfg-if", "derive_more", - "parity-scale-codec 3.5.0", + "parity-scale-codec", "scale-info-derive", ] @@ -4475,7 +4508,7 @@ dependencies = [ "hmac 0.12.1", "pbkdf2 0.11.0", "salsa20", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] @@ -4514,7 +4547,16 @@ version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a" dependencies = [ - "secp256k1-sys", + "secp256k1-sys 0.4.2", +] + +[[package]] +name = "secp256k1" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +dependencies = [ + "secp256k1-sys 0.8.1", ] [[package]] @@ -4526,6 +4568,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +dependencies = [ + "cc", +] + [[package]] name = "security-framework" version = "2.9.1" @@ -4572,18 +4623,29 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.163" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-hex" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca37e3e4d1b39afd7ff11ee4e947efae85adfddf4841787bfa47c470e96dc26d" +dependencies = [ + "array-init", + "serde", + "smallvec 0.6.14", +] + [[package]] name = "serde_derive" -version = "1.0.163" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -4592,9 +4654,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -4663,16 +4725,16 @@ dependencies = [ "hex", "hex-literal", "hyper", + "indexer-common", "lazy_static", "libsecp256k1", "log", "metrics-exporter-prometheus", - "native", "once_cell", "prometheus", "regex", "reqwest", - "secp256k1", + "secp256k1 0.20.3", "serde", "serde_json", "sha3", @@ -4727,9 +4789,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", @@ -4780,6 +4842,18 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +[[package]] +name = "simple_asn1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror", + "time 0.3.21", +] + [[package]] name = "siphasher" version = "0.3.10" @@ -4801,6 +4875,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" +dependencies = [ + "maybe-uninit", +] + [[package]] name = "smallvec" version = "1.10.0" @@ -4826,13 +4909,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "solang-parser" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a94494913728908efa7a25a2dd2e4f037e714897985c24273c40596638ed909" +checksum = "7cb9fa2fa2fa6837be8a2495486ff92e3ffe68a99b6eeba288e139efdd842457" dependencies = [ - "itertools 0.10.5", + "itertools 0.11.0", "lalrpop", "lalrpop-util", "phf", @@ -4921,8 +5014,8 @@ dependencies = [ "rust_decimal", "serde", "serde_json", - "sha2 0.10.6", - "smallvec", + "sha2 0.10.7", + "smallvec 1.10.0", "sqlformat", "thiserror", "time 0.3.21", @@ -4960,7 +5053,7 @@ dependencies = [ "quote", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.7", "sqlx-core", "sqlx-mysql", "sqlx-postgres", @@ -4980,7 +5073,7 @@ dependencies = [ "atoi", "base64 0.21.2", "bigdecimal", - "bitflags 2.3.1", + "bitflags 2.4.0", "byteorder", "bytes", "crc", @@ -5006,8 +5099,8 @@ dependencies = [ "rust_decimal", "serde", "sha1", - "sha2 0.10.6", - "smallvec", + "sha2 0.10.7", + "smallvec 1.10.0", "sqlx-core", "stringprep", "thiserror", @@ -5025,7 +5118,7 @@ dependencies = [ "atoi", "base64 0.21.2", "bigdecimal", - "bitflags 2.3.1", + "bitflags 2.4.0", "byteorder", "crc", "dotenvy", @@ -5049,8 +5142,8 @@ dependencies = [ "serde", "serde_json", "sha1", - "sha2 0.10.6", - "smallvec", + "sha2 0.10.7", + "smallvec 1.10.0", "sqlx-core", "stringprep", "thiserror", @@ -5167,19 +5260,19 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "svm-rs" -version = "0.2.23" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a04fc4f5cd35c700153b233f5575ccb3237e0f941fa5049d9e98254d10bf2fe" +checksum = "597e3a746727984cb7ea2487b6a40726cad0dbe86628e7d429aa6b8c4c153db4" dependencies = [ + "dirs", "fs2", "hex", - "home", "once_cell", "reqwest", "semver", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", "url", "zip", @@ -5258,15 +5351,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.5.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", - "fastrand", + "fastrand 2.0.0", "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.45.0", + "rustix 0.38.13", + "windows-sys 0.48.0", ] [[package]] @@ -5393,11 +5486,10 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", @@ -5406,7 +5498,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.4", "tokio-macros", "windows-sys 0.48.0", ] @@ -5467,16 +5559,16 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec509ac96e9a0c43427c74f003127d953a265737636129424288d27cb5c4b12c" +checksum = "2b2dbec703c26b00d74844519606ef15d09a7d6857860f84ad223dec002ddea2" dependencies = [ "futures-util", "log", "rustls", "tokio", "tokio-rustls", - "tungstenite 0.19.0", + "tungstenite 0.20.0", "webpki-roots 0.23.1", ] @@ -5683,7 +5775,7 @@ dependencies = [ "serde", "serde_json", "sharded-slab", - "smallvec", + "smallvec 1.10.0", "thread_local", "tracing", "tracing-core", @@ -5718,9 +5810,9 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15fba1a6d6bb030745759a9a2a588bfe8490fc8b4751a277db3a0be1c9ebbf67" +checksum = "e862a1c4128df0112ab625f55cd5c934bcb4312ba80b39ae4b4835a3fd58e649" dependencies = [ "byteorder", "bytes", @@ -5734,7 +5826,6 @@ dependencies = [ "thiserror", "url", "utf-8", - "webpki", ] [[package]] @@ -5749,18 +5840,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" -[[package]] -name = "uint" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9db035e67dfaf7edd9aebfe8676afcd63eed53c8a4044fed514c8cccf1835177" -dependencies = [ - "byteorder", - "crunchy", - "rustc-hex", - "static_assertions", -] - [[package]] name = "uint" version = "0.9.5" @@ -5835,9 +5914,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.3.1" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -6029,33 +6108,20 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" dependencies = [ - "webpki", + "rustls-webpki 0.100.1", ] [[package]] name = "webpki-roots" -version = "0.23.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" -dependencies = [ - "rustls-webpki", -] +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" [[package]] name = "whoami" @@ -6261,11 +6327,12 @@ dependencies = [ [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7b1de4d6..c0b50447 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,7 @@ [workspace] members = [ - "native", + "common", "service", - # "common", ] resolver = "2" diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 00000000..aa9e5381 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "indexer-common" +version = "0.1.0" +edition = "2021" + +[dependencies] +alloy-primitives = { version = "0.3.3", features = ["serde"] } +anyhow = "1.0.75" +arc-swap = "1.6.0" +bs58 = "0.5.0" +eip-712-derive = { git = "https://github.com/graphprotocol/eip-712-derive" } +ethereum-types = "0.14.1" +ethers = "2.0.10" +ethers-core = "2.0.10" +faux = { version = "0.1.10", optional = true } +keccak-hash = "0.10.0" +lazy_static = "1.4.0" +log = "0.4.20" +reqwest = "0.11.20" +secp256k1 = { version = "0.27.0", features = ["recovery"] } +serde = { version = "1.0.188", features = ["derive"] } +serde_json = "1.0.107" +tokio = { version = "1.32.0", features = ["full", "macros", "rt"] } + +[dev-dependencies] +env_logger = "0.9.0" +faux = "0.1.10" +test-log = "0.2.12" +wiremock = "0.5.19" + +[features] +mock = ["dep:faux"] diff --git a/service/src/common/allocation.rs b/common/src/allocations/mod.rs similarity index 97% rename from service/src/common/allocation.rs rename to common/src/allocations/mod.rs index ff4e86e5..4e050f2d 100644 --- a/service/src/common/allocation.rs +++ b/common/src/allocations/mod.rs @@ -4,15 +4,15 @@ use alloy_primitives::Address; use anyhow::Result; use ethers::signers::coins_bip39::English; -use ethers::signers::MnemonicBuilder; -use ethers::signers::Signer; -use ethers::signers::Wallet; +use ethers::signers::{MnemonicBuilder, Signer, Wallet}; use ethers_core::k256::ecdsa::SigningKey; use ethers_core::types::U256; use serde::Deserialize; use serde::Deserializer; -use crate::common::types::SubgraphDeploymentID; +use crate::types::SubgraphDeploymentID; + +pub mod monitor; #[derive(Debug, Eq, PartialEq)] pub struct Allocation { @@ -148,8 +148,9 @@ pub fn allocation_signer(indexer_mnemonic: &str, allocation: &Allocation) -> Res mod test { use std::str::FromStr; + use crate::prelude::SubgraphDeploymentID; + use super::*; - use crate::common::types::SubgraphDeploymentID; const INDEXER_OPERATOR_MNEMONIC: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; diff --git a/service/src/allocation_monitor.rs b/common/src/allocations/monitor.rs similarity index 95% rename from service/src/allocation_monitor.rs rename to common/src/allocations/monitor.rs index 73942f0a..1980ae4b 100644 --- a/service/src/allocation_monitor.rs +++ b/common/src/allocations/monitor.rs @@ -10,7 +10,7 @@ use log::{info, warn}; use tokio::sync::watch::{Receiver, Sender}; use tokio::sync::RwLock; -use crate::{common::allocation::Allocation, common::network_subgraph::NetworkSubgraph}; +use crate::prelude::{Allocation, NetworkSubgraph}; #[derive(Debug)] struct AllocationMonitorInner { @@ -23,14 +23,14 @@ struct AllocationMonitorInner { watch_receiver: Receiver<()>, } -#[cfg_attr(test, faux::create)] +#[cfg_attr(any(test, feature = "mock"), faux::create)] #[derive(Debug, Clone)] pub struct AllocationMonitor { _monitor_handle: Arc>, inner: Arc, } -#[cfg_attr(test, faux::methods)] +#[cfg_attr(any(test, feature = "mock"), faux::methods)] impl AllocationMonitor { pub async fn new( network_subgraph: NetworkSubgraph, @@ -79,9 +79,7 @@ impl AllocationMonitor { .to_string(), Some(serde_json::json!({ "id": graph_network_id })), ) - .await?; - - let res_json: serde_json::Value = serde_json::from_str(res.graphql_response.as_str()) + .await .map_err(|e| { anyhow::anyhow!( "Failed to parse current epoch response from network subgraph: {}", @@ -89,8 +87,7 @@ impl AllocationMonitor { ) })?; - res_json - .get("data") + res.get("data") .and_then(|d| d.get("graphNetwork")) .and_then(|d| d.get("currentEpoch")) .and_then(|d| d.as_u64()) @@ -104,7 +101,7 @@ impl AllocationMonitor { indexer_address: &Address, closed_at_epoch_threshold: u64, ) -> Result> { - let res = network_subgraph + let mut res = network_subgraph .network_query( r#" query allocations($indexer: ID!, $closedAtEpochThreshold: Int!) { @@ -157,9 +154,7 @@ impl AllocationMonitor { .to_string(), Some(serde_json::json!({ "indexer": indexer_address, "closedAtEpochThreshold": closed_at_epoch_threshold })), ) - .await; - - let mut res_json: serde_json::Value = serde_json::from_str(res?.graphql_response.as_str()) + .await .map_err(|e| { anyhow::anyhow!( "Failed to fetch current allocations from network subgraph: {}", @@ -167,7 +162,7 @@ impl AllocationMonitor { ) })?; - let indexer_json = res_json + let indexer_json = res .get_mut("data") .and_then(|d| d.get_mut("indexer")) .ok_or_else(|| anyhow::anyhow!("No data / indexer not found on chain",))?; @@ -286,7 +281,7 @@ mod tests { use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; - use crate::common::network_subgraph::NetworkSubgraph; + use crate::prelude::NetworkSubgraph; use crate::test_vectors; use super::*; diff --git a/common/src/attestations/mod.rs b/common/src/attestations/mod.rs new file mode 100644 index 00000000..21ee4aa5 --- /dev/null +++ b/common/src/attestations/mod.rs @@ -0,0 +1,188 @@ +// Copyright 2023-, GraphOps and Semiotic Labs. +// SPDX-License-Identifier: Apache-2.0 + +use anyhow::Result; +use ethers::signers::coins_bip39::English; +use ethers::signers::MnemonicBuilder; +use ethers::signers::Signer; +use ethers::signers::Wallet; +use ethers_core::k256::ecdsa::SigningKey; + +use crate::prelude::{Allocation, SubgraphDeploymentID}; + +pub mod signer; +pub mod signers; + +pub fn derive_key_pair( + indexer_mnemonic: &str, + epoch: u64, + deployment: &SubgraphDeploymentID, + index: u64, +) -> Result> { + let mut derivation_path = format!("m/{}/", epoch); + derivation_path.push_str( + &deployment + .ipfs_hash() + .as_bytes() + .iter() + .map(|char| char.to_string()) + .collect::>() + .join("/"), + ); + derivation_path.push_str(format!("/{}", index).as_str()); + + Ok(MnemonicBuilder::::default() + .derivation_path(&derivation_path) + .expect("Valid derivation path") + .phrase(indexer_mnemonic) + .build()?) +} + +pub fn attestation_signer_for_allocation( + indexer_mnemonic: &str, + allocation: &Allocation, +) -> Result { + // Guess the allocation index by enumerating all indexes in the + // range [0, 100] and checking for a match + for i in 0..100 { + // The allocation was either created at the epoch it intended to or one + // epoch later. So try both both. + for created_at_epoch in [allocation.created_at_epoch, allocation.created_at_epoch - 1] { + let allocation_wallet = derive_key_pair( + indexer_mnemonic, + created_at_epoch, + &allocation.subgraph_deployment.id, + i, + )?; + if allocation_wallet.address().as_fixed_bytes() == allocation.id { + return Ok(allocation_wallet.signer().clone()); + } + } + } + Err(anyhow::anyhow!( + "Could not find allocation signer for allocation {}", + allocation.id + )) +} + +#[cfg(test)] +mod tests { + use alloy_primitives::Address; + use ethers_core::types::U256; + use std::str::FromStr; + use test_log::test; + + use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment, SubgraphDeploymentID}; + + use super::*; + + const INDEXER_OPERATOR_MNEMONIC: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; + + #[test] + fn test_derive_key_pair() { + assert_eq!( + derive_key_pair( + INDEXER_OPERATOR_MNEMONIC, + 953, + &SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a" + ) + .unwrap(), + 0 + ) + .unwrap() + .address() + .as_fixed_bytes(), + Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap() + ); + + assert_eq!( + derive_key_pair( + INDEXER_OPERATOR_MNEMONIC, + 940, + &SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a" + ) + .unwrap(), + 2 + ) + .unwrap() + .address() + .as_fixed_bytes(), + Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap() + ); + } + + #[test] + fn test_allocation_signer() { + // Note that we use `derive_key_pair` to derive the private key + + let allocation = Allocation { + id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), + status: AllocationStatus::Null, + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + ) + .unwrap(), + denied_at: None, + staked_tokens: U256::zero(), + signalled_tokens: U256::zero(), + query_fees_amount: U256::zero(), + }, + indexer: Address::ZERO, + allocated_tokens: U256::zero(), + created_at_epoch: 940, + created_at_block_hash: "".to_string(), + closed_at_epoch: None, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }; + assert_eq!( + attestation_signer_for_allocation(INDEXER_OPERATOR_MNEMONIC, &allocation).unwrap(), + *derive_key_pair( + INDEXER_OPERATOR_MNEMONIC, + 940, + &allocation.subgraph_deployment.id, + 2 + ) + .unwrap() + .signer() + ); + } + + #[test] + fn test_allocation_signer_error() { + // Note that because allocation will try 200 derivations paths, this is a slow test + + let allocation = Allocation { + // Purposefully wrong address + id: Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(), + status: AllocationStatus::Null, + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + ) + .unwrap(), + denied_at: None, + staked_tokens: U256::zero(), + signalled_tokens: U256::zero(), + query_fees_amount: U256::zero(), + }, + indexer: Address::ZERO, + allocated_tokens: U256::zero(), + created_at_epoch: 940, + created_at_block_hash: "".to_string(), + closed_at_epoch: None, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }; + assert!(attestation_signer_for_allocation(INDEXER_OPERATOR_MNEMONIC, &allocation).is_err()); + } +} diff --git a/native/src/attestation.rs b/common/src/attestations/signer.rs similarity index 74% rename from native/src/attestation.rs rename to common/src/attestations/signer.rs index bd11640e..a0119188 100644 --- a/native/src/attestation.rs +++ b/common/src/attestations/signer.rs @@ -1,13 +1,18 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use super::*; +use alloy_primitives::Address; use eip_712_derive::{ - sign_typed, Bytes32, DomainSeparator, Eip712Domain, MemberVisitor, StructType, U256, + sign_typed, Bytes32, DomainSeparator, Eip712Domain, MemberVisitor, StructType, }; +use ethers::utils::hex; +use ethers_core::k256::ecdsa::SigningKey; +use ethers_core::types::U256; +use keccak_hash::keccak; use secp256k1::SecretKey; use std::convert::TryInto; +/// An attestation signer tied to a specific allocation via its signer key #[derive(Debug, Clone)] pub struct AttestationSigner { subgraph_deployment_id: Bytes32, @@ -17,7 +22,7 @@ pub struct AttestationSigner { impl AttestationSigner { pub fn new( - chain_id: U256, + chain_id: eip_712_derive::U256, dispute_manager: Address, signer: SecretKey, subgraph_deployment_id: Bytes32, @@ -31,7 +36,7 @@ impl AttestationSigner { name: "Graph Protocol".to_owned(), version: "0".to_owned(), chain_id, - verifying_contract: eip_712_derive::Address(dispute_manager), + verifying_contract: eip_712_derive::Address(dispute_manager.into()), salt, }; let domain_separator = DomainSeparator::new(&domain); @@ -95,3 +100,22 @@ pub struct Attestation { pub r: Bytes32, pub s: Bytes32, } + +/// Helper for creating an AttestationSigner +pub fn create_attestation_signer( + chain_id: U256, + dispute_manager_address: Address, + signer: SigningKey, + deployment_id: [u8; 32], +) -> anyhow::Result { + // Tedious conversions to the "indexer_native" types + let mut chain_id_bytes = [0u8; 32]; + chain_id.to_big_endian(&mut chain_id_bytes); + let signer = AttestationSigner::new( + eip_712_derive::U256(chain_id_bytes), + dispute_manager_address, + secp256k1::SecretKey::from_slice(&signer.to_bytes())?, + deployment_id, + ); + Ok(signer) +} diff --git a/service/src/attestation_signers.rs b/common/src/attestations/signers.rs similarity index 84% rename from service/src/attestation_signers.rs rename to common/src/attestations/signers.rs index 6b8aaadf..e14bb5d8 100644 --- a/service/src/attestation_signers.rs +++ b/common/src/attestations/signers.rs @@ -4,15 +4,13 @@ use alloy_primitives::Address; use ethers_core::types::U256; use log::{error, info, warn}; -use native::attestation::AttestationSigner; use std::collections::HashMap; use std::sync::Arc; use tokio::sync::RwLock; -use crate::{ - allocation_monitor::AllocationMonitor, common::allocation::allocation_signer, - util::create_attestation_signer, -}; +use crate::prelude::{AllocationMonitor, AttestationSigner}; + +use super::{attestation_signer_for_allocation, signer::create_attestation_signer}; #[derive(Debug, Clone)] pub struct AttestationSigners { @@ -21,7 +19,7 @@ pub struct AttestationSigners { } #[derive(Debug)] -struct AttestationSignersInner { +pub(crate) struct AttestationSignersInner { attestation_signers: Arc>>, allocation_monitor: AllocationMonitor, indexer_mnemonic: String, @@ -55,7 +53,7 @@ impl AttestationSigners { } } - async fn update_attestation_signers(inner: Arc) { + pub(crate) async fn update_attestation_signers(inner: Arc) { let mut attestation_signers_write = inner.attestation_signers.write().await; for allocation in inner .allocation_monitor @@ -66,14 +64,15 @@ impl AttestationSigners { if let std::collections::hash_map::Entry::Vacant(e) = attestation_signers_write.entry(allocation.id) { - match allocation_signer(&inner.indexer_mnemonic, allocation).and_then(|signer| { - create_attestation_signer( - inner.chain_id, - inner.dispute_manager, - signer, - allocation.subgraph_deployment.id.bytes32(), - ) - }) { + match attestation_signer_for_allocation(&inner.indexer_mnemonic, allocation) + .and_then(|signer| { + create_attestation_signer( + inner.chain_id, + inner.dispute_manager, + signer, + allocation.subgraph_deployment.id.bytes32(), + ) + }) { Ok(signer) => { e.insert(signer); info!( @@ -120,15 +119,17 @@ impl AttestationSigners { #[cfg(test)] mod tests { + use alloy_primitives::Address; + use ethers_core::types::U256; use std::str::FromStr; + use std::sync::Arc; - use test_log::test; - + use crate::prelude::AllocationMonitor; use crate::test_vectors; use super::*; - #[test(tokio::test)] + #[tokio::test] async fn test_update_attestation_signers() { unsafe { let mut mock_allocation_monitor = AllocationMonitor::faux(); diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 00000000..33908443 --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,23 @@ +// Copyright 2023-, GraphOps and Semiotic Labs. +// SPDX-License-Identifier: Apache-2.0 + +pub mod allocations; +pub mod attestations; +pub mod network_subgraph; +pub mod signature_verification; +pub mod types; + +#[cfg(test)] +mod test_vectors; + +pub mod prelude { + pub use super::allocations::monitor::AllocationMonitor; + pub use super::allocations::{Allocation, AllocationStatus, SubgraphDeployment}; + pub use super::attestations::{ + attestation_signer_for_allocation, + signer::{create_attestation_signer, AttestationSigner}, + signers::AttestationSigners, + }; + pub use super::network_subgraph::NetworkSubgraph; + pub use super::types::*; +} diff --git a/service/src/common/network_subgraph.rs b/common/src/network_subgraph/mod.rs similarity index 79% rename from service/src/common/network_subgraph.rs rename to common/src/network_subgraph/mod.rs index 7e7c3121..d8fc317e 100644 --- a/service/src/common/network_subgraph.rs +++ b/common/src/network_subgraph/mod.rs @@ -7,8 +7,7 @@ use reqwest::{header, Client, Url}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use crate::common::types::GraphQLQuery; -use crate::query_processor::{QueryError, UnattestedQueryResult}; +use crate::types::GraphQLQuery; #[derive(Debug, Serialize, Deserialize, PartialEq)] pub struct Response { @@ -64,47 +63,29 @@ impl NetworkSubgraph { pub async fn network_query_raw( &self, body: String, - ) -> Result { - let request = self - .client + ) -> Result { + self.client .post(Url::clone(&self.network_subgraph_url)) .body(body.clone()) - .header(header::CONTENT_TYPE, "application/json"); - - let response = request.send().await?; - - // actually parse the JSON for the graphQL schema - let response_text = response.text().await?; - Ok(UnattestedQueryResult { - graphql_response: response_text, - attestable: false, - }) + .header(header::CONTENT_TYPE, "application/json") + .send() + .await } pub async fn network_query( &self, query: String, variables: Option, - ) -> Result { + ) -> Result { let body = GraphQLQuery { query, variables }; self.network_query_raw( serde_json::to_string(&body).expect("serialize network GraphQL query"), ) + .await? + .json::() .await } - - pub async fn execute_network_free_query( - &self, - query: String, - ) -> Result, QueryError> { - let response = self.network_query_raw(query).await?; - - Ok(Response { - result: response, - status: 200, - }) - } } #[cfg(test)] @@ -155,13 +136,11 @@ mod test { let query = r#""{\"data\":{\"graphNetwork\":{\"currentEpoch\":960}}}""#; - let response = network_subgraph + // Check that the response is valid JSON + network_subgraph .network_query(query.to_string(), None) .await .unwrap(); - - // Check that the response is valid JSON - let _json: serde_json::Value = serde_json::from_str(&response.graphql_response).unwrap(); } #[tokio::test] @@ -178,12 +157,10 @@ mod test { } "#; - let response = network_subgraph + // Check that the response is valid JSON + network_subgraph .network_query(query.to_string(), None) .await .unwrap(); - - // Check that the response is valid JSON - let _json: serde_json::Value = serde_json::from_str(&response.graphql_response).unwrap(); } } diff --git a/native/src/signature_verification.rs b/common/src/signature_verification.rs similarity index 81% rename from native/src/signature_verification.rs rename to common/src/signature_verification.rs index 5a7fccae..c76dbbbb 100644 --- a/native/src/signature_verification.rs +++ b/common/src/signature_verification.rs @@ -1,7 +1,12 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use super::*; +use alloy_primitives::Address; +use arc_swap::ArcSwap; +use keccak_hash::keccak; +use lazy_static::lazy_static; +use secp256k1::{ecdsa::RecoverableSignature, Message, PublicKey, Secp256k1, VerifyOnly}; +use std::sync::Arc; lazy_static! { static ref SECP256K1: Secp256k1 = Secp256k1::verification_only(); @@ -29,7 +34,7 @@ impl SignatureVerifier { match self.signer.load().as_ref() { // If we already have the public key we can do the fast path. Signer::PublicKey(signer) => Ok(SECP256K1 - .verify(&message, &signature.to_standard(), signer) + .verify_ecdsa(&message, &signature.to_standard(), signer) .is_ok()), // If we don't have the public key, but have the address instead // we derive the address from the recovered key. If it's a match @@ -38,13 +43,13 @@ impl SignatureVerifier { // verify method instead of the slow recover method. Signer::Address(addr) => { let recovered_signer = SECP256K1 - .recover(&message, signature) + .recover_ecdsa(&message, signature) .map_err(|_| "Failed to recover signature")?; let ser = recovered_signer.serialize_uncompressed(); debug_assert_eq!(ser[0], 0x04); let pk_hash = keccak(&ser[1..]); - let equal = &pk_hash[12..] == addr; + let equal = pk_hash[12..] == addr; if equal { self.signer diff --git a/common/src/test_vectors.rs b/common/src/test_vectors.rs new file mode 100644 index 00000000..d4f3e2f0 --- /dev/null +++ b/common/src/test_vectors.rs @@ -0,0 +1,225 @@ +// Copyright 2023-, GraphOps and Semiotic Labs. +// SPDX-License-Identifier: Apache-2.0 + +use std::{collections::HashMap, str::FromStr}; + +use alloy_primitives::Address; +use ethers_core::types::U256; + +use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment, SubgraphDeploymentID}; + +pub const INDEXER_OPERATOR_MNEMONIC: &str = + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; +pub const INDEXER_ADDRESS: &str = "0x1234567890123456789012345678901234567890"; +pub const NETWORK_SUBGRAPH_ID: &str = "QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP"; +pub const DISPUTE_MANAGER_ADDRESS: &str = "0xdeadbeefcafebabedeadbeefcafebabedeadbeef"; + +/// The allocation IDs below are generated using the mnemonic +/// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" +/// and the following epoch and index: +/// +/// - (createdAtEpoch, 0) +/// - (createdAtEpoch-1, 0) +/// - (createdAtEpoch, 2) +/// - (createdAtEpoch-1, 1) +/// +/// Using https://github.com/graphprotocol/indexer/blob/f8786c979a8ed0fae93202e499f5ce25773af473/packages/indexer-common/src/allocations/keys.ts#L41-L71 +pub const ALLOCATIONS_QUERY_RESPONSE: &str = r#" + { + "data": { + "indexer": { + "activeAllocations": [ + { + "id": "0xfa44c72b753a66591f241c7dc04e8178c30e13af", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "5081382841000000014901161", + "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", + "createdAtEpoch": 953, + "closedAtEpoch": null, + "subgraphDeployment": { + "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + "deniedAt": 0, + "stakedTokens": "96183284152000000014901161", + "signalledTokens": "182832939554154667498047", + "queryFeesAmount": "19861336072168874330350" + } + }, + { + "id": "0xdd975e30aafebb143e54d215db8a3e8fd916a701", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "601726452999999979510903", + "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", + "createdAtEpoch": 953, + "closedAtEpoch": null, + "subgraphDeployment": { + "id": "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", + "deniedAt": 0, + "stakedTokens": "53885041676589999979510903", + "signalledTokens": "104257136417832003117925", + "queryFeesAmount": "2229358609434396563687" + } + } + ], + "recentlyClosedAllocations": [ + { + "id": "0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "5247998688000000081956387", + "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", + "createdAtEpoch": 940, + "closedAtEpoch": 953, + "subgraphDeployment": { + "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + "deniedAt": 0, + "stakedTokens": "96183284152000000014901161", + "signalledTokens": "182832939554154667498047", + "queryFeesAmount": "19861336072168874330350" + } + }, + { + "id": "0x69f961358846fdb64b04e1fd7b2701237c13cd9a", + "indexer": { + "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" + }, + "allocatedTokens": "2502334654999999795109034", + "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", + "createdAtEpoch": 940, + "closedAtEpoch": 953, + "subgraphDeployment": { + "id": "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", + "deniedAt": 0, + "stakedTokens": "85450761241000000055879354", + "signalledTokens": "154944508746646550301048", + "queryFeesAmount": "4293718622418791971020" + } + } + ] + } + } + } +"#; + +/// These are the expected json-serialized contents of the value returned by +/// AllocationMonitor::current_eligible_allocations with the values above at epoch threshold 940. +pub fn expected_eligible_allocations() -> HashMap { + HashMap::from([ + ( + Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), + Allocation { + id: Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(), + created_at_block_hash: + "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), + created_at_epoch: 953, + closed_at_epoch: None, + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), + signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), + query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ( + Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), + Allocation { + id: Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("601726452999999979510903").unwrap(), + created_at_block_hash: + "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), + created_at_epoch: 953, + closed_at_epoch: None, + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("53885041676589999979510903").unwrap(), + signalled_tokens: U256::from_str("104257136417832003117925").unwrap(), + query_fees_amount: U256::from_str("2229358609434396563687").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ( + Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), + Allocation { + id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(), + created_at_block_hash: + "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), + created_at_epoch: 940, + closed_at_epoch: Some(953), + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), + signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), + query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ( + Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), + Allocation { + id: Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), + indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(), + created_at_block_hash: + "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), + created_at_epoch: 940, + closed_at_epoch: Some(953), + subgraph_deployment: SubgraphDeployment { + id: SubgraphDeploymentID::new( + "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", + ) + .unwrap(), + denied_at: Some(0), + staked_tokens: U256::from_str("85450761241000000055879354").unwrap(), + signalled_tokens: U256::from_str("154944508746646550301048").unwrap(), + query_fees_amount: U256::from_str("4293718622418791971020").unwrap(), + }, + status: AllocationStatus::Null, + closed_at_epoch_start_block_hash: None, + previous_epoch_start_block_hash: None, + poi: None, + query_fee_rebates: None, + query_fees_collected: None, + }, + ), + ]) +} diff --git a/service/src/common/types.rs b/common/src/types.rs similarity index 90% rename from service/src/common/types.rs rename to common/src/types.rs index 0e06c767..cf701719 100644 --- a/service/src/common/types.rs +++ b/common/src/types.rs @@ -1,10 +1,11 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use ethers::utils::hex; use serde::{Deserialize, Serialize}; use serde_json::Value; -/// GraphQLQuery request to a reqwest client +/// A serializable GraphQL request #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GraphQLQuery { pub query: String, @@ -12,28 +13,6 @@ pub struct GraphQLQuery { pub variables: Option, } -/// Subgraph identifier type: Subgraph name with field 'value' -pub struct SubgraphName { - value: String, -} - -/// Implement SubgraphName constructor -impl SubgraphName { - fn new(name: &str) -> SubgraphName { - SubgraphName { - // or call this field name - value: name.to_owned(), - } - } -} - -/// Implement SubgraphName String representation -impl ToString for SubgraphName { - fn to_string(&self) -> String { - self.value.to_string() - } -} - /// Subgraph identifier type: SubgraphDeploymentID with field 'value' #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SubgraphDeploymentID { diff --git a/native/Cargo.toml b/native/Cargo.toml deleted file mode 100644 index 70678606..00000000 --- a/native/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "native" -version = "0.1.0" -authors = ["Zac Burns "] -license = "MIT" -edition = "2018" -exclude = ["artifacts.json", "index.node"] - -# [lib] -# name = "native" -# crate-type = ["cdylib"] - -# [build-dependencies] -# neon-build = "0.9.1" - -[dependencies] -# neon = "0.9" -# neon-utils = { git = "https://github.com/edgeandnode/neon-utils", rev = "2507d4f" } -secp256k1 = { version = "0.20", features = ["recovery"] } -never = "0.1" -keccak-hash = "0.5.1" -lazy_static = "1.4" -arc-swap = "1.2" -eip-712-derive = { git = "https://github.com/graphprotocol/eip-712-derive" } -hex = "0.4.2" -primitive-types = "0.8" diff --git a/native/src/lib.rs b/native/src/lib.rs deleted file mode 100644 index 327ac884..00000000 --- a/native/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2023-, GraphOps and Semiotic Labs. -// SPDX-License-Identifier: Apache-2.0 - -use arc_swap::ArcSwap; -use keccak_hash::keccak; -use lazy_static::lazy_static; -use secp256k1::{recovery::RecoverableSignature, Message, PublicKey, Secp256k1, VerifyOnly}; -use std::sync::Arc; - -pub mod attestation; -pub mod signature_verification; - -type Address = [u8; 20]; diff --git a/service/Cargo.toml b/service/Cargo.toml index 1d185c2c..15608bc1 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -8,7 +8,7 @@ license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -native = { path = "../native" } +indexer-common = { path = "../common" } confy = "0.5.1" ethers-core = "2.0.0" ethers = "2.0.0" @@ -64,6 +64,7 @@ alloy-sol-types = "0.3.2" [dev-dependencies] faux = "0.1.10" hex-literal = "0.4.1" +indexer-common = { path = "../common", features = ["mock"] } test-log = "0.2.12" wiremock = "0.5.19" diff --git a/service/src/common/indexer_management/mod.rs b/service/src/common/indexer_management/mod.rs index 2995a9a9..62c86036 100644 --- a/service/src/common/indexer_management/mod.rs +++ b/service/src/common/indexer_management/mod.rs @@ -6,10 +6,9 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use sqlx::{FromRow, PgPool}; -use super::{ - indexer_error::{IndexerError, IndexerErrorCause, IndexerErrorCode}, - types::SubgraphDeploymentID, -}; +use indexer_common::prelude::SubgraphDeploymentID; + +use super::indexer_error::{IndexerError, IndexerErrorCause, IndexerErrorCode}; #[derive(Debug, FromRow, Clone, Serialize, Deserialize, SimpleObject)] pub struct CostModel { diff --git a/service/src/common/mod.rs b/service/src/common/mod.rs index df4f5cd2..ad3394d5 100644 --- a/service/src/common/mod.rs +++ b/service/src/common/mod.rs @@ -2,9 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 pub mod address; -pub mod allocation; pub mod database; pub mod indexer_error; pub mod indexer_management; -pub mod network_subgraph; -pub mod types; diff --git a/service/src/escrow_monitor.rs b/service/src/escrow_monitor.rs index d16bff28..47453807 100644 --- a/service/src/escrow_monitor.rs +++ b/service/src/escrow_monitor.rs @@ -1,20 +1,17 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::collections::HashMap; - -use std::sync::Arc; - use alloy_primitives::Address; use anyhow::Result; use ethereum_types::U256; use log::{error, info}; - use serde::Deserialize; - +use std::collections::HashMap; +use std::sync::Arc; use tokio::sync::RwLock; -use crate::common::types::GraphQLQuery; +use indexer_common::prelude::GraphQLQuery; + use crate::graph_node::GraphNodeInstance; #[derive(Debug)] diff --git a/service/src/main.rs b/service/src/main.rs index 59fa1fed..5763a35e 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -5,25 +5,21 @@ use alloy_primitives::Address; use alloy_sol_types::eip712_domain; use axum::Server; use dotenvy::dotenv; - use ethereum_types::U256; - use std::{net::SocketAddr, str::FromStr}; - use tracing::info; +use indexer_common::prelude::{AllocationMonitor, AttestationSigners, NetworkSubgraph}; + use util::{package_version, shutdown_signal}; use crate::{ - common::database, common::network_subgraph::NetworkSubgraph, config::Cli, - metrics::handle_serve_metrics, query_processor::QueryProcessor, server::create_server, - util::public_key, + common::database, config::Cli, metrics::handle_serve_metrics, query_processor::QueryProcessor, + server::create_server, util::public_key, }; use server::ServerOptions; -mod allocation_monitor; -mod attestation_signers; mod common; mod config; mod escrow_monitor; @@ -74,7 +70,7 @@ async fn main() -> Result<(), std::io::Error> { &config.network_subgraph.network_subgraph_endpoint, ); - let allocation_monitor = allocation_monitor::AllocationMonitor::new( + let allocation_monitor = AllocationMonitor::new( network_subgraph.clone(), config.ethereum.indexer_address, 1, @@ -83,7 +79,7 @@ async fn main() -> Result<(), std::io::Error> { .await .expect("Initialize allocation monitor"); - let attestation_signers = attestation_signers::AttestationSigners::new( + let attestation_signers = AttestationSigners::new( allocation_monitor.clone(), config.ethereum.mnemonic.clone(), // TODO: Chain ID should be a config diff --git a/service/src/query_processor.rs b/service/src/query_processor.rs index 436c35b6..19f66141 100644 --- a/service/src/query_processor.rs +++ b/service/src/query_processor.rs @@ -3,12 +3,11 @@ use ethers_core::types::{Signature, U256}; use log::error; -use native::attestation::AttestationSigner; use serde::{Deserialize, Serialize}; use tap_core::tap_manager::SignedReceipt; -use crate::attestation_signers::AttestationSigners; -use crate::common::types::SubgraphDeploymentID; +use indexer_common::prelude::{AttestationSigner, AttestationSigners, SubgraphDeploymentID}; + use crate::graph_node::GraphNodeInstance; use crate::tap_manager::TapManager; @@ -162,9 +161,9 @@ mod tests { use alloy_primitives::Address; use hex_literal::hex; - use crate::{ - common::allocation::{allocation_signer, Allocation, AllocationStatus, SubgraphDeployment}, - util::create_attestation_signer, + use indexer_common::prelude::{ + attestation_signer_for_allocation, create_attestation_signer, Allocation, AllocationStatus, + SubgraphDeployment, }; use super::*; @@ -260,7 +259,8 @@ mod tests { query_fees_collected: None, }; - let allocation_key = allocation_signer(INDEXER_OPERATOR_MNEMONIC, allocation).unwrap(); + let allocation_key = + attestation_signer_for_allocation(INDEXER_OPERATOR_MNEMONIC, allocation).unwrap(); let attestation_signer = create_attestation_signer( U256::from(1), diff --git a/service/src/server/mod.rs b/service/src/server/mod.rs index 39778fd6..075c993d 100644 --- a/service/src/server/mod.rs +++ b/service/src/server/mod.rs @@ -1,15 +1,15 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use axum::{ +pub(crate) use axum::{ error_handling::HandleErrorLayer, handler::Handler, http::{Method, StatusCode}, routing::get, }; + use axum::{routing::post, Extension, Router}; use sqlx::PgPool; - use std::time::Duration; use tower::{BoxError, ServiceBuilder}; use tower_http::{ @@ -19,8 +19,9 @@ use tower_http::{ }; use tracing::Level; +use indexer_common::prelude::NetworkSubgraph; + use crate::{ - common::network_subgraph::NetworkSubgraph, query_processor::QueryProcessor, server::routes::{network_ratelimiter, slow_ratelimiter}, util::PackageVersion, diff --git a/service/src/server/routes/network.rs b/service/src/server/routes/network.rs index 8d79cfa2..12880b0b 100644 --- a/service/src/server/routes/network.rs +++ b/service/src/server/routes/network.rs @@ -7,6 +7,7 @@ use axum::{ response::IntoResponse, Json, }; +use serde_json::Value; use crate::server::ServerOptions; @@ -38,14 +39,25 @@ pub async fn network_queries( Err(e) => return bad_request_response(&e.to_string()), }; - let request = server + let response = server .network_subgraph - .execute_network_free_query(query_string) + .network_query_raw(query_string) .await .expect("Failed to execute free network subgraph query"); - match request.status { - 200 => (StatusCode::OK, Json(request.result)).into_response(), - _ => bad_request_response("Bad response from Graph node"), + if response.status().is_success() { + ( + StatusCode::OK, + Json( + response + .json::() + .await + // FIXME: Don't use expect here + .expect("Failed to parse network subgraph query result"), + ), + ) + .into_response() + } else { + bad_request_response("Bad response from Graph node") } } diff --git a/service/src/server/routes/subgraphs.rs b/service/src/server/routes/subgraphs.rs index 5c3dc417..b21eeac9 100644 --- a/service/src/server/routes/subgraphs.rs +++ b/service/src/server/routes/subgraphs.rs @@ -7,11 +7,11 @@ use axum::{ response::IntoResponse, Json, }; - use tracing::trace; +use indexer_common::prelude::SubgraphDeploymentID; + use crate::{ - common::types::SubgraphDeploymentID, metrics, query_processor::FreeQuery, server::{ diff --git a/service/src/tap_manager.rs b/service/src/tap_manager.rs index cd799619..4a4795b9 100644 --- a/service/src/tap_manager.rs +++ b/service/src/tap_manager.rs @@ -1,18 +1,19 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::sync::Arc; - use alloy_sol_types::Eip712Domain; use log::error; use sqlx::{types::BigDecimal, PgPool}; +use std::sync::Arc; use tap_core::tap_manager::SignedReceipt; -use crate::{allocation_monitor, escrow_monitor, query_processor::QueryError}; +use indexer_common::prelude::AllocationMonitor; + +use crate::{escrow_monitor, query_processor::QueryError}; #[derive(Clone, Debug)] pub struct TapManager { - allocation_monitor: allocation_monitor::AllocationMonitor, + allocation_monitor: AllocationMonitor, escrow_monitor: escrow_monitor::EscrowMonitor, pgpool: PgPool, domain_separator: Arc, @@ -21,7 +22,7 @@ pub struct TapManager { impl TapManager { pub fn new( pgpool: PgPool, - allocation_monitor: allocation_monitor::AllocationMonitor, + allocation_monitor: AllocationMonitor, escrow_monitor: escrow_monitor::EscrowMonitor, domain_separator: Eip712Domain, ) -> Self { @@ -105,7 +106,7 @@ mod test { use tap_core::tap_manager::SignedReceipt; use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; - use crate::allocation_monitor::AllocationMonitor; + use indexer_common::prelude::AllocationMonitor; use super::*; diff --git a/service/src/test_vectors.rs b/service/src/test_vectors.rs index d6d7fe6e..f8ff89e5 100644 --- a/service/src/test_vectors.rs +++ b/service/src/test_vectors.rs @@ -1,231 +1,12 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::{collections::HashMap, str::FromStr}; - use alloy_primitives::Address; use ethers_core::types::U256; +use std::collections::HashMap; +use std::str::FromStr; -use crate::common::{ - allocation::{Allocation, AllocationStatus, SubgraphDeployment}, - types::SubgraphDeploymentID, -}; - -pub const INDEXER_OPERATOR_MNEMONIC: &str = - "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; pub const INDEXER_ADDRESS: &str = "0x1234567890123456789012345678901234567890"; -pub const NETWORK_SUBGRAPH_ID: &str = "QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP"; -pub const DISPUTE_MANAGER_ADDRESS: &str = "0xdeadbeefcafebabedeadbeefcafebabedeadbeef"; - -/// The allocation IDs below are generated using the mnemonic -/// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" -/// and the following epoch and index: -/// -/// - (createdAtEpoch, 0) -/// - (createdAtEpoch-1, 0) -/// - (createdAtEpoch, 2) -/// - (createdAtEpoch-1, 1) -/// -/// Using https://github.com/graphprotocol/indexer/blob/f8786c979a8ed0fae93202e499f5ce25773af473/packages/indexer-common/src/allocations/keys.ts#L41-L71 -pub const ALLOCATIONS_QUERY_RESPONSE: &str = r#" - { - "data": { - "indexer": { - "activeAllocations": [ - { - "id": "0xfa44c72b753a66591f241c7dc04e8178c30e13af", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "5081382841000000014901161", - "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", - "createdAtEpoch": 953, - "closedAtEpoch": null, - "subgraphDeployment": { - "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - "deniedAt": 0, - "stakedTokens": "96183284152000000014901161", - "signalledTokens": "182832939554154667498047", - "queryFeesAmount": "19861336072168874330350" - } - }, - { - "id": "0xdd975e30aafebb143e54d215db8a3e8fd916a701", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "601726452999999979510903", - "createdAtBlockHash": "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf", - "createdAtEpoch": 953, - "closedAtEpoch": null, - "subgraphDeployment": { - "id": "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", - "deniedAt": 0, - "stakedTokens": "53885041676589999979510903", - "signalledTokens": "104257136417832003117925", - "queryFeesAmount": "2229358609434396563687" - } - } - ], - "recentlyClosedAllocations": [ - { - "id": "0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "5247998688000000081956387", - "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", - "createdAtEpoch": 940, - "closedAtEpoch": 953, - "subgraphDeployment": { - "id": "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - "deniedAt": 0, - "stakedTokens": "96183284152000000014901161", - "signalledTokens": "182832939554154667498047", - "queryFeesAmount": "19861336072168874330350" - } - }, - { - "id": "0x69f961358846fdb64b04e1fd7b2701237c13cd9a", - "indexer": { - "id": "0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c" - }, - "allocatedTokens": "2502334654999999795109034", - "createdAtBlockHash": "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887", - "createdAtEpoch": 940, - "closedAtEpoch": 953, - "subgraphDeployment": { - "id": "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", - "deniedAt": 0, - "stakedTokens": "85450761241000000055879354", - "signalledTokens": "154944508746646550301048", - "queryFeesAmount": "4293718622418791971020" - } - } - ] - } - } - } -"#; - -/// These are the expected json-serialized contents of the value returned by -/// AllocationMonitor::current_eligible_allocations with the values above at epoch threshold 940. -pub fn expected_eligible_allocations() -> HashMap { - HashMap::from([ - ( - Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), - Allocation { - id: Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(), - created_at_block_hash: - "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), - created_at_epoch: 953, - closed_at_epoch: None, - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), - signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), - query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ( - Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), - Allocation { - id: Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("601726452999999979510903").unwrap(), - created_at_block_hash: - "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), - created_at_epoch: 953, - closed_at_epoch: None, - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xcda7fa0405d6fd10721ed13d18823d24b535060d8ff661f862b26c23334f13bf", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("53885041676589999979510903").unwrap(), - signalled_tokens: U256::from_str("104257136417832003117925").unwrap(), - query_fees_amount: U256::from_str("2229358609434396563687").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ( - Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), - Allocation { - id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(), - created_at_block_hash: - "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), - created_at_epoch: 940, - closed_at_epoch: Some(953), - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("96183284152000000014901161").unwrap(), - signalled_tokens: U256::from_str("182832939554154667498047").unwrap(), - query_fees_amount: U256::from_str("19861336072168874330350").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ( - Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), - Allocation { - id: Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(), - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), - allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(), - created_at_block_hash: - "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), - created_at_epoch: 940, - closed_at_epoch: Some(953), - subgraph_deployment: SubgraphDeployment { - id: SubgraphDeploymentID::new( - "0xc064c354bc21dd958b1d41b67b8ef161b75d2246b425f68ed4c74964ae705cbd", - ) - .unwrap(), - denied_at: Some(0), - staked_tokens: U256::from_str("85450761241000000055879354").unwrap(), - signalled_tokens: U256::from_str("154944508746646550301048").unwrap(), - query_fees_amount: U256::from_str("4293718622418791971020").unwrap(), - }, - status: AllocationStatus::Null, - closed_at_epoch_start_block_hash: None, - previous_epoch_start_block_hash: None, - poi: None, - query_fee_rebates: None, - query_fees_collected: None, - }, - ), - ]) -} pub const ESCROW_QUERY_RESPONSE: &str = r#" { diff --git a/service/src/util.rs b/service/src/util.rs index ee709d96..ae7e1ec4 100644 --- a/service/src/util.rs +++ b/service/src/util.rs @@ -1,16 +1,10 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy_primitives::Address; -use ethereum_types::U256; use ethers::signers::WalletError; -use ethers_core::k256::ecdsa::SigningKey; -use native::attestation::AttestationSigner; use serde::Serialize; use std::collections::HashMap; - use std::fs; - use tokio::signal; use toml::Value; use tracing::{ @@ -80,25 +74,6 @@ pub fn public_key(value: &str) -> Result { Ok(addr) } -/// Helper for creating an AttestationSigner -pub fn create_attestation_signer( - chain_id: U256, - dispute_manager_address: Address, - signer: SigningKey, - deployment_id: [u8; 32], -) -> anyhow::Result { - // Tedious conversions to the "indexer_native" types - let mut chain_id_bytes = [0u8; 32]; - chain_id.to_big_endian(&mut chain_id_bytes); - let signer = AttestationSigner::new( - eip_712_derive::U256(chain_id_bytes), - Into::<[u8; 20]>::into(dispute_manager_address), - secp256k1::SecretKey::from_slice(&signer.to_bytes())?, - deployment_id, - ); - Ok(signer) -} - /// Sets up tracing, allows log level to be set from the environment variables pub fn init_tracing(format: String) -> Result<(), SetGlobalDefaultError> { let filter = EnvFilter::from_default_env();