@@ -85,33 +85,33 @@ impl FraudProofExtension {
85
85
}
86
86
87
87
/// Trait Impl to query and verify Domains Fraud proof.
88
- pub struct FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor > {
88
+ pub struct FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor , EFC > {
89
89
consensus_client : Arc < Client > ,
90
90
executor : Arc < Executor > ,
91
- domain_extensions_factory : Box < dyn ExtensionsFactory < DomainBlock > > ,
91
+ domain_extensions_factory_creator : EFC ,
92
92
_phantom : PhantomData < ( Block , DomainBlock ) > ,
93
93
}
94
94
95
- impl < Block , Client , DomainBlock , Executor >
96
- FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor >
95
+ impl < Block , Client , DomainBlock , Executor , EFC >
96
+ FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor , EFC >
97
97
{
98
98
pub fn new (
99
99
consensus_client : Arc < Client > ,
100
100
executor : Arc < Executor > ,
101
- domain_extensions_factory : Box < dyn ExtensionsFactory < DomainBlock > > ,
101
+ domain_extensions_factory_creator : EFC ,
102
102
) -> Self {
103
103
FraudProofHostFunctionsImpl {
104
104
consensus_client,
105
105
executor,
106
- domain_extensions_factory ,
106
+ domain_extensions_factory_creator ,
107
107
_phantom : Default :: default ( ) ,
108
108
}
109
109
}
110
110
}
111
111
112
112
// TODO: Revisit the host function implementation once we decide best strategy to structure them.
113
- impl < Block , Client , DomainBlock , Executor >
114
- FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor >
113
+ impl < Block , Client , DomainBlock , Executor , EFC >
114
+ FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor , EFC >
115
115
where
116
116
Block : BlockT ,
117
117
Block :: Hash : From < H256 > ,
@@ -120,6 +120,7 @@ where
120
120
Client : BlockBackend < Block > + HeaderBackend < Block > + ProvideRuntimeApi < Block > ,
121
121
Client :: Api : DomainsApi < Block , DomainBlock :: Header > + BundleProducerElectionApi < Block , Balance > ,
122
122
Executor : CodeExecutor + RuntimeVersionOf ,
123
+ EFC : Fn ( Arc < Client > , Arc < Executor > ) -> Box < dyn ExtensionsFactory < DomainBlock > > + Send + Sync ,
123
124
{
124
125
fn get_block_randomness ( & self , consensus_block_hash : H256 ) -> Option < Randomness > {
125
126
let runtime_api = self . consensus_client . runtime_api ( ) ;
@@ -297,6 +298,36 @@ where
297
298
. ok ( )
298
299
}
299
300
301
+ fn is_valid_xdm (
302
+ & self ,
303
+ consensus_block_hash : H256 ,
304
+ domain_id : DomainId ,
305
+ opaque_extrinsic : OpaqueExtrinsic ,
306
+ ) -> Option < bool > {
307
+ let runtime_code = self . get_domain_runtime_code ( consensus_block_hash, domain_id) ?;
308
+ let mut domain_stateless_runtime =
309
+ StatelessRuntime :: < DomainBlock , _ > :: new ( self . executor . clone ( ) , runtime_code. into ( ) ) ;
310
+ let extension_factory = ( self . domain_extensions_factory_creator ) (
311
+ self . consensus_client . clone ( ) ,
312
+ self . executor . clone ( ) ,
313
+ ) ;
314
+ domain_stateless_runtime. set_extension_factory ( extension_factory) ;
315
+
316
+ let consensus_api = self . consensus_client . runtime_api ( ) ;
317
+ let domain_initial_state = consensus_api
318
+ . domain_instance_data ( consensus_block_hash. into ( ) , domain_id)
319
+ . expect ( "Runtime Api must not fail. This is unrecoverable error" ) ?
320
+ . 0
321
+ . raw_genesis
322
+ . into_storage ( ) ;
323
+ domain_stateless_runtime. set_storage ( domain_initial_state) ;
324
+
325
+ let encoded_extrinsic = opaque_extrinsic. encode ( ) ;
326
+ domain_stateless_runtime
327
+ . is_valid_xdm ( encoded_extrinsic)
328
+ . expect ( "Runtime api must not fail. This is an unrecoverable error" )
329
+ }
330
+
300
331
fn is_decodable_extrinsic (
301
332
& self ,
302
333
consensus_block_hash : H256 ,
@@ -389,8 +420,8 @@ where
389
420
}
390
421
}
391
422
392
- impl < Block , Client , DomainBlock , Executor > FraudProofHostFunctions
393
- for FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor >
423
+ impl < Block , Client , DomainBlock , Executor , EFC > FraudProofHostFunctions
424
+ for FraudProofHostFunctionsImpl < Block , Client , DomainBlock , Executor , EFC >
394
425
where
395
426
Block : BlockT ,
396
427
Block :: Hash : From < H256 > ,
@@ -400,6 +431,7 @@ where
400
431
Client : BlockBackend < Block > + HeaderBackend < Block > + ProvideRuntimeApi < Block > ,
401
432
Client :: Api : DomainsApi < Block , DomainBlock :: Header > + BundleProducerElectionApi < Block , Balance > ,
402
433
Executor : CodeExecutor + RuntimeVersionOf ,
434
+ EFC : Fn ( Arc < Client > , Arc < Executor > ) -> Box < dyn ExtensionsFactory < DomainBlock > > + Send + Sync ,
403
435
{
404
436
fn get_fraud_proof_verification_info (
405
437
& self ,
@@ -515,6 +547,12 @@ where
515
547
self . storage_key ( consensus_block_hash, domain_id, req) ,
516
548
) )
517
549
}
550
+ FraudProofVerificationInfoRequest :: XDMValidationCheck {
551
+ domain_id,
552
+ opaque_extrinsic,
553
+ } => Some ( FraudProofVerificationInfoResponse :: XDMValidationCheck (
554
+ self . is_valid_xdm ( consensus_block_hash, domain_id, opaque_extrinsic) ,
555
+ ) ) ,
518
556
}
519
557
}
520
558
@@ -574,9 +612,11 @@ where
574
612
} ;
575
613
576
614
let ( domain_block_number, domain_block_hash) = domain_block_id;
577
- let mut domain_extensions = self
578
- . domain_extensions_factory
579
- . extensions_for ( domain_block_hash. into ( ) , domain_block_number. into ( ) ) ;
615
+ let mut domain_extensions = ( self . domain_extensions_factory_creator ) (
616
+ self . consensus_client . clone ( ) ,
617
+ self . executor . clone ( ) ,
618
+ )
619
+ . extensions_for ( domain_block_hash. into ( ) , domain_block_number. into ( ) ) ;
580
620
581
621
execution_proof_check :: < <DomainBlock :: Header as HeaderT >:: Hashing , _ > (
582
622
pre_state_root. into ( ) ,
0 commit comments