11// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22// SPDX-License-Identifier: Apache-2.0
33
4- use alloy :: dyn_abi :: Eip712Domain ;
4+ use crate :: middleware :: Sender ;
55use alloy:: primitives:: Address ;
6- use indexer_monitor:: EscrowAccounts ;
76use sqlx:: postgres:: PgListener ;
87use sqlx:: PgPool ;
98use std:: collections:: HashSet ;
@@ -15,23 +14,16 @@ use tap_core::receipt::{
1514 state:: Checking ,
1615 ReceiptWithState ,
1716} ;
18- use tokio:: sync:: watch:: Receiver ;
1917use tracing:: error;
2018
2119pub struct DenyListCheck {
22- escrow_accounts : Receiver < EscrowAccounts > ,
23- domain_separator : Eip712Domain ,
2420 sender_denylist : Arc < RwLock < HashSet < Address > > > ,
2521 _sender_denylist_watcher_handle : Arc < tokio:: task:: JoinHandle < ( ) > > ,
2622 sender_denylist_watcher_cancel_token : tokio_util:: sync:: CancellationToken ,
2723}
2824
2925impl DenyListCheck {
30- pub async fn new (
31- pgpool : PgPool ,
32- escrow_accounts : Receiver < EscrowAccounts > ,
33- domain_separator : Eip712Domain ,
34- ) -> Self {
26+ pub async fn new ( pgpool : PgPool ) -> Self {
3527 // Listen to pg_notify events. We start it before updating the sender_denylist so that we
3628 // don't miss any updates. PG will buffer the notifications until we start consuming them.
3729 let mut pglistener = PgListener :: connect_with ( & pgpool. clone ( ) ) . await . unwrap ( ) ;
@@ -57,8 +49,6 @@ impl DenyListCheck {
5749 sender_denylist_watcher_cancel_token. clone ( ) ,
5850 ) ) ) ;
5951 Self {
60- domain_separator,
61- escrow_accounts,
6252 sender_denylist,
6353 _sender_denylist_watcher_handle : sender_denylist_watcher_handle,
6454 sender_denylist_watcher_cancel_token,
@@ -152,29 +142,19 @@ impl DenyListCheck {
152142impl Check for DenyListCheck {
153143 async fn check (
154144 & self ,
155- _ : & tap_core:: receipt:: Context ,
156- receipt : & ReceiptWithState < Checking > ,
145+ ctx : & tap_core:: receipt:: Context ,
146+ _ : & ReceiptWithState < Checking > ,
157147 ) -> CheckResult {
158- let receipt_signer = receipt
159- . signed_receipt ( )
160- . recover_signer ( & self . domain_separator )
161- . map_err ( |e| {
162- error ! ( "Failed to recover receipt signer: {}" , e) ;
163- anyhow:: anyhow!( e)
164- } )
165- . map_err ( CheckError :: Failed ) ?;
166- let escrow_accounts_snapshot = self . escrow_accounts . borrow ( ) ;
167-
168- let receipt_sender = escrow_accounts_snapshot
169- . get_sender_for_signer ( & receipt_signer)
170- . map_err ( |e| CheckError :: Failed ( e. into ( ) ) ) ?;
148+ let Sender ( receipt_sender) = ctx
149+ . get :: < Sender > ( )
150+ . ok_or ( CheckError :: Failed ( anyhow:: anyhow!( "Could not find sender" ) ) ) ?;
171151
172152 // Check that the sender is not denylisted
173153 if self
174154 . sender_denylist
175155 . read ( )
176156 . unwrap ( )
177- . contains ( & receipt_sender)
157+ . contains ( receipt_sender)
178158 {
179159 return Err ( CheckError :: Failed ( anyhow:: anyhow!(
180160 "Received a receipt from a denylisted sender: {}" ,
@@ -200,26 +180,16 @@ mod tests {
200180
201181 use alloy:: hex:: ToHexExt ;
202182 use tap_core:: receipt:: { Context , ReceiptWithState } ;
203- use tokio:: sync:: watch;
204183
205- use test_assets:: {
206- self , create_signed_receipt, ESCROW_ACCOUNTS_BALANCES , ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS ,
207- TAP_EIP712_DOMAIN , TAP_SENDER ,
208- } ;
184+ use test_assets:: { self , create_signed_receipt, TAP_SENDER } ;
209185
210186 use super :: * ;
211187
212188 const ALLOCATION_ID : & str = "0xdeadbeefcafebabedeadbeefcafebabedeadbeef" ;
213189
214190 async fn new_deny_list_check ( pgpool : PgPool ) -> DenyListCheck {
215191 // Mock escrow accounts
216- let escrow_accounts_rx = watch:: channel ( EscrowAccounts :: new (
217- ESCROW_ACCOUNTS_BALANCES . to_owned ( ) ,
218- ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS . to_owned ( ) ,
219- ) )
220- . 1 ;
221-
222- DenyListCheck :: new ( pgpool, escrow_accounts_rx, TAP_EIP712_DOMAIN . to_owned ( ) ) . await
192+ DenyListCheck :: new ( pgpool) . await
223193 }
224194
225195 #[ sqlx:: test( migrations = "../../migrations" ) ]
@@ -244,9 +214,12 @@ mod tests {
244214
245215 let checking_receipt = ReceiptWithState :: new ( signed_receipt) ;
246216
217+ let mut ctx = Context :: new ( ) ;
218+ ctx. insert ( Sender ( TAP_SENDER . 1 ) ) ;
219+
247220 // Check that the receipt is rejected
248221 assert ! ( deny_list_check
249- . check( & Context :: new ( ) , & checking_receipt)
222+ . check( & ctx , & checking_receipt)
250223 . await
251224 . is_err( ) ) ;
252225 }
@@ -262,8 +235,10 @@ mod tests {
262235 // Check that the receipt is valid
263236 let checking_receipt = ReceiptWithState :: new ( signed_receipt) ;
264237
238+ let mut ctx = Context :: new ( ) ;
239+ ctx. insert ( Sender ( TAP_SENDER . 1 ) ) ;
265240 deny_list_check
266- . check ( & Context :: new ( ) , & checking_receipt)
241+ . check ( & ctx , & checking_receipt)
267242 . await
268243 . unwrap ( ) ;
269244
@@ -282,7 +257,7 @@ mod tests {
282257 // Check that the receipt is rejected
283258 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
284259 assert ! ( deny_list_check
285- . check( & Context :: new ( ) , & checking_receipt)
260+ . check( & ctx , & checking_receipt)
286261 . await
287262 . is_err( ) ) ;
288263
@@ -301,7 +276,7 @@ mod tests {
301276 // Check that the receipt is valid again
302277 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
303278 deny_list_check
304- . check ( & Context :: new ( ) , & checking_receipt)
279+ . check ( & ctx , & checking_receipt)
305280 . await
306281 . unwrap ( ) ;
307282 }
0 commit comments