Skip to content

Commit c3ede8f

Browse files
gusinaciopedrohba1
andauthored
feat: grpc client for tap aggregator (#583)
* feat: remove jsonrpc client in favor of grpc client Co-authored-by: Gustavo Inacio <[email protected]> Signed-off-by: pedro bufulin <[email protected]> Signed-off-by: Gustavo Inacio <[email protected]> * refactor: adjust endpoint in test * chore: cargo fmt * refactor: remove commented code and unnecessary stop of handler in test * test: handle error from failed connection * feat: log out endpoint in case of failed connection attempt * ci: add TapAggregator server mock to minimize changes to tests * ci: fix line indent * ci: force ri rerun * refactor: cargo fmt * ci: move mock server start to test-and-coverage * test: test aggregator server helper function * test: instantiate server instead of using mock * ci: remove unnecessary step * refactor: correct typo * refactor: correct typo * refactor: replace space * refactor: remove unnecessary message * test: fix hanging test Signed-off-by: Gustavo Inacio <[email protected]> * refactor: change expect with context Signed-off-by: Gustavo Inacio <[email protected]> * test: use get_grpc_url() to spawn a grpc Signed-off-by: Gustavo Inacio <[email protected]> * test: use server_url directly Signed-off-by: Gustavo Inacio <[email protected]> * test: update all tests to use get_grpc_url Signed-off-by: Gustavo Inacio <[email protected]> * chore: add comment about compression Signed-off-by: Gustavo Inacio <[email protected]> --------- Signed-off-by: pedro bufulin <[email protected]> Signed-off-by: Gustavo Inacio <[email protected]> Co-authored-by: pedro bufulin <[email protected]>
1 parent 9f99732 commit c3ede8f

File tree

8 files changed

+231
-207
lines changed

8 files changed

+231
-207
lines changed

Cargo.lock

Lines changed: 86 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ uuid = { version = "1.11.0", features = ["v7"] }
5252
tracing = { version = "0.1.40", default-features = false }
5353
bigdecimal = "0.4.3"
5454
build-info = "0.0.39"
55-
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1c6e29f", default-features = false }
56-
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1c6e29f", default-features = false }
55+
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "6af1add", default-features = false }
56+
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "6af1add", default-features = false }
5757
tracing-subscriber = { version = "0.3", features = [
5858
"json",
5959
"env-filter",
6060
"ansi",
6161
], default-features = false }
62-
thegraph-core = { version = "0.9.6", features = [
62+
thegraph-core = { version = "0.10.0", features = [
6363
"attestation",
6464
"alloy-eip712",
6565
"alloy-sol-types",

crates/tap-agent/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ lazy_static.workspace = true
3131
thegraph-core.workspace = true
3232
clap.workspace = true
3333
tracing-subscriber.workspace = true
34+
tonic.workspace = true
3435
bigdecimal = { workspace = true, features = ["serde"] }
3536
graphql_client.workspace = true
3637

@@ -48,5 +49,6 @@ futures = { version = "0.3.30", default-features = false }
4849
[dev-dependencies]
4950
tempfile = "3.8.0"
5051
wiremock.workspace = true
52+
wiremock-grpc = "0.0.3-alpha3"
5153
test-assets = { path = "../test-assets" }
5254
test-log = { version = "0.2.12", default-features = false }

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
time::Duration,
88
};
99

10+
use anyhow::Context;
1011
use bigdecimal::{num_bigint::ToBigInt, ToPrimitive};
1112
use futures::{stream, StreamExt};
1213
use indexer_monitor::{EscrowAccounts, SubgraphClient};
@@ -15,19 +16,20 @@ use indexer_query::{
1516
unfinalized_transactions, UnfinalizedTransactions,
1617
};
1718
use indexer_watcher::watch_pipe;
18-
use jsonrpsee::http_client::HttpClientBuilder;
1919
use lazy_static::lazy_static;
2020
use prometheus::{register_gauge_vec, register_int_gauge_vec, GaugeVec, IntGaugeVec};
2121
use ractor::{Actor, ActorProcessingErr, ActorRef, MessagingErr, SupervisionEvent};
2222
use reqwest::Url;
2323
use sqlx::PgPool;
24+
use tap_aggregator::grpc::tap_aggregator_client::TapAggregatorClient;
2425
use tap_core::rav::SignedRAV;
2526
use thegraph_core::alloy::{
2627
hex::ToHexExt,
2728
primitives::{Address, U256},
2829
sol_types::Eip712Domain,
2930
};
3031
use tokio::{sync::watch::Receiver, task::JoinHandle};
32+
use tonic::transport::{Channel, Endpoint};
3133
use tracing::Level;
3234

3335
use super::sender_allocation::{
@@ -171,7 +173,7 @@ pub struct State {
171173

172174
domain_separator: Eip712Domain,
173175
pgpool: PgPool,
174-
sender_aggregator: jsonrpsee::http_client::HttpClient,
176+
sender_aggregator: TapAggregatorClient<Channel>,
175177

176178
// Backoff info
177179
backoff_info: BackoffInfo,
@@ -603,10 +605,21 @@ impl Actor for SenderAccount {
603605
.with_label_values(&[&sender_id.to_string()])
604606
.set(config.trigger_value as f64);
605607

606-
let sender_aggregator = HttpClientBuilder::default()
607-
.request_timeout(config.rav_request_timeout)
608-
.build(&sender_aggregator_endpoint)?;
608+
let endpoint = Endpoint::new(sender_aggregator_endpoint.to_string())
609+
.context("Failed to create an endpoint for the sender aggregator")?;
609610

611+
let sender_aggregator = TapAggregatorClient::connect(endpoint.clone())
612+
.await
613+
.with_context(|| {
614+
format!(
615+
"Failed to connect to the TapAggregator endpoint '{}'",
616+
endpoint.uri()
617+
)
618+
})?;
619+
// wiremock_grpc used for tests doesn't support Zstd compression
620+
#[cfg(not(test))]
621+
let sender_aggregator =
622+
sender_aggregator.send_compressed(tonic::codec::CompressionEncoding::Zstd);
610623
let state = State {
611624
prefix,
612625
sender_fee_tracker: SenderFeeTracker::new(config.rav_request_buffer),
@@ -1070,7 +1083,7 @@ pub mod tests {
10701083
assert_not_triggered, assert_triggered,
10711084
test::{
10721085
actors::{create_mock_sender_allocation, MockSenderAllocation, TestableActor},
1073-
create_rav, store_rav_with_options, INDEXER, TAP_EIP712_DOMAIN_SEPARATOR,
1086+
create_rav, get_grpc_url, store_rav_with_options, INDEXER, TAP_EIP712_DOMAIN_SEPARATOR,
10741087
},
10751088
};
10761089

@@ -1192,6 +1205,8 @@ pub mod tests {
11921205
))
11931206
.expect("Failed to update escrow_accounts channel");
11941207

1208+
// Start a new mock aggregator server for this test
1209+
11951210
let prefix = format!(
11961211
"test-{}",
11971212
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
@@ -1206,7 +1221,7 @@ pub mod tests {
12061221
escrow_subgraph,
12071222
network_subgraph,
12081223
domain_separator: TAP_EIP712_DOMAIN_SEPARATOR.clone(),
1209-
sender_aggregator_endpoint: Url::parse(DUMMY_URL).unwrap(),
1224+
sender_aggregator_endpoint: Url::parse(&get_grpc_url().await).unwrap(),
12101225
allocation_ids: HashSet::new(),
12111226
prefix: Some(prefix.clone()),
12121227
retry_interval: RETRY_DURATION,

crates/tap-agent/src/agent/sender_accounts_manager.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ mod tests {
609609
use reqwest::Url;
610610
use ruint::aliases::U256;
611611
use sqlx::{postgres::PgListener, PgPool};
612-
use test_assets::{flush_messages, TAP_SENDER as SENDER};
612+
use test_assets::{flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
613613
use thegraph_core::alloy::hex::ToHexExt;
614614
use tokio::sync::{mpsc, mpsc::error::TryRecvError, watch, Notify};
615615

@@ -624,8 +624,8 @@ mod tests {
624624
},
625625
test::{
626626
actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor},
627-
create_rav, create_received_receipt, store_rav, store_receipt, ALLOCATION_ID_0,
628-
ALLOCATION_ID_1, INDEXER, SENDER_2, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR,
627+
create_rav, create_received_receipt, get_grpc_url, store_rav, store_receipt,
628+
ALLOCATION_ID_0, ALLOCATION_ID_1, INDEXER, SENDER_2, TAP_EIP712_DOMAIN_SEPARATOR,
629629
},
630630
};
631631

@@ -670,6 +670,7 @@ mod tests {
670670

671671
let (_, escrow_accounts_rx) = watch::channel(EscrowAccounts::default());
672672

673+
// Start a new mock aggregator server for this test
673674
let prefix = format!(
674675
"test-{}",
675676
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
@@ -683,8 +684,8 @@ mod tests {
683684
escrow_subgraph,
684685
network_subgraph,
685686
sender_aggregator_endpoints: HashMap::from([
686-
(SENDER.1, Url::parse("http://localhost:8000").unwrap()),
687-
(SENDER_2.1, Url::parse("http://localhost:8000").unwrap()),
687+
(SENDER.1, Url::parse(&get_grpc_url().await).unwrap()),
688+
(SENDER_2.1, Url::parse(&get_grpc_url().await).unwrap()),
688689
]),
689690
prefix: Some(prefix.clone()),
690691
};
@@ -727,8 +728,8 @@ mod tests {
727728
escrow_subgraph: get_subgraph_client().await,
728729
network_subgraph: get_subgraph_client().await,
729730
sender_aggregator_endpoints: HashMap::from([
730-
(SENDER.1, Url::parse("http://localhost:8000").unwrap()),
731-
(SENDER_2.1, Url::parse("http://localhost:8000").unwrap()),
731+
(SENDER.1, Url::parse(&get_grpc_url().await).unwrap()),
732+
(SENDER_2.1, Url::parse(&get_grpc_url().await).unwrap()),
732733
]),
733734
prefix: Some(prefix),
734735
},

0 commit comments

Comments
 (0)