@@ -13,8 +13,15 @@ use linera_base::{
13
13
identifiers:: { ChainId , MessageId } ,
14
14
ownership:: ChainOwnership ,
15
15
} ;
16
- use linera_client:: { chain_listener:: ClientContext , config:: GenesisConfig } ;
17
- use linera_core:: { client:: ChainClient , data_types:: ClientOutcome , node:: ValidatorNodeProvider } ;
16
+ use linera_client:: {
17
+ chain_clients:: ChainClients ,
18
+ chain_listener:: { ChainListener , ChainListenerConfig , ClientContext } ,
19
+ config:: GenesisConfig ,
20
+ } ;
21
+ use linera_core:: {
22
+ data_types:: ClientOutcome ,
23
+ node:: { ValidatorNode , ValidatorNodeProvider } ,
24
+ } ;
18
25
use linera_execution:: committee:: ValidatorName ;
19
26
use linera_storage:: { Clock as _, Storage } ;
20
27
use serde:: Deserialize ;
@@ -33,15 +40,17 @@ where
33
40
S : Storage ,
34
41
{
35
42
genesis_config : Arc < GenesisConfig > ,
36
- client : Arc < Mutex < ChainClient < P , S > > > ,
43
+ clients : ChainClients < P , S > ,
44
+ chain_id : ChainId ,
37
45
}
38
46
39
47
/// The root GraphQL mutation type.
40
48
pub struct MutationRoot < P , S , C >
41
49
where
42
50
S : Storage ,
43
51
{
44
- client : Arc < Mutex < ChainClient < P , S > > > ,
52
+ clients : ChainClients < P , S > ,
53
+ chain_id : ChainId ,
45
54
context : Arc < Mutex < C > > ,
46
55
amount : Amount ,
47
56
end_timestamp : Timestamp ,
84
93
85
94
/// Returns the current committee's validators.
86
95
async fn current_validators ( & self ) -> Result < Vec < Validator > , Error > {
87
- let client = self . client . lock ( ) . await ;
96
+ let client = self . clients . try_client_lock ( & self . chain_id ) . await ? ;
88
97
let committee = client. local_committee ( ) . await ?;
89
98
Ok ( committee
90
99
. validators ( )
@@ -119,7 +128,7 @@ where
119
128
C : ClientContext < ValidatorNodeProvider = P , Storage = S > + Send + ' static ,
120
129
{
121
130
async fn do_claim ( & self , public_key : PublicKey ) -> Result < ClaimOutcome , Error > {
122
- let client = self . client . lock ( ) . await ;
131
+ let client = self . clients . try_client_lock ( & self . chain_id ) . await ? ;
123
132
124
133
if self . start_timestamp < self . end_timestamp {
125
134
let local_time = client. storage_client ( ) . clock ( ) . current_time ( ) ;
@@ -149,7 +158,7 @@ where
149
158
let result = client
150
159
. open_chain ( ownership, ApplicationPermissions :: default ( ) , self . amount )
151
160
. await ;
152
- self . context . lock ( ) . await . update_wallet ( & * client) . await ?;
161
+ self . context . lock ( ) . await . update_wallet ( & client) . await ?;
153
162
let ( message_id, certificate) = match result? {
154
163
ClientOutcome :: Committed ( result) => result,
155
164
ClientOutcome :: WaitForTimeout ( timeout) => {
@@ -189,9 +198,12 @@ pub struct FaucetService<P, S, C>
189
198
where
190
199
S : Storage ,
191
200
{
192
- client : Arc < Mutex < ChainClient < P , S > > > ,
201
+ clients : ChainClients < P , S > ,
202
+ chain_id : ChainId ,
193
203
context : Arc < Mutex < C > > ,
194
204
genesis_config : Arc < GenesisConfig > ,
205
+ config : ChainListenerConfig ,
206
+ storage : S ,
195
207
port : NonZeroU16 ,
196
208
amount : Amount ,
197
209
end_timestamp : Timestamp ,
@@ -205,9 +217,12 @@ where
205
217
{
206
218
fn clone ( & self ) -> Self {
207
219
Self {
208
- client : self . client . clone ( ) ,
220
+ clients : self . clients . clone ( ) ,
221
+ chain_id : self . chain_id ,
209
222
context : self . context . clone ( ) ,
210
223
genesis_config : self . genesis_config . clone ( ) ,
224
+ config : self . config . clone ( ) ,
225
+ storage : self . storage . clone ( ) ,
211
226
port : self . port ,
212
227
amount : self . amount ,
213
228
end_timestamp : self . end_timestamp ,
@@ -220,25 +235,35 @@ where
220
235
impl < P , S , C > FaucetService < P , S , C >
221
236
where
222
237
P : ValidatorNodeProvider + Send + Sync + Clone + ' static ,
238
+ <<P as ValidatorNodeProvider >:: Node as ValidatorNode >:: NotificationStream : Send ,
223
239
S : Storage + Clone + Send + Sync + ' static ,
224
240
C : ClientContext < ValidatorNodeProvider = P , Storage = S > + Send + ' static ,
225
241
{
226
242
/// Creates a new instance of the faucet service.
243
+ #[ allow( clippy:: too_many_arguments) ]
227
244
pub async fn new (
228
245
port : NonZeroU16 ,
229
- client : ChainClient < P , S > ,
246
+ chain_id : ChainId ,
230
247
context : C ,
231
248
amount : Amount ,
232
249
end_timestamp : Timestamp ,
233
250
genesis_config : Arc < GenesisConfig > ,
251
+ config : ChainListenerConfig ,
252
+ storage : S ,
234
253
) -> anyhow:: Result < Self > {
254
+ let clients = ChainClients :: < P , S > :: from_clients ( context. clients ( ) ) . await ;
255
+ let context = Arc :: new ( Mutex :: new ( context) ) ;
256
+ let client = clients. try_client_lock ( & chain_id) . await ?;
235
257
let start_timestamp = client. storage_client ( ) . clock ( ) . current_time ( ) ;
236
258
client. process_inbox ( ) . await ?;
237
259
let start_balance = client. local_balance ( ) . await ?;
238
260
Ok ( Self {
239
- client : Arc :: new ( Mutex :: new ( client) ) ,
240
- context : Arc :: new ( Mutex :: new ( context) ) ,
261
+ clients,
262
+ chain_id,
263
+ context,
241
264
genesis_config,
265
+ config,
266
+ storage,
242
267
port,
243
268
amount,
244
269
end_timestamp,
@@ -249,7 +274,8 @@ where
249
274
250
275
pub fn schema ( & self ) -> Schema < QueryRoot < P , S > , MutationRoot < P , S , C > , EmptySubscription > {
251
276
let mutation_root = MutationRoot {
252
- client : self . client . clone ( ) ,
277
+ clients : self . clients . clone ( ) ,
278
+ chain_id : self . chain_id ,
253
279
context : self . context . clone ( ) ,
254
280
amount : self . amount ,
255
281
end_timestamp : self . end_timestamp ,
@@ -258,7 +284,8 @@ where
258
284
} ;
259
285
let query_root = QueryRoot {
260
286
genesis_config : self . genesis_config . clone ( ) ,
261
- client : self . client . clone ( ) ,
287
+ clients : self . clients . clone ( ) ,
288
+ chain_id : self . chain_id ,
262
289
} ;
263
290
Schema :: build ( query_root, mutation_root, EmptySubscription ) . finish ( )
264
291
}
@@ -277,6 +304,10 @@ where
277
304
278
305
info ! ( "GraphiQL IDE: http://localhost:{}" , port) ;
279
306
307
+ ChainListener :: new ( self . config . clone ( ) , self . clients . clone ( ) )
308
+ . run ( self . context . clone ( ) , self . storage . clone ( ) )
309
+ . await ;
310
+
280
311
axum:: serve (
281
312
tokio:: net:: TcpListener :: bind ( SocketAddr :: from ( ( [ 0 , 0 , 0 , 0 ] , port) ) ) . await ?,
282
313
app,
0 commit comments