Skip to content

Commit 0817632

Browse files
authored
refactor: update check escrow receipt check (#629)
* refactor: update check escrow receipt check Signed-off-by: Gustavo Inacio <[email protected]> * refactor: update deny list check for v2 Signed-off-by: Gustavo Inacio <[email protected]> --------- Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 387d660 commit 0817632

18 files changed

+240
-102
lines changed

.sqlx/query-f1d8dcf24c9677ef789469d37733f354c5d246db5bb1506839cd7b07cdcc7065.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

+2-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] }
7676
bip39 = "2.0.0"
7777
rstest = "0.23.0"
7878
wiremock = "0.6.1"
79-
typed-builder = "0.20.0"
79+
bon = "3.3"
8080
tonic = { version = "0.12.3", features = ["tls-roots", "gzip"] }
8181
prost = "0.13.4"
8282
prost-types = "0.13.3"

crates/monitor/src/escrow_accounts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl EscrowAccounts {
8888

8989
pub type EscrowAccountsWatcher = Receiver<EscrowAccounts>;
9090

91-
pub async fn escrow_accounts(
91+
pub async fn escrow_accounts_v1(
9292
escrow_subgraph: &'static SubgraphClient,
9393
indexer_address: Address,
9494
interval: Duration,
@@ -243,7 +243,7 @@ mod tests {
243243
);
244244
mock_server.register(mock).await;
245245

246-
let mut accounts = escrow_accounts(
246+
let mut accounts = escrow_accounts_v1(
247247
escrow_subgraph,
248248
test_assets::INDEXER_ADDRESS,
249249
Duration::from_secs(60),

crates/monitor/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use crate::{
1515
deployment_to_allocation::{deployment_to_allocation, DeploymentToAllocationWatcher},
1616
dispute_manager::{dispute_manager, DisputeManagerWatcher},
1717
escrow_accounts::{
18-
escrow_accounts, escrow_accounts_v2, EscrowAccounts, EscrowAccountsError,
18+
escrow_accounts_v1, escrow_accounts_v2, EscrowAccounts, EscrowAccountsError,
1919
EscrowAccountsWatcher,
2020
},
2121
};

crates/service/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ graphql = { git = "https://github.com/edgeandnode/toolshed", tag = "graphql-v0.3
4040
tap_core.workspace = true
4141
tap_graph.workspace = true
4242
uuid.workspace = true
43-
typed-builder.workspace = true
43+
bon.workspace = true
4444
tower_governor = { version = "0.5.0", features = ["axum"] }
4545
governor = "0.8.0"
4646
tower-http = { version = "0.6.2", features = [

crates/service/src/middleware/sender.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ use crate::{error::IndexerServiceError, tap::TapReceipt};
1717
pub struct SenderState {
1818
/// Used to recover the signer address
1919
pub domain_separator: Eip712Domain,
20-
/// Used to get the sender address given the signer address
21-
pub escrow_accounts: watch::Receiver<EscrowAccounts>,
20+
/// Used to get the sender address given the signer address if v1 receipt
21+
pub escrow_accounts_v1: watch::Receiver<EscrowAccounts>,
22+
/// Used to get the sender address given the signer address if v2 receipt
23+
pub escrow_accounts_v2: watch::Receiver<EscrowAccounts>,
2224
}
2325

2426
/// The current query Sender address
@@ -45,10 +47,16 @@ pub async fn sender_middleware(
4547
) -> Result<Response, IndexerServiceError> {
4648
if let Some(receipt) = request.extensions().get::<TapReceipt>() {
4749
let signer = receipt.recover_signer(&state.domain_separator)?;
48-
let sender = state
49-
.escrow_accounts
50-
.borrow()
51-
.get_sender_for_signer(&signer)?;
50+
let sender = match receipt {
51+
TapReceipt::V1(_) => state
52+
.escrow_accounts_v1
53+
.borrow()
54+
.get_sender_for_signer(&signer)?,
55+
TapReceipt::V2(_) => state
56+
.escrow_accounts_v2
57+
.borrow()
58+
.get_sender_for_signer(&signer)?,
59+
};
5260
request.extensions_mut().insert(Sender(sender));
5361
}
5462

@@ -78,14 +86,22 @@ mod tests {
7886

7987
#[tokio::test]
8088
async fn test_sender_middleware() {
81-
let escrow_accounts = watch::channel(EscrowAccounts::new(
89+
let escrow_accounts_v1 = watch::channel(EscrowAccounts::new(
8290
ESCROW_ACCOUNTS_BALANCES.to_owned(),
8391
ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS.to_owned(),
8492
))
8593
.1;
94+
95+
let escrow_accounts_v2 = watch::channel(EscrowAccounts::new(
96+
ESCROW_ACCOUNTS_BALANCES.to_owned(),
97+
ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS.to_owned(),
98+
))
99+
.1;
100+
86101
let state = SenderState {
87102
domain_separator: test_assets::TAP_EIP712_DOMAIN.clone(),
88-
escrow_accounts,
103+
escrow_accounts_v1,
104+
escrow_accounts_v2,
89105
};
90106

91107
let middleware = from_fn_with_state(state, sender_middleware);

crates/service/src/service/router.rs

+35-22
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use indexer_config::{
1717
ServiceConfig, ServiceTapConfig,
1818
};
1919
use indexer_monitor::{
20-
attestation_signers, deployment_to_allocation, dispute_manager, escrow_accounts,
21-
indexer_allocations, AllocationWatcher, DisputeManagerWatcher, EscrowAccountsWatcher,
22-
SubgraphClient,
20+
attestation_signers, deployment_to_allocation, dispute_manager, escrow_accounts_v1,
21+
escrow_accounts_v2, indexer_allocations, AllocationWatcher, DisputeManagerWatcher,
22+
EscrowAccountsWatcher, SubgraphClient,
2323
};
2424
use reqwest::Method;
2525
use tap_core::{manager::Manager, receipt::checks::CheckList};
@@ -34,7 +34,6 @@ use tower_http::{
3434
trace::TraceLayer,
3535
validate_request::ValidateRequestHeaderLayer,
3636
};
37-
use typed_builder::TypedBuilder;
3837

3938
use super::{release::IndexerServiceRelease, GraphNodeState};
4039
use crate::{
@@ -51,7 +50,7 @@ use crate::{
5150
wallet::public_key,
5251
};
5352

54-
#[derive(TypedBuilder)]
53+
#[derive(bon::Builder)]
5554
pub struct ServiceRouter {
5655
// database
5756
database: sqlx::PgPool,
@@ -60,7 +59,6 @@ pub struct ServiceRouter {
6059
// graphnode client
6160
http_client: reqwest::Client,
6261
// release info
63-
#[builder(default, setter(strip_option))]
6462
release: Option<IndexerServiceRelease>,
6563

6664
// configuration
@@ -71,23 +69,21 @@ pub struct ServiceRouter {
7169
timestamp_buffer_secs: Duration,
7270

7371
// either provide subgraph or watcher
74-
#[builder(default, setter(transform =
72+
#[builder(with =
7573
|subgraph: &'static SubgraphClient,
76-
config: EscrowSubgraphConfig|
77-
Some((subgraph, config))))]
74+
config: EscrowSubgraphConfig|
75+
(subgraph, config))]
7876
escrow_subgraph: Option<(&'static SubgraphClient, EscrowSubgraphConfig)>,
79-
#[builder(default, setter(strip_option))]
80-
escrow_accounts: Option<EscrowAccountsWatcher>,
77+
escrow_accounts_v1: Option<EscrowAccountsWatcher>,
78+
79+
escrow_accounts_v2: Option<EscrowAccountsWatcher>,
8180

8281
// provide network subgraph or allocations + dispute manager
83-
#[builder(default, setter(transform =
84-
|subgraph: &'static SubgraphClient,
85-
config: NetworkSubgraphConfig|
86-
Some((subgraph, config))))]
82+
#[builder(with = |subgraph: &'static SubgraphClient,
83+
config: NetworkSubgraphConfig|
84+
(subgraph, config))]
8785
network_subgraph: Option<(&'static SubgraphClient, NetworkSubgraphConfig)>,
88-
#[builder(default, setter(strip_option))]
8986
allocations: Option<AllocationWatcher>,
90-
#[builder(default, setter(strip_option))]
9187
dispute_manager: Option<DisputeManagerWatcher>,
9288
}
9389

@@ -141,11 +137,26 @@ impl ServiceRouter {
141137
(None, None) => panic!("No allocations or network subgraph was provided"),
142138
};
143139

144-
// Monitor escrow accounts
140+
// Monitor escrow accounts v1
141+
// if not provided, create monitor from subgraph
142+
let escrow_accounts_v1 = match (self.escrow_accounts_v1, self.escrow_subgraph.as_ref()) {
143+
(Some(escrow_account), _) => escrow_account,
144+
(_, Some((escrow_subgraph, escrow))) => escrow_accounts_v1(
145+
escrow_subgraph,
146+
indexer_address,
147+
escrow.config.syncing_interval_secs,
148+
true, // Reject thawing signers eagerly
149+
)
150+
.await
151+
.expect("Error creating escrow_accounts channel"),
152+
(None, None) => panic!("No escrow accounts or escrow subgraph was provided"),
153+
};
154+
155+
// Monitor escrow accounts v2
145156
// if not provided, create monitor from subgraph
146-
let escrow_accounts = match (self.escrow_accounts, self.escrow_subgraph.as_ref()) {
157+
let escrow_accounts_v2 = match (self.escrow_accounts_v2, self.escrow_subgraph.as_ref()) {
147158
(Some(escrow_account), _) => escrow_account,
148-
(_, Some((escrow_subgraph, escrow))) => escrow_accounts(
159+
(_, Some((escrow_subgraph, escrow))) => escrow_accounts_v2(
149160
escrow_subgraph,
150161
indexer_address,
151162
escrow.config.syncing_interval_secs,
@@ -255,7 +266,8 @@ impl ServiceRouter {
255266
let checks = IndexerTapContext::get_checks(
256267
self.database,
257268
allocations.clone(),
258-
escrow_accounts.clone(),
269+
escrow_accounts_v1.clone(),
270+
escrow_accounts_v2.clone(),
259271
timestamp_error_tolerance,
260272
receipt_max_value,
261273
)
@@ -299,7 +311,8 @@ impl ServiceRouter {
299311
deployment_to_allocation,
300312
};
301313
let sender_state = SenderState {
302-
escrow_accounts,
314+
escrow_accounts_v1,
315+
escrow_accounts_v2,
303316
domain_separator: self.domain_separator,
304317
};
305318

crates/service/src/tap.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ impl IndexerTapContext {
4848
pub async fn get_checks(
4949
pgpool: PgPool,
5050
indexer_allocations: Receiver<HashMap<Address, Allocation>>,
51-
escrow_accounts: Receiver<EscrowAccounts>,
51+
escrow_accounts_v1: Receiver<EscrowAccounts>,
52+
escrow_accounts_v2: Receiver<EscrowAccounts>,
5253
timestamp_error_tolerance: Duration,
5354
receipt_max_value: u128,
5455
) -> Vec<ReceiptCheck<TapReceipt>> {
5556
vec![
5657
Arc::new(AllocationEligible::new(indexer_allocations)),
57-
Arc::new(SenderBalanceCheck::new(escrow_accounts)),
58+
Arc::new(SenderBalanceCheck::new(
59+
escrow_accounts_v1,
60+
escrow_accounts_v2,
61+
)),
5862
Arc::new(TimestampCheck::new(timestamp_error_tolerance)),
5963
Arc::new(DenyListCheck::new(pgpool.clone()).await),
6064
Arc::new(ReceiptMaxValueCheck::new(receipt_max_value)),

0 commit comments

Comments
 (0)