From 2663e8b4da983f99c06acae7eaa32752d978baf3 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Fri, 24 Jan 2025 18:48:13 +0100 Subject: [PATCH] refactor: use generic manager Signed-off-by: Gustavo Inacio --- Cargo.lock | 179 +++++++++--------- Cargo.toml | 10 +- crates/dips/src/lib.rs | 16 +- crates/dips/src/server.rs | 9 +- crates/service/src/database/dips.rs | 2 - crates/service/src/middleware/auth/tap.rs | 11 +- crates/service/src/service.rs | 4 +- crates/service/src/tap.rs | 4 +- .../src/tap/checks/allocation_eligible.rs | 6 +- .../service/src/tap/checks/deny_list_check.rs | 6 +- .../src/tap/checks/receipt_max_val_check.rs | 12 +- .../src/tap/checks/sender_balance_check.rs | 6 +- .../service/src/tap/checks/timestamp_check.rs | 14 +- crates/service/src/tap/checks/value_check.rs | 10 +- crates/service/src/tap/receipt_store.rs | 8 +- crates/tap-agent/src/agent/sender_account.rs | 10 +- .../tap-agent/src/agent/sender_allocation.rs | 41 ++-- .../src/tap/context/checks/allocation_id.rs | 6 +- .../src/tap/context/checks/signature.rs | 6 +- .../tap-agent/src/tap/context/checks/value.rs | 6 +- crates/tap-agent/src/tap/context/escrow.rs | 12 +- crates/tap-agent/src/tap/context/rav.rs | 16 +- crates/tap-agent/src/tap/context/receipt.rs | 90 ++++----- crates/tap-agent/src/test.rs | 15 +- 24 files changed, 251 insertions(+), 248 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 788b3948..c102b540 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,9 +68,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "alloy" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59febb24956a41c29bb5f450978fbe825bd6456b3f80586c8bd558dc882e7b6a" +checksum = "bbcc41e8a11a4975b18ec6afba2cc48d591fa63336a4c526dacb50479a8d6b35" dependencies = [ "alloy-consensus", "alloy-contract", @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "alloy-consensus" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88e1edea70787c33e11197d3f32ae380f3db19e6e061e539a5bcf8184a6b326" +checksum = "f4138dc275554afa6f18c4217262ac9388790b2fc393c2dfe03c51d357abf013" dependencies = [ "alloy-eips", "alloy-primitives", @@ -125,9 +125,9 @@ dependencies = [ [[package]] name = "alloy-consensus-any" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b1bb53f40c0273cd1975573cd457b39213e68584e36d1401d25fd0398a1d65" +checksum = "0fa04e1882c31288ce1028fdf31b6ea94cfa9eafa2e497f903ded631c8c6a42c" dependencies = [ "alloy-consensus", "alloy-eips", @@ -139,9 +139,9 @@ dependencies = [ [[package]] name = "alloy-contract" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b668c78c4b1f12f474ede5a85e8ce550d0aa1ef7d49fd1d22855a43b960e725" +checksum = "5f21886c1fea0626f755a49b2ac653b396fb345233f6170db2da3d0ada31560c" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", @@ -155,7 +155,7 @@ dependencies = [ "alloy-transport", "futures", "futures-util", - "thiserror 2.0.3", + "thiserror 2.0.11", ] [[package]] @@ -202,9 +202,9 @@ dependencies = [ [[package]] name = "alloy-eip7702" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" +checksum = "cabf647eb4650c91a9d38cb6f972bb320009e7e9d61765fb688a86f1563b33e8" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -215,9 +215,9 @@ dependencies = [ [[package]] name = "alloy-eips" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9fadfe089e9ccc0650473f2d4ef0a28bc015bbca5631d9f0f09e49b557fdb3" +checksum = "52dd5869ed09e399003e0e0ec6903d981b2a92e74c5d37e6b40890bad2517526" dependencies = [ "alloy-eip2930", "alloy-eip7702", @@ -233,10 +233,11 @@ dependencies = [ [[package]] name = "alloy-genesis" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2a4cf7b70f3495788e74ce1c765260ffe38820a2a774ff4aacb62e31ea73f9" +checksum = "e7d2a7fe5c1a9bd6793829ea21a636f30fc2b3f5d2e7418ba86d96e41dd1f460" dependencies = [ + "alloy-eips", "alloy-primitives", "alloy-serde", "alloy-trie", @@ -257,23 +258,23 @@ dependencies = [ [[package]] name = "alloy-json-rpc" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e29040b9d5fe2fb70415531882685b64f8efd08dfbd6cc907120650504821105" +checksum = "2008bedb8159a255b46b7c8614516eda06679ea82f620913679afbd8031fea72" dependencies = [ "alloy-primitives", "alloy-sol-types", "serde", "serde_json", - "thiserror 2.0.3", + "thiserror 2.0.11", "tracing", ] [[package]] name = "alloy-network" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510cc00b318db0dfccfdd2d032411cfae64fc144aef9679409e014145d3dacc4" +checksum = "4556f01fe41d0677495df10a648ddcf7ce118b0e8aa9642a0e2b6dd1fb7259de" dependencies = [ "alloy-consensus", "alloy-consensus-any", @@ -291,14 +292,14 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror 2.0.3", + "thiserror 2.0.11", ] [[package]] name = "alloy-network-primitives" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9081c099e798b8a2bba2145eb82a9a146f01fc7a35e9ab6e7b43305051f97550" +checksum = "f31c3c6b71340a1d076831823f09cb6e02de01de5c6630a9631bdb36f947ff80" dependencies = [ "alloy-consensus", "alloy-eips", @@ -337,9 +338,9 @@ dependencies = [ [[package]] name = "alloy-provider" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc2dfaddd9a30aa870a78a4e1316e3e115ec1e12e552cbc881310456b85c1f24" +checksum = "5a22c4441b3ebe2d77fa9cf629ba68c3f713eb91779cff84275393db97eddd82" dependencies = [ "alloy-chains", "alloy-consensus", @@ -368,7 +369,7 @@ dependencies = [ "schnellru", "serde", "serde_json", - "thiserror 2.0.3", + "thiserror 2.0.11", "tokio", "tracing", "url", @@ -377,9 +378,9 @@ dependencies = [ [[package]] name = "alloy-pubsub" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "695809e743628d54510c294ad17a4645bd9f465aeb0d20ee9ce9877c9712dc9c" +checksum = "2269fd635f7b505f27c63a3cb293148cd02301efce4c8bdd9ff54fbfc4a20e23" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -418,9 +419,9 @@ dependencies = [ [[package]] name = "alloy-rpc-client" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531137b283547d5b9a5cafc96b006c64ef76810c681d606f28be9781955293b6" +checksum = "d06a292b37e182e514903ede6e623b9de96420e8109ce300da288a96d88b7e4b" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -444,9 +445,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3410a472ce26c457e9780f708ee6bd540b30f88f1f31fdab7a11d00bd6aa1aee" +checksum = "9383845dd924939e7ab0298bbfe231505e20928907d7905aa3bf112287305e06" dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", @@ -457,9 +458,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-any" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed98e1af55a7d856bfa385f30f63d8d56be2513593655c904a8f4a7ec963aa3e" +checksum = "ca445cef0eb6c2cf51cfb4e214fbf1ebd00893ae2e6f3b944c8101b07990f988" dependencies = [ "alloy-consensus-any", "alloy-rpc-types-eth", @@ -468,9 +469,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-engine" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03bd16fa4959255ebf4a7702df08f325e5631df5cdca07c8a8e58bdc10fe02e3" +checksum = "4a5f821f30344862a0b6eb9a1c2eb91dfb2ff44c7489f37152a526cdcab79264" dependencies = [ "alloy-consensus", "alloy-eips", @@ -484,9 +485,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-eth" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8737d7a6e37ca7bba9c23e9495c6534caec6760eb24abc9d5ffbaaba147818e1" +checksum = "0938bc615c02421bd86c1733ca7205cc3d99a122d9f9bff05726bd604b76a5c2" dependencies = [ "alloy-consensus", "alloy-consensus-any", @@ -496,17 +497,17 @@ dependencies = [ "alloy-rlp", "alloy-serde", "alloy-sol-types", - "derive_more", "itertools 0.13.0", "serde", "serde_json", + "thiserror 2.0.11", ] [[package]] name = "alloy-serde" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5851bf8d5ad33014bd0c45153c603303e730acc8a209450a7ae6b4a12c2789e2" +checksum = "ae0465c71d4dced7525f408d84873aeebb71faf807d22d74c4a426430ccd9b55" dependencies = [ "alloy-primitives", "serde", @@ -515,9 +516,9 @@ dependencies = [ [[package]] name = "alloy-signer" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e10ca565da6500cca015ba35ee424d59798f2e1b85bc0dd8f81dafd401f029a" +checksum = "9bfa395ad5cc952c82358d31e4c68b27bf4a89a5456d9b27e226e77dac50e4ff" dependencies = [ "alloy-dyn-abi", "alloy-primitives", @@ -526,14 +527,14 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror 2.0.3", + "thiserror 2.0.11", ] [[package]] name = "alloy-signer-aws" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e774d4203ad7dbeba06876c8528a169b7cb56770bd900bc061e6a2c2756a736" +checksum = "0eb06810c34427d499863817eb506acf57cb9ded9224b374116cae4e22dbd4e9" dependencies = [ "alloy-consensus", "alloy-network", @@ -543,15 +544,15 @@ dependencies = [ "aws-sdk-kms", "k256", "spki", - "thiserror 2.0.3", + "thiserror 2.0.11", "tracing", ] [[package]] name = "alloy-signer-gcp" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9843facd50077d2010ac0ef9e9176f8a06f2e2c8e653d83d82859803c623c6fc" +checksum = "d629e63fec8802ad53706d46e8eceeeae2b135c6648d0de41669a523bf17df4a" dependencies = [ "alloy-consensus", "alloy-network", @@ -561,15 +562,15 @@ dependencies = [ "gcloud-sdk", "k256", "spki", - "thiserror 2.0.3", + "thiserror 2.0.11", "tracing", ] [[package]] name = "alloy-signer-ledger" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08367716d2eee6f15f0f7ee2e855decbfedd12be12fe5f490a2d2717deda95bf" +checksum = "b426789566a19252cb46b757d91543a6f8e70330c72f312b86c5878595d092ef" dependencies = [ "alloy-consensus", "alloy-dyn-abi", @@ -581,15 +582,15 @@ dependencies = [ "coins-ledger", "futures-util", "semver 1.0.23", - "thiserror 2.0.3", + "thiserror 2.0.11", "tracing", ] [[package]] name = "alloy-signer-local" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47fababf5a745133490cde927d48e50267f97d3d1209b9fc9f1d1d666964d172" +checksum = "fbdc63ce9eda1283fcbaca66ba4a414b841c0e3edbeef9c86a71242fc9e84ccc" dependencies = [ "alloy-consensus", "alloy-network", @@ -600,7 +601,7 @@ dependencies = [ "coins-bip39", "k256", "rand", - "thiserror 2.0.3", + "thiserror 2.0.11", ] [[package]] @@ -678,9 +679,9 @@ dependencies = [ [[package]] name = "alloy-transport" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "538a04a37221469cac0ce231b737fd174de2fdfcdd843bdd068cb39ed3e066ad" +checksum = "d17722a198f33bbd25337660787aea8b8f57814febb7c746bc30407bdfc39448" dependencies = [ "alloy-json-rpc", "base64 0.22.1", @@ -688,7 +689,7 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror 2.0.3", + "thiserror 2.0.11", "tokio", "tower 0.5.2", "tracing", @@ -698,9 +699,9 @@ dependencies = [ [[package]] name = "alloy-transport-http" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed40eb1e1265b2911512f6aa1dcece9702d078f5a646730c45e39e2be00ac1c" +checksum = "6e1509599021330a31c4a6816b655e34bf67acb1cc03c564e09fd8754ff6c5de" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -713,9 +714,9 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a172a59d24706b26a79a837f86d51745cb26ca6f8524712acd0208a14cff95" +checksum = "fa4da44bc9a5155ab599666d26decafcf12204b72a80eeaba7c5e234ee8ac205" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -732,9 +733,9 @@ dependencies = [ [[package]] name = "alloy-transport-ws" -version = "0.8.3" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fba0e39d181d13c266dbb8ca54ed584a2c66d6e9279afca89c7a6b1825e98abb" +checksum = "58011745b2f17b334db40df9077d75b181f78360a5bc5c35519e15d4bfce15e2" dependencies = [ "alloy-pubsub", "alloy-transport", @@ -4160,9 +4161,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.167" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libm" @@ -5309,7 +5310,7 @@ dependencies = [ "rustc-hash", "rustls 0.23.19", "socket2 0.5.8", - "thiserror 2.0.3", + "thiserror 2.0.11", "tokio", "tracing", ] @@ -5328,7 +5329,7 @@ dependencies = [ "rustls 0.23.19", "rustls-pki-types", "slab", - "thiserror 2.0.3", + "thiserror 2.0.11", "tinyvec", "tracing", "web-time", @@ -6564,7 +6565,7 @@ dependencies = [ "serde_json", "sha2", "smallvec", - "thiserror 2.0.3", + "thiserror 2.0.11", "tokio", "tokio-stream", "tracing", @@ -6651,7 +6652,7 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror 2.0.3", + "thiserror 2.0.11", "tracing", "uuid", "whoami", @@ -6693,7 +6694,7 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror 2.0.3", + "thiserror 2.0.11", "tracing", "uuid", "whoami", @@ -6912,7 +6913,7 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tap_aggregator" version = "0.3.3" -source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=6af1add#6af1add4a326c77100491ba353050cb38f319631" +source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=1fc51a3#1fc51a3ff9ce74027b47a0e6d026a5bedd9ca00c" dependencies = [ "alloy", "anyhow", @@ -6926,7 +6927,6 @@ dependencies = [ "prometheus", "prost", "rayon", - "ruint", "serde", "serde_json", "strum", @@ -6934,14 +6934,14 @@ dependencies = [ "tokio", "tonic", "tonic-build", - "tower 0.4.13", + "tower 0.5.2", "tracing-subscriber", ] [[package]] name = "tap_core" version = "2.0.0" -source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=6af1add#6af1add4a326c77100491ba353050cb38f319631" +source = "git+https://github.com/semiotic-ai/timeline-aggregation-protocol?rev=1fc51a3#1fc51a3ff9ce74027b47a0e6d026a5bedd9ca00c" dependencies = [ "alloy", "anyhow", @@ -6949,7 +6949,7 @@ dependencies = [ "async-trait", "rand", "serde", - "thiserror 1.0.69", + "thiserror 2.0.11", "tokio", ] @@ -7023,14 +7023,13 @@ dependencies = [ [[package]] name = "thegraph-core" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bcee8212008d3f49e00b4d052b6c3c7b422d8fd7c8c92efe9aa608762473293" +source = "git+https://github.com/edgeandnode/toolshed?rev=a1d0509#a1d0509db12e28aaa6dfc2e85d3e9087583d3e25" dependencies = [ "alloy", "bs58", "serde", "serde_with", - "thiserror 1.0.69", + "thiserror 2.0.11", ] [[package]] @@ -7057,11 +7056,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" dependencies = [ - "thiserror-impl 2.0.3", + "thiserror-impl 2.0.11", ] [[package]] @@ -7077,9 +7076,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2", "quote", @@ -7172,9 +7171,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.42.0" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" dependencies = [ "backtrace", "bytes", @@ -7190,9 +7189,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", @@ -7471,7 +7470,7 @@ dependencies = [ "governor", "http 1.1.0", "pin-project 1.1.8", - "thiserror 2.0.3", + "thiserror 2.0.11", "tower 0.5.2", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index fa9784de..fe623f5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ axum = { version = "0.7.9", default-features = false, features = [ "http1", "http2", ] } -tokio = "1.40" +tokio = "1" prometheus = "0.13.3" anyhow = { version = "1.0.72" } thiserror = "1.0.49" @@ -52,14 +52,14 @@ 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 = "6af1add", default-features = false } -tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "6af1add", default-features = false } +tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1fc51a3", default-features = false } +tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1fc51a3", default-features = false } tracing-subscriber = { version = "0.3", features = [ "json", "env-filter", "ansi", ], default-features = false } -thegraph-core = { version = "0.10.0", features = [ +thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "a1d0509", features = [ "attestation", "alloy-eip712", "alloy-sol-types", @@ -67,7 +67,7 @@ thegraph-core = { version = "0.10.0", features = [ "alloy-signers", "alloy-signer-local", "alloy-signer-mnemonic", - "serde" + "serde", ] } thegraph-graphql-http = { version = "0.3.2", features = ["reqwest"] } graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] } diff --git a/crates/dips/src/lib.rs b/crates/dips/src/lib.rs index da9a5a6e..2c369b87 100644 --- a/crates/dips/src/lib.rs +++ b/crates/dips/src/lib.rs @@ -22,9 +22,8 @@ pub mod server; pub mod store; use store::AgreementStore; -use uuid::Uuid; - use thiserror::Error; +use uuid::Uuid; sol! { // EIP712 encoded bytes, ABI - ethers @@ -264,9 +263,10 @@ pub async fn validate_and_cancel_agreement( #[cfg(test)] mod test { - use std::sync::Arc; - - use std::time::{Duration, SystemTime, UNIX_EPOCH}; + use std::{ + sync::Arc, + time::{Duration, SystemTime, UNIX_EPOCH}, + }; use thegraph_core::{ alloy::{ @@ -276,12 +276,12 @@ mod test { }, attestation::eip712_domain, }; - - use crate::{CancellationRequest, DipsError}; - use crate::{IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata}; use uuid::Uuid; pub use crate::store::{AgreementStore, InMemoryAgreementStore}; + use crate::{ + CancellationRequest, DipsError, IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata, + }; #[tokio::test] async fn test_validate_and_create_agreement() -> anyhow::Result<()> { diff --git a/crates/dips/src/server.rs b/crates/dips/src/server.rs index 24bab8df..0999f6bb 100644 --- a/crates/dips/src/server.rs +++ b/crates/dips/src/server.rs @@ -3,14 +3,15 @@ use std::{str::FromStr, sync::Arc, time::Duration}; +use anyhow::anyhow; +use async_trait::async_trait; +use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain}; +use uuid::Uuid; + use crate::{ proto::graphprotocol::indexer::dips::*, store::AgreementStore, validate_and_cancel_agreement, validate_and_create_agreement, DipsError, }; -use anyhow::anyhow; -use async_trait::async_trait; -use thegraph_core::alloy::{dyn_abi::Eip712Domain, primitives::Address}; -use uuid::Uuid; #[derive(Debug)] pub struct DipsServer { diff --git a/crates/service/src/database/dips.rs b/crates/service/src/database/dips.rs index 2709ec03..b90bd367 100644 --- a/crates/service/src/database/dips.rs +++ b/crates/service/src/database/dips.rs @@ -4,11 +4,9 @@ use anyhow::bail; use axum::async_trait; use build_info::chrono::Utc; - use indexer_dips::{ store::AgreementStore, SignedCancellationRequest, SignedIndexingAgreementVoucher, }; - use sqlx::PgPool; use thegraph_core::alloy::rlp::Decodable; use uuid::Uuid; diff --git a/crates/service/src/middleware/auth/tap.rs b/crates/service/src/middleware/auth/tap.rs index 68a58b7a..7ae57def 100644 --- a/crates/service/src/middleware/auth/tap.rs +++ b/crates/service/src/middleware/auth/tap.rs @@ -18,6 +18,7 @@ use axum::{ }; use tap_core::{ manager::{adapters::ReceiptStore, Manager}, + rav::ReceiptAggregateVoucher, receipt::{Context, SignedReceipt}, }; use tower_http::auth::AsyncAuthorizeRequest; @@ -30,7 +31,7 @@ use crate::{error::IndexerServiceError, middleware::prometheus_metrics::MetricLa /// /// Requires SignedReceipt, MetricLabels and Arc extensions pub fn tap_receipt_authorize( - tap_manager: Arc>, + tap_manager: Arc>, failed_receipt_metric: &'static prometheus::CounterVec, ) -> impl AsyncAuthorizeRequest< B, @@ -40,7 +41,7 @@ pub fn tap_receipt_authorize( > + Clone + Send where - T: ReceiptStore + Sync + Send + 'static, + T: ReceiptStore + Sync + Send + 'static, B: Send, { move |request: Request| { @@ -91,7 +92,7 @@ mod tests { receipt::{ checks::{Check, CheckError, CheckList, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }, }; use test_assets::{ @@ -133,11 +134,11 @@ mod tests { struct MyCheck; #[async_trait::async_trait] - impl Check for MyCheck { + impl Check for MyCheck { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { if receipt.signed_receipt().message.nonce == FAILED_NONCE { Err(CheckError::Failed(anyhow::anyhow!("Failed"))) diff --git a/crates/service/src/service.rs b/crates/service/src/service.rs index 194b112e..9d20f0d9 100644 --- a/crates/service/src/service.rs +++ b/crates/service/src/service.rs @@ -6,6 +6,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration}; use anyhow::anyhow; use axum::{extract::Request, serve, ServiceExt}; +use clap::Parser; use indexer_config::{Config, DipsConfig, GraphNodeConfig, SubgraphConfig}; use indexer_dips::{ proto::graphprotocol::indexer::dips::agreement_service_server::{ @@ -19,14 +20,13 @@ use reqwest::Url; use tap_core::tap_eip712_domain; use tokio::{net::TcpListener, signal}; use tower_http::normalize_path::NormalizePath; +use tracing::info; use crate::{ cli::Cli, database::{self, dips::PsqlAgreementStore}, metrics::serve_metrics, }; -use clap::Parser; -use tracing::info; mod release; mod router; diff --git a/crates/service/src/tap.rs b/crates/service/src/tap.rs index e6ca2b48..f503f8d0 100644 --- a/crates/service/src/tap.rs +++ b/crates/service/src/tap.rs @@ -7,7 +7,7 @@ use indexer_allocation::Allocation; use indexer_monitor::EscrowAccounts; use receipt_store::{DatabaseReceipt, InnerContext}; use sqlx::PgPool; -use tap_core::receipt::checks::ReceiptCheck; +use tap_core::receipt::{checks::ReceiptCheck, SignedReceipt}; use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain}; use tokio::sync::{ mpsc::{self, Sender}, @@ -48,7 +48,7 @@ impl IndexerTapContext { escrow_accounts: Receiver, timestamp_error_tolerance: Duration, receipt_max_value: u128, - ) -> Vec { + ) -> Vec> { vec![ Arc::new(AllocationEligible::new(indexer_allocations)), Arc::new(SenderBalanceCheck::new(escrow_accounts)), diff --git a/crates/service/src/tap/checks/allocation_eligible.rs b/crates/service/src/tap/checks/allocation_eligible.rs index 94d8505a..2f07971b 100644 --- a/crates/service/src/tap/checks/allocation_eligible.rs +++ b/crates/service/src/tap/checks/allocation_eligible.rs @@ -8,7 +8,7 @@ use indexer_allocation::Allocation; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; use thegraph_core::alloy::primitives::Address; use tokio::sync::watch::Receiver; @@ -25,11 +25,11 @@ impl AllocationEligible { } } #[async_trait::async_trait] -impl Check for AllocationEligible { +impl Check for AllocationEligible { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { let allocation_id = receipt.signed_receipt().message.allocation_id; if !self diff --git a/crates/service/src/tap/checks/deny_list_check.rs b/crates/service/src/tap/checks/deny_list_check.rs index 7a0d716f..33b12e0a 100644 --- a/crates/service/src/tap/checks/deny_list_check.rs +++ b/crates/service/src/tap/checks/deny_list_check.rs @@ -11,7 +11,7 @@ use sqlx::{postgres::PgListener, PgPool}; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; use thegraph_core::alloy::primitives::Address; @@ -153,11 +153,11 @@ impl DenyListCheck { } #[async_trait::async_trait] -impl Check for DenyListCheck { +impl Check for DenyListCheck { async fn check( &self, ctx: &tap_core::receipt::Context, - _: &ReceiptWithState, + _: &ReceiptWithState, ) -> CheckResult { let Sender(receipt_sender) = ctx .get::() 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 e4dbcbd4..de6e8cad 100644 --- a/crates/service/src/tap/checks/receipt_max_val_check.rs +++ b/crates/service/src/tap/checks/receipt_max_val_check.rs @@ -9,7 +9,7 @@ pub struct ReceiptMaxValueCheck { use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; impl ReceiptMaxValueCheck { @@ -19,11 +19,11 @@ impl ReceiptMaxValueCheck { } #[async_trait::async_trait] -impl Check for ReceiptMaxValueCheck { +impl Check for ReceiptMaxValueCheck { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { let receipt_value = receipt.signed_receipt().message.value; @@ -54,7 +54,9 @@ mod tests { use super::*; use crate::tap::Eip712Domain; - fn create_signed_receipt_with_custom_value(value: u128) -> ReceiptWithState { + fn create_signed_receipt_with_custom_value( + value: u128, + ) -> ReceiptWithState { let index: u32 = 0; let wallet: PrivateKeySigner = MnemonicBuilder::::default() .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") @@ -86,7 +88,7 @@ mod tests { &wallet, ) .unwrap(); - ReceiptWithState::::new(receipt) + ReceiptWithState::new(receipt) } const RECEIPT_LIMIT: u128 = 10; diff --git a/crates/service/src/tap/checks/sender_balance_check.rs b/crates/service/src/tap/checks/sender_balance_check.rs index c9704dcc..1cea6ea5 100644 --- a/crates/service/src/tap/checks/sender_balance_check.rs +++ b/crates/service/src/tap/checks/sender_balance_check.rs @@ -6,7 +6,7 @@ use indexer_monitor::EscrowAccounts; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; use thegraph_core::alloy::primitives::U256; use tokio::sync::watch::Receiver; @@ -24,11 +24,11 @@ impl SenderBalanceCheck { } #[async_trait::async_trait] -impl Check for SenderBalanceCheck { +impl Check for SenderBalanceCheck { async fn check( &self, ctx: &tap_core::receipt::Context, - _: &ReceiptWithState, + _: &ReceiptWithState, ) -> CheckResult { let escrow_accounts_snapshot = self.escrow_accounts.borrow(); diff --git a/crates/service/src/tap/checks/timestamp_check.rs b/crates/service/src/tap/checks/timestamp_check.rs index fde2fb82..905262b7 100644 --- a/crates/service/src/tap/checks/timestamp_check.rs +++ b/crates/service/src/tap/checks/timestamp_check.rs @@ -11,7 +11,7 @@ pub struct TimestampCheck { use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; impl TimestampCheck { @@ -23,11 +23,11 @@ impl TimestampCheck { } #[async_trait::async_trait] -impl Check for TimestampCheck { +impl Check for TimestampCheck { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { let timestamp_now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) @@ -52,7 +52,9 @@ mod tests { use std::time::{Duration, SystemTime}; use tap_core::{ - receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState}, + receipt::{ + checks::Check, state::Checking, Context, Receipt, ReceiptWithState, SignedReceipt, + }, signed_message::EIP712SignedMessage, tap_eip712_domain, }; @@ -66,7 +68,7 @@ mod tests { fn create_signed_receipt_with_custom_timestamp( timestamp_ns: u64, - ) -> ReceiptWithState { + ) -> ReceiptWithState { let index: u32 = 0; let wallet: PrivateKeySigner = MnemonicBuilder::::default() .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") @@ -89,7 +91,7 @@ mod tests { &wallet, ) .unwrap(); - ReceiptWithState::::new(receipt) + ReceiptWithState::new(receipt) } #[tokio::test] diff --git a/crates/service/src/tap/checks/value_check.rs b/crates/service/src/tap/checks/value_check.rs index 0caf3785..21babe19 100644 --- a/crates/service/src/tap/checks/value_check.rs +++ b/crates/service/src/tap/checks/value_check.rs @@ -18,7 +18,7 @@ use sqlx::{ use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - Context, ReceiptWithState, + Context, ReceiptWithState, SignedReceipt, }; use thegraph_core::DeploymentId; @@ -303,8 +303,12 @@ impl MinimumValue { } #[async_trait::async_trait] -impl Check for MinimumValue { - async fn check(&self, ctx: &Context, receipt: &ReceiptWithState) -> CheckResult { +impl Check for MinimumValue { + async fn check( + &self, + ctx: &Context, + receipt: &ReceiptWithState, + ) -> CheckResult { let agora_query = ctx .get() .ok_or(CheckError::Failed(anyhow!("Could not find agora query")))?; diff --git a/crates/service/src/tap/receipt_store.rs b/crates/service/src/tap/receipt_store.rs index 2d284197..6bab7176 100644 --- a/crates/service/src/tap/receipt_store.rs +++ b/crates/service/src/tap/receipt_store.rs @@ -6,7 +6,7 @@ use bigdecimal::num_bigint::BigInt; use sqlx::{types::BigDecimal, PgPool}; use tap_core::{ manager::adapters::ReceiptStore, - receipt::{state::Checking, ReceiptWithState}, + receipt::{state::Checking, ReceiptWithState, SignedReceipt}, }; use thegraph_core::alloy::{hex::ToHexExt, sol_types::Eip712Domain}; use tokio::{sync::mpsc::Receiver, task::JoinHandle}; @@ -96,12 +96,12 @@ impl IndexerTapContext { } #[async_trait::async_trait] -impl ReceiptStore for IndexerTapContext { +impl ReceiptStore for IndexerTapContext { type AdapterError = AdapterError; async fn store_receipt( &self, - receipt: ReceiptWithState, + receipt: ReceiptWithState, ) -> Result { let db_receipt = DatabaseReceipt::from_receipt(receipt, &self.domain_separator)?; self.receipt_producer.send(db_receipt).await.map_err(|e| { @@ -125,7 +125,7 @@ pub struct DatabaseReceipt { impl DatabaseReceipt { fn from_receipt( - receipt: ReceiptWithState, + receipt: ReceiptWithState, separator: &Eip712Domain, ) -> anyhow::Result { let receipt = receipt.signed_receipt(); diff --git a/crates/tap-agent/src/agent/sender_account.rs b/crates/tap-agent/src/agent/sender_account.rs index de8219ca..5e2b46fe 100644 --- a/crates/tap-agent/src/agent/sender_account.rs +++ b/crates/tap-agent/src/agent/sender_account.rs @@ -22,7 +22,7 @@ use ractor::{Actor, ActorProcessingErr, ActorRef, MessagingErr, SupervisionEvent use reqwest::Url; use sqlx::PgPool; use tap_aggregator::grpc::tap_aggregator_client::TapAggregatorClient; -use tap_core::rav::SignedRAV; +use tap_core::rav::SignedRav; use thegraph_core::alloy::{ hex::ToHexExt, primitives::{Address, U256}, @@ -98,7 +98,7 @@ type Balance = U256; pub enum ReceiptFees { NewReceipt(u128, u64), UpdateValue(UnaggregatedReceipts), - RavRequestResponse((UnaggregatedReceipts, anyhow::Result>)), + RavRequestResponse((UnaggregatedReceipts, anyhow::Result>)), Retry, } @@ -109,7 +109,7 @@ pub enum SenderAccountMessage { NewAllocationId(Address), UpdateReceiptFees(Address, ReceiptFees), UpdateInvalidReceiptFees(Address, UnaggregatedReceipts), - UpdateRav(SignedRAV), + UpdateRav(SignedRav), #[cfg(test)] GetSenderFeeTracker(ractor::RpcReplyPort), #[cfg(test)] @@ -281,7 +281,7 @@ impl State { }; allocation - .cast(SenderAllocationMessage::TriggerRAVRequest) + .cast(SenderAllocationMessage::TriggerRavRequest) .map_err(|e| { anyhow::anyhow!( "Error while sending and waiting message for actor {allocation_id}. Error: {e}" @@ -296,7 +296,7 @@ impl State { fn finalize_rav_request( &mut self, allocation_id: Address, - rav_response: (UnaggregatedReceipts, anyhow::Result>), + rav_response: (UnaggregatedReceipts, anyhow::Result>), ) { self.sender_fee_tracker.finish_rav_request(allocation_id); let (fees, rav_result) = rav_response; diff --git a/crates/tap-agent/src/agent/sender_allocation.rs b/crates/tap-agent/src/agent/sender_allocation.rs index 0c0f938a..e3d87dfa 100644 --- a/crates/tap-agent/src/agent/sender_allocation.rs +++ b/crates/tap-agent/src/agent/sender_allocation.rs @@ -14,12 +14,12 @@ use ractor::{Actor, ActorProcessingErr, ActorRef}; use sqlx::{types::BigDecimal, PgPool}; use tap_aggregator::grpc::{tap_aggregator_client::TapAggregatorClient, RavRequest}; use tap_core::{ - manager::adapters::RAVRead, - rav::{RAVRequest, ReceiptAggregateVoucher, SignedRAV}, + manager::adapters::RavRead, + rav::{ReceiptAggregateVoucher, SignedRav}, receipt::{ checks::{Check, CheckList}, state::Failed, - Context, ReceiptWithState, + Context, ReceiptWithState, SignedReceipt, }, signed_message::EIP712SignedMessage, }; @@ -90,7 +90,8 @@ pub enum RavError { Other(#[from] anyhow::Error), } -type TapManager = tap_core::manager::Manager; +type TapManager = + tap_core::manager::Manager; /// Manages unaggregated fees and the TAP lifecyle for a specific (allocation, sender) pair. pub struct SenderAllocation; @@ -98,7 +99,7 @@ pub struct SenderAllocation; pub struct SenderAllocationState { unaggregated_fees: UnaggregatedReceipts, invalid_receipts_fees: UnaggregatedReceipts, - latest_rav: Option, + latest_rav: Option, pgpool: PgPool, tap_manager: TapManager, allocation_id: Address, @@ -148,7 +149,7 @@ pub struct SenderAllocationArgs { #[derive(Debug)] pub enum SenderAllocationMessage { NewReceipt(NewReceiptNotification), - TriggerRAVRequest, + TriggerRavRequest, #[cfg(test)] GetUnaggregatedReceipts(ractor::RpcReplyPort), } @@ -304,7 +305,7 @@ impl Actor for SenderAllocation { ReceiptFees::NewReceipt(fees, timestamp_ns), ))?; } - SenderAllocationMessage::TriggerRAVRequest => { + SenderAllocationMessage::TriggerRavRequest => { let rav_result = if state.unaggregated_fees.value > 0 { state.request_rav().await.map(|_| state.latest_rav.clone()) } else { @@ -345,7 +346,7 @@ impl SenderAllocationState { config, }: SenderAllocationArgs, ) -> anyhow::Result { - let required_checks: Vec> = vec![ + let required_checks: Vec + Send + Sync>> = vec![ Arc::new( AllocationId::new( config.indexer_address, @@ -525,9 +526,9 @@ impl SenderAllocationState { /// Request a RAV from the sender's TAP aggregator. Only one RAV request will be running at a /// time through the use of an internal guard. - async fn rav_requester_single(&mut self) -> Result { + async fn rav_requester_single(&mut self) -> Result { tracing::trace!("rav_requester_single()"); - let RAVRequest { + let tap_core::rav::RavRequest { valid_receipts, previous_rav, invalid_receipts, @@ -546,7 +547,7 @@ impl SenderAllocationState { invalid_receipts.is_empty(), ) { // All receipts are invalid - (Err(tap_core::Error::NoValidReceiptsForRAVRequest), true, false) => { + (Err(tap_core::Error::NoValidReceiptsForRavRequest), true, false) => { tracing::warn!( "Found {} invalid receipts for allocation {} and sender {}.", invalid_receipts.len(), @@ -647,7 +648,7 @@ impl SenderAllocationState { // The 3 errors below signal an invalid RAV, which should be about problems with the // sender. The sender could be malicious. Err( - e @ tap_core::Error::InvalidReceivedRAV { + e @ tap_core::Error::InvalidReceivedRav { expected_rav: _, received_rav: _, } @@ -675,7 +676,7 @@ impl SenderAllocationState { } Ok(signed_rav) } - (Err(tap_core::Error::NoValidReceiptsForRAVRequest), true, true) => Err(anyhow!( + (Err(tap_core::Error::NoValidReceiptsForRavRequest), true, true) => Err(anyhow!( "It looks like there are no valid receipts for the RAV request.\ This may happen if your `rav_request_trigger_value` is too low \ and no receipts were found outside the `rav_request_timestamp_buffer_ms`.\ @@ -725,7 +726,7 @@ impl SenderAllocationState { async fn store_invalid_receipts( &mut self, - receipts: &[ReceiptWithState], + receipts: &[ReceiptWithState], ) -> anyhow::Result<()> { let reciepts_len = receipts.len(); let mut reciepts_signers = Vec::with_capacity(reciepts_len); @@ -874,7 +875,7 @@ pub mod tests { use tap_core::receipt::{ checks::{Check, CheckError, CheckList, CheckResult}, state::Checking, - Context, ReceiptWithState, + Context, ReceiptWithState, SignedReceipt, }; use test_assets::{ flush_messages, ALLOCATION_ID_0, TAP_EIP712_DOMAIN as TAP_EIP712_DOMAIN_SEPARATOR, @@ -1200,7 +1201,7 @@ pub mod tests { // Trigger a RAV request manually and wait for updated fees. sender_allocation - .cast(SenderAllocationMessage::TriggerRAVRequest) + .cast(SenderAllocationMessage::TriggerRavRequest) .unwrap(); flush_messages(¬ify).await; @@ -1462,11 +1463,11 @@ pub mod tests { struct FailingCheck; #[async_trait::async_trait] - impl Check for FailingCheck { + impl Check for FailingCheck { async fn check( &self, _: &tap_core::receipt::Context, - _receipt: &ReceiptWithState, + _receipt: &ReceiptWithState, ) -> CheckResult { Err(CheckError::Failed(anyhow::anyhow!("Failing check"))) } @@ -1558,7 +1559,7 @@ pub mod tests { // Trigger a RAV request manually and wait for updated fees. // this should fail because there's no receipt with valid timestamp sender_allocation - .cast(SenderAllocationMessage::TriggerRAVRequest) + .cast(SenderAllocationMessage::TriggerRavRequest) .unwrap(); flush_messages(¬ify).await; @@ -1645,7 +1646,7 @@ pub mod tests { // Trigger a RAV request manually and wait for updated fees. // this should fail because there's no receipt with valid timestamp sender_allocation - .cast(SenderAllocationMessage::TriggerRAVRequest) + .cast(SenderAllocationMessage::TriggerRavRequest) .unwrap(); flush_messages(¬ify).await; 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 734d4dd4..b49d209a 100644 --- a/crates/tap-agent/src/tap/context/checks/allocation_id.rs +++ b/crates/tap-agent/src/tap/context/checks/allocation_id.rs @@ -10,7 +10,7 @@ use indexer_watcher::new_watcher; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; use thegraph_core::alloy::primitives::Address; use tokio::sync::watch::Receiver; @@ -46,11 +46,11 @@ impl AllocationId { } #[async_trait::async_trait] -impl Check for AllocationId { +impl Check for AllocationId { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { let allocation_id = receipt.signed_receipt().message.allocation_id; // TODO: Remove the if block below? Each TAP Monitor is specific to an allocation diff --git a/crates/tap-agent/src/tap/context/checks/signature.rs b/crates/tap-agent/src/tap/context/checks/signature.rs index c750557e..6fff734b 100644 --- a/crates/tap-agent/src/tap/context/checks/signature.rs +++ b/crates/tap-agent/src/tap/context/checks/signature.rs @@ -6,7 +6,7 @@ use indexer_monitor::EscrowAccounts; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }; use thegraph_core::alloy::{primitives::U256, sol_types::Eip712Domain}; use tokio::sync::watch::Receiver; @@ -26,11 +26,11 @@ impl Signature { } #[async_trait::async_trait] -impl Check for Signature { +impl Check for Signature { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { let signer = receipt .signed_receipt() diff --git a/crates/tap-agent/src/tap/context/checks/value.rs b/crates/tap-agent/src/tap/context/checks/value.rs index 414095d1..a44c7020 100644 --- a/crates/tap-agent/src/tap/context/checks/value.rs +++ b/crates/tap-agent/src/tap/context/checks/value.rs @@ -11,7 +11,7 @@ use tap_core::{ receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, - ReceiptWithState, + ReceiptWithState, SignedReceipt, }, signed_message::MessageId, }; @@ -23,11 +23,11 @@ pub struct Value { } #[async_trait::async_trait] -impl Check for Value { +impl Check for Value { async fn check( &self, _: &tap_core::receipt::Context, - receipt: &ReceiptWithState, + receipt: &ReceiptWithState, ) -> CheckResult { let value = receipt.signed_receipt().message.value; let query_id = receipt.signed_receipt().unique_hash(); diff --git a/crates/tap-agent/src/tap/context/escrow.rs b/crates/tap-agent/src/tap/context/escrow.rs index 268448c1..db86f2b4 100644 --- a/crates/tap-agent/src/tap/context/escrow.rs +++ b/crates/tap-agent/src/tap/context/escrow.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use async_trait::async_trait; -use tap_core::manager::adapters::EscrowHandler as EscrowAdapterTrait; +use tap_core::manager::adapters::SignatureChecker; use thegraph_core::alloy::primitives::Address; use super::{error::AdapterError, TapAgentContext}; @@ -22,17 +22,9 @@ impl From for AdapterError { // In any case, we don't want to fail a receipt because of this. // The receipt is fine, just the escrow account that is not. #[async_trait] -impl EscrowAdapterTrait for TapAgentContext { +impl SignatureChecker for TapAgentContext { type AdapterError = AdapterError; - async fn get_available_escrow(&self, _signer: Address) -> Result { - Ok(0) - } - - async fn subtract_escrow(&self, _signer: Address, _value: u128) -> Result<(), AdapterError> { - Ok(()) - } - async fn verify_signer(&self, signer: Address) -> Result { let escrow_accounts = self.escrow_accounts.borrow(); let sender = escrow_accounts diff --git a/crates/tap-agent/src/tap/context/rav.rs b/crates/tap-agent/src/tap/context/rav.rs index 4ac2cf44..b4fa7134 100644 --- a/crates/tap-agent/src/tap/context/rav.rs +++ b/crates/tap-agent/src/tap/context/rav.rs @@ -9,8 +9,8 @@ use bigdecimal::{ }; use sqlx::types::{chrono, BigDecimal}; use tap_core::{ - manager::adapters::{RAVRead, RAVStore}, - rav::{ReceiptAggregateVoucher, SignedRAV}, + manager::adapters::{RavRead, RavStore}, + rav::{ReceiptAggregateVoucher, SignedRav}, }; #[allow(deprecated)] use thegraph_core::alloy::signers::Signature; @@ -19,10 +19,10 @@ use thegraph_core::alloy::{hex::ToHexExt, primitives::Address}; use super::{error::AdapterError, TapAgentContext}; #[async_trait::async_trait] -impl RAVRead for TapAgentContext { +impl RavRead for TapAgentContext { type AdapterError = AdapterError; - async fn last_rav(&self) -> Result, Self::AdapterError> { + async fn last_rav(&self) -> Result, Self::AdapterError> { let row = sqlx::query!( r#" SELECT signature, allocation_id, timestamp_ns, value_aggregate @@ -78,7 +78,7 @@ impl RAVRead for TapAgentContext { timestampNs: timestamp_ns, valueAggregate: value_aggregate, }; - Ok(Some(SignedRAV { + Ok(Some(SignedRav { message: rav, signature, })) @@ -89,10 +89,10 @@ impl RAVRead for TapAgentContext { } #[async_trait::async_trait] -impl RAVStore for TapAgentContext { +impl RavStore for TapAgentContext { type AdapterError = AdapterError; - async fn update_last_rav(&self, rav: SignedRAV) -> Result<(), Self::AdapterError> { + async fn update_last_rav(&self, rav: SignedRav) -> Result<(), Self::AdapterError> { let signature_bytes: Vec = rav.signature.as_bytes().to_vec(); let _fut = sqlx::query!( @@ -142,7 +142,7 @@ mod test { use crate::test::{create_rav, ALLOCATION_ID_0}; #[derive(Debug)] - struct TestableRav(SignedRAV); + struct TestableRav(SignedRav); impl Eq for TestableRav {} diff --git a/crates/tap-agent/src/tap/context/receipt.rs b/crates/tap-agent/src/tap/context/receipt.rs index f9418f43..020e7100 100644 --- a/crates/tap-agent/src/tap/context/receipt.rs +++ b/crates/tap-agent/src/tap/context/receipt.rs @@ -71,14 +71,14 @@ fn rangebounds_to_pgrange>(range: R) -> PgRange } #[async_trait::async_trait] -impl ReceiptRead for TapAgentContext { +impl ReceiptRead for TapAgentContext { type AdapterError = AdapterError; async fn retrieve_receipts_in_timestamp_range + Send>( &self, timestamp_range_ns: R, receipts_limit: Option, - ) -> Result>, Self::AdapterError> { + ) -> Result>, Self::AdapterError> { let signers = signers_trimmed(self.escrow_accounts.clone(), self.sender) .await .map_err(|e| AdapterError::ReceiptRead { @@ -150,7 +150,7 @@ impl ReceiptRead for TapAgentContext { Ok(ReceiptWithState::new(signed_receipt)) }) - .collect::>, AdapterError>>()?; + .collect::>, AdapterError>>()?; safe_truncate_receipts(&mut receipts, receipts_limit); @@ -262,29 +262,30 @@ mod test { async fn retrieve_range_and_check + Send>( storage_adapter: &TapAgentContext, escrow_accounts: Receiver, - received_receipt_vec: &[ReceiptWithState], + received_receipt_vec: &[ReceiptWithState], range: R, ) -> anyhow::Result<()> { let escrow_accounts_snapshot = escrow_accounts.borrow(); // Filtering the received receipts by timestamp range - let received_receipt_vec: Vec> = received_receipt_vec - .iter() - .filter(|received_receipt| { - range.contains(&received_receipt.signed_receipt().message.timestamp_ns) - && (received_receipt.signed_receipt().message.allocation_id - == storage_adapter.allocation_id) - && (escrow_accounts_snapshot - .get_sender_for_signer( - &received_receipt - .signed_receipt() - .recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR) - .unwrap(), - ) - .map_or(false, |v| v == storage_adapter.sender)) - }) - .cloned() - .collect(); + let received_receipt_vec: Vec> = + received_receipt_vec + .iter() + .filter(|received_receipt| { + range.contains(&received_receipt.signed_receipt().message.timestamp_ns) + && (received_receipt.signed_receipt().message.allocation_id + == storage_adapter.allocation_id) + && (escrow_accounts_snapshot + .get_sender_for_signer( + &received_receipt + .signed_receipt() + .recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR) + .unwrap(), + ) + .map_or(false, |v| v == storage_adapter.sender)) + }) + .cloned() + .collect(); // Retrieving receipts in timestamp range from the database, convert to json Value let recovered_received_receipt_vec = storage_adapter @@ -312,7 +313,7 @@ mod test { async fn remove_range_and_check + Send>( storage_adapter: &TapAgentContext, escrow_accounts: Receiver, - received_receipt_vec: &[ReceiptWithState], + received_receipt_vec: &[ReceiptWithState], range: R, ) -> anyhow::Result<()> { let escrow_accounts_snapshot = escrow_accounts.borrow(); @@ -335,28 +336,29 @@ mod test { // Remove the received receipts by timestamp range for the correct (allocation_id, // sender) - let received_receipt_vec: Vec<(u64, &ReceiptWithState)> = received_receipt_vec - .iter() - .filter(|(_, received_receipt)| { - if (received_receipt.signed_receipt().message.allocation_id - == storage_adapter.allocation_id) - && (escrow_accounts_snapshot - .get_sender_for_signer( - &received_receipt - .signed_receipt() - .recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR) - .unwrap(), - ) - .map_or(false, |v| v == storage_adapter.sender)) - { - !range.contains(&received_receipt.signed_receipt().message.timestamp_ns) - } else { - true - } - // !range.contains(&received_receipt.signed_receipt().message.timestamp_ns) - }) - .cloned() - .collect(); + let received_receipt_vec: Vec<(u64, &ReceiptWithState)> = + received_receipt_vec + .iter() + .filter(|(_, received_receipt)| { + if (received_receipt.signed_receipt().message.allocation_id + == storage_adapter.allocation_id) + && (escrow_accounts_snapshot + .get_sender_for_signer( + &received_receipt + .signed_receipt() + .recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR) + .unwrap(), + ) + .map_or(false, |v| v == storage_adapter.sender)) + { + !range.contains(&received_receipt.signed_receipt().message.timestamp_ns) + } else { + true + } + // !range.contains(&received_receipt.signed_receipt().message.timestamp_ns) + }) + .cloned() + .collect(); // Removing the received receipts in timestamp range from the database storage_adapter diff --git a/crates/tap-agent/src/test.rs b/crates/tap-agent/src/test.rs index 405ea399..f3c62335 100644 --- a/crates/tap-agent/src/test.rs +++ b/crates/tap-agent/src/test.rs @@ -1,13 +1,14 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use std::net::SocketAddr; + use bigdecimal::num_bigint::BigInt; use lazy_static::lazy_static; use sqlx::{types::BigDecimal, PgPool}; -use std::net::SocketAddr; use tap_aggregator::server::run_server; use tap_core::{ - rav::{ReceiptAggregateVoucher, SignedRAV}, + rav::{ReceiptAggregateVoucher, SignedRav}, receipt::{state::Checking, Receipt, ReceiptWithState, SignedReceipt}, signed_message::EIP712SignedMessage, tap_eip712_domain, @@ -37,7 +38,7 @@ pub fn create_rav( signer_wallet: PrivateKeySigner, timestamp_ns: u64, value_aggregate: u128, -) -> SignedRAV { +) -> SignedRav { EIP712SignedMessage::new( &TAP_EIP712_DOMAIN_SEPARATOR, ReceiptAggregateVoucher { @@ -58,7 +59,7 @@ pub fn create_received_receipt( nonce: u64, timestamp_ns: u64, value: u128, -) -> ReceiptWithState { +) -> ReceiptWithState { let receipt = EIP712SignedMessage::new( &TAP_EIP712_DOMAIN_SEPARATOR, Receipt { @@ -144,7 +145,7 @@ pub fn wallet(index: u32) -> (PrivateKeySigner, Address) { pub async fn store_rav( pgpool: &PgPool, - signed_rav: SignedRAV, + signed_rav: SignedRav, sender: Address, ) -> anyhow::Result<()> { store_rav_with_options(pgpool, signed_rav, sender, false, false).await @@ -181,7 +182,7 @@ async fn create_grpc_aggregator() -> (JoinHandle<()>, SocketAddr) { pub async fn store_rav_with_options( pgpool: &PgPool, - signed_rav: SignedRAV, + signed_rav: SignedRav, sender: Address, last: bool, final_rav: bool, @@ -426,7 +427,7 @@ pub mod actors { _state: &mut Self::State, ) -> Result<(), ActorProcessingErr> { match message { - SenderAllocationMessage::TriggerRAVRequest => { + SenderAllocationMessage::TriggerRavRequest => { self.triggered_rav_request.notify_one(); if let Some(sender_account) = self.sender_actor.as_ref() { let signed_rav = create_rav(