44use anyhow:: { anyhow, Context } ;
55use fendermint_actor_f3_light_client:: types;
66use fendermint_crypto:: PublicKey ;
7+ // Temporarily disabled due to [email protected] compatibility issues 8+ // use filecoin_f3_lightclient::F3Client;
79use fvm_shared:: address:: Address ;
810use ipc_api:: subnet_id:: SubnetID ;
911use ipc_provider:: config:: subnet:: { EVMSubnet , SubnetConfig } ;
@@ -350,13 +352,15 @@ pub async fn seal_genesis(genesis_file: &PathBuf, args: &SealGenesisArgs) -> any
350352 builder. write_to ( args. output_path . clone ( ) ) . await
351353}
352354
353- /// Fetches F3 parameters from the parent Filecoin chain
355+ /// Fetches F3 certificate data from the parent Filecoin chain
354356async fn fetch_f3_params_from_parent (
355357 parent_endpoint : & url:: Url ,
356358 parent_auth_token : Option < & String > ,
357359) -> anyhow:: Result < Option < ipc:: F3Params > > {
360+ use std:: convert:: TryFrom ;
361+
358362 tracing:: info!(
359- "Fetching F3 parameters from parent chain at {}" ,
363+ "Fetching F3 certificate data from parent chain at {}" ,
360364 parent_endpoint
361365 ) ;
362366
@@ -368,28 +372,11 @@ async fn fetch_f3_params_from_parent(
368372 // We use a dummy subnet ID here since F3 data is at the chain level, not subnet-specific
369373 let lotus_client = LotusJsonRPCClient :: new ( jsonrpc_client, SubnetID :: default ( ) ) ;
370374
371- // Fetch F3 certificate which contains instance ID and finalized epochs
372- let certificate = lotus_client. f3_get_certificate ( ) . await ?;
373-
374- match certificate {
375- Some ( cert) => {
376- let instance_id = cert. gpbft_instance ;
375+ // Fetch F3 data using the Lotus client
376+ match lotus_client. f3_get_instance_id ( ) . await {
377+ Ok ( instance_id) => {
377378 tracing:: info!( "Found F3 instance ID: {}" , instance_id) ;
378379
379- // Extract finalized epochs from the EC chain
380- let finalized_epochs: Vec < i64 > =
381- cert. ec_chain . iter ( ) . map ( |entry| entry. epoch ) . collect ( ) ;
382-
383- if finalized_epochs. is_empty ( ) {
384- return Err ( anyhow:: anyhow!( "F3 certificate has empty EC chain" ) ) ;
385- }
386-
387- tracing:: info!(
388- "Found {} finalized epochs, latest: {}" ,
389- finalized_epochs. len( ) ,
390- finalized_epochs. iter( ) . max( ) . unwrap_or( & 0 )
391- ) ;
392-
393380 // Get power table for this instance
394381 let power_table_response = lotus_client. f3_get_power_table ( instance_id) . await ?;
395382
@@ -412,15 +399,36 @@ async fn fetch_f3_params_from_parent(
412399 . collect ( ) ;
413400 let power_table = power_table?;
414401
415- tracing:: info!( "Successfully fetched F3 parameters from parent chain" ) ;
402+ // Get latest certificate to extract finalized epochs
403+ let certificate = lotus_client. f3_get_certificate ( ) . await ?;
404+ let finalized_epochs = if let Some ( cert_response) = certificate {
405+ // Collect all finalized epochs from the EC chain
406+ let epochs: Vec < i64 > = cert_response
407+ . ec_chain
408+ . iter ( )
409+ . map ( |entry| entry. epoch )
410+ . collect ( ) ;
411+
412+ if epochs. is_empty ( ) {
413+ return Err ( anyhow:: anyhow!( "F3 certificate has empty EC chain" ) ) ;
414+ }
415+
416+ epochs
417+ } else {
418+ // No certificate yet - start with empty finalized chain
419+ Vec :: new ( )
420+ } ;
421+
422+ tracing:: info!( "Successfully fetched F3 certificate data from parent chain" ) ;
416423 Ok ( Some ( ipc:: F3Params {
417424 instance_id,
418425 power_table,
419426 finalized_epochs,
420427 } ) )
421428 }
422- None => Err ( anyhow:: anyhow!(
423- "No F3 certificate available - F3 might not be running on the parent chain"
429+ Err ( e) => Err ( anyhow:: anyhow!(
430+ "Failed to fetch F3 certificate data from parent chain: {}" ,
431+ e
424432 ) ) ,
425433 }
426434}
@@ -450,20 +458,13 @@ pub async fn new_genesis_from_parent(
450458
451459 let genesis_info = parent_provider. get_genesis_info ( & args. subnet_id ) . await ?;
452460
453- // Fetch F3 certificate data from parent chain if Filecoin RPC endpoint is provided.
454- // If not provided, it means the parent is not Filecoin (e.g., a Fendermint subnet)
455- // and F3 data is not available.
456- let f3_params = if let Some ( ref parent_filecoin_rpc) = args. parent_filecoin_rpc {
457- tracing:: info!( "Fetching F3 data from parent Filecoin chain" ) ;
458- fetch_f3_params_from_parent (
459- parent_filecoin_rpc,
460- args. parent_filecoin_auth_token . as_ref ( ) ,
461- )
462- . await ?
463- } else {
464- tracing:: info!( "Skipping F3 data fetch - parent is not Filecoin" ) ;
465- None
466- } ;
461+ // Fetch F3 certificate data from parent chain using Lotus client directly
462+ // This requires the Filecoin/Lotus RPC endpoint, not the EVM endpoint
463+ let f3_params = fetch_f3_params_from_parent (
464+ & args. parent_filecoin_rpc ,
465+ args. parent_filecoin_auth_token . as_ref ( ) ,
466+ )
467+ . await ?;
467468
468469 tracing:: debug!( "F3 params: {:?}" , f3_params) ;
469470
0 commit comments