From 9738a1110a5313619539ef66e9fdb9f26dfb02be Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Thu, 19 Dec 2024 12:49:10 +0100 Subject: [PATCH] feat: use thegraph-core alloy crate Signed-off-by: Lorenzo Delgado --- Cargo.lock | 257 +++++++++++------- Cargo.toml | 25 +- crates/allocation/Cargo.toml | 1 - crates/allocation/src/lib.rs | 6 +- crates/attestation/Cargo.toml | 1 - crates/attestation/src/lib.rs | 63 +++-- crates/config/Cargo.toml | 1 - crates/config/src/config.rs | 47 ++-- crates/dips/Cargo.toml | 4 +- crates/dips/src/lib.rs | 35 ++- crates/monitor/Cargo.toml | 1 - crates/monitor/src/allocations.rs | 26 +- crates/monitor/src/attestation.rs | 21 +- crates/monitor/src/client/monitor.rs | 27 +- crates/monitor/src/client/subgraph_client.rs | 38 +-- .../monitor/src/deployment_to_allocation.rs | 4 +- crates/monitor/src/dispute_manager.rs | 17 +- crates/monitor/src/escrow_accounts.rs | 20 +- crates/query/Cargo.toml | 1 - crates/query/src/lib.rs | 4 +- crates/service/Cargo.toml | 11 +- crates/service/src/database/cost_model.rs | 12 +- crates/service/src/database/dips.rs | 3 +- crates/service/src/database/mod.rs | 3 +- crates/service/src/error.rs | 3 +- crates/service/src/main.rs | 3 +- crates/service/src/metrics.rs | 5 +- crates/service/src/middleware/allocation.rs | 20 +- crates/service/src/middleware/attestation.rs | 7 +- .../src/middleware/attestation_signer.rs | 13 +- crates/service/src/middleware/auth.rs | 16 +- crates/service/src/middleware/auth/tap.rs | 4 +- crates/service/src/middleware/deployment.rs | 5 +- crates/service/src/middleware/labels.rs | 21 +- .../src/middleware/prometheus_metrics.rs | 8 +- crates/service/src/middleware/sender.rs | 8 +- crates/service/src/middleware/tap_context.rs | 7 +- crates/service/src/middleware/tap_receipt.rs | 4 +- crates/service/src/routes/cost.rs | 3 +- crates/service/src/routes/dips.rs | 31 ++- crates/service/src/routes/request_handler.rs | 6 +- crates/service/src/routes/static_subgraph.rs | 6 +- crates/service/src/service.rs | 9 +- crates/service/src/service/router.rs | 20 +- .../service/src/service/tap_receipt_header.rs | 1 - crates/service/src/tap.rs | 27 +- .../src/tap/checks/allocation_eligible.rs | 3 +- .../service/src/tap/checks/deny_list_check.rs | 31 ++- .../src/tap/checks/receipt_max_val_check.rs | 23 +- .../src/tap/checks/sender_balance_check.rs | 2 +- .../service/src/tap/checks/timestamp_check.rs | 15 +- crates/service/src/tap/checks/value_check.rs | 30 +- crates/service/src/tap/receipt_store.rs | 15 +- crates/service/src/wallet.rs | 4 +- crates/service/tests/router_test.rs | 21 +- crates/tap-agent/Cargo.toml | 5 +- crates/tap-agent/src/agent.rs | 11 +- crates/tap-agent/src/agent/sender_account.rs | 194 +++++++------ .../src/agent/sender_accounts_manager.rs | 122 +++++---- .../tap-agent/src/agent/sender_allocation.rs | 141 +++++----- crates/tap-agent/src/cli.rs | 14 +- crates/tap-agent/src/database.rs | 3 +- crates/tap-agent/src/lib.rs | 2 +- crates/tap-agent/src/main.rs | 21 +- crates/tap-agent/src/metrics.rs | 7 +- crates/tap-agent/src/tap/context.rs | 2 +- .../src/tap/context/checks/allocation_id.rs | 2 +- .../src/tap/context/checks/signature.rs | 2 +- crates/tap-agent/src/tap/context/error.rs | 2 +- crates/tap-agent/src/tap/context/escrow.rs | 2 +- crates/tap-agent/src/tap/context/rav.rs | 23 +- crates/tap-agent/src/tap/context/receipt.rs | 32 +-- crates/tap-agent/src/tap/mod.rs | 3 +- crates/tap-agent/src/test.rs | 48 ++-- .../tap-agent/src/tracker/generic_tracker.rs | 13 +- .../tap-agent/src/tracker/global_tracker.rs | 3 +- .../tap-agent/src/tracker/sender_fee_stats.rs | 3 +- crates/tap-agent/src/tracker/tracker_tests.rs | 9 +- crates/test-assets/Cargo.toml | 1 - crates/test-assets/src/lib.rs | 137 +++++----- crates/watcher/src/lib.rs | 5 +- rustfmt.toml | 4 + 82 files changed, 939 insertions(+), 871 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c337b9f7..fb6e5705 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,9 +68,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "alloy" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea8ebf106e84a1c37f86244df7da0c7587e697b71a0d565cce079449b85ac6f8" +checksum = "02b0561294ccedc6181e5528b850b4579e3fbde696507baa00109bfd9054c5bb" dependencies = [ "alloy-consensus", "alloy-contract", @@ -107,25 +107,41 @@ dependencies = [ [[package]] name = "alloy-consensus" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed961a48297c732a5d97ee321aa8bb5009ecadbcb077d8bec90cb54e651629" +checksum = "a101d4d016f47f13890a74290fdd17b05dd175191d9337bc600791fb96e4dea8" dependencies = [ "alloy-eips", "alloy-primitives", "alloy-rlp", "alloy-serde", + "alloy-trie", "auto_impl", "c-kzg", "derive_more", + "k256", + "serde", +] + +[[package]] +name = "alloy-consensus-any" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa60357dda9a3d0f738f18844bd6d0f4a5924cc5cf00bfad2ff1369897966123" +dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-primitives", + "alloy-rlp", + "alloy-serde", "serde", ] [[package]] name = "alloy-contract" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "460ab80ce4bda1c80bcf96fe7460520476f2c7b734581c6567fac2708e2a60ef" +checksum = "2869e4fb31331d3b8c58c7db567d1e4e4e94ef64640beda3b6dd9b7045690941" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", @@ -139,7 +155,7 @@ dependencies = [ "alloy-transport", "futures", "futures-util", - "thiserror 1.0.69", + "thiserror 2.0.3", ] [[package]] @@ -186,9 +202,9 @@ dependencies = [ [[package]] name = "alloy-eip7702" -version = "0.3.2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ffc577390ce50234e02d841214b3dc0bea6aaaae8e04bbf3cb82e9a45da9eb" +checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -199,9 +215,9 @@ dependencies = [ [[package]] name = "alloy-eips" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69e06cf9c37be824b9d26d6d101114fdde6af0c87de2828b414c05c4b3daa71" +checksum = "8b6755b093afef5925f25079dd5a7c8d096398b804ba60cb5275397b06b31689" dependencies = [ "alloy-eip2930", "alloy-eip7702", @@ -217,12 +233,13 @@ dependencies = [ [[package]] name = "alloy-genesis" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dde15e14944a88bd6a57d325e9a49b75558746fe16aaccc79713ae50a6a9574c" +checksum = "aeec8e6eab6e52b7c9f918748c9b811e87dbef7312a2e3a2ca1729a92966a6af" dependencies = [ "alloy-primitives", "alloy-serde", + "alloy-trie", "serde", ] @@ -240,29 +257,31 @@ dependencies = [ [[package]] name = "alloy-json-rpc" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5979e0d5a7bf9c7eb79749121e8256e59021af611322aee56e77e20776b4b3" +checksum = "4fa077efe0b834bcd89ff4ba547f48fb081e4fdc3673dd7da1b295a2cf2bb7b7" dependencies = [ "alloy-primitives", "alloy-sol-types", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.3", "tracing", ] [[package]] name = "alloy-network" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "204237129086ce5dc17a58025e93739b01b45313841f98fa339eb1d780511e57" +checksum = "209a1882a08e21aca4aac6e2a674dc6fcf614058ef8cb02947d63782b1899552" dependencies = [ "alloy-consensus", + "alloy-consensus-any", "alloy-eips", "alloy-json-rpc", "alloy-network-primitives", "alloy-primitives", + "alloy-rpc-types-any", "alloy-rpc-types-eth", "alloy-serde", "alloy-signer", @@ -270,14 +289,16 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "thiserror 1.0.69", + "serde", + "serde_json", + "thiserror 2.0.3", ] [[package]] name = "alloy-network-primitives" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514f70ee2a953db21631cd817b13a1571474ec77ddc03d47616d5e8203489fde" +checksum = "c20219d1ad261da7a6331c16367214ee7ded41d001fabbbd656fbf71898b2773" dependencies = [ "alloy-consensus", "alloy-eips", @@ -316,9 +337,9 @@ dependencies = [ [[package]] name = "alloy-provider" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4814d141ede360bb6cd1b4b064f1aab9de391e7c4d0d4d50ac89ea4bc1e25fbd" +checksum = "9eefa6f4c798ad01f9b4202d02cea75f5ec11fa180502f4701e2b47965a8c0bb" dependencies = [ "alloy-chains", "alloy-consensus", @@ -347,7 +368,7 @@ dependencies = [ "schnellru", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.3", "tokio", "tracing", "url", @@ -356,9 +377,9 @@ dependencies = [ [[package]] name = "alloy-pubsub" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ba46eb69ddf7a9925b81f15229cb74658e6eebe5dd30a5b74e2cd040380573" +checksum = "aac9a7210e0812b1d814118f426f57eb7fc260a419224dd1c76d169879c06907" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -397,9 +418,9 @@ dependencies = [ [[package]] name = "alloy-rpc-client" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc2bd1e7403463a5f2c61e955bcc9d3072b63aa177442b0f9aa6a6d22a941e3" +checksum = "ed30bf1041e84cabc5900f52978ca345dd9969f2194a945e6fdec25b0620705c" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -423,9 +444,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eea9bf1abdd506f985a53533f5ac01296bcd6102c5e139bbc5d40bc468d2c916" +checksum = "5ab686b0fa475d2a4f5916c5f07797734a691ec58e44f0f55d4746ea39cbcefb" dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", @@ -434,11 +455,22 @@ dependencies = [ "serde", ] +[[package]] +name = "alloy-rpc-types-any" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "200661999b6e235d9840be5d60a6e8ae2f0af9eb2a256dd378786744660e36ec" +dependencies = [ + "alloy-consensus-any", + "alloy-rpc-types-eth", + "alloy-serde", +] + [[package]] name = "alloy-rpc-types-engine" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "886d22d41992287a235af2f3af4299b5ced2bcafb81eb835572ad35747476946" +checksum = "5d297268357e3eae834ddd6888b15f764cbc0f4b3be9265f5f6ec239013f3d68" dependencies = [ "alloy-consensus", "alloy-eips", @@ -452,11 +484,12 @@ dependencies = [ [[package]] name = "alloy-rpc-types-eth" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b034779a4850b4b03f5be5ea674a1cf7d746b2da762b34d1860ab45e48ca27" +checksum = "a0600b8b5e2dc0cab12cbf91b5a885c35871789fb7b3a57b434bd4fced5b7a8b" dependencies = [ "alloy-consensus", + "alloy-consensus-any", "alloy-eips", "alloy-network-primitives", "alloy-primitives", @@ -471,9 +504,9 @@ dependencies = [ [[package]] name = "alloy-serde" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028e72eaa9703e4882344983cfe7636ce06d8cce104a78ea62fd19b46659efc4" +checksum = "9afa753a97002a33b2ccb707d9f15f31c81b8c1b786c95b73cc62bb1d1fd0c3f" dependencies = [ "alloy-primitives", "serde", @@ -482,9 +515,9 @@ dependencies = [ [[package]] name = "alloy-signer" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "592c185d7100258c041afac51877660c7bf6213447999787197db4842f0e938e" +checksum = "9b2cbff01a673936c2efd7e00d4c0e9a4dbbd6d600e2ce298078d33efbb19cd7" dependencies = [ "alloy-dyn-abi", "alloy-primitives", @@ -493,14 +526,14 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror 1.0.69", + "thiserror 2.0.3", ] [[package]] name = "alloy-signer-aws" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a406102908a4e51834f32c4e5c1b29aa2c407b3fd23a5cad129c28b56d85e1b8" +checksum = "71ce77227fdb9059fd7a3b38a8679c0dae95d81886ee8c13ef8ad99d74866bbd" dependencies = [ "alloy-consensus", "alloy-network", @@ -510,15 +543,15 @@ dependencies = [ "aws-sdk-kms", "k256", "spki", - "thiserror 1.0.69", + "thiserror 2.0.3", "tracing", ] [[package]] name = "alloy-signer-gcp" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d363e12280cb43747d3b62a1e6f00d595bc1a56464bb20200c6b6ca5d68185" +checksum = "7622438a51e1fa6379cad6bff52e0cde88b0d4e5e3f2f15e5feebdee527ef5f2" dependencies = [ "alloy-consensus", "alloy-network", @@ -528,15 +561,15 @@ dependencies = [ "gcloud-sdk", "k256", "spki", - "thiserror 1.0.69", + "thiserror 2.0.3", "tracing", ] [[package]] name = "alloy-signer-ledger" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a642c9f66ac73ae0d5398ce7ce3ce5bdfad5658d549abd48ea48962e585dca" +checksum = "b7b56789cbd13bace37acd7afd080aa7002ed65ab84f0220cd0c32e162b0afd6" dependencies = [ "alloy-consensus", "alloy-dyn-abi", @@ -548,15 +581,15 @@ dependencies = [ "coins-ledger", "futures-util", "semver 1.0.23", - "thiserror 1.0.69", + "thiserror 2.0.3", "tracing", ] [[package]] name = "alloy-signer-local" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6614f02fc1d5b079b2a4a5320018317b506fd0a6d67c1fd5542a71201724986c" +checksum = "bd6d988cb6cd7d2f428a74476515b1a6e901e08c796767f9f93311ab74005c8b" dependencies = [ "alloy-consensus", "alloy-network", @@ -567,7 +600,7 @@ dependencies = [ "coins-bip39", "k256", "rand", - "thiserror 1.0.69", + "thiserror 2.0.3", ] [[package]] @@ -645,9 +678,9 @@ dependencies = [ [[package]] name = "alloy-transport" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be77579633ebbc1266ae6fd7694f75c408beb1aeb6865d0b18f22893c265a061" +checksum = "d69d36982b9e46075ae6b792b0f84208c6c2c15ad49f6c500304616ef67b70e0" dependencies = [ "alloy-json-rpc", "base64 0.22.1", @@ -655,7 +688,7 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.3", "tokio", "tower 0.5.1", "tracing", @@ -665,9 +698,9 @@ dependencies = [ [[package]] name = "alloy-transport-http" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fd1a5d0827939847983b46f2f79510361f901dc82f8e3c38ac7397af142c6e" +checksum = "2e02ffd5d93ffc51d72786e607c97de3b60736ca3e636ead0ec1f7dce68ea3fd" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -680,9 +713,9 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8073d1186bfeeb8fbdd1292b6f1a0731f3aed8e21e1463905abfae0b96a887a6" +checksum = "1b6f8b87cb84bae6d81ae6604b37741c8116f84f9784a0ecc6038c302e679d23" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -699,9 +732,9 @@ dependencies = [ [[package]] name = "alloy-transport-ws" -version = "0.5.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61f27837bb4a1d6c83a28231c94493e814882f0e9058648a97e908a5f3fc9fcf" +checksum = "9c085c4e1e7680b723ffc558f61a22c061ed3f70eb3436f93f3936779c59cec1" dependencies = [ "alloy-pubsub", "alloy-transport", @@ -715,6 +748,22 @@ dependencies = [ "ws_stream_wasm", ] +[[package]] +name = "alloy-trie" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a5fd8fea044cc9a8c8a50bb6f28e31f0385d820f116c5b98f6f4e55d6e5590b" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "arrayvec 0.7.6", + "derive_more", + "nybbles", + "serde", + "smallvec", + "tracing", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -926,6 +975,9 @@ name = "arrayvec" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +dependencies = [ + "serde", +] [[package]] name = "ascii" @@ -1177,9 +1229,9 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.4.3" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10d5c055aa540164d9561a0e2e74ad30f0dcf7393c3a92f6733ddf9c5762468" +checksum = "300a12520b4e6d08b73f77680f12c16e8ae43250d55100e0b2be46d78da16a48" dependencies = [ "aws-credential-types", "aws-sigv4", @@ -1202,9 +1254,9 @@ dependencies = [ [[package]] name = "aws-sdk-kms" -version = "1.50.0" +version = "1.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd059dacda4dfd5b57f2bd453fc6555f9acb496cb77508d517da24cf5d73167" +checksum = "0ff4c717bf02350576b1542d7534edda68b95299b72700424978afd125b0b507" dependencies = [ "aws-credential-types", "aws-runtime", @@ -1224,9 +1276,9 @@ dependencies = [ [[package]] name = "aws-sigv4" -version = "1.2.5" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5619742a0d8f253be760bfbb8e8e8368c69e3587e4637af5754e488a611499b1" +checksum = "7d3820e0c08d0737872ff3c7c1f21ebbb6693d832312d6152bf18ef50a5471c2" dependencies = [ "aws-credential-types", "aws-smithy-http", @@ -1247,9 +1299,9 @@ dependencies = [ [[package]] name = "aws-smithy-async" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62220bc6e97f946ddd51b5f1361f78996e704677afc518a4ff66b7a72ea1378c" +checksum = "8aa8ff1492fd9fb99ae28e8467af0dbbb7c31512b16fabf1a0f10d7bb6ef78bb" dependencies = [ "futures-util", "pin-project-lite", @@ -1278,18 +1330,18 @@ dependencies = [ [[package]] name = "aws-smithy-json" -version = "0.60.7" +version = "0.61.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4683df9469ef09468dad3473d129960119a0d3593617542b7d52086c8486f2d6" +checksum = "ee4e69cc50921eb913c6b662f8d909131bb3e6ad6cb6090d3a39b66fc5c52095" dependencies = [ "aws-smithy-types", ] [[package]] name = "aws-smithy-runtime" -version = "1.7.3" +version = "1.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be28bd063fa91fd871d131fc8b68d7cd4c5fa0869bea68daca50dcb1cbd76be2" +checksum = "431a10d0e07e09091284ef04453dae4069283aa108d209974d67e77ae1caa658" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -1327,9 +1379,9 @@ dependencies = [ [[package]] name = "aws-smithy-types" -version = "1.2.9" +version = "1.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbd94a32b3a7d55d3806fe27d98d3ad393050439dd05eb53ece36ec5e3d3510" +checksum = "8ecbf4d5dfb169812e2b240a4350f15ad3c6b03a54074e5712818801615f2dc5" dependencies = [ "base64-simd", "bytes", @@ -3538,7 +3590,6 @@ dependencies = [ name = "indexer-allocation" version = "0.1.0" dependencies = [ - "alloy", "anyhow", "indexer-query", "serde", @@ -3549,7 +3600,6 @@ dependencies = [ name = "indexer-attestation" version = "0.1.0" dependencies = [ - "alloy", "anyhow", "indexer-allocation", "test-assets", @@ -3561,7 +3611,6 @@ dependencies = [ name = "indexer-config" version = "1.2.2" dependencies = [ - "alloy", "bigdecimal", "bip39", "figment", @@ -3584,9 +3633,7 @@ dependencies = [ name = "indexer-dips" version = "0.1.0" dependencies = [ - "alloy", "alloy-rlp", - "alloy-sol-types", "anyhow", "thegraph-core", "thiserror 1.0.69", @@ -3596,7 +3643,6 @@ dependencies = [ name = "indexer-monitor" version = "0.1.0" dependencies = [ - "alloy", "anyhow", "axum", "bip39", @@ -3622,7 +3668,6 @@ dependencies = [ name = "indexer-query" version = "0.1.0" dependencies = [ - "alloy", "anyhow", "graphql_client", "serde", @@ -3633,7 +3678,6 @@ dependencies = [ name = "indexer-service-rs" version = "1.4.0" dependencies = [ - "alloy", "anyhow", "async-graphql", "async-graphql-axum", @@ -3691,7 +3735,6 @@ dependencies = [ name = "indexer-tap-agent" version = "1.7.4" dependencies = [ - "alloy", "anyhow", "async-trait", "axum", @@ -4543,6 +4586,19 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "nybbles" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95f06be0417d97f81fe4e5c86d7d01b392655a9cac9c19a848aa033e18937b23" +dependencies = [ + "alloy-rlp", + "const-hex", + "proptest", + "serde", + "smallvec", +] + [[package]] name = "object" version = "0.36.5" @@ -5043,9 +5099,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" dependencies = [ "bytes", "prost-derive", @@ -5053,9 +5109,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", "itertools 0.13.0", @@ -5066,9 +5122,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" +checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc" dependencies = [ "prost", ] @@ -5176,9 +5232,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.7" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a626c6807713b15cac82a6acaccd6043c9a5408c24baae07611fec3f243da" +checksum = "1c40286217b4ba3a71d644d752e6a0b71f13f1b6a2c5311acfcbe0c2418ed904" dependencies = [ "cfg_aliases 0.2.1", "libc", @@ -6721,7 +6777,7 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tap_aggregator" version = "0.3.2" -source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=61b47b3#61b47b3b96aaa1437fc390eb581636d51134b006" +source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=1c6e29f#1c6e29f56fc1672087070c7e8e710bac0564e273" dependencies = [ "alloy", "anyhow", @@ -6745,7 +6801,7 @@ dependencies = [ [[package]] name = "tap_core" version = "2.0.0" -source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=61b47b3#61b47b3b96aaa1437fc390eb581636d51134b006" +source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=1c6e29f#1c6e29f56fc1672087070c7e8e710bac0564e273" dependencies = [ "alloy", "anyhow", @@ -6774,7 +6830,6 @@ dependencies = [ name = "test-assets" version = "0.1.0" dependencies = [ - "alloy", "bip39", "indexer-allocation", "lazy_static", @@ -6806,17 +6861,15 @@ dependencies = [ [[package]] name = "thegraph-core" -version = "0.7.0" -source = "git+https://github.com/edgeandnode/toolshed?rev=1663534fc1738e2db1b11cb54b5bb478ee970d40#1663534fc1738e2db1b11cb54b5bb478ee970d40" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e669ad507b7afcf8b2d303e98de2d8bcd7af56042a8626cd708838349cc4d928" dependencies = [ - "alloy-primitives", - "alloy-signer", - "alloy-sol-types", + "alloy", "bs58", "serde", "serde_with", "thiserror 1.0.69", - "url", ] [[package]] @@ -7691,9 +7744,9 @@ dependencies = [ [[package]] name = "wasmtimer" -version = "0.2.1" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7ed9d8b15c7fb594d72bfb4b5a276f3d2029333cd93a932f376f5937f6f80ee" +checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23" dependencies = [ "futures", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index 89bee41c..fd64e46c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,16 +17,6 @@ resolver = "2" opt-level = 3 [workspace.dependencies] -alloy = { version = "=0.5.4", features = [ - "kzg", - "signer-mnemonic", - "dyn-abi", - "sol-types", - "signer-local", - "eip712", - "rlp", - "signers", -], default-features = false } clap = "4.4.3" lazy_static = "1.4.0" axum = { version = "0.7.9", default-features = false, features = [ @@ -62,14 +52,23 @@ uuid = { version = "1.11.0", features = ["v7"] } tracing = { version = "0.1.40", default-features = false } bigdecimal = "0.4.3" build-info = "0.0.39" -tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "61b47b3", default-features = false } -tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "61b47b3", default-features = false } +tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1c6e29f", default-features = false } +tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1c6e29f", default-features = false } tracing-subscriber = { version = "0.3", features = [ "json", "env-filter", "ansi", ], default-features = false } -thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "1663534fc1738e2db1b11cb54b5bb478ee970d40" } +thegraph-core = { version = "0.9.6", features = [ + "attestation", + "alloy-eip712", + "alloy-sol-types", + "alloy-rlp", + "alloy-signers", + "alloy-signer-local", + "alloy-signer-mnemonic", + "serde" +] } thegraph-graphql-http = { version = "0.3.2", features = ["reqwest"] } graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] } bip39 = "2.0.0" diff --git a/crates/allocation/Cargo.toml b/crates/allocation/Cargo.toml index 99453d25..47311d0e 100644 --- a/crates/allocation/Cargo.toml +++ b/crates/allocation/Cargo.toml @@ -6,6 +6,5 @@ edition = "2021" [dependencies] indexer-query = { path = "../query" } serde = { workspace = true, features = ["derive"] } -alloy.workspace = true thegraph-core.workspace = true anyhow.workspace = true diff --git a/crates/allocation/src/lib.rs b/crates/allocation/src/lib.rs index 8f2f296c..360ea786 100644 --- a/crates/allocation/src/lib.rs +++ b/crates/allocation/src/lib.rs @@ -3,10 +3,12 @@ use std::str::FromStr; -use alloy::primitives::U256; use indexer_query::allocations_query; use serde::{Deserialize, Deserializer}; -use thegraph_core::{Address, DeploymentId}; +use thegraph_core::{ + alloy::primitives::{Address, U256}, + DeploymentId, +}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Allocation { diff --git a/crates/attestation/Cargo.toml b/crates/attestation/Cargo.toml index 621651c5..71a4c08d 100644 --- a/crates/attestation/Cargo.toml +++ b/crates/attestation/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" [dependencies] indexer-allocation = { path = "../allocation" } -alloy.workspace = true thegraph-core.workspace = true anyhow.workspace = true diff --git a/crates/attestation/src/lib.rs b/crates/attestation/src/lib.rs index 9adad16f..baf17988 100644 --- a/crates/attestation/src/lib.rs +++ b/crates/attestation/src/lib.rs @@ -1,16 +1,20 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::{ - dyn_abi::Eip712Domain, - signers::{ - k256, - local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, +use indexer_allocation::Allocation; +use thegraph_core::{ + alloy::{ + primitives::{Address, ChainId}, + signers::{ + k256, + local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, + }, + sol_types::Eip712Domain, }, + attestation, + attestation::Attestation, + DeploymentId, }; -use thegraph_core::{attestation, Address, Attestation, ChainId, DeploymentId}; - -use indexer_allocation::Allocation; pub fn derive_key_pair( indexer_mnemonic: &str, @@ -92,7 +96,7 @@ fn wallet_for_allocation( // 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. + // epoch later. So try both. for created_at_epoch in [allocation.created_at_epoch, allocation.created_at_epoch - 1] { // The allocation ID is the address of a unique key pair, we just // need to find the right one by enumerating them all @@ -117,14 +121,20 @@ fn wallet_for_allocation( #[cfg(test)] mod tests { - use alloy::primitives::U256; use std::str::FromStr; - use test_log::test; use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment}; use test_assets::DISPUTE_MANAGER_ADDRESS; + use test_log::test; + use thegraph_core::{ + alloy::{ + primitives::{address, Address, U256}, + signers::local::PrivateKeySigner, + }, + deployment_id, DeploymentId, + }; - use super::*; + use super::{derive_key_pair, AttestationSigner}; const INDEXER_OPERATOR_MNEMONIC: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; @@ -134,30 +144,28 @@ mod tests { derive_key_pair( INDEXER_OPERATOR_MNEMONIC, 953, - &DeploymentId::from_str( + &deployment_id!( "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a" - ) - .unwrap(), + ), 0 ) .unwrap() .address(), - Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap() + address!("fa44c72b753a66591f241c7dc04e8178c30e13af") ); assert_eq!( derive_key_pair( INDEXER_OPERATOR_MNEMONIC, 940, - &DeploymentId::from_str( + &deployment_id!( "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a" - ) - .unwrap(), + ), 2 ) .unwrap() .address(), - Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap() + address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658") ); } @@ -166,13 +174,12 @@ mod tests { // Note that we use `derive_key_pair` to derive the private key let allocation = Allocation { - id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(), + id: address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658"), status: AllocationStatus::Null, subgraph_deployment: SubgraphDeployment { - id: DeploymentId::from_str( - "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a", - ) - .unwrap(), + id: deployment_id!( + "0xbbde25a2c85f55b53b7698b9476610c3d1202d88870e66502ab0076b7218f98a" + ), denied_at: None, }, indexer: Address::ZERO, @@ -192,7 +199,7 @@ mod tests { INDEXER_OPERATOR_MNEMONIC, &allocation, 1, - *DISPUTE_MANAGER_ADDRESS + DISPUTE_MANAGER_ADDRESS ) .unwrap() .signer @@ -213,7 +220,7 @@ mod tests { let allocation = Allocation { // Purposefully wrong address - id: Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(), + id: address!("deadbeefcafebabedeadbeefcafebabedeadbeef"), status: AllocationStatus::Null, subgraph_deployment: SubgraphDeployment { id: DeploymentId::from_str( @@ -237,7 +244,7 @@ mod tests { INDEXER_OPERATOR_MNEMONIC, &allocation, 1, - *DISPUTE_MANAGER_ADDRESS + DISPUTE_MANAGER_ADDRESS ) .is_err()); } diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index 078a6bba..9d599cb3 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -4,7 +4,6 @@ version = "1.2.2" edition = "2021" [dependencies] -alloy.workspace = true serde.workspace = true thegraph-core.workspace = true tracing.workspace = true diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 6604ca1e..3315dfe6 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -1,29 +1,26 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; -use figment::{ - providers::{Env, Format, Toml}, - Figment, -}; -use serde_repr::Deserialize_repr; -use serde_with::DurationSecondsWithFrac; use std::{ collections::HashMap, + env, net::{Ipv4Addr, SocketAddr, SocketAddrV4}, path::PathBuf, str::FromStr, time::Duration, }; -use tracing::warn; -use alloy::primitives::Address; +use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; use bip39::Mnemonic; +use figment::{ + providers::{Env, Format, Toml}, + Figment, +}; use regex::Regex; use serde::Deserialize; -use serde_with::serde_as; -use std::env; -use thegraph_core::DeploymentId; +use serde_repr::Deserialize_repr; +use serde_with::{serde_as, DurationSecondsWithFrac}; +use thegraph_core::{alloy::primitives::Address, DeploymentId}; use url::Url; use crate::NonZeroGRT; @@ -57,7 +54,7 @@ impl<'de> Deserialize<'de> for ConfigWrapper { D: serde::Deserializer<'de>, { let config: Config = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown configuration field: {}", path); + tracing::warn!("Ignoring unknown configuration field: {}", path); })?; Ok(ConfigWrapper(config)) @@ -158,7 +155,7 @@ impl Config { x if *x <= 1.into() => { return Err("trigger_value_divisor must be greater than 1".to_string()) } - x if *x > 1.into() && *x < 10.into() => warn!( + x if *x > 1.into() && *x < 10.into() => tracing::warn!( "It's recommended that trigger_value_divisor \ be a value greater than 10." ), @@ -176,7 +173,7 @@ impl Config { .to_u128() .unwrap() { - warn!( + tracing::warn!( "Trigger value is too low, currently below 0.1 GRT. \ Please modify `max_amount_willing_to_lose_grt` or `trigger_value_divisor`. \ It is best to have a higher trigger value, ideally above 1 GRT. \ @@ -190,7 +187,7 @@ impl Config { let usual_grt_price = BigDecimal::from_str("0.0001").unwrap() * ten; if self.tap.max_amount_willing_to_lose_grt.get_value() < usual_grt_price.to_u128().unwrap() { - warn!( + tracing::warn!( "Your `max_amount_willing_to_lose_grt` value is too close to zero. \ This may deny the sender too often or even break the whole system. \ It's recommended it to be a value greater than 100x an usual query price." @@ -200,7 +197,7 @@ impl Config { if self.subgraphs.escrow.config.syncing_interval_secs < Duration::from_secs(10) || self.subgraphs.network.config.syncing_interval_secs < Duration::from_secs(10) { - warn!( + tracing::warn!( "Your `syncing_interval_secs` value it too low. \ This may overload your graph-node instance, \ a recommended value is about 60 seconds." @@ -210,7 +207,7 @@ impl Config { if self.subgraphs.escrow.config.syncing_interval_secs > Duration::from_secs(600) || self.subgraphs.network.config.syncing_interval_secs > Duration::from_secs(600) { - warn!( + tracing::warn!( "Your `syncing_interval_secs` value it too high. \ This may cause issues while reacting to updates in the blockchain. \ a recommended value is about 60 seconds." @@ -218,7 +215,7 @@ impl Config { } if self.tap.rav_request.timestamp_buffer_secs < Duration::from_secs(10) { - warn!( + tracing::warn!( "Your `tap.rav_request.timestamp_buffer_secs` value it too low. \ You may discart receipts in case of any synchronization issues, \ a recommended value is about 30 seconds." @@ -423,15 +420,15 @@ pub struct RavRequestConfig { #[cfg(test)] mod tests { - use alloy::primitives::FixedBytes; + use std::{env, fs, path::PathBuf}; + use figment::value::Uncased; use sealed_test::prelude::*; - use std::{env, fs, path::PathBuf, str::FromStr}; + use thegraph_core::alloy::primitives::address; use tracing_test::traced_test; - use crate::{Config, ConfigPrefix}; - use super::{DatabaseConfig, SHARED_PREFIX}; + use crate::{Config, ConfigPrefix}; #[test] fn test_minimal_config() { @@ -451,9 +448,7 @@ mod tests { ) .unwrap(); max_config.dips = Some(crate::DipsConfig { - allowed_payers: vec![thegraph_core::Address( - FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(), - )], + allowed_payers: vec![address!("3333333333333333333333333333333333333333")], cancellation_time_tolerance: None, }); diff --git a/crates/dips/Cargo.toml b/crates/dips/Cargo.toml index cf481f7d..5cd5cb54 100644 --- a/crates/dips/Cargo.toml +++ b/crates/dips/Cargo.toml @@ -4,9 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy.workspace = true thiserror.workspace = true anyhow.workspace = true -alloy-sol-types = "=0.8.15" -alloy-rlp = "0.3.9" +alloy-rlp = "0.3.9" thegraph-core.workspace = true diff --git a/crates/dips/src/lib.rs b/crates/dips/src/lib.rs index 80d559e4..b14b77b0 100644 --- a/crates/dips/src/lib.rs +++ b/crates/dips/src/lib.rs @@ -1,17 +1,18 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::str::FromStr; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; - -pub use alloy; -pub use alloy_rlp; - -use alloy::core::primitives::Address; -use alloy::rlp::{RlpDecodable, RlpEncodable}; -use alloy::{primitives::PrimitiveSignature as Signature, signers::SignerSync}; -use alloy_rlp::Encodable; -use thegraph_core::alloy_sol_types::{sol, Eip712Domain, SolStruct}; +use std::{ + str::FromStr, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; + +use alloy_rlp::{Encodable, RlpDecodable, RlpEncodable}; +use thegraph_core::alloy::{ + primitives::{Address, PrimitiveSignature as Signature}, + signers::SignerSync, + sol, + sol_types::{Eip712Domain, SolStruct}, +}; use thiserror::Error; sol! { @@ -212,10 +213,14 @@ impl SignedCancellationRequest { mod test { use std::time::{Duration, SystemTime, UNIX_EPOCH}; - use alloy::primitives::{Address, FixedBytes, U256}; - use alloy::signers::local::PrivateKeySigner; - use alloy::sol_types::SolStruct; - use thegraph_core::attestation::eip712_domain; + use thegraph_core::{ + alloy::{ + primitives::{Address, FixedBytes, U256}, + signers::local::PrivateKeySigner, + sol_types::SolStruct, + }, + attestation::eip712_domain, + }; use crate::{ AgreementVoucherValidationError, CancellationRequest, CancellationRequestValidationError, diff --git a/crates/monitor/Cargo.toml b/crates/monitor/Cargo.toml index f3bf6c43..15bbde36 100644 --- a/crates/monitor/Cargo.toml +++ b/crates/monitor/Cargo.toml @@ -9,7 +9,6 @@ indexer-allocation = { path = "../allocation" } indexer-attestation = { path = "../attestation" } indexer-watcher = { path = "../watcher" } thiserror.workspace = true -alloy.workspace = true anyhow.workspace = true reqwest = { workspace = true, features = ["json"] } tracing.workspace = true diff --git a/crates/monitor/src/allocations.rs b/crates/monitor/src/allocations.rs index 2fd88c1b..4f4a926f 100644 --- a/crates/monitor/src/allocations.rs +++ b/crates/monitor/src/allocations.rs @@ -1,17 +1,19 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::client::SubgraphClient; -use alloy::{primitives::Address, primitives::TxHash}; -use indexer_allocation::Allocation; -use indexer_query::allocations_query::{self, AllocationsQuery}; -use indexer_watcher::new_watcher; use std::{ collections::HashMap, time::{Duration, SystemTime, UNIX_EPOCH}, }; + +use indexer_allocation::Allocation; +use indexer_query::allocations_query::{self, AllocationsQuery}; +use indexer_watcher::new_watcher; +use thegraph_core::alloy::primitives::{Address, TxHash}; use tokio::sync::watch::Receiver; +use crate::client::SubgraphClient; + /// Receiver of Map between allocation id and allocation struct pub type AllocationWatcher = Receiver>; @@ -88,13 +90,15 @@ pub async fn get_allocations( #[cfg(test)] mod test { - const NETWORK_SUBGRAPH_URL: &str = - "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum"; - use std::str::FromStr; + use std::time::Duration; + use thegraph_core::alloy::primitives::address; + + use super::get_allocations; use crate::client::{DeploymentDetails, SubgraphClient}; - use super::*; + const NETWORK_SUBGRAPH_URL: &str = + "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum"; async fn network_subgraph_client() -> &'static SubgraphClient { Box::leak(Box::new( @@ -112,7 +116,7 @@ mod test { async fn test_network_query() { let result = get_allocations( network_subgraph_client().await, - Address::from_str("0x326c584e0f0eab1f1f83c93cc6ae1acc0feba0bc").unwrap(), + address!("326c584e0f0eab1f1f83c93cc6ae1acc0feba0bc"), Duration::from_secs(1712448507), ) .await; @@ -124,7 +128,7 @@ mod test { async fn test_network_query_empty_response() { let result = get_allocations( network_subgraph_client().await, - Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(), + address!("deadbeefcafebabedeadbeefcafebabedeadbeef"), Duration::from_secs(1712448507), ) .await diff --git a/crates/monitor/src/attestation.rs b/crates/monitor/src/attestation.rs index 3bb62575..3dc64028 100644 --- a/crates/monitor/src/attestation.rs +++ b/crates/monitor/src/attestation.rs @@ -1,15 +1,17 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, +}; + use bip39::Mnemonic; use indexer_allocation::Allocation; use indexer_attestation::AttestationSigner; use indexer_watcher::join_and_map_watcher; -use std::sync::Arc; -use std::{collections::HashMap, sync::Mutex}; -use thegraph_core::{Address, ChainId}; +use thegraph_core::alloy::primitives::{Address, ChainId}; use tokio::sync::watch::Receiver; -use tracing::warn; use crate::{AllocationWatcher, DisputeManagerWatcher}; @@ -48,7 +50,7 @@ fn modify_sigers( attestation_signers_map: &'static Mutex>, allocations: &HashMap, dispute_manager: &Address, -) -> HashMap { +) -> HashMap { let mut signers = attestation_signers_map.lock().unwrap(); // Remove signers for allocations that are no longer active or recently closed signers.retain(|id, _| allocations.contains_key(id)); @@ -63,7 +65,7 @@ fn modify_sigers( signers.insert(*id, signer); } Err(e) => { - warn!( + tracing::warn!( "Failed to establish signer for allocation {}, deployment {}, createdAtEpoch {}: {}", allocation.id, allocation.subgraph_deployment.id, allocation.created_at_epoch, e @@ -78,16 +80,17 @@ fn modify_sigers( #[cfg(test)] mod tests { - use tokio::sync::watch; + use std::collections::HashMap; use test_assets::{DISPUTE_MANAGER_ADDRESS, INDEXER_ALLOCATIONS, INDEXER_MNEMONIC}; + use tokio::sync::watch; - use super::*; + use super::attestation_signers; #[tokio::test] async fn test_attestation_signers_update_with_allocations() { let (allocations_tx, allocations_rx) = watch::channel(HashMap::new()); - let (_, dispute_manager_rx) = watch::channel(*DISPUTE_MANAGER_ADDRESS); + let (_, dispute_manager_rx) = watch::channel(DISPUTE_MANAGER_ADDRESS); let mut signers = attestation_signers( allocations_rx, INDEXER_MNEMONIC.clone(), diff --git a/crates/monitor/src/client/monitor.rs b/crates/monitor/src/client/monitor.rs index 53ba9de1..17273ff7 100644 --- a/crates/monitor/src/client/monitor.rs +++ b/crates/monitor/src/client/monitor.rs @@ -8,13 +8,12 @@ use indexer_query::{ deployment_status_query::{self, Health}, DeploymentStatusQuery, }; +use indexer_watcher::new_watcher; use reqwest::Url; use serde::Deserialize; use thegraph_core::DeploymentId; use tokio::sync::watch::Receiver; -use indexer_watcher::new_watcher; - #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] pub struct DeploymentStatus { pub synced: bool, @@ -63,13 +62,15 @@ pub async fn check_deployment_status( #[cfg(test)] mod tests { - use std::str::FromStr; - + use reqwest::Url; use serde_json::json; - use wiremock::matchers::{method, path}; - use wiremock::{Mock, MockServer, ResponseTemplate}; + use thegraph_core::deployment_id; + use wiremock::{ + matchers::{method, path}, + Mock, MockServer, ResponseTemplate, + }; - use super::*; + use super::{monitor_deployment_status, DeploymentStatus}; #[tokio::test] async fn test_parses_synced_and_healthy_response() { @@ -80,8 +81,7 @@ mod tests { .unwrap() .join("/status") .unwrap(); - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); Mock::given(method("POST")) .and(path("/status")) @@ -120,8 +120,7 @@ mod tests { .unwrap() .join("/status") .unwrap(); - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); Mock::given(method("POST")) .and(path("/status")) @@ -160,8 +159,7 @@ mod tests { .unwrap() .join("/status") .unwrap(); - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); Mock::given(method("POST")) .and(path("/status")) @@ -200,8 +198,7 @@ mod tests { .unwrap() .join("/status") .unwrap(); - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); Mock::given(method("POST")) .and(path("/status")) diff --git a/crates/monitor/src/client/subgraph_client.rs b/crates/monitor/src/client/subgraph_client.rs index 12009168..a0f18fb0 100644 --- a/crates/monitor/src/client/subgraph_client.rs +++ b/crates/monitor/src/client/subgraph_client.rs @@ -1,14 +1,14 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use super::monitor::{monitor_deployment_status, DeploymentStatus}; use anyhow::anyhow; use axum::body::Bytes; use graphql_client::GraphQLQuery; use reqwest::{header, Url}; use thegraph_core::DeploymentId; use tokio::sync::watch::Receiver; -use tracing::warn; + +use super::monitor::{monitor_deployment_status, DeploymentStatus}; pub type ResponseResult = Result; @@ -201,7 +201,7 @@ impl SubgraphClient { if let Some(ref local_client) = self.local_client { match local_client.query::(variables.clone()).await { Ok(response) => return Ok(response), - Err(err) => warn!( + Err(err) => tracing::warn!( "Failed to query local subgraph deployment `{}`, trying remote deployment next: {}", local_client.query_url, err ), @@ -213,9 +213,10 @@ impl SubgraphClient { .query::(variables) .await .map_err(|err| { - warn!( + tracing::warn!( "Failed to query remote subgraph deployment `{}`: {}", - self.remote_client.query_url, err + self.remote_client.query_url, + err ); err @@ -228,7 +229,7 @@ impl SubgraphClient { if let Some(ref local_client) = self.local_client { match local_client.query_raw(query.clone()).await { Ok(response) => return Ok(response), - Err(err) => warn!( + Err(err) => tracing::warn!( "Failed to query local subgraph deployment `{}`, trying remote deployment next: {}", local_client.query_url, err ), @@ -237,9 +238,10 @@ impl SubgraphClient { // Try the remote client self.remote_client.query_raw(query).await.map_err(|err| { - warn!( + tracing::warn!( "Failed to query remote subgraph deployment `{}`: {}", - self.remote_client.query_url, err + self.remote_client.query_url, + err ); err @@ -249,14 +251,15 @@ impl SubgraphClient { #[cfg(test)] mod test { - use std::str::FromStr; - use indexer_query::{current_epoch, user_query, CurrentEpoch, UserQuery}; use serde_json::json; - use wiremock::matchers::{method, path}; - use wiremock::{Mock, MockServer, ResponseTemplate}; + use thegraph_core::deployment_id; + use wiremock::{ + matchers::{method, path}, + Mock, MockServer, ResponseTemplate, + }; - use super::*; + use super::{DeploymentDetails, SubgraphClient}; const NETWORK_SUBGRAPH_URL: &str = "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-goerli"; @@ -311,8 +314,7 @@ mod test { #[tokio::test] async fn test_uses_local_deployment_if_healthy_and_synced() { - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); let mock_server_status = MockServer::start().await; mock_server_status @@ -392,8 +394,7 @@ mod test { #[tokio::test] async fn test_uses_query_url_if_local_deployment_is_unhealthy() { - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); let mock_server_status = MockServer::start().await; mock_server_status @@ -473,8 +474,7 @@ mod test { #[tokio::test] async fn test_uses_query_url_if_local_deployment_is_not_synced() { - let deployment = - DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap(); + let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); let mock_server_status = MockServer::start().await; mock_server_status diff --git a/crates/monitor/src/deployment_to_allocation.rs b/crates/monitor/src/deployment_to_allocation.rs index d8e53e77..ce961148 100644 --- a/crates/monitor/src/deployment_to_allocation.rs +++ b/crates/monitor/src/deployment_to_allocation.rs @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 use std::collections::HashMap; -use thegraph_core::{Address, DeploymentId}; -use tokio::sync::watch::Receiver; use indexer_watcher::map_watcher; +use thegraph_core::{alloy::primitives::Address, DeploymentId}; +use tokio::sync::watch::Receiver; use crate::AllocationWatcher; diff --git a/crates/monitor/src/dispute_manager.rs b/crates/monitor/src/dispute_manager.rs index f867ce84..6f2b2459 100644 --- a/crates/monitor/src/dispute_manager.rs +++ b/crates/monitor/src/dispute_manager.rs @@ -1,14 +1,16 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::client::SubgraphClient; -use alloy::primitives::Address; +use std::time::Duration; + use anyhow::Error; use indexer_query::dispute_manager::{self, DisputeManager}; use indexer_watcher::new_watcher; -use std::time::Duration; +use thegraph_core::alloy::primitives::Address; use tokio::sync::watch::Receiver; +use crate::client::SubgraphClient; + /// Watcher for Dispute Manager Address pub type DisputeManagerWatcher = Receiver
; @@ -31,6 +33,8 @@ pub async fn dispute_manager( #[cfg(test)] mod test { + use std::time::Duration; + use serde_json::json; use test_assets::DISPUTE_MANAGER_ADDRESS; use tokio::time::sleep; @@ -39,9 +43,8 @@ mod test { Mock, MockServer, ResponseTemplate, }; - use crate::{client::DeploymentDetails, client::SubgraphClient}; - - use super::*; + use super::dispute_manager; + use crate::client::{DeploymentDetails, SubgraphClient}; async fn setup_mock_network_subgraph() -> (&'static SubgraphClient, MockServer) { // Set up a mock network subgraph @@ -84,6 +87,6 @@ mod test { .unwrap(); sleep(Duration::from_millis(50)).await; let result = *dispute_manager.borrow(); - assert_eq!(result, *DISPUTE_MANAGER_ADDRESS); + assert_eq!(result, DISPUTE_MANAGER_ADDRESS); } } diff --git a/crates/monitor/src/escrow_accounts.rs b/crates/monitor/src/escrow_accounts.rs index 0ae8f11f..1fb36b7f 100644 --- a/crates/monitor/src/escrow_accounts.rs +++ b/crates/monitor/src/escrow_accounts.rs @@ -7,12 +7,11 @@ use std::{ time::Duration, }; -use alloy::primitives::{Address, U256}; use anyhow::{anyhow, Result}; use indexer_query::escrow_account::{self, EscrowAccountQuery}; +use thegraph_core::alloy::primitives::{Address, U256}; use thiserror::Error; use tokio::sync::watch::Receiver; -use tracing::{error, warn}; use crate::client::SubgraphClient; @@ -133,7 +132,7 @@ async fn get_escrow_accounts( U256::from_str(&account.total_amount_thawing)?, ) .unwrap_or_else(|| { - warn!( + tracing::warn!( "Balance minus total amount thawing underflowed for account {}. \ Setting balance to 0, no queries will be served for this sender.", account.sender.id @@ -166,17 +165,20 @@ async fn get_escrow_accounts( #[cfg(test)] mod tests { + use std::time::Duration; + use test_assets::{ ESCROW_ACCOUNTS_BALANCES, ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS, ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS, }; use test_log::test; - use wiremock::matchers::{method, path}; - use wiremock::{Mock, MockServer, ResponseTemplate}; - - use crate::client::DeploymentDetails; + use wiremock::{ + matchers::{method, path}, + Mock, MockServer, ResponseTemplate, + }; - use super::*; + use super::{escrow_accounts, EscrowAccounts}; + use crate::client::{DeploymentDetails, SubgraphClient}; #[test] fn test_new_escrow_accounts() { @@ -222,7 +224,7 @@ mod tests { let mut accounts = escrow_accounts( escrow_subgraph, - *test_assets::INDEXER_ADDRESS, + test_assets::INDEXER_ADDRESS, Duration::from_secs(60), true, ) diff --git a/crates/query/Cargo.toml b/crates/query/Cargo.toml index a4331d2e..e8903211 100644 --- a/crates/query/Cargo.toml +++ b/crates/query/Cargo.toml @@ -7,5 +7,4 @@ edition = "2021" graphql_client.workspace = true thegraph-core.workspace = true serde.workspace = true -alloy.workspace = true anyhow.workspace = true diff --git a/crates/query/src/lib.rs b/crates/query/src/lib.rs index 7c133a6c..38c8a43e 100644 --- a/crates/query/src/lib.rs +++ b/crates/query/src/lib.rs @@ -4,8 +4,8 @@ use graphql_client::GraphQLQuery; pub mod dispute_manager { - use alloy::primitives::Address; use graphql_client::GraphQLQuery; + use thegraph_core::alloy::primitives::Address; type Bytes = Address; #[derive(GraphQLQuery)] @@ -37,8 +37,8 @@ pub mod escrow_account { } pub mod allocations_query { - use alloy::primitives::{B256, U256}; use graphql_client::GraphQLQuery; + use thegraph_core::alloy::primitives::{B256, U256}; type BigInt = U256; type Bytes = B256; diff --git a/crates/service/Cargo.toml b/crates/service/Cargo.toml index 5d4b2f72..167e19c2 100644 --- a/crates/service/Cargo.toml +++ b/crates/service/Cargo.toml @@ -38,19 +38,18 @@ base64.workspace = true graphql = { git = "https://github.com/edgeandnode/toolshed", tag = "graphql-v0.3.0" } tap_core.workspace = true uuid.workspace = true -alloy.workspace = true typed-builder.workspace = true tower_governor = { version = "0.5.0", features = ["axum"] } governor = "0.8.0" tower-http = { version = "0.6.2", features = [ - "auth", - "cors", - "normalize-path", - "trace", + "auth", + "cors", + "normalize-path", + "trace", ] } autometrics = { version = "1.0.1", features = ["prometheus-exporter"] } axum-extra = { version = "0.9.3", features = [ - "typed-header", + "typed-header", ], default-features = false } tokio-util = "0.7.10" cost-model = { git = "https://github.com/graphprotocol/agora", rev = "3ed34ca" } diff --git a/crates/service/src/database/cost_model.rs b/crates/service/src/database/cost_model.rs index 6a26e29d..1ae10629 100644 --- a/crates/service/src/database/cost_model.rs +++ b/crates/service/src/database/cost_model.rs @@ -1,10 +1,11 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use std::{collections::HashSet, str::FromStr}; + use serde::{Deserialize, Serialize}; use serde_json::Value; use sqlx::PgPool; -use std::{collections::HashSet, str::FromStr}; use thegraph_core::{DeploymentId, ParseDeploymentIdError}; /// Internal cost model representation as stored in the database. @@ -193,6 +194,7 @@ pub(crate) mod test { use std::str::FromStr; use sqlx::PgPool; + use thegraph_core::deployment_id; use super::*; @@ -388,8 +390,7 @@ pub(crate) mod test { } // Third test: query for missing cost model - let missing_deployment = - DeploymentId::from_str("Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap(); + let missing_deployment = deployment_id!("Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); let models = cost_models(&pool, &[missing_deployment]) .await .expect("cost models query for missing deployment"); @@ -412,7 +413,7 @@ pub(crate) mod test { ) .unwrap(); let deployment_id_from_hash = - DeploymentId::from_str("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss").unwrap(); + deployment_id!("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss"); assert_eq!(deployment_id_from_bytes, deployment_id_from_hash); @@ -453,8 +454,7 @@ pub(crate) mod test { } // Test that querying a non-existing deployment returns the default cost model - let missing_deployment = - DeploymentId::from_str("Qmnononononononononononononononononononononono").unwrap(); + let missing_deployment = deployment_id!("Qmnononononononononononononononononononononono"); let model = cost_model(&pool, &missing_deployment) .await .expect("cost model query") diff --git a/crates/service/src/database/dips.rs b/crates/service/src/database/dips.rs index 317b341f..eb667764 100644 --- a/crates/service/src/database/dips.rs +++ b/crates/service/src/database/dips.rs @@ -3,13 +3,12 @@ use std::collections::HashMap; -use alloy::rlp::Decodable; use anyhow::bail; use axum::async_trait; use build_info::chrono::Utc; - use indexer_dips::{SignedCancellationRequest, SignedIndexingAgreementVoucher}; use sqlx::PgPool; +use thegraph_core::alloy::rlp::Decodable; use uuid::Uuid; #[async_trait] diff --git a/crates/service/src/database/mod.rs b/crates/service/src/database/mod.rs index 96d78e94..e97d4137 100644 --- a/crates/service/src/database/mod.rs +++ b/crates/service/src/database/mod.rs @@ -7,13 +7,12 @@ pub mod dips; use std::time::Duration; use sqlx::{postgres::PgPoolOptions, PgPool}; -use tracing::debug; const DATABASE_TIMEOUT: Duration = Duration::from_secs(30); const DATABASE_MAX_CONNECTIONS: u32 = 50; pub async fn connect(url: &str) -> PgPool { - debug!("Connecting to database"); + tracing::debug!("Connecting to database"); PgPoolOptions::new() .max_connections(DATABASE_MAX_CONNECTIONS) diff --git a/crates/service/src/error.rs b/crates/service/src/error.rs index eba52af1..86a13622 100644 --- a/crates/service/src/error.rs +++ b/crates/service/src/error.rs @@ -11,8 +11,7 @@ use axum::{ use indexer_monitor::EscrowAccountsError; use reqwest::StatusCode; use serde::Serialize; -use tap_core::receipt::ReceiptError; -use tap_core::Error as TapError; +use tap_core::{receipt::ReceiptError, Error as TapError}; use thegraph_core::DeploymentId; use thiserror::Error; diff --git a/crates/service/src/main.rs b/crates/service/src/main.rs index dbb359e9..9214c770 100644 --- a/crates/service/src/main.rs +++ b/crates/service/src/main.rs @@ -4,8 +4,7 @@ use std::process::ExitCode; use indexer_service_rs::service::run; -use tracing::level_filters::LevelFilter; -use tracing::subscriber::set_global_default; +use tracing::{level_filters::LevelFilter, subscriber::set_global_default}; use tracing_subscriber::{EnvFilter, FmtSubscriber}; #[tokio::main] diff --git a/crates/service/src/metrics.rs b/crates/service/src/metrics.rs index 56fb04ba..994bd988 100644 --- a/crates/service/src/metrics.rs +++ b/crates/service/src/metrics.rs @@ -10,7 +10,6 @@ use prometheus::{ }; use reqwest::StatusCode; use tokio::net::TcpListener; -use tracing::{error, info}; lazy_static! { /// Metric registered in global registry for @@ -37,7 +36,7 @@ lazy_static! { } pub fn serve_metrics(host_and_port: SocketAddr) { - info!(address = %host_and_port, "Serving prometheus metrics"); + tracing::info!(address = %host_and_port, "Serving prometheus metrics"); tokio::spawn(async move { let router = Router::new().route( @@ -49,7 +48,7 @@ pub fn serve_metrics(host_and_port: SocketAddr) { match encoder.encode_to_string(&metric_families) { Ok(s) => (StatusCode::OK, s), Err(e) => { - error!("Error encoding metrics: {}", e); + tracing::error!("Error encoding metrics: {}", e); ( StatusCode::INTERNAL_SERVER_ERROR, format!("Error encoding metrics: {}", e), diff --git a/crates/service/src/middleware/allocation.rs b/crates/service/src/middleware/allocation.rs index 9779f90e..b6790a5d 100644 --- a/crates/service/src/middleware/allocation.rs +++ b/crates/service/src/middleware/allocation.rs @@ -3,17 +3,17 @@ use std::collections::HashMap; -use alloy::primitives::Address; use axum::{ extract::{Request, State}, middleware::Next, response::Response, }; use tap_core::receipt::SignedReceipt; -use thegraph_core::DeploymentId; +use thegraph_core::{alloy::primitives::Address, DeploymentId}; use tokio::sync::watch; -/// The current query Allocation Id address +/// The current query Allocation ID address +// TODO: Use thegraph-core::AllocationId instead #[derive(Clone)] pub struct Allocation(pub Address); @@ -58,11 +58,6 @@ pub async fn allocation_middleware( #[cfg(test)] mod tests { - use crate::middleware::allocation::Allocation; - - use super::{allocation_middleware, AllocationState}; - - use alloy::primitives::Address; use axum::{ body::Body, http::{Extensions, Request}, @@ -72,14 +67,17 @@ mod tests { }; use reqwest::StatusCode; use test_assets::{create_signed_receipt, SignedReceiptRequest, ESCROW_SUBGRAPH_DEPLOYMENT}; + use thegraph_core::alloy::primitives::Address; use tokio::sync::watch; use tower::ServiceExt; + use super::{allocation_middleware, Allocation, AllocationState}; + #[tokio::test] async fn test_allocation_middleware() { - let deployment = *ESCROW_SUBGRAPH_DEPLOYMENT; - let deployment_to_allocation = - watch::channel(vec![(deployment, Address::ZERO)].into_iter().collect()).1; + let deployment = ESCROW_SUBGRAPH_DEPLOYMENT; + let (_, deployment_to_allocation) = + watch::channel(vec![(deployment, Address::ZERO)].into_iter().collect()); let state = AllocationState { deployment_to_allocation, }; diff --git a/crates/service/src/middleware/attestation.rs b/crates/service/src/middleware/attestation.rs index 24d7ae88..2110eb96 100644 --- a/crates/service/src/middleware/attestation.rs +++ b/crates/service/src/middleware/attestation.rs @@ -9,11 +9,10 @@ use axum::{ middleware::Next, response::{IntoResponse, Response}, }; +use indexer_attestation::AttestationSigner; use reqwest::StatusCode; use serde::Serialize; -use thegraph_core::Attestation; - -use indexer_attestation::AttestationSigner; +use thegraph_core::attestation::Attestation; use crate::error::StatusCodeExt; @@ -104,7 +103,6 @@ impl IntoResponse for AttestationError { #[cfg(test)] mod tests { - use alloy::primitives::Address; use axum::{ body::{to_bytes, Body}, http::{Request, Response}, @@ -116,6 +114,7 @@ mod tests { use indexer_attestation::AttestationSigner; use reqwest::StatusCode; use test_assets::{INDEXER_ALLOCATIONS, INDEXER_MNEMONIC}; + use thegraph_core::alloy::primitives::Address; use tower::ServiceExt; use crate::middleware::{ diff --git a/crates/service/src/middleware/attestation_signer.rs b/crates/service/src/middleware/attestation_signer.rs index f859292e..bddd0c07 100644 --- a/crates/service/src/middleware/attestation_signer.rs +++ b/crates/service/src/middleware/attestation_signer.rs @@ -1,14 +1,15 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::primitives::Address; +use std::collections::HashMap; + use axum::{ extract::{Request, State}, middleware::Next, response::Response, }; use indexer_attestation::AttestationSigner; -use std::collections::HashMap; +use thegraph_core::alloy::primitives::Address; use tokio::sync::watch; use super::Allocation; @@ -37,8 +38,6 @@ pub async fn signer_middleware( #[cfg(test)] mod tests { - use crate::middleware::{allocation::Allocation, signer_middleware, AttestationState}; - use axum::{body::Body, http::Request, middleware::from_fn_with_state, routing::get, Router}; use indexer_attestation::AttestationSigner; use indexer_monitor::attestation_signers; @@ -47,14 +46,16 @@ mod tests { use tokio::sync::{mpsc::channel, watch}; use tower::Service; + use crate::middleware::{allocation::Allocation, signer_middleware, AttestationState}; + #[tokio::test] async fn test_attestation_signer_middleware() { - let allocations = (*INDEXER_ALLOCATIONS).clone(); + let allocations = INDEXER_ALLOCATIONS.clone(); let allocation = **allocations.keys().collect::>().first().unwrap(); let (_, allocations_rx) = watch::channel(allocations); - let (_, dispute_manager_rx) = watch::channel(*DISPUTE_MANAGER_ADDRESS); + let (_, dispute_manager_rx) = watch::channel(DISPUTE_MANAGER_ADDRESS); let attestation_signers = attestation_signers( allocations_rx, INDEXER_MNEMONIC.clone(), diff --git a/crates/service/src/middleware/auth.rs b/crates/service/src/middleware/auth.rs index 4c20c60e..f0a6c2cb 100644 --- a/crates/service/src/middleware/auth.rs +++ b/crates/service/src/middleware/auth.rs @@ -13,18 +13,22 @@ pub use tap::tap_receipt_authorize; mod tests { use std::sync::Arc; - use axum::body::Body; - use axum::http::{Request, Response}; + use axum::{ + body::Body, + http::{Request, Response}, + }; use reqwest::{header, StatusCode}; use sqlx::PgPool; use tap_core::{manager::Manager, receipt::checks::CheckList}; + use test_assets::{ + assert_while_retry, create_signed_receipt, SignedReceiptRequest, TAP_EIP712_DOMAIN, + }; use tower::{Service, ServiceBuilder, ServiceExt}; use tower_http::auth::AsyncRequireAuthorizationLayer; - use crate::middleware::auth::{self, Bearer, OrExt}; - use crate::tap::IndexerTapContext; - use test_assets::{ - assert_while_retry, create_signed_receipt, SignedReceiptRequest, TAP_EIP712_DOMAIN, + use crate::{ + middleware::auth::{self, Bearer, OrExt}, + tap::IndexerTapContext, }; const BEARER_TOKEN: &str = "test"; diff --git a/crates/service/src/middleware/auth/tap.rs b/crates/service/src/middleware/auth/tap.rs index f8c42f62..68a58b7a 100644 --- a/crates/service/src/middleware/auth/tap.rs +++ b/crates/service/src/middleware/auth/tap.rs @@ -76,9 +76,7 @@ where mod tests { use core::panic; - use rstest::*; use std::sync::Arc; - use tower::{Service, ServiceBuilder, ServiceExt}; use axum::{ body::Body, @@ -86,6 +84,7 @@ mod tests { }; use prometheus::core::Collector; use reqwest::StatusCode; + use rstest::*; use sqlx::PgPool; use tap_core::{ manager::Manager, @@ -98,6 +97,7 @@ mod tests { use test_assets::{ assert_while_retry, create_signed_receipt, SignedReceiptRequest, TAP_EIP712_DOMAIN, }; + use tower::{Service, ServiceBuilder, ServiceExt}; use tower_http::auth::AsyncRequireAuthorizationLayer; use crate::{ diff --git a/crates/service/src/middleware/deployment.rs b/crates/service/src/middleware/deployment.rs index 45f2e111..d5648f3c 100644 --- a/crates/service/src/middleware/deployment.rs +++ b/crates/service/src/middleware/deployment.rs @@ -20,7 +20,6 @@ pub async fn deployment_middleware(mut request: Request, next: Next) -> Response #[cfg(test)] mod tests { - use super::deployment_middleware; use axum::{ body::Body, http::{Extensions, Request}, @@ -33,11 +32,13 @@ mod tests { use thegraph_core::DeploymentId; use tower::ServiceExt; + use super::deployment_middleware; + #[tokio::test] async fn test_deployment_middleware() { let middleware = from_fn(deployment_middleware); - let deployment = *ESCROW_SUBGRAPH_DEPLOYMENT; + let deployment = ESCROW_SUBGRAPH_DEPLOYMENT; let handle = move |extensions: Extensions| async move { let received_deployment = extensions diff --git a/crates/service/src/middleware/labels.rs b/crates/service/src/middleware/labels.rs index 798d28bb..21e3d6a6 100644 --- a/crates/service/src/middleware/labels.rs +++ b/crates/service/src/middleware/labels.rs @@ -81,16 +81,6 @@ pub async fn labels_middleware(mut request: Request, next: Next) -> Response { #[cfg(test)] mod tests { - use crate::middleware::{ - allocation::Allocation, - labels::{NO_ALLOCATION, NO_DEPLOYMENT_ID, NO_SENDER}, - prometheus_metrics::MetricLabels, - sender::Sender, - }; - - use super::labels_middleware; - - use alloy::primitives::Address; use axum::{ body::Body, http::{Extensions, Request}, @@ -100,13 +90,22 @@ mod tests { }; use reqwest::StatusCode; use test_assets::ESCROW_SUBGRAPH_DEPLOYMENT; + use thegraph_core::alloy::primitives::Address; use tower::ServiceExt; + use super::labels_middleware; + use crate::middleware::{ + allocation::Allocation, + labels::{NO_ALLOCATION, NO_DEPLOYMENT_ID, NO_SENDER}, + prometheus_metrics::MetricLabels, + sender::Sender, + }; + #[tokio::test] async fn test_label_middleware() { let middleware = from_fn(labels_middleware); - let deployment = *ESCROW_SUBGRAPH_DEPLOYMENT; + let deployment = ESCROW_SUBGRAPH_DEPLOYMENT; let sender = Address::ZERO; let allocation = Address::ZERO; diff --git a/crates/service/src/middleware/prometheus_metrics.rs b/crates/service/src/middleware/prometheus_metrics.rs index a16128fd..b9ac1686 100644 --- a/crates/service/src/middleware/prometheus_metrics.rs +++ b/crates/service/src/middleware/prometheus_metrics.rs @@ -3,8 +3,6 @@ //! update metrics in case it succeeds or fails -use axum::http::Request; -use pin_project::pin_project; use std::{ future::Future, pin::Pin, @@ -12,6 +10,9 @@ use std::{ task::{Context, Poll}, time::Instant, }; + +use axum::http::Request; +use pin_project::pin_project; use tower::{Layer, Service}; use crate::error::StatusCodeExt; @@ -141,13 +142,12 @@ mod tests { use reqwest::StatusCode; use tower::{Service, ServiceBuilder, ServiceExt}; + use super::MetricLabelProvider; use crate::{ error::StatusCodeExt, middleware::prometheus_metrics::{MetricLabels, PrometheusMetricsMiddlewareLayer}, }; - use super::MetricLabelProvider; - struct TestLabel; impl MetricLabelProvider for TestLabel { fn get_labels(&self) -> Vec<&str> { diff --git a/crates/service/src/middleware/sender.rs b/crates/service/src/middleware/sender.rs index 7153a317..ecfb48d0 100644 --- a/crates/service/src/middleware/sender.rs +++ b/crates/service/src/middleware/sender.rs @@ -1,7 +1,6 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::{dyn_abi::Eip712Domain, primitives::Address}; use axum::{ extract::{Request, State}, middleware::Next, @@ -9,6 +8,7 @@ use axum::{ }; use indexer_monitor::EscrowAccounts; use tap_core::receipt::SignedReceipt; +use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain}; use tokio::sync::watch; use crate::error::IndexerServiceError; @@ -58,9 +58,6 @@ pub async fn sender_middleware( #[cfg(test)] mod tests { - use crate::middleware::sender::SenderState; - - use super::{sender_middleware, Sender}; use axum::{ body::Body, http::{Extensions, Request}, @@ -77,6 +74,9 @@ mod tests { use tokio::sync::watch; use tower::ServiceExt; + use super::{sender_middleware, Sender}; + use crate::middleware::sender::SenderState; + #[tokio::test] async fn test_sender_middleware() { let escrow_accounts = watch::channel(EscrowAccounts::new( diff --git a/crates/service/src/middleware/tap_context.rs b/crates/service/src/middleware/tap_context.rs index 30dcf35b..e2b93cad 100644 --- a/crates/service/src/middleware/tap_context.rs +++ b/crates/service/src/middleware/tap_context.rs @@ -5,7 +5,6 @@ //! //! Requires Deployment Id extension to available -use serde_json::value::RawValue; use std::sync::Arc; use axum::{ @@ -15,12 +14,12 @@ use axum::{ response::Response, RequestExt, }; +use serde_json::value::RawValue; use tap_core::receipt::Context; use thegraph_core::DeploymentId; -use crate::{error::IndexerServiceError, tap::AgoraQuery}; - use super::sender::Sender; +use crate::{error::IndexerServiceError, tap::AgoraQuery}; /// Graphql query body to be decoded and passed to agora context #[derive(Debug, serde::Deserialize, serde::Serialize)] @@ -92,7 +91,7 @@ mod tests { #[tokio::test] async fn test_context_middleware() { let middleware = from_fn(context_middleware); - let deployment = *ESCROW_SUBGRAPH_DEPLOYMENT; + let deployment = ESCROW_SUBGRAPH_DEPLOYMENT; let query_body = QueryBody { query: "hello".to_string(), variables: None, diff --git a/crates/service/src/middleware/tap_receipt.rs b/crates/service/src/middleware/tap_receipt.rs index 44f08bbe..3d068443 100644 --- a/crates/service/src/middleware/tap_receipt.rs +++ b/crates/service/src/middleware/tap_receipt.rs @@ -24,8 +24,6 @@ pub async fn receipt_middleware(mut request: Request, next: Next) -> Response { #[cfg(test)] mod tests { - use crate::{middleware::tap_receipt::receipt_middleware, service::TapReceipt}; - use axum::{ body::Body, http::{Extensions, Request}, @@ -39,6 +37,8 @@ mod tests { use test_assets::{create_signed_receipt, SignedReceiptRequest}; use tower::ServiceExt; + use crate::{middleware::tap_receipt::receipt_middleware, service::TapReceipt}; + #[tokio::test] async fn test_receipt_middleware() { let middleware = from_fn(receipt_middleware); diff --git a/crates/service/src/routes/cost.rs b/crates/service/src/routes/cost.rs index 17b690da..bafb7383 100644 --- a/crates/service/src/routes/cost.rs +++ b/crates/service/src/routes/cost.rs @@ -3,7 +3,6 @@ use std::str::FromStr; -use crate::database::cost_model::{self, CostModel}; use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject}; use lazy_static::lazy_static; use prometheus::{ @@ -15,6 +14,8 @@ use serde_json::Value; use sqlx::PgPool; use thegraph_core::DeploymentId; +use crate::database::cost_model::{self, CostModel}; + lazy_static! { pub static ref COST_MODEL_METRIC: HistogramVec = register_histogram_vec!( "indexer_cost_model_seconds", diff --git a/crates/service/src/routes/dips.rs b/crates/service/src/routes/dips.rs index 378be816..d9014dfa 100644 --- a/crates/service/src/routes/dips.rs +++ b/crates/service/src/routes/dips.rs @@ -1,20 +1,19 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::time::Duration; -use std::{str::FromStr, sync::Arc}; +use std::{str::FromStr, sync::Arc, time::Duration}; use anyhow::bail; use async_graphql::{Context, EmptySubscription, FieldResult, Object, Schema, SimpleObject}; use base64::{engine::general_purpose::STANDARD, Engine}; use indexer_config::{BlockchainConfig, DipsConfig}; -use indexer_dips::alloy::dyn_abi::Eip712Domain; -use indexer_dips::SignedCancellationRequest; use indexer_dips::{ - alloy::core::primitives::Address, alloy_rlp::Decodable, SignedIndexingAgreementVoucher, - SubgraphIndexingVoucherMetadata, + SignedCancellationRequest, SignedIndexingAgreementVoucher, SubgraphIndexingVoucherMetadata, +}; +use thegraph_core::{ + alloy::{primitives::Address, rlp::Decodable, sol_types::Eip712Domain}, + attestation::eip712_domain, }; -use thegraph_core::attestation::eip712_domain; use uuid::Uuid; use crate::database::dips::AgreementStore; @@ -266,14 +265,16 @@ async fn validate_and_cancel_agreement( mod test { use std::sync::Arc; - use alloy::signers::local::PrivateKeySigner; use base64::{engine::general_purpose::STANDARD, Engine}; - use indexer_dips::{ - alloy::core::primitives::{Address, FixedBytes, U256}, - alloy_rlp::{self}, - IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata, + use indexer_dips::{IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata}; + use thegraph_core::{ + alloy::{ + primitives::{Address, FixedBytes, U256}, + rlp, + signers::local::PrivateKeySigner, + }, + attestation::eip712_domain, }; - use thegraph_core::attestation::eip712_domain; use uuid::Uuid; use crate::database::dips::{AgreementStore, InMemoryAgreementStore}; @@ -303,12 +304,12 @@ mod test { maxEpochsPerCollection: 1000, minEpochsPerCollection: 1000, durationEpochs: 1000, - metadata: alloy_rlp::encode(metadata).into(), + metadata: rlp::encode(metadata).into(), }; let domain = eip712_domain(0, Address::ZERO); let voucher = voucher.sign(&domain, payer)?; - let rlp_voucher = alloy_rlp::encode(voucher.clone()); + let rlp_voucher = rlp::encode(voucher.clone()); let b64 = STANDARD.encode(rlp_voucher); let id = Uuid::now_v7(); diff --git a/crates/service/src/routes/request_handler.rs b/crates/service/src/routes/request_handler.rs index 03ec43f0..23a7ca5e 100644 --- a/crates/service/src/routes/request_handler.rs +++ b/crates/service/src/routes/request_handler.rs @@ -1,7 +1,6 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::{error::SubgraphServiceError, middleware::AttestationInput, service::GraphNodeState}; use axum::{ extract::{Path, State}, http::{HeaderValue, Response}, @@ -9,7 +8,8 @@ use axum::{ }; use reqwest::header::CONTENT_TYPE; use thegraph_core::DeploymentId; -use tracing::trace; + +use crate::{error::SubgraphServiceError, middleware::AttestationInput, service::GraphNodeState}; const GRAPH_ATTESTABLE: &str = "graph-attestable"; const GRAPH_INDEXED: &str = "graph-indexed"; @@ -19,7 +19,7 @@ pub async fn request_handler( State(state): State, req: String, ) -> Result { - trace!("Handling request for deployment `{deployment}`"); + tracing::trace!("Handling request for deployment `{deployment}`"); let deployment_url = state .graph_node_query_base_url diff --git a/crates/service/src/routes/static_subgraph.rs b/crates/service/src/routes/static_subgraph.rs index 57dd0030..a1ce644e 100644 --- a/crates/service/src/routes/static_subgraph.rs +++ b/crates/service/src/routes/static_subgraph.rs @@ -2,11 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 use axum::{body::Bytes, extract::State, response::IntoResponse, Json}; +use indexer_monitor::SubgraphClient; use reqwest::StatusCode; use serde_json::json; -use tracing::warn; - -use indexer_monitor::SubgraphClient; #[autometrics::autometrics] pub async fn static_subgraph_request_handler( @@ -19,7 +17,7 @@ pub async fn static_subgraph_request_handler( response.status(), response.headers().to_owned(), response.text().await.inspect_err(|e| { - warn!("Failed to read response body: {}", e); + tracing::warn!("Failed to read response body: {}", e); })?, )) } diff --git a/crates/service/src/service.rs b/crates/service/src/service.rs index c9b28b9b..eaa0615a 100644 --- a/crates/service/src/service.rs +++ b/crates/service/src/service.rs @@ -5,6 +5,7 @@ use std::{net::SocketAddr, time::Duration}; use anyhow::anyhow; use axum::{extract::Request, serve, ServiceExt}; +use clap::Parser; use indexer_config::{Config, GraphNodeConfig, SubgraphConfig}; use indexer_monitor::{DeploymentDetails, SubgraphClient}; use release::IndexerServiceRelease; @@ -14,8 +15,6 @@ use tokio::{net::TcpListener, signal}; use tower_http::normalize_path::NormalizePath; use crate::{cli::Cli, database, metrics::serve_metrics}; -use clap::Parser; -use tracing::{error, info}; mod release; mod router; @@ -41,7 +40,7 @@ pub async fn run() -> anyhow::Result<()> { // Load the service configuration let config = Config::parse(indexer_config::ConfigPrefix::Service, cli.config.as_ref()) .map_err(|e| { - error!( + tracing::error!( "Invalid configuration file `{}`: {}, if a value is missing you can also use \ --config to fill the rest of the values", cli.config.unwrap_or_default().display(), @@ -108,7 +107,7 @@ pub async fn run() -> anyhow::Result<()> { serve_metrics(config.metrics.get_socket_addr()); - info!( + tracing::info!( address = %host_and_port, "Serving requests", ); @@ -169,5 +168,5 @@ async fn shutdown_handler() { _ = terminate => {}, } - info!("Signal received, starting graceful shutdown"); + tracing::info!("Signal received, starting graceful shutdown"); } diff --git a/crates/service/src/service/router.rs b/crates/service/src/service/router.rs index f70d6c9e..8768c7bb 100644 --- a/crates/service/src/service/router.rs +++ b/crates/service/src/service/router.rs @@ -3,7 +3,6 @@ use std::{sync::Arc, time::Duration}; -use alloy::dyn_abi::Eip712Domain; use async_graphql_axum::GraphQL; use axum::{ extract::MatchedPath, @@ -24,6 +23,7 @@ use indexer_monitor::{ }; use reqwest::Method; use tap_core::{manager::Manager, receipt::checks::CheckList}; +use thegraph_core::alloy::sol_types::Eip712Domain; use tower::ServiceBuilder; use tower_governor::{ governor::GovernorConfigBuilder, key_extractor::SmartIpKeyExtractor, GovernorLayer, @@ -34,9 +34,9 @@ use tower_http::{ trace::TraceLayer, validate_request::ValidateRequestHeaderLayer, }; -use tracing::{info, info_span, warn}; use typed_builder::TypedBuilder; +use super::{release::IndexerServiceRelease, GraphNodeState}; use crate::{ database::dips::{AgreementStore, InMemoryAgreementStore}, metrics::{FAILED_RECEIPT, HANDLER_HISTOGRAM}, @@ -56,8 +56,6 @@ use crate::{ wallet::public_key, }; -use super::{release::IndexerServiceRelease, GraphNodeState}; - #[derive(TypedBuilder)] pub struct ServiceRouter { // database @@ -222,7 +220,7 @@ impl ServiceRouter { self.network_subgraph.as_ref(), ) { (Some(free_auth_token), true, Some((network_subgraph, _))) => { - info!("Serving network subgraph at /network"); + tracing::info!("Serving network subgraph at /network"); let auth_layer = ValidateRequestHeaderLayer::bearer(free_auth_token); @@ -235,7 +233,7 @@ impl ServiceRouter { ) } (_, true, _) => { - warn!("`serve_network_subgraph` is enabled but no `serve_auth_token` provided. Disabling it."); + tracing::warn!("`serve_network_subgraph` is enabled but no `serve_auth_token` provided. Disabling it."); Router::new() } _ => Router::new(), @@ -248,7 +246,7 @@ impl ServiceRouter { self.escrow_subgraph, ) { (Some(free_auth_token), true, Some((escrow_subgraph, _))) => { - info!("Serving escrow subgraph at /escrow"); + tracing::info!("Serving escrow subgraph at /escrow"); let auth_layer = ValidateRequestHeaderLayer::bearer(free_auth_token); @@ -261,7 +259,7 @@ impl ServiceRouter { ) } (_, true, _) => { - warn!("`serve_escrow_subgraph` is enabled but no `serve_auth_token` provided. Disabling it."); + tracing::warn!("`serve_escrow_subgraph` is enabled but no `serve_auth_token` provided. Disabling it."); Router::new() } _ => Router::new(), @@ -367,14 +365,14 @@ impl ServiceRouter { .get::() .map(MatchedPath::as_str); - info_span!( + tracing::info_span!( "http_request", %method, %uri, matched_path, ) }) - // we disable failures here because we doing our own error logging + // we disable failures here because we are doing our own error logging .on_failure( |_error: tower_http::classify::ServerErrorsFailureClass, _latency: Duration, @@ -389,7 +387,7 @@ impl ServiceRouter { let operator_address = Json(serde_json::json!({ "publicKey": public_key(&operator_mnemonic)?})); - // Graphnode state + // Graph node state let graphnode_state = GraphNodeState { graph_node_client: self.http_client, graph_node_status_url: self.graph_node.status_url, diff --git a/crates/service/src/service/tap_receipt_header.rs b/crates/service/src/service/tap_receipt_header.rs index 71df4696..814b2c93 100644 --- a/crates/service/src/service/tap_receipt_header.rs +++ b/crates/service/src/service/tap_receipt_header.rs @@ -49,7 +49,6 @@ impl Header for TapReceipt { mod test { use axum::http::HeaderValue; use axum_extra::headers::Header; - use test_assets::{create_signed_receipt, SignedReceiptRequest}; use super::TapReceipt; diff --git a/crates/service/src/tap.rs b/crates/service/src/tap.rs index 77d5e1b8..e6ca2b48 100644 --- a/crates/service/src/tap.rs +++ b/crates/service/src/tap.rs @@ -1,26 +1,25 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::tap::checks::allocation_eligible::AllocationEligible; -use crate::tap::checks::deny_list_check::DenyListCheck; -use crate::tap::checks::receipt_max_val_check::ReceiptMaxValueCheck; -use crate::tap::checks::sender_balance_check::SenderBalanceCheck; -use crate::tap::checks::timestamp_check::TimestampCheck; -use crate::tap::checks::value_check::MinimumValue; -use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; +use std::{collections::HashMap, fmt::Debug, sync::Arc, time::Duration}; + use indexer_allocation::Allocation; use indexer_monitor::EscrowAccounts; use receipt_store::{DatabaseReceipt, InnerContext}; use sqlx::PgPool; -use std::fmt::Debug; -use std::time::Duration; -use std::{collections::HashMap, sync::Arc}; use tap_core::receipt::checks::ReceiptCheck; -use tokio::sync::mpsc::{self, Sender}; -use tokio::sync::watch::Receiver; +use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain}; +use tokio::sync::{ + mpsc::{self, Sender}, + watch::Receiver, +}; use tokio_util::sync::CancellationToken; -use tracing::error; + +use crate::tap::checks::{ + allocation_eligible::AllocationEligible, deny_list_check::DenyListCheck, + receipt_max_val_check::ReceiptMaxValueCheck, sender_balance_check::SenderBalanceCheck, + timestamp_check::TimestampCheck, value_check::MinimumValue, +}; mod checks; mod receipt_store; diff --git a/crates/service/src/tap/checks/allocation_eligible.rs b/crates/service/src/tap/checks/allocation_eligible.rs index 965a7b13..94d8505a 100644 --- a/crates/service/src/tap/checks/allocation_eligible.rs +++ b/crates/service/src/tap/checks/allocation_eligible.rs @@ -3,15 +3,14 @@ use std::collections::HashMap; -use alloy::primitives::Address; use anyhow::anyhow; - use indexer_allocation::Allocation; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, ReceiptWithState, }; +use thegraph_core::alloy::primitives::Address; use tokio::sync::watch::Receiver; pub struct AllocationEligible { diff --git a/crates/service/src/tap/checks/deny_list_check.rs b/crates/service/src/tap/checks/deny_list_check.rs index 6838b02b..11a6776b 100644 --- a/crates/service/src/tap/checks/deny_list_check.rs +++ b/crates/service/src/tap/checks/deny_list_check.rs @@ -1,20 +1,21 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::middleware::Sender; -use alloy::primitives::Address; -use sqlx::postgres::PgListener; -use sqlx::PgPool; -use std::collections::HashSet; -use std::sync::RwLock; -use std::{str::FromStr, sync::Arc}; -use tap_core::receipt::checks::CheckError; +use std::{ + collections::HashSet, + str::FromStr, + sync::{Arc, RwLock}, +}; + +use sqlx::{postgres::PgListener, PgPool}; use tap_core::receipt::{ - checks::{Check, CheckResult}, + checks::{Check, CheckError, CheckResult}, state::Checking, ReceiptWithState, }; -use tracing::error; +use thegraph_core::alloy::primitives::Address; + +use crate::middleware::Sender; pub struct DenyListCheck { sender_denylist: Arc>>, @@ -132,7 +133,7 @@ impl DenyListCheck { } // UPDATE and TRUNCATE are not expected to happen. Reload the entire denylist. _ => { - error!( + tracing::error!( "Received an unexpected denylist table notification: {}. Reloading entire \ denylist.", denylist_notification.tg_op @@ -189,12 +190,12 @@ impl Drop for DenyListCheck { #[cfg(test)] mod tests { - use alloy::hex::ToHexExt; - use tap_core::receipt::{Context, ReceiptWithState}; - + use sqlx::PgPool; + use tap_core::receipt::{checks::Check, Context, ReceiptWithState}; use test_assets::{self, create_signed_receipt, SignedReceiptRequest, TAP_SENDER}; + use thegraph_core::alloy::hex::ToHexExt; - use super::*; + use super::{DenyListCheck, Sender}; async fn new_deny_list_check(pgpool: PgPool) -> DenyListCheck { // Mock escrow accounts diff --git a/crates/service/src/tap/checks/receipt_max_val_check.rs b/crates/service/src/tap/checks/receipt_max_val_check.rs index 8d480fff..c138266f 100644 --- a/crates/service/src/tap/checks/receipt_max_val_check.rs +++ b/crates/service/src/tap/checks/receipt_max_val_check.rs @@ -39,22 +39,23 @@ impl Check for ReceiptMaxValueCheck { } #[cfg(test)] mod tests { - use alloy::primitives::Address; - use alloy::signers::local::coins_bip39::English; - use alloy::signers::local::MnemonicBuilder; - use alloy::signers::local::PrivateKeySigner; - use std::str::FromStr; - use std::time::Duration; - use std::time::SystemTime; - use tap_core::receipt::Context; + use std::{ + str::FromStr, + time::{Duration, SystemTime}, + }; - use super::*; - use crate::tap::Eip712Domain; use tap_core::{ - receipt::{checks::Check, state::Checking, Receipt, ReceiptWithState}, + receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState}, signed_message::EIP712SignedMessage, tap_eip712_domain, }; + use thegraph_core::alloy::{ + primitives::Address, + signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, + }; + + use super::*; + use crate::tap::Eip712Domain; fn create_signed_receipt_with_custom_value(value: u128) -> ReceiptWithState { let index: u32 = 0; diff --git a/crates/service/src/tap/checks/sender_balance_check.rs b/crates/service/src/tap/checks/sender_balance_check.rs index 25f37508..c9704dcc 100644 --- a/crates/service/src/tap/checks/sender_balance_check.rs +++ b/crates/service/src/tap/checks/sender_balance_check.rs @@ -1,7 +1,6 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::primitives::U256; use anyhow::anyhow; use indexer_monitor::EscrowAccounts; use tap_core::receipt::{ @@ -9,6 +8,7 @@ use tap_core::receipt::{ state::Checking, ReceiptWithState, }; +use thegraph_core::alloy::primitives::U256; use tokio::sync::watch::Receiver; use crate::middleware::Sender; diff --git a/crates/service/src/tap/checks/timestamp_check.rs b/crates/service/src/tap/checks/timestamp_check.rs index 21974292..12615e8c 100644 --- a/crates/service/src/tap/checks/timestamp_check.rs +++ b/crates/service/src/tap/checks/timestamp_check.rs @@ -1,8 +1,9 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use anyhow::anyhow; use std::time::{Duration, SystemTime}; +use anyhow::anyhow; + pub struct TimestampCheck { timestamp_error_tolerance: Duration, } @@ -50,18 +51,18 @@ impl Check for TimestampCheck { mod tests { use std::str::FromStr; - use alloy::{ + use tap_core::{ + receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState}, + signed_message::EIP712SignedMessage, + tap_eip712_domain, + }; + use thegraph_core::alloy::{ primitives::Address, signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, }; use super::*; use crate::tap::Eip712Domain; - use tap_core::{ - receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState}, - signed_message::EIP712SignedMessage, - tap_eip712_domain, - }; fn create_signed_receipt_with_custom_timestamp( timestamp_ns: u64, diff --git a/crates/service/src/tap/checks/value_check.rs b/crates/service/src/tap/checks/value_check.rs index 23b1c399..0caf3785 100644 --- a/crates/service/src/tap/checks/value_check.rs +++ b/crates/service/src/tap/checks/value_check.rs @@ -1,6 +1,13 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use std::{ + collections::HashMap, + str::FromStr, + sync::{Arc, RwLock}, + time::{Duration, Instant}, +}; + use ::cost_model::CostModel; use anyhow::anyhow; use bigdecimal::ToPrimitive; @@ -8,21 +15,12 @@ use sqlx::{ postgres::{PgListener, PgNotification}, PgPool, }; -use std::time::Duration; -use std::{ - collections::HashMap, - str::FromStr, - sync::{Arc, RwLock}, - time::Instant, -}; -use thegraph_core::DeploymentId; -use tracing::error; - use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, Context, ReceiptWithState, }; +use thegraph_core::DeploymentId; use crate::database::cost_model; @@ -135,7 +133,7 @@ impl CostModelWatcher { cost_model_write.insert(deployment_id, model); } Err(_) => { - error!( + tracing::error!( "Received insert request for an invalid deployment_id: {}", deployment_id ) @@ -156,7 +154,7 @@ impl CostModelWatcher { self.cost_models.write().unwrap().remove(&deployment_id); } Err(_) => { - error!( + tracing::error!( "Received delete request for an invalid deployment_id: {}", deployment_id ) @@ -167,7 +165,7 @@ impl CostModelWatcher { } async fn handle_unexpected_notification(&self, payload: &str) { - error!( + tracing::error!( "Received an unexpected cost model table notification: {}. Reloading entire \ cost model.", payload @@ -365,19 +363,17 @@ enum CostModelNotification { #[cfg(test)] mod tests { use std::time::Duration; - use test_assets::{create_signed_receipt, flush_messages, SignedReceiptRequest}; use sqlx::PgPool; use tap_core::receipt::{checks::Check, Context, ReceiptWithState}; + use test_assets::{create_signed_receipt, flush_messages, SignedReceiptRequest}; use tokio::time::sleep; - use super::AgoraQuery; + use super::{AgoraQuery, MinimumValue}; use crate::database::cost_model::test::{ self, add_cost_models, global_cost_model, to_db_models, }; - use super::MinimumValue; - #[sqlx::test(migrations = "../../migrations")] async fn initialize_check(pgpool: PgPool) { let check = MinimumValue::new(pgpool, Duration::from_secs(0)).await; diff --git a/crates/service/src/tap/receipt_store.rs b/crates/service/src/tap/receipt_store.rs index 71e397bb..2d284197 100644 --- a/crates/service/src/tap/receipt_store.rs +++ b/crates/service/src/tap/receipt_store.rs @@ -1,7 +1,6 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::{dyn_abi::Eip712Domain, hex::ToHexExt}; use anyhow::anyhow; use bigdecimal::num_bigint::BigInt; use sqlx::{types::BigDecimal, PgPool}; @@ -9,9 +8,9 @@ use tap_core::{ manager::adapters::ReceiptStore, receipt::{state::Checking, ReceiptWithState}, }; -use tokio::{select, sync::mpsc::Receiver, task::JoinHandle}; +use thegraph_core::alloy::{hex::ToHexExt, sol_types::Eip712Domain}; +use tokio::{sync::mpsc::Receiver, task::JoinHandle}; use tokio_util::sync::CancellationToken; -use tracing::error; use super::{AdapterError, IndexerTapContext}; @@ -64,7 +63,7 @@ impl InnerContext { .execute(&self.pgpool) .await .map_err(|e| { - error!("Failed to store receipt: {}", e); + tracing::error!("Failed to store receipt: {}", e); anyhow!(e) })?; @@ -82,11 +81,11 @@ impl IndexerTapContext { tokio::spawn(async move { loop { let mut buffer = Vec::with_capacity(BUFFER_SIZE); - select! { + tokio::select! { biased; _ = receiver.recv_many(&mut buffer, BUFFER_SIZE) => { if let Err(e) = inner_context.store_receipts(buffer).await { - error!("Failed to store receipts: {}", e); + tracing::error!("Failed to store receipts: {}", e); } } _ = cancelation_token.cancelled() => { break }, @@ -106,7 +105,7 @@ impl ReceiptStore for IndexerTapContext { ) -> Result { let db_receipt = DatabaseReceipt::from_receipt(receipt, &self.domain_separator)?; self.receipt_producer.send(db_receipt).await.map_err(|e| { - error!("Failed to queue receipt for storage: {}", e); + tracing::error!("Failed to queue receipt for storage: {}", e); anyhow!(e) })?; @@ -136,7 +135,7 @@ impl DatabaseReceipt { let signer_address = receipt .recover_signer(separator) .map_err(|e| { - error!("Failed to recover receipt signer: {}", e); + tracing::error!("Failed to recover receipt signer: {}", e); anyhow!(e) })? .encode_hex(); diff --git a/crates/service/src/wallet.rs b/crates/service/src/wallet.rs index d1777adc..3fd30131 100644 --- a/crates/service/src/wallet.rs +++ b/crates/service/src/wallet.rs @@ -1,10 +1,10 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::signers::local::{ +use bip39::Mnemonic; +use thegraph_core::alloy::signers::local::{ coins_bip39::English, LocalSignerError, MnemonicBuilder, PrivateKeySigner, }; -use bip39::Mnemonic; /// Build Wallet from Private key or Mnemonic pub fn build_wallet(value: &str) -> Result { diff --git a/crates/service/tests/router_test.rs b/crates/service/tests/router_test.rs index ff3a40ed..cf7f22ba 100644 --- a/crates/service/tests/router_test.rs +++ b/crates/service/tests/router_test.rs @@ -3,7 +3,6 @@ use std::{net::SocketAddr, time::Duration}; -use alloy::primitives::Address; use axum::{body::to_bytes, extract::ConnectInfo, http::Request, Extension}; use axum_extra::headers::Header; use indexer_config::{BlockchainConfig, GraphNodeConfig, IndexerConfig, NonZeroGRT}; @@ -17,6 +16,7 @@ use sqlx::PgPool; use test_assets::{ create_signed_receipt, SignedReceiptRequest, INDEXER_ALLOCATIONS, TAP_EIP712_DOMAIN, }; +use thegraph_core::alloy::primitives::Address; use tokio::sync::watch; use tower::Service; use wiremock::{ @@ -71,7 +71,7 @@ async fn full_integration_test(database: PgPool) { status_url: graph_node_url.clone(), }) .indexer(IndexerConfig { - indexer_address: *test_assets::INDEXER_ADDRESS, + indexer_address: test_assets::INDEXER_ADDRESS, operator_mnemonic: test_assets::INDEXER_MNEMONIC.clone(), }) .service(indexer_config::ServiceConfig { @@ -87,7 +87,7 @@ async fn full_integration_test(database: PgPool) { }) .blockchain(BlockchainConfig { chain_id: indexer_config::TheGraphChainId::Test, - receipts_verifier_address: *test_assets::VERIFIER_ADDRESS, + receipts_verifier_address: test_assets::VERIFIER_ADDRESS, }) .timestamp_buffer_secs(Duration::from_secs(10)) .escrow_accounts(escrow_accounts) @@ -95,6 +95,13 @@ async fn full_integration_test(database: PgPool) { .allocations(allocations) .build(); + let receipt = create_signed_receipt( + SignedReceiptRequest::builder() + .allocation_id(allocation.id) + .value(100) + .build(), + ) + .await; let socket_info = Extension(ConnectInfo(SocketAddr::from(([0, 0, 0, 0], 1337)))); let mut app = router.create_router().await.unwrap().layer(socket_info); @@ -110,14 +117,6 @@ async fn full_integration_test(database: PgPool) { let res = String::from_utf8(bytes.into()).unwrap(); insta::assert_snapshot!(res); - let receipt = create_signed_receipt( - SignedReceiptRequest::builder() - .allocation_id(allocation.id) - .value(100) - .build(), - ) - .await; - let query = QueryBody { query: "query".into(), variables: None, diff --git a/crates/tap-agent/Cargo.toml b/crates/tap-agent/Cargo.toml index 6a613d8e..bbdf0819 100644 --- a/crates/tap-agent/Cargo.toml +++ b/crates/tap-agent/Cargo.toml @@ -14,7 +14,6 @@ indexer-watcher = { path = "../watcher" } indexer-allocation = { path = "../allocation" } indexer-config = { path = "../config" } indexer-query = { path = "../query" } -alloy.workspace = true anyhow.workspace = true async-trait.workspace = true sqlx.workspace = true @@ -36,12 +35,12 @@ bigdecimal = { workspace = true, features = ["serde"] } graphql_client.workspace = true ruint = { version = "1.12.3", features = [ - "num-traits", + "num-traits", ], default-features = false } futures-util = { version = "0.3.28", default-features = false } jsonrpsee = { version = "0.24.0", features = ["http-client", "tracing"] } ractor = { version = "0.13", features = [ - "async-trait", + "async-trait", ], default-features = false } tap_aggregator.workspace = true futures = { version = "0.3.30", default-features = false } diff --git a/crates/tap-agent/src/agent.rs b/crates/tap-agent/src/agent.rs index 2e1a3208..f570241a 100644 --- a/crates/tap-agent/src/agent.rs +++ b/crates/tap-agent/src/agent.rs @@ -6,15 +6,14 @@ use indexer_config::{ SubgraphConfig, SubgraphsConfig, TapConfig, }; use indexer_monitor::{escrow_accounts, indexer_allocations, DeploymentDetails, SubgraphClient}; -use ractor::concurrency::JoinHandle; -use ractor::{Actor, ActorRef}; +use ractor::{concurrency::JoinHandle, Actor, ActorRef}; use sender_account::SenderAccountConfig; +use sender_accounts_manager::SenderAccountsManager; -use crate::agent::sender_accounts_manager::{ - SenderAccountsManagerArgs, SenderAccountsManagerMessage, +use crate::{ + agent::sender_accounts_manager::{SenderAccountsManagerArgs, SenderAccountsManagerMessage}, + database, CONFIG, EIP_712_DOMAIN, }; -use crate::{database, CONFIG, EIP_712_DOMAIN}; -use sender_accounts_manager::SenderAccountsManager; pub mod sender_account; pub mod sender_accounts_manager; diff --git a/crates/tap-agent/src/agent/sender_account.rs b/crates/tap-agent/src/agent/sender_account.rs index 1dcfd325..5415e415 100644 --- a/crates/tap-agent/src/agent/sender_account.rs +++ b/crates/tap-agent/src/agent/sender_account.rs @@ -1,44 +1,44 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::hex::ToHexExt; -use alloy::primitives::U256; - -use bigdecimal::num_bigint::ToBigInt; -use bigdecimal::ToPrimitive; +use std::{ + collections::{HashMap, HashSet}, + str::FromStr, + time::Duration, +}; +use bigdecimal::{num_bigint::ToBigInt, ToPrimitive}; use futures::{stream, StreamExt}; -use indexer_query::unfinalized_transactions; +use indexer_monitor::{EscrowAccounts, SubgraphClient}; use indexer_query::{ closed_allocations::{self, ClosedAllocations}, - UnfinalizedTransactions, + unfinalized_transactions, UnfinalizedTransactions, }; use indexer_watcher::watch_pipe; use jsonrpsee::http_client::HttpClientBuilder; +use lazy_static::lazy_static; use prometheus::{register_gauge_vec, register_int_gauge_vec, GaugeVec, IntGaugeVec}; -use reqwest::Url; -use std::collections::{HashMap, HashSet}; -use std::str::FromStr; -use std::time::Duration; -use tokio::sync::watch::Receiver; -use tokio::task::JoinHandle; - -use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; -use anyhow::Result; -use indexer_monitor::{EscrowAccounts, SubgraphClient}; use ractor::{Actor, ActorProcessingErr, ActorRef, MessagingErr, SupervisionEvent}; +use reqwest::Url; use sqlx::PgPool; use tap_core::rav::SignedRAV; -use tracing::{error, warn, Level}; - -use super::sender_allocation::{SenderAllocation, SenderAllocationArgs}; -use crate::adaptative_concurrency::AdaptiveLimiter; -use crate::agent::sender_allocation::{AllocationConfig, SenderAllocationMessage}; -use crate::agent::unaggregated_receipts::UnaggregatedReceipts; -use crate::backoff::BackoffInfo; -use crate::tracker::{SenderFeeTracker, SimpleFeeTracker}; -use lazy_static::lazy_static; +use thegraph_core::alloy::{ + hex::ToHexExt, + primitives::{Address, U256}, + sol_types::Eip712Domain, +}; +use tokio::{sync::watch::Receiver, task::JoinHandle}; +use tracing::Level; + +use super::sender_allocation::{ + AllocationConfig, SenderAllocation, SenderAllocationArgs, SenderAllocationMessage, +}; +use crate::{ + adaptative_concurrency::AdaptiveLimiter, + agent::unaggregated_receipts::UnaggregatedReceipts, + backoff::BackoffInfo, + tracker::{SenderFeeTracker, SimpleFeeTracker}, +}; lazy_static! { static ref SENDER_DENIED: IntGaugeVec = @@ -213,7 +213,7 @@ impl State { &self, sender_account_ref: ActorRef, allocation_id: Address, - ) -> Result<()> { + ) -> anyhow::Result<()> { tracing::trace!( %self.sender, %allocation_id, @@ -250,7 +250,7 @@ impl State { sender_allocation_id } - async fn rav_request_for_heaviest_allocation(&mut self) -> Result<()> { + async fn rav_request_for_heaviest_allocation(&mut self) -> anyhow::Result<()> { let allocation_id = self .sender_fee_tracker .get_heaviest_allocation_id() @@ -270,7 +270,7 @@ impl State { self.rav_request_for_allocation(allocation_id).await } - async fn rav_request_for_allocation(&mut self, allocation_id: Address) -> Result<()> { + async fn rav_request_for_allocation(&mut self, allocation_id: Address) -> anyhow::Result<()> { let sender_allocation_id = self.format_sender_allocation(&allocation_id); let allocation = ActorRef::::where_is(sender_allocation_id); @@ -308,9 +308,11 @@ impl State { Err(err) => { self.sender_fee_tracker.failed_rav_backoff(allocation_id); self.adaptive_limiter.on_failure(); - error!( + tracing::error!( "Error while requesting RAV for sender {} and allocation {}: {}", - self.sender, allocation_id, err + self.sender, + allocation_id, + err ); } }; @@ -478,7 +480,7 @@ impl Actor for SenderAccount { prefix, retry_interval, }: Self::Arguments, - ) -> std::result::Result { + ) -> Result { let myself_clone = myself.clone(); let _indexer_allocations_handle = watch_pipe(indexer_allocations, move |allocation_ids| { let allocation_ids = allocation_ids.clone(); @@ -486,7 +488,7 @@ impl Actor for SenderAccount { myself_clone .cast(SenderAccountMessage::UpdateAllocationIds(allocation_ids)) .unwrap_or_else(|e| { - error!("Error while updating allocation_ids: {:?}", e); + tracing::error!("Error while updating allocation_ids: {:?}", e); }); async {} }); @@ -559,9 +561,10 @@ impl Actor for SenderAccount { non_redeemed_ravs, )) .unwrap_or_else(|e| { - error!( + tracing::error!( "Error while updating balance for sender {}: {:?}", - sender_id, e + sender_id, + e ); }); } @@ -646,7 +649,7 @@ impl Actor for SenderAccount { myself: ActorRef, message: Self::Msg, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { tracing::span!( Level::TRACE, "SenderAccount handle()", @@ -806,7 +809,7 @@ impl Actor for SenderAccount { .create_sender_allocation(myself.clone(), *allocation_id) .await { - error!( + tracing::error!( %error, %allocation_id, "There was an error while creating Sender Allocation." @@ -824,7 +827,7 @@ impl Actor for SenderAccount { let really_closed = state .check_closed_allocations(possibly_closed_allocations.clone()) .await - .inspect_err(|err| error!(error = %err, "There was an error while querying the subgraph for closed allocations")) + .inspect_err(|err| tracing::error!(error = %err, "There was an error while querying the subgraph for closed allocations")) .unwrap_or_default(); // Remove sender allocations @@ -841,7 +844,7 @@ impl Actor for SenderAccount { new_allocation_ids.remove(allocation_id); } } else { - warn!(%allocation_id, "Missing allocation was not closed yet"); + tracing::warn!(%allocation_id, "Missing allocation was not closed yet"); } } @@ -857,7 +860,7 @@ impl Actor for SenderAccount { .create_sender_allocation(myself.clone(), allocation_id) .await { - error!( + tracing::error!( %error, %allocation_id, "There was an error while creating Sender Allocation." @@ -932,7 +935,7 @@ impl Actor for SenderAccount { myself: ActorRef, message: SupervisionEvent, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { tracing::trace!( sender = %state.sender, message = ?message, @@ -1000,7 +1003,7 @@ impl Actor for SenderAccount { .create_sender_allocation(myself.clone(), allocation_id) .await { - error!( + tracing::error!( %error, %allocation_id, "Error while recreating Sender Allocation." @@ -1014,7 +1017,7 @@ impl Actor for SenderAccount { } impl SenderAccount { - pub async fn deny_sender(pool: &sqlx::PgPool, sender: Address) { + pub async fn deny_sender(pool: &PgPool, sender: Address) { sqlx::query!( r#" INSERT INTO scalar_tap_denylist (sender_address) @@ -1030,33 +1033,46 @@ impl SenderAccount { #[cfg(test)] pub mod tests { - use super::{SenderAccount, SenderAccountArgs, SenderAccountMessage}; - use crate::agent::sender_account::ReceiptFees; - use crate::agent::sender_allocation::SenderAllocationMessage; - use crate::agent::unaggregated_receipts::UnaggregatedReceipts; - use crate::test::actors::{create_mock_sender_allocation, MockSenderAllocation, TestableActor}; - use crate::test::{create_rav, store_rav_with_options, INDEXER, TAP_EIP712_DOMAIN_SEPARATOR}; - use crate::{assert_not_triggered, assert_triggered}; - - use alloy::hex::ToHexExt; - use alloy::primitives::{Address, U256}; + use std::{ + collections::{HashMap, HashSet}, + sync::{atomic::AtomicU32, Arc}, + time::{Duration, SystemTime, UNIX_EPOCH}, + }; + use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient}; use ractor::{call, Actor, ActorRef, ActorStatus}; use reqwest::Url; use serde_json::json; use sqlx::PgPool; - use std::collections::{HashMap, HashSet}; - use std::sync::atomic::AtomicU32; - use std::sync::Arc; - use std::time::{Duration, SystemTime, UNIX_EPOCH}; use test_assets::{ flush_messages, ALLOCATION_ID_0, ALLOCATION_ID_1, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER, }; - use tokio::sync::watch::{self, Sender}; - use tokio::sync::Notify; - use wiremock::matchers::{body_string_contains, method}; - use wiremock::{Mock, MockGuard, MockServer, ResponseTemplate}; + use thegraph_core::alloy::{ + hex::ToHexExt, + primitives::{Address, U256}, + }; + use tokio::sync::{ + watch::{self, Sender}, + Notify, + }; + use wiremock::{ + matchers::{body_string_contains, method}, + Mock, MockGuard, MockServer, ResponseTemplate, + }; + + use super::{SenderAccount, SenderAccountArgs, SenderAccountMessage}; + use crate::{ + agent::{ + sender_account::ReceiptFees, sender_allocation::SenderAllocationMessage, + unaggregated_receipts::UnaggregatedReceipts, + }, + assert_not_triggered, assert_triggered, + test::{ + actors::{create_mock_sender_allocation, MockSenderAllocation, TestableActor}, + create_rav, store_rav_with_options, INDEXER, TAP_EIP712_DOMAIN_SEPARATOR, + }, + }; // we implement the PartialEq and Eq traits for SenderAccountMessage to be able to compare impl Eq for SenderAccountMessage {} @@ -1248,7 +1264,7 @@ pub mod tests { // we expect it to create a sender allocation sender_account .cast(SenderAccountMessage::UpdateAllocationIds( - vec![*ALLOCATION_ID_0].into_iter().collect(), + vec![ALLOCATION_ID_0].into_iter().collect(), )) .unwrap(); notify.notified().await; @@ -1335,7 +1351,7 @@ pub mod tests { // we expect it to create a sender allocation sender_account - .cast(SenderAccountMessage::NewAllocationId(*ALLOCATION_ID_0)) + .cast(SenderAccountMessage::NewAllocationId(ALLOCATION_ID_0)) .unwrap(); flush_messages(¬ify).await; @@ -1348,7 +1364,7 @@ pub mod tests { // nothing should change because we already created sender_account .cast(SenderAccountMessage::UpdateAllocationIds( - vec![*ALLOCATION_ID_0].into_iter().collect(), + vec![ALLOCATION_ID_0].into_iter().collect(), )) .unwrap(); @@ -1426,14 +1442,14 @@ pub mod tests { let (triggered_rav_request, _, _) = create_mock_sender_allocation( prefix, SENDER.1, - *ALLOCATION_ID_0, + ALLOCATION_ID_0, sender_account.clone(), ) .await; sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(TRIGGER_VALUE - 1, get_current_timestamp_u64_ns()), )) .unwrap(); @@ -1461,14 +1477,14 @@ pub mod tests { let (triggered_rav_request, _, _) = create_mock_sender_allocation( prefix, SENDER.1, - *ALLOCATION_ID_0, + ALLOCATION_ID_0, sender_account.clone(), ) .await; sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(TRIGGER_VALUE, get_current_timestamp_u64_ns()), )) .unwrap(); @@ -1481,7 +1497,7 @@ pub mod tests { sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::Retry, )) .unwrap(); @@ -1507,14 +1523,14 @@ pub mod tests { let (triggered_rav_request, _, _) = create_mock_sender_allocation( prefix, SENDER.1, - *ALLOCATION_ID_0, + ALLOCATION_ID_0, sender_account.clone(), ) .await; sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(1, get_current_timestamp_u64_ns()), )) .unwrap(); @@ -1524,7 +1540,7 @@ pub mod tests { sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(1, get_current_timestamp_u64_ns()), )) .unwrap(); @@ -1535,7 +1551,7 @@ pub mod tests { sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::Retry, )) .unwrap(); @@ -1549,7 +1565,7 @@ pub mod tests { let (mock_escrow_subgraph_server, _mock_ecrow_subgraph) = mock_escrow_subgraph().await; let (sender_account, _, prefix, _) = create_sender_account( pgpool, - vec![*ALLOCATION_ID_0].into_iter().collect(), + vec![ALLOCATION_ID_0].into_iter().collect(), TRIGGER_VALUE, TRIGGER_VALUE, &mock_escrow_subgraph_server.uri(), @@ -1591,7 +1607,7 @@ pub mod tests { .expect("Should not fail to insert into denylist"); // make sure there's a reason to keep denied - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, false) .await .unwrap(); @@ -1630,7 +1646,7 @@ pub mod tests { let (triggered_rav_request, next_value, _) = create_mock_sender_allocation( prefix, SENDER.1, - *ALLOCATION_ID_0, + ALLOCATION_ID_0, sender_account.clone(), ) .await; @@ -1641,7 +1657,7 @@ pub mod tests { sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(TRIGGER_VALUE, get_current_timestamp_u64_ns()), )) .unwrap(); @@ -1664,7 +1680,7 @@ pub mod tests { let max_unaggregated_fees_per_sender: u128 = 1000; - // Making sure no RAV is gonna be triggered during the test + // Making sure no RAV is going to be triggered during the test let (sender_account, notify, _, _) = create_sender_account( pgpool.clone(), HashSet::new(), @@ -1680,7 +1696,7 @@ pub mod tests { ($value:expr) => { sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { value: $value, last_id: 11, @@ -1697,7 +1713,7 @@ pub mod tests { ($value:expr) => { sender_account .cast(SenderAccountMessage::UpdateInvalidReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, UnaggregatedReceipts { value: $value, last_id: 11, @@ -1758,7 +1774,7 @@ pub mod tests { #[sqlx::test(migrations = "../../migrations")] async fn test_initialization_with_pending_ravs_over_the_limit(pgpool: PgPool) { // add last non-final ravs - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, false) .await .unwrap(); @@ -1781,13 +1797,13 @@ pub mod tests { #[sqlx::test(migrations = "../../migrations")] async fn test_unaggregated_fees_over_balance(pgpool: PgPool) { // add last non-final ravs - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE / 2); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE / 2); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, false) .await .unwrap(); // other rav final, should not be taken into account - let signed_rav = create_rav(*ALLOCATION_ID_1, SIGNER.0.clone(), 4, ESCROW_VALUE / 2); + let signed_rav = create_rav(ALLOCATION_ID_1, SIGNER.0.clone(), 4, ESCROW_VALUE / 2); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, true) .await .unwrap(); @@ -1822,7 +1838,7 @@ pub mod tests { ($value:expr) => { sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { value: $value, last_id: 11, @@ -1892,12 +1908,12 @@ pub mod tests { .await; // redeemed - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, false) .await .unwrap(); - let signed_rav = create_rav(*ALLOCATION_ID_1, SIGNER.0.clone(), 4, ESCROW_VALUE - 1); + let signed_rav = create_rav(ALLOCATION_ID_1, SIGNER.0.clone(), 4, ESCROW_VALUE - 1); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, false) .await .unwrap(); @@ -1953,7 +1969,7 @@ pub mod tests { #[sqlx::test(migrations = "../../migrations")] async fn test_thawing_deposit_process(pgpool: PgPool) { // add last non-final ravs - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE / 2); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, ESCROW_VALUE / 2); store_rav_with_options(&pgpool, signed_rav, SENDER.1, true, false) .await .unwrap(); @@ -2034,7 +2050,7 @@ pub mod tests { // set retry sender_account .cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(TRIGGER_VALUE, get_current_timestamp_u64_ns()), )) .unwrap(); diff --git a/crates/tap-agent/src/agent/sender_accounts_manager.rs b/crates/tap-agent/src/agent/sender_accounts_manager.rs index 75b5b94c..53829ec3 100644 --- a/crates/tap-agent/src/agent/sender_accounts_manager.rs +++ b/crates/tap-agent/src/agent/sender_accounts_manager.rs @@ -1,32 +1,34 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::collections::HashSet; -use std::time::Duration; -use std::{collections::HashMap, str::FromStr}; - -use super::sender_account::{ - SenderAccount, SenderAccountArgs, SenderAccountConfig, SenderAccountMessage, +use std::{ + collections::{HashMap, HashSet}, + str::FromStr, + time::Duration, }; -use crate::agent::sender_allocation::SenderAllocationMessage; -use crate::lazy_static; -use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; -use anyhow::Result; + use anyhow::{anyhow, bail}; use futures::{stream, StreamExt}; use indexer_allocation::Allocation; use indexer_monitor::{EscrowAccounts, SubgraphClient}; use indexer_watcher::watch_pipe; use prometheus::{register_counter_vec, CounterVec}; -use ractor::concurrency::JoinHandle; -use ractor::{Actor, ActorCell, ActorProcessingErr, ActorRef, SupervisionEvent}; +use ractor::{ + concurrency::JoinHandle, Actor, ActorCell, ActorProcessingErr, ActorRef, SupervisionEvent, +}; use reqwest::Url; use serde::Deserialize; use sqlx::{postgres::PgListener, PgPool}; -use tokio::select; -use tokio::sync::watch::{self, Receiver}; -use tracing::{error, warn}; +use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain}; +use tokio::{ + select, + sync::watch::{self, Receiver}, +}; + +use super::sender_account::{ + SenderAccount, SenderAccountArgs, SenderAccountConfig, SenderAccountMessage, +}; +use crate::{agent::sender_allocation::SenderAllocationMessage, lazy_static}; lazy_static! { static ref RECEIPTS_CREATED: CounterVec = register_counter_vec!( @@ -103,7 +105,7 @@ impl Actor for SenderAccountsManager { sender_aggregator_endpoints, prefix, }: Self::Arguments, - ) -> std::result::Result { + ) -> Result { let (allocations_tx, allocations_rx) = watch::channel(HashSet::
::new()); watch_pipe(indexer_allocations.clone(), move |allocation_id| { let allocation_set = allocation_id.keys().cloned().collect::>(); @@ -121,7 +123,7 @@ impl Actor for SenderAccountsManager { myself_clone .cast(SenderAccountsManagerMessage::UpdateSenderAccounts(senders)) .unwrap_or_else(|e| { - error!("Error while updating sender_accounts: {:?}", e); + tracing::error!("Error while updating sender_accounts: {:?}", e); }); async {} }); @@ -173,7 +175,7 @@ impl Actor for SenderAccountsManager { &self, _: ActorRef, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { // Abort the notification watcher on drop. Otherwise it may panic because the PgPool could // get dropped before. (Observed in tests) if let Some(handle) = &state.new_receipts_watcher_handle { @@ -187,7 +189,7 @@ impl Actor for SenderAccountsManager { myself: ActorRef, msg: Self::Msg, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { tracing::trace!( message = ?msg, "New SenderAccountManager message" @@ -224,7 +226,7 @@ impl Actor for SenderAccountsManager { myself: ActorRef, message: SupervisionEvent, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { match message { SupervisionEvent::ActorTerminated(cell, _, reason) => { let sender_id = cell.get_name(); @@ -293,9 +295,10 @@ impl State { .create_sender_account(supervisor, sender_id, allocation_ids) .await { - error!( + tracing::error!( "There was an error while starting the sender {}, denying it. Error: {:?}", - sender_id, e + sender_id, + e ); SenderAccount::deny_sender(&self.pgpool, sender_id).await; } @@ -308,7 +311,7 @@ impl State { allocation_ids: HashSet
, ) -> anyhow::Result<()> { let Ok(args) = self.new_sender_account_args(&sender_id, allocation_ids) else { - warn!( + tracing::warn!( "Sender {} is not on your [tap.sender_aggregator_endpoints] list. \ \ This means that you don't recognize this sender and don't want to \ @@ -437,7 +440,7 @@ impl State { &self, sender_id: &Address, allocation_ids: HashSet
, - ) -> Result { + ) -> anyhow::Result { Ok(SenderAccountArgs { config: self.config, pgpool: self.pgpool.clone(), @@ -479,7 +482,7 @@ async fn new_receipts_watcher( ); loop { let Ok(pg_notification) = pglistener.recv().await else { - error!( + tracing::error!( "should be able to receive Postgres Notify events on the channel \ 'scalar_tap_receipt_notification'" ); @@ -488,7 +491,7 @@ async fn new_receipts_watcher( let Ok(new_receipt_notification) = serde_json::from_str::(pg_notification.payload()) else { - error!( + tracing::error!( "should be able to deserialize the Postgres Notify event payload as a \ NewReceiptNotification", ); @@ -501,7 +504,7 @@ async fn new_receipts_watcher( ) .await { - error!("{}", e); + tracing::error!("{}", e); } } // shutdown the whole system @@ -509,14 +512,14 @@ async fn new_receipts_watcher( .kill_and_wait(None) .await .expect("Failed to kill manager."); - error!("Manager killed"); + tracing::error!("Manager killed"); } async fn handle_notification( new_receipt_notification: NewReceiptNotification, escrow_accounts_rx: Receiver, prefix: Option<&str>, -) -> Result<()> { +) -> anyhow::Result<()> { tracing::trace!( notification = ?new_receipt_notification, "New receipt notification detected!" @@ -545,10 +548,11 @@ async fn handle_notification( ); let Some(sender_allocation) = ActorRef::::where_is(actor_name) else { - warn!( + tracing::warn!( "No sender_allocation found for sender_address {}, allocation_id {} to process new \ receipt notification. Starting a new sender_allocation.", - sender_address, allocation_id + sender_address, + allocation_id ); let sender_account_name = format!( "{}{sender_address}", @@ -594,32 +598,36 @@ async fn handle_notification( #[cfg(test)] mod tests { - use super::{ - new_receipts_watcher, SenderAccountsManager, SenderAccountsManagerArgs, - SenderAccountsManagerMessage, State, + use std::{ + collections::{HashMap, HashSet}, + sync::Arc, + time::Duration, }; - use crate::agent::sender_account::tests::PREFIX_ID; - use crate::agent::sender_account::{SenderAccountConfig, SenderAccountMessage}; - use crate::agent::sender_accounts_manager::{handle_notification, NewReceiptNotification}; - use crate::test::actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor}; - use crate::test::{ - create_rav, create_received_receipt, store_rav, store_receipt, ALLOCATION_ID_0, - ALLOCATION_ID_1, INDEXER, SENDER_2, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR, - }; - use alloy::hex::ToHexExt; + use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient}; - use ractor::concurrency::JoinHandle; - use ractor::{Actor, ActorRef, ActorStatus}; + use ractor::{concurrency::JoinHandle, Actor, ActorRef, ActorStatus}; use reqwest::Url; use ruint::aliases::U256; - use sqlx::postgres::PgListener; - use sqlx::PgPool; - use std::collections::{HashMap, HashSet}; - use std::sync::Arc; - use std::time::Duration; + use sqlx::{postgres::PgListener, PgPool}; use test_assets::{flush_messages, TAP_SENDER as SENDER}; - use tokio::sync::mpsc::error::TryRecvError; - use tokio::sync::{mpsc, watch, Notify}; + use thegraph_core::alloy::hex::ToHexExt; + use tokio::sync::{mpsc, mpsc::error::TryRecvError, watch, Notify}; + + use super::{ + new_receipts_watcher, SenderAccountsManager, SenderAccountsManagerArgs, + SenderAccountsManagerMessage, State, + }; + use crate::{ + agent::{ + sender_account::{tests::PREFIX_ID, SenderAccountConfig, SenderAccountMessage}, + sender_accounts_manager::{handle_notification, NewReceiptNotification}, + }, + test::{ + actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor}, + create_rav, create_received_receipt, store_rav, store_receipt, ALLOCATION_ID_0, + ALLOCATION_ID_1, INDEXER, SENDER_2, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR, + }, + }; const DUMMY_URL: &str = "http://localhost:1234"; @@ -634,7 +642,7 @@ mod tests { )) } - fn get_config() -> &'static super::SenderAccountConfig { + fn get_config() -> &'static SenderAccountConfig { Box::leak(Box::new(SenderAccountConfig { rav_request_buffer: Duration::from_millis(1), max_amount_willing_to_lose_grt: 0, @@ -740,7 +748,7 @@ mod tests { } // add non-final ravs - let signed_rav = create_rav(*ALLOCATION_ID_1, SIGNER.0.clone(), 4, 10); + let signed_rav = create_rav(ALLOCATION_ID_1, SIGNER.0.clone(), 4, 10); store_rav(&pgpool, signed_rav, SENDER.1).await.unwrap(); let pending_allocation_id = state.get_pending_sender_allocation_id().await; @@ -951,7 +959,7 @@ mod tests { let new_receipt_notification = NewReceiptNotification { id: 1, - allocation_id: *ALLOCATION_ID_0, + allocation_id: ALLOCATION_ID_0, signer_address: SIGNER.1, timestamp_ns: 1, value: 1, @@ -963,7 +971,7 @@ mod tests { assert_eq!( rx.recv().await.unwrap(), - SenderAccountMessage::NewAllocationId(*ALLOCATION_ID_0) + SenderAccountMessage::NewAllocationId(ALLOCATION_ID_0) ); sender_account.stop_and_wait(None, None).await.unwrap(); join_handle.await.unwrap(); diff --git a/crates/tap-agent/src/agent/sender_allocation.rs b/crates/tap-agent/src/agent/sender_allocation.rs index fd0d8bf5..990155d6 100644 --- a/crates/tap-agent/src/agent/sender_allocation.rs +++ b/crates/tap-agent/src/agent/sender_allocation.rs @@ -6,8 +6,6 @@ use std::{ time::{Duration, Instant}, }; -use alloy::primitives::Address; -use alloy::{dyn_abi::Eip712Domain, hex::ToHexExt}; use anyhow::{anyhow, ensure, Result}; use bigdecimal::{num_bigint::BigInt, ToPrimitive}; use indexer_monitor::{EscrowAccounts, SubgraphClient}; @@ -26,22 +24,26 @@ use tap_core::{ }, signed_message::EIP712SignedMessage, }; +use thegraph_core::alloy::{hex::ToHexExt, primitives::Address, sol_types::Eip712Domain}; +use thiserror::Error; use tokio::sync::watch::Receiver; -use tracing::{debug, error, warn}; - -use crate::{agent::sender_account::ReceiptFees, lazy_static}; -use crate::agent::sender_account::SenderAccountMessage; -use crate::agent::sender_accounts_manager::NewReceiptNotification; -use crate::agent::unaggregated_receipts::UnaggregatedReceipts; +use super::sender_account::SenderAccountConfig; use crate::{ - tap::context::checks::AllocationId, - tap::context::{checks::Signature, TapAgentContext}, - tap::signers_trimmed, + agent::{ + sender_account::{ReceiptFees, SenderAccountMessage}, + sender_accounts_manager::NewReceiptNotification, + unaggregated_receipts::UnaggregatedReceipts, + }, + lazy_static, + tap::{ + context::{ + checks::{AllocationId, Signature}, + TapAgentContext, + }, + signers_trimmed, + }, }; -use thiserror::Error; - -use super::sender_account::SenderAccountConfig; lazy_static! { static ref CLOSED_SENDER_ALLOCATIONS: CounterVec = register_counter_vec!( @@ -218,7 +220,7 @@ impl Actor for SenderAllocation { break; } Err(err) => { - error!( + tracing::error!( error = %err, "There was an error while calculating the last unaggregated receipts. Retrying in 30 seconds..."); tokio::time::sleep(Duration::from_secs(30)).await; @@ -228,13 +230,13 @@ impl Actor for SenderAllocation { // Request a RAV and mark the allocation as final. while state.unaggregated_fees.value > 0 { if let Err(err) = state.request_rav().await { - error!(error = %err, "There was an error while requesting rav. Retrying in 30 seconds..."); + tracing::error!(error = %err, "There was an error while requesting rav. Retrying in 30 seconds..."); tokio::time::sleep(Duration::from_secs(30)).await; } } while let Err(err) = state.mark_rav_last().await { - error!( + tracing::error!( error = %err, %state.allocation_id, %state.sender, @@ -274,7 +276,7 @@ impl Actor for SenderAllocation { } = notification; if id <= unaggregated_fees.last_id { // our world assumption is wrong - warn!( + tracing::warn!( last_id = %id, "Received a receipt notification that was already calculated." ); @@ -287,7 +289,7 @@ impl Actor for SenderAllocation { .checked_add(fees) .unwrap_or_else(|| { // This should never happen, but if it does, we want to know about it. - error!( + tracing::error!( "Overflow when adding receipt value {} to total unaggregated fees {} \ for allocation {} and sender {}. Setting total unaggregated fees to \ u128::MAX.", @@ -545,7 +547,7 @@ impl SenderAllocationState { ) { // All receipts are invalid (Err(tap_core::Error::NoValidReceiptsForRAVRequest), true, false) => { - warn!( + tracing::warn!( "Found {} invalid receipts for allocation {} and sender {}.", invalid_receipts.len(), self.allocation_id, @@ -601,7 +603,7 @@ impl SenderAllocationState { .await .inspect_err(|err| { if let jsonrpsee::core::ClientError::RequestTimeout = &err { - warn!( + tracing::warn!( "Rav request is timing out, maybe request_timeout_secs is too \ low in your config file, try adding more secs to the value. \ If the problem persists after doing so please open an issue" @@ -617,7 +619,7 @@ impl SenderAllocationState { // // store them before we call remove_obsolete_receipts() if !invalid_receipts.is_empty() { - warn!( + tracing::warn!( "Found {} invalid receipts for allocation {} and sender {}.", invalid_receipts.len(), self.allocation_id, @@ -631,7 +633,7 @@ impl SenderAllocationState { } if let Some(warnings) = response.warnings { - warn!("Warnings from sender's TAP aggregator: {:?}", warnings); + tracing::warn!("Warnings from sender's TAP aggregator: {:?}", warnings); } match self .tap_manager @@ -710,9 +712,10 @@ impl SenderAllocationState { match updated_rows.rows_affected() { // in case no rav was marked as final 0 => { - warn!( + tracing::warn!( "No RAVs were updated as last for allocation {} and sender {}.", - self.allocation_id, self.sender + self.allocation_id, + self.sender ); Ok(()) } @@ -746,10 +749,10 @@ impl SenderAllocationState { let receipt_signer = receipt .recover_signer(&self.domain_separator) .map_err(|e| { - error!("Failed to recover receipt signer: {}", e); + tracing::error!("Failed to recover receipt signer: {}", e); anyhow!(e) })?; - debug!( + tracing::debug!( "Receipt for allocation {} and signer {} failed reason: {}", allocation_id.encode_hex(), receipt_signer.encode_hex(), @@ -792,7 +795,7 @@ impl SenderAllocationState { .execute(&self.pgpool) .await .map_err(|e| { - error!("Failed to store invalid receipt: {}", e); + tracing::error!("Failed to store invalid receipt: {}", e); anyhow!(e) })?; @@ -807,11 +810,14 @@ impl SenderAllocationState { .checked_add(fees) .unwrap_or_else(|| { // This should never happen, but if it does, we want to know about it. - error!( + tracing::error!( "Overflow when adding receipt value {} to invalid receipts fees {} \ for allocation {} and sender {}. Setting total unaggregated fees to \ u128::MAX.", - fees, self.invalid_receipts_fees.value, self.allocation_id, self.sender + fees, + self.invalid_receipts_fees.value, + self.allocation_id, + self.sender ); u128::MAX }); @@ -857,20 +863,10 @@ impl SenderAllocationState { #[cfg(test)] pub mod tests { - use super::{ - SenderAllocation, SenderAllocationArgs, SenderAllocationMessage, SenderAllocationState, - }; - use crate::{ - agent::{ - sender_account::{ReceiptFees, SenderAccountMessage}, - sender_accounts_manager::NewReceiptNotification, - unaggregated_receipts::UnaggregatedReceipts, - }, - test::{ - actors::{create_mock_sender_account, TestableActor}, - create_rav, create_received_receipt, store_invalid_receipt, store_rav, store_receipt, - INDEXER, - }, + use std::{ + collections::HashMap, + sync::Arc, + time::{Duration, SystemTime, UNIX_EPOCH}, }; use futures::future::join_all; @@ -880,11 +876,6 @@ pub mod tests { use ruint::aliases::U256; use serde_json::json; use sqlx::PgPool; - use std::{ - collections::HashMap, - sync::Arc, - time::{Duration, SystemTime, UNIX_EPOCH}, - }; use tap_aggregator::{jsonrpsee_helpers::JsonRpcResponse, server::run_server}; use tap_core::receipt::{ checks::{Check, CheckError, CheckList, CheckResult}, @@ -901,6 +892,22 @@ pub mod tests { Mock, MockGuard, MockServer, Respond, ResponseTemplate, }; + use super::{ + SenderAllocation, SenderAllocationArgs, SenderAllocationMessage, SenderAllocationState, + }; + use crate::{ + agent::{ + sender_account::{ReceiptFees, SenderAccountMessage}, + sender_accounts_manager::NewReceiptNotification, + unaggregated_receipts::UnaggregatedReceipts, + }, + test::{ + actors::{create_mock_sender_account, TestableActor}, + create_rav, create_received_receipt, store_invalid_receipt, store_rav, store_receipt, + INDEXER, + }, + }; + const DUMMY_URL: &str = "http://localhost:1234"; async fn mock_escrow_subgraph() -> (MockServer, MockGuard) { @@ -951,7 +958,7 @@ pub mod tests { .unwrap(); SenderAllocationArgs { pgpool: pgpool.clone(), - allocation_id: *ALLOCATION_ID_0, + allocation_id: ALLOCATION_ID_0, sender: SENDER.1, escrow_accounts: escrow_accounts_rx, escrow_subgraph, @@ -1017,7 +1024,7 @@ pub mod tests { // Should emit a message to the sender account with the unaggregated fees. let expected_message = SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { last_id: 10, value: 55u128, @@ -1060,7 +1067,7 @@ pub mod tests { // Should emit a message to the sender account with the unaggregated fees. let expected_message = SenderAccountMessage::UpdateInvalidReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, UnaggregatedReceipts { last_id: 10, value: 55u128, @@ -1073,7 +1080,7 @@ pub mod tests { assert_eq!( last_message_emitted, SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts::default()) ) ); @@ -1101,7 +1108,7 @@ pub mod tests { SenderAllocationMessage::NewReceipt(NewReceiptNotification { id: 0, value: 10, - allocation_id: *ALLOCATION_ID_0, + allocation_id: ALLOCATION_ID_0, signer_address: SIGNER.1, timestamp_ns: 0, }) @@ -1118,7 +1125,7 @@ pub mod tests { SenderAllocationMessage::NewReceipt(NewReceiptNotification { id: 1, value: 20, - allocation_id: *ALLOCATION_ID_0, + allocation_id: ALLOCATION_ID_0, signer_address: SIGNER.1, timestamp_ns, }) @@ -1129,14 +1136,14 @@ pub mod tests { // should emit update aggregate fees message to sender account let expected_message = SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::NewReceipt(20u128, timestamp_ns), ); let startup_load_msg = message_receiver.recv().await.unwrap(); assert_eq!( startup_load_msg, SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { value: 0, last_id: 0, @@ -1222,7 +1229,7 @@ pub mod tests { assert_eq!( startup_msg, SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { value: 90, last_id: 20, @@ -1233,7 +1240,7 @@ pub mod tests { // Check if the sender received invalid receipt fees let expected_message = SenderAccountMessage::UpdateInvalidReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, UnaggregatedReceipts { last_id: 0, value: 45u128, @@ -1275,7 +1282,7 @@ pub mod tests { assert_eq!( message_receiver.recv().await.unwrap(), SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts::default()) ) ); @@ -1291,7 +1298,7 @@ pub mod tests { fn respond(&self, _request: &wiremock::Request) -> wiremock::ResponseTemplate { self.data.notify_one(); - let mock_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 10, 45); + let mock_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 10, 45); let json_response = JsonRpcResponse { data: mock_rav, @@ -1443,7 +1450,7 @@ pub mod tests { // Add the RAV to the database. // This RAV has timestamp 4. The sender_allocation should only consider receipts // with a timestamp greater than 4. - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, 10); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, 10); store_rav(&pgpool, signed_rav, SENDER.1).await.unwrap(); // Add receipts to the database. @@ -1472,7 +1479,7 @@ pub mod tests { .await; let state = SenderAllocationState::new(args).await.unwrap(); - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, 10); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, 10); // just unit test if it is working let result = state @@ -1537,7 +1544,7 @@ pub mod tests { #[sqlx::test(migrations = "../../migrations")] async fn test_mark_rav_last(pgpool: PgPool) { let (mock_escrow_subgraph_server, _mock_ecrow_subgraph) = mock_escrow_subgraph().await; - let signed_rav = create_rav(*ALLOCATION_ID_0, SIGNER.0.clone(), 4, 10); + let signed_rav = create_rav(ALLOCATION_ID_0, SIGNER.0.clone(), 4, 10); store_rav(&pgpool, signed_rav, SENDER.1).await.unwrap(); let args = create_sender_allocation_args( @@ -1594,7 +1601,7 @@ pub mod tests { assert_eq!( startup_msg, SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { value: 45, last_id: 10, @@ -1694,7 +1701,7 @@ pub mod tests { assert_eq!( startup_msg, SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::UpdateValue(UnaggregatedReceipts { value: 16220184412847561580, last_id: 10, @@ -1708,7 +1715,7 @@ pub mod tests { assert_eq!( invalid_receipts, SenderAccountMessage::UpdateInvalidReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, UnaggregatedReceipts { value: TOTAL_SUM, last_id: 0, diff --git a/crates/tap-agent/src/cli.rs b/crates/tap-agent/src/cli.rs index 74fb8876..6ba4514b 100644 --- a/crates/tap-agent/src/cli.rs +++ b/crates/tap-agent/src/cli.rs @@ -1,12 +1,14 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use anyhow::Result; +use std::path::PathBuf; + use clap::Parser; use indexer_config::{Config as IndexerConfig, ConfigPrefix}; -use std::path::PathBuf; -use tracing::subscriber::{set_global_default, SetGlobalDefaultError}; -use tracing::{error, level_filters::LevelFilter}; +use tracing::{ + level_filters::LevelFilter, + subscriber::{set_global_default, SetGlobalDefaultError}, +}; use tracing_subscriber::{EnvFilter, FmtSubscriber}; #[derive(Parser)] @@ -36,10 +38,10 @@ fn init_tracing(format: String) -> Result<(), SetGlobalDefaultError> { } } -pub fn get_config() -> Result { +pub fn get_config() -> anyhow::Result { let cli = Cli::parse(); let config = IndexerConfig::parse(ConfigPrefix::Tap, cli.config.as_ref()).map_err(|e| { - error!( + tracing::error!( "Invalid configuration file `{}`: {}, if a value is missing you can also use \ --config to fill the rest of the values", cli.config.unwrap_or_default().display(), diff --git a/crates/tap-agent/src/database.rs b/crates/tap-agent/src/database.rs index b2b532df..5cc32e92 100644 --- a/crates/tap-agent/src/database.rs +++ b/crates/tap-agent/src/database.rs @@ -4,11 +4,10 @@ use std::time::Duration; use sqlx::{postgres::PgPoolOptions, PgPool}; -use tracing::debug; pub async fn connect(config: indexer_config::DatabaseConfig) -> PgPool { let url = &config.get_formated_postgres_url(); - debug!( + tracing::debug!( postgres_host = tracing::field::debug(&url.host()), postgres_port = tracing::field::debug(&url.port()), postgres_database = tracing::field::debug(&url.path()), diff --git a/crates/tap-agent/src/lib.rs b/crates/tap-agent/src/lib.rs index a02728e0..d0f6452e 100644 --- a/crates/tap-agent/src/lib.rs +++ b/crates/tap-agent/src/lib.rs @@ -1,10 +1,10 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::dyn_abi::Eip712Domain; use indexer_config::Config; use lazy_static::lazy_static; use tap_core::tap_eip712_domain; +use thegraph_core::alloy::sol_types::Eip712Domain; lazy_static! { pub static ref CONFIG: Config = cli::get_config().expect("Failed to load configuration"); diff --git a/crates/tap-agent/src/main.rs b/crates/tap-agent/src/main.rs index 942e88b8..3627af8a 100644 --- a/crates/tap-agent/src/main.rs +++ b/crates/tap-agent/src/main.rs @@ -1,34 +1,31 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use anyhow::Result; +use indexer_tap_agent::{agent, metrics, CONFIG}; use ractor::ActorStatus; use tokio::signal::unix::{signal, SignalKind}; -use tracing::{debug, error, info}; - -use indexer_tap_agent::{agent, metrics, CONFIG}; #[tokio::main] -async fn main() -> Result<()> { +async fn main() -> anyhow::Result<()> { // Parse basic configurations, also initializes logging. lazy_static::initialize(&CONFIG); let (manager, handler) = agent::start_agent().await; - info!("TAP Agent started."); + tracing::info!("TAP Agent started."); tokio::spawn(metrics::run_server(CONFIG.metrics.port)); - info!("Metrics port opened"); + tracing::info!("Metrics port opened"); // Have tokio wait for SIGTERM or SIGINT. let mut signal_sigint = signal(SignalKind::interrupt())?; let mut signal_sigterm = signal(SignalKind::terminate())?; tokio::select! { - _ = handler => error!("SenderAccountsManager stopped"), - _ = signal_sigint.recv() => debug!("Received SIGINT."), - _ = signal_sigterm.recv() => debug!("Received SIGTERM."), + _ = handler => tracing::error!("SenderAccountsManager stopped"), + _ = signal_sigint.recv() => tracing::debug!("Received SIGINT."), + _ = signal_sigterm.recv() => tracing::debug!("Received SIGTERM."), } // If we're here, we've received a signal to exit. - info!("Shutting down..."); + tracing::info!("Shutting down..."); // We don't want our actor to run any shutdown logic, so we kill it. if manager.get_status() == ActorStatus::Running { @@ -39,6 +36,6 @@ async fn main() -> Result<()> { } // Stop the server and wait for it to finish gracefully. - debug!("Goodbye!"); + tracing::debug!("Goodbye!"); Ok(()) } diff --git a/crates/tap-agent/src/metrics.rs b/crates/tap-agent/src/metrics.rs index dde56cdc..19ce7e4a 100644 --- a/crates/tap-agent/src/metrics.rs +++ b/crates/tap-agent/src/metrics.rs @@ -6,7 +6,6 @@ use std::{net::SocketAddr, panic}; use axum::{http::StatusCode, response::IntoResponse, routing::get, Router}; use futures_util::FutureExt; use prometheus::TextEncoder; -use tracing::{debug, error, info}; async fn handler_metrics() -> (StatusCode, String) { let metric_families = prometheus::gather(); @@ -15,7 +14,7 @@ async fn handler_metrics() -> (StatusCode, String) { match encoder.encode_to_string(&metric_families) { Ok(s) => (StatusCode::OK, s), Err(e) => { - error!("Error encoding metrics: {}", e); + tracing::error!("Error encoding metrics: {}", e); ( StatusCode::INTERNAL_SERVER_ERROR, format!("Error encoding metrics: {}", e), @@ -38,11 +37,11 @@ async fn _run_server(port: u16) { .expect("Failed to Bind metrics address`"); let server = axum::serve(listener, app.into_make_service()); - info!("Metrics server listening on {}", addr); + tracing::info!("Metrics server listening on {}", addr); let res = server.await; - debug!("Metrics server stopped"); + tracing::debug!("Metrics server stopped"); if let Err(err) = res { panic!("Metrics server error: {:#?}", err); diff --git a/crates/tap-agent/src/tap/context.rs b/crates/tap-agent/src/tap/context.rs index b543bb21..15efdbca 100644 --- a/crates/tap-agent/src/tap/context.rs +++ b/crates/tap-agent/src/tap/context.rs @@ -1,9 +1,9 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::primitives::Address; use indexer_monitor::EscrowAccounts; use sqlx::PgPool; +use thegraph_core::alloy::primitives::Address; use tokio::sync::watch::Receiver; pub mod checks; diff --git a/crates/tap-agent/src/tap/context/checks/allocation_id.rs b/crates/tap-agent/src/tap/context/checks/allocation_id.rs index 46990da9..734d4dd4 100644 --- a/crates/tap-agent/src/tap/context/checks/allocation_id.rs +++ b/crates/tap-agent/src/tap/context/checks/allocation_id.rs @@ -3,7 +3,6 @@ use std::time::Duration; -use alloy::primitives::Address; use anyhow::anyhow; use indexer_monitor::SubgraphClient; use indexer_query::{tap_transactions, TapTransactions}; @@ -13,6 +12,7 @@ use tap_core::receipt::{ state::Checking, ReceiptWithState, }; +use thegraph_core::alloy::primitives::Address; use tokio::sync::watch::Receiver; pub struct AllocationId { diff --git a/crates/tap-agent/src/tap/context/checks/signature.rs b/crates/tap-agent/src/tap/context/checks/signature.rs index 8010062f..c750557e 100644 --- a/crates/tap-agent/src/tap/context/checks/signature.rs +++ b/crates/tap-agent/src/tap/context/checks/signature.rs @@ -1,7 +1,6 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::{dyn_abi::Eip712Domain, primitives::U256}; use anyhow::anyhow; use indexer_monitor::EscrowAccounts; use tap_core::receipt::{ @@ -9,6 +8,7 @@ use tap_core::receipt::{ state::Checking, ReceiptWithState, }; +use thegraph_core::alloy::{primitives::U256, sol_types::Eip712Domain}; use tokio::sync::watch::Receiver; pub struct Signature { diff --git a/crates/tap-agent/src/tap/context/error.rs b/crates/tap-agent/src/tap/context/error.rs index aa5d443f..4120fbab 100644 --- a/crates/tap-agent/src/tap/context/error.rs +++ b/crates/tap-agent/src/tap/context/error.rs @@ -1,7 +1,7 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::primitives::Address; +use thegraph_core::alloy::primitives::Address; #[derive(Debug, thiserror::Error)] pub enum AdapterError { diff --git a/crates/tap-agent/src/tap/context/escrow.rs b/crates/tap-agent/src/tap/context/escrow.rs index bded312e..268448c1 100644 --- a/crates/tap-agent/src/tap/context/escrow.rs +++ b/crates/tap-agent/src/tap/context/escrow.rs @@ -1,9 +1,9 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::primitives::Address; use async_trait::async_trait; use tap_core::manager::adapters::EscrowHandler as EscrowAdapterTrait; +use thegraph_core::alloy::primitives::Address; use super::{error::AdapterError, TapAgentContext}; diff --git a/crates/tap-agent/src/tap/context/rav.rs b/crates/tap-agent/src/tap/context/rav.rs index 6ada1a51..43003759 100644 --- a/crates/tap-agent/src/tap/context/rav.rs +++ b/crates/tap-agent/src/tap/context/rav.rs @@ -3,17 +3,20 @@ use std::str::FromStr; -use super::{error::AdapterError, TapAgentContext}; -#[allow(deprecated)] -use alloy::signers::Signature; -use alloy::{hex::ToHexExt, primitives::Address}; -use bigdecimal::num_bigint::{BigInt, ToBigInt}; -use bigdecimal::ToPrimitive; +use bigdecimal::{ + num_bigint::{BigInt, ToBigInt}, + ToPrimitive, +}; use sqlx::types::{chrono, BigDecimal}; use tap_core::{ manager::adapters::{RAVRead, RAVStore}, rav::{ReceiptAggregateVoucher, SignedRAV}, }; +#[allow(deprecated)] +use thegraph_core::alloy::signers::Signature; +use thegraph_core::alloy::{hex::ToHexExt, primitives::Address}; + +use super::{error::AdapterError, TapAgentContext}; #[async_trait::async_trait] impl RAVRead for TapAgentContext { @@ -132,11 +135,11 @@ impl RAVStore for TapAgentContext { mod test { use indexer_monitor::EscrowAccounts; use sqlx::PgPool; + use test_assets::TAP_SENDER as SENDER; use tokio::sync::watch; use super::*; use crate::test::{create_rav, ALLOCATION_ID_0, SIGNER}; - use test_assets::TAP_SENDER as SENDER; #[derive(Debug)] struct TestableRav(SignedRAV); @@ -156,14 +159,14 @@ mod test { let value_aggregate = u128::MAX; let context = TapAgentContext::new( pool.clone(), - *ALLOCATION_ID_0, + ALLOCATION_ID_0, SENDER.1, watch::channel(EscrowAccounts::default()).1, ); // Insert a rav let mut new_rav = create_rav( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, SIGNER.0.clone(), timestamp_ns, value_aggregate, @@ -179,7 +182,7 @@ mod test { // Update the RAV 3 times in quick succession for i in 0..3 { new_rav = create_rav( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, SIGNER.0.clone(), timestamp_ns + i, value_aggregate - (i as u128), diff --git a/crates/tap-agent/src/tap/context/receipt.rs b/crates/tap-agent/src/tap/context/receipt.rs index 9d3c9fa3..572816d3 100644 --- a/crates/tap-agent/src/tap/context/receipt.rs +++ b/crates/tap-agent/src/tap/context/receipt.rs @@ -7,18 +7,16 @@ use std::{ str::FromStr, }; -use alloy::hex::ToHexExt; -use alloy::primitives::Address; use bigdecimal::{num_bigint::ToBigInt, ToPrimitive}; use sqlx::{postgres::types::PgRange, types::BigDecimal}; use tap_core::{ manager::adapters::{safe_truncate_receipts, ReceiptDelete, ReceiptRead}, receipt::{state::Checking, Receipt, ReceiptWithState, SignedReceipt}, }; - -use crate::tap::signers_trimmed; +use thegraph_core::alloy::{hex::ToHexExt, primitives::Address}; use super::{error::AdapterError, TapAgentContext}; +use crate::tap::signers_trimmed; impl From for AdapterError { fn from(error: TryFromIntError) -> Self { AdapterError::ReceiptRead { @@ -192,23 +190,25 @@ impl ReceiptDelete for TapAgentContext { #[cfg(test)] mod test { - use super::*; - use crate::test::{create_received_receipt, store_receipt, SENDER_2}; - use alloy::{primitives::U256, signers::local::PrivateKeySigner}; - use anyhow::Result; + use std::collections::HashMap; + use indexer_monitor::EscrowAccounts; use lazy_static::lazy_static; use sqlx::PgPool; - use std::collections::HashMap; use test_assets::{ ALLOCATION_ID_0, ALLOCATION_ID_1, TAP_EIP712_DOMAIN as TAP_EIP712_DOMAIN_SEPARATOR, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER, }; + use thegraph_core::alloy::{primitives::U256, signers::local::PrivateKeySigner}; use tokio::sync::watch::{self, Receiver}; + use super::*; + use crate::test::{create_received_receipt, store_receipt, SENDER_2}; + + const ALLOCATION_ID_IRRELEVANT: Address = ALLOCATION_ID_1; + lazy_static! { static ref SENDER_IRRELEVANT: (PrivateKeySigner, Address) = SENDER_2.clone(); - static ref ALLOCATION_ID_IRRELEVANT: Address = *ALLOCATION_ID_1; } /// Insert a single receipt and retrieve it from the database using the adapter. @@ -222,7 +222,7 @@ mod test { .1; let storage_adapter = - TapAgentContext::new(pgpool, *ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone()); + TapAgentContext::new(pgpool, ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone()); let received_receipt = create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, u64::MAX, u64::MAX, u128::MAX); @@ -252,7 +252,7 @@ mod test { escrow_accounts: Receiver, received_receipt_vec: &[ReceiptWithState], range: R, - ) -> Result<()> { + ) -> anyhow::Result<()> { let escrow_accounts_snapshot = escrow_accounts.borrow(); // Filtering the received receipts by timestamp range @@ -302,7 +302,7 @@ mod test { escrow_accounts: Receiver, received_receipt_vec: &[ReceiptWithState], range: R, - ) -> Result<()> { + ) -> anyhow::Result<()> { let escrow_accounts_snapshot = escrow_accounts.borrow(); // Storing the receipts @@ -434,7 +434,7 @@ mod test { let storage_adapter = TapAgentContext::new( pgpool.clone(), - *ALLOCATION_ID_0, + ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone(), ); @@ -502,7 +502,7 @@ mod test { let storage_adapter = TapAgentContext::new( pgpool.clone(), - *ALLOCATION_ID_0, + ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone(), ); @@ -629,7 +629,7 @@ mod test { .1; let storage_adapter = - TapAgentContext::new(pgpool, *ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone()); + TapAgentContext::new(pgpool, ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone()); // Creating 10 receipts with timestamps 42 to 51 let mut received_receipt_vec = Vec::new(); diff --git a/crates/tap-agent/src/tap/mod.rs b/crates/tap-agent/src/tap/mod.rs index ef120840..d4b11d92 100644 --- a/crates/tap-agent/src/tap/mod.rs +++ b/crates/tap-agent/src/tap/mod.rs @@ -1,9 +1,8 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy::hex::ToHexExt; -use alloy::primitives::Address; use indexer_monitor::EscrowAccounts; +use thegraph_core::alloy::{hex::ToHexExt, primitives::Address}; use tokio::sync::watch::Receiver; pub mod context; diff --git a/crates/tap-agent/src/test.rs b/crates/tap-agent/src/test.rs index b3fa14b9..8413198d 100644 --- a/crates/tap-agent/src/test.rs +++ b/crates/tap-agent/src/test.rs @@ -1,32 +1,25 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::str::FromStr; - -use alloy::{ - primitives::hex::ToHexExt, - signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, -}; use bigdecimal::num_bigint::BigInt; - -use sqlx::types::BigDecimal; - -use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; use lazy_static::lazy_static; -use sqlx::PgPool; +use sqlx::{types::BigDecimal, PgPool}; use tap_core::{ rav::{ReceiptAggregateVoucher, SignedRAV}, receipt::{state::Checking, Receipt, ReceiptWithState, SignedReceipt}, signed_message::EIP712SignedMessage, tap_eip712_domain, }; +use thegraph_core::alloy::{ + primitives::{address, hex::ToHexExt, Address}, + signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, + sol_types::Eip712Domain, +}; + +pub const ALLOCATION_ID_0: Address = address!("abababababababababababababababababababab"); +pub const ALLOCATION_ID_1: Address = address!("bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc"); lazy_static! { - pub static ref ALLOCATION_ID_0: Address = - Address::from_str("0xabababababababababababababababababababab").unwrap(); - pub static ref ALLOCATION_ID_1: Address = - Address::from_str("0xbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc").unwrap(); // pub static ref SENDER: (PrivateKeySigner, Address) = wallet(0); pub static ref SENDER_2: (PrivateKeySigner, Address) = wallet(1); pub static ref SIGNER: (PrivateKeySigner, Address) = wallet(2); @@ -187,9 +180,10 @@ pub mod actors { use ractor::{Actor, ActorProcessingErr, ActorRef, SupervisionEvent}; use test_assets::{ALLOCATION_ID_0, TAP_SIGNER}; - use thegraph_core::Address; + use thegraph_core::alloy::primitives::Address; use tokio::sync::{mpsc, watch, Notify}; + use super::create_rav; use crate::agent::{ sender_account::{ReceiptFees, SenderAccountMessage}, sender_accounts_manager::NewReceiptNotification, @@ -197,8 +191,6 @@ pub mod actors { unaggregated_receipts::UnaggregatedReceipts, }; - use super::create_rav; - pub struct DummyActor; impl DummyActor { @@ -227,7 +219,7 @@ pub mod actors { T: Actor, { inner: T, - pub notify: Arc, + pub notify: Arc, } impl TestableActor @@ -294,7 +286,7 @@ pub mod actors { &self, myself: ActorRef, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { self.inner.post_stop(myself, state).await } @@ -303,7 +295,7 @@ pub mod actors { myself: ActorRef, msg: Self::Msg, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { let result = self.inner.handle(myself, msg, state).await; self.notify.notify_one(); result @@ -314,7 +306,7 @@ pub mod actors { myself: ActorRef, message: SupervisionEvent, state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { self.inner .handle_supervisor_evt(myself, message, state) .await @@ -406,13 +398,13 @@ pub mod actors { self.triggered_rav_request.notify_one(); if let Some(sender_account) = self.sender_actor.as_ref() { let signed_rav = create_rav( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, TAP_SIGNER.0.clone(), 4, *self.next_rav_value.borrow(), ); sender_account.cast(SenderAccountMessage::UpdateReceiptFees( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, ReceiptFees::RavRequestResponse(( UnaggregatedReceipts { value: *self.next_unaggregated_fees_value.borrow(), @@ -459,7 +451,7 @@ pub mod actors { } pub struct MockSenderAccount { - pub last_message_emitted: tokio::sync::mpsc::Sender, + pub last_message_emitted: mpsc::Sender, } #[async_trait::async_trait] @@ -472,7 +464,7 @@ pub mod actors { &self, _myself: ActorRef, _allocation_ids: Self::Arguments, - ) -> std::result::Result { + ) -> Result { Ok(()) } @@ -481,7 +473,7 @@ pub mod actors { _myself: ActorRef, message: Self::Msg, _state: &mut Self::State, - ) -> std::result::Result<(), ActorProcessingErr> { + ) -> Result<(), ActorProcessingErr> { self.last_message_emitted.send(message).await.unwrap(); Ok(()) } diff --git a/crates/tap-agent/src/tracker/generic_tracker.rs b/crates/tap-agent/src/tracker/generic_tracker.rs index 0e2d4648..d81a392b 100644 --- a/crates/tap-agent/src/tracker/generic_tracker.rs +++ b/crates/tap-agent/src/tracker/generic_tracker.rs @@ -1,18 +1,19 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::agent::unaggregated_receipts::UnaggregatedReceipts; - -use super::{ - global_tracker::GlobalTracker, AllocationStats, DefaultFromExtra, DurationInfo, SenderFeeStats, -}; -use alloy::primitives::Address; use std::{ collections::{HashMap, HashSet}, marker::PhantomData, time::Duration, }; +use thegraph_core::alloy::primitives::Address; + +use super::{ + global_tracker::GlobalTracker, AllocationStats, DefaultFromExtra, DurationInfo, SenderFeeStats, +}; +use crate::agent::unaggregated_receipts::UnaggregatedReceipts; + #[derive(Debug, Clone, Copy, Default, PartialEq)] pub struct GlobalFeeTracker { pub(super) requesting: u128, diff --git a/crates/tap-agent/src/tracker/global_tracker.rs b/crates/tap-agent/src/tracker/global_tracker.rs index 719f94bd..a29df32d 100644 --- a/crates/tap-agent/src/tracker/global_tracker.rs +++ b/crates/tap-agent/src/tracker/global_tracker.rs @@ -1,9 +1,8 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::agent::unaggregated_receipts::UnaggregatedReceipts; - use super::GlobalFeeTracker; +use crate::agent::unaggregated_receipts::UnaggregatedReceipts; pub trait GlobalTracker: Sized { fn get_total_fee(&self) -> u128; diff --git a/crates/tap-agent/src/tracker/sender_fee_stats.rs b/crates/tap-agent/src/tracker/sender_fee_stats.rs index 517f1ffd..dcef47dd 100644 --- a/crates/tap-agent/src/tracker/sender_fee_stats.rs +++ b/crates/tap-agent/src/tracker/sender_fee_stats.rs @@ -6,9 +6,8 @@ use std::{ time::{Duration, SystemTime, UNIX_EPOCH}, }; -use crate::{agent::unaggregated_receipts::UnaggregatedReceipts, backoff::BackoffInfo}; - use super::{AllocationStats, DefaultFromExtra, DurationInfo}; +use crate::{agent::unaggregated_receipts::UnaggregatedReceipts, backoff::BackoffInfo}; #[derive(Debug, Clone, Default)] pub struct SenderFeeStats { diff --git a/crates/tap-agent/src/tracker/tracker_tests.rs b/crates/tap-agent/src/tracker/tracker_tests.rs index 1053b85c..9904c7ed 100644 --- a/crates/tap-agent/src/tracker/tracker_tests.rs +++ b/crates/tap-agent/src/tracker/tracker_tests.rs @@ -1,15 +1,16 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::{agent::unaggregated_receipts::UnaggregatedReceipts, tracker::SenderFeeTracker}; - -use super::SimpleFeeTracker; -use alloy::primitives::address; use std::{ thread::sleep, time::{Duration, SystemTime, UNIX_EPOCH}, }; +use thegraph_core::alloy::primitives::address; + +use super::SimpleFeeTracker; +use crate::{agent::unaggregated_receipts::UnaggregatedReceipts, tracker::SenderFeeTracker}; + #[test] fn test_allocation_id_tracker() { let allocation_id_0 = address!("abababababababababababababababababababab"); diff --git a/crates/test-assets/Cargo.toml b/crates/test-assets/Cargo.toml index 5c5e298a..568c14b9 100644 --- a/crates/test-assets/Cargo.toml +++ b/crates/test-assets/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" [dependencies] indexer-allocation = { path = "../allocation" } -alloy.workspace = true bip39 = "2.0.0" lazy_static.workspace = true tap_core.workspace = true diff --git a/crates/test-assets/src/lib.rs b/crates/test-assets/src/lib.rs index bd766383..71caa494 100644 --- a/crates/test-assets/src/lib.rs +++ b/crates/test-assets/src/lib.rs @@ -1,23 +1,28 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use std::{collections::HashMap, str::FromStr, time::Duration}; - -use alloy::{ - dyn_abi::Eip712Domain, - primitives::U256, - signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, +use std::{ + collections::HashMap, + str::FromStr, + time::{Duration, SystemTime, UNIX_EPOCH}, }; + use bip39::Mnemonic; +use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment}; use lazy_static::lazy_static; use tap_core::{ receipt::{Receipt, SignedReceipt}, signed_message::EIP712SignedMessage, tap_eip712_domain, }; -use thegraph_core::{Address, DeploymentId}; - -use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment}; +use thegraph_core::{ + alloy::{ + primitives::{address, Address, U256}, + signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, + sol_types::Eip712Domain, + }, + deployment_id, DeploymentId, +}; use tokio::sync::Notify; use typed_builder::TypedBuilder; @@ -55,16 +60,16 @@ macro_rules! assert_while_retry { }; } -/// 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 +// 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 ESCROW_QUERY_RESPONSE: &str = r#" { @@ -110,43 +115,38 @@ pub const ESCROW_QUERY_RESPONSE: &str = r#" } "#; -lazy_static! { - pub static ref NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP").unwrap(); - pub static ref ESCROW_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss").unwrap(); +pub const NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = + deployment_id!("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP"); +pub const ESCROW_SUBGRAPH_DEPLOYMENT: DeploymentId = + deployment_id!("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss"); - pub static ref INDEXER_MNEMONIC: Mnemonic = Mnemonic::from_str( - "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", - ).unwrap(); - - pub static ref INDEXER_ADDRESS: Address = - Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(); +pub const INDEXER_ADDRESS: Address = address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"); - pub static ref DISPUTE_MANAGER_ADDRESS: Address = - Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(); +pub const DISPUTE_MANAGER_ADDRESS: Address = address!("deadbeefcafebabedeadbeefcafebabedeadbeef"); +pub const ALLOCATION_ID_0: Address = address!("fa44c72b753a66591f241c7dc04e8178c30e13af"); - pub static ref ALLOCATION_ID_0: Address = - Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap(); +pub const ALLOCATION_ID_1: Address = address!("dd975e30aafebb143e54d215db8a3e8fd916a701"); - pub static ref ALLOCATION_ID_1: Address = - Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap(); +pub const ALLOCATION_ID_2: Address = address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658"); - pub static ref ALLOCATION_ID_2: Address = - Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(); - - pub static ref ALLOCATION_ID_3: Address = - Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap(); +pub const ALLOCATION_ID_3: Address = address!("69f961358846fdb64b04e1fd7b2701237c13cd9a"); +pub const VERIFIER_ADDRESS: Address = address!("1111111111111111111111111111111111111111"); +lazy_static! { + pub static ref INDEXER_MNEMONIC: Mnemonic = Mnemonic::from_str( + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + ).unwrap(); /// 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 static ref INDEXER_ALLOCATIONS: HashMap = HashMap::from([ ( - *ALLOCATION_ID_0, + ALLOCATION_ID_0, Allocation { - id: *ALLOCATION_ID_0, - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + id: ALLOCATION_ID_0, + indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"), allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(), created_at_block_hash: "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), @@ -167,10 +167,10 @@ lazy_static! { }, ), ( - *ALLOCATION_ID_1, + ALLOCATION_ID_1, Allocation { - id: *ALLOCATION_ID_1, - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + id: ALLOCATION_ID_1, + indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"), allocated_tokens: U256::from_str("601726452999999979510903").unwrap(), created_at_block_hash: "0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(), @@ -191,10 +191,10 @@ lazy_static! { }, ), ( - *ALLOCATION_ID_2, + ALLOCATION_ID_2, Allocation { - id: *ALLOCATION_ID_2, - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + id: ALLOCATION_ID_2, + indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"), allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(), created_at_block_hash: "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), @@ -215,10 +215,10 @@ lazy_static! { }, ), ( - *ALLOCATION_ID_3, + ALLOCATION_ID_3, Allocation { - id: *ALLOCATION_ID_3, - indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(), + id: ALLOCATION_ID_3, + indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"), allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(), created_at_block_hash: "0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(), @@ -241,43 +241,43 @@ lazy_static! { ]); pub static ref ESCROW_ACCOUNTS_BALANCES: HashMap = HashMap::from([ - (Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), U256::from(24)), // TAP_SENDER - (Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), U256::from(42)), - (Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), U256::from(2975)), + (address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), U256::from(24)), // TAP_SENDER + (address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"), U256::from(42)), + (address!("192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002"), U256::from(2975)), ]); /// Maps signers back to their senders pub static ref ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS: HashMap = HashMap::from([ ( - Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER - Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER + address!("533661F0fb14d2E8B26223C86a610Dd7D2260892"), // TAP_SIGNER + address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER ), ( - Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(), - Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER + address!("2740f6fA9188cF53ffB6729DDD21575721dE92ce"), + address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER ), ( - Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap(), - Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), + address!("245059163ff6ee14279aa7b35ea8f0fdb967df6e"), + address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"), ), ]); pub static ref ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS: HashMap> = HashMap::from([ ( - Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER + address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER vec![ - Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER - Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(), + address!("533661F0fb14d2E8B26223C86a610Dd7D2260892"), // TAP_SIGNER + address!("2740f6fA9188cF53ffB6729DDD21575721dE92ce"), ], ), ( - Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), - vec![Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap()], + address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"), + vec![address!("245059163ff6ee14279aa7b35ea8f0fdb967df6e")], ), ( - Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), + address!("192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002"), vec![], ), ]); @@ -307,17 +307,14 @@ lazy_static! { (wallet, address) }; - pub static ref VERIFIER_ADDRESS: Address = Address::from([0x11u8; 20]); pub static ref TAP_EIP712_DOMAIN: Eip712Domain = tap_eip712_domain( 1, - *VERIFIER_ADDRESS + VERIFIER_ADDRESS ); } -use std::time::{SystemTime, UNIX_EPOCH}; - #[derive(TypedBuilder)] pub struct SignedReceiptRequest { #[builder(default = Address::ZERO)] diff --git a/crates/watcher/src/lib.rs b/crates/watcher/src/lib.rs index 931c62fb..444eb1bc 100644 --- a/crates/watcher/src/lib.rs +++ b/crates/watcher/src/lib.rs @@ -14,7 +14,6 @@ use tokio::{ task::JoinHandle, time::{self, sleep}, }; -use tracing::{error, warn}; /// Creates a new watcher that auto initializes it with initial_value /// and updates it given an interval @@ -41,7 +40,7 @@ where Ok(value) => tx.send(value).expect("Failed to update channel"), Err(err) => { // TODO mark it as delayed - warn!(error = %err, "There was an error while updating watcher"); + tracing::warn!(error = %err, "There was an error while updating watcher"); // Sleep for a bit before we retry sleep(interval.div_f32(2.0)).await; } @@ -106,7 +105,7 @@ where function(value).await; } Err(err) => { - error!("There was an error piping the watcher results: {err}"); + tracing::error!("There was an error piping the watcher results: {err}"); break; } }; diff --git a/rustfmt.toml b/rustfmt.toml index 3a26366d..aeab5f4f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,5 @@ edition = "2021" +unstable_features = true +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +reorder_modules = true