Skip to content

Commit

Permalink
Fix genesis block sync (paritytech#917)
Browse files Browse the repository at this point in the history
* fix mapping-sync sync_genesis_block

* fix lint

* use legacy current_block before api version v2

* empty commit
  • Loading branch information
shunsukew authored Dec 9, 2022
1 parent 661d178 commit e9c7743
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions client/mapping-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,24 @@ where
{
let id = BlockId::Hash(header.hash());

let has_api = client
if let Some(api_version) = client
.runtime_api()
.has_api::<dyn EthereumRuntimeRPCApi<Block>>(&id)
.map_err(|e| format!("{:?}", e))?;

if has_api {
let block = client
.runtime_api()
.current_block(&id)
.map_err(|e| format!("{:?}", e))?;
.api_version::<dyn EthereumRuntimeRPCApi<Block>>(&id)
.map_err(|e| format!("{:?}", e))?
{
let block = if api_version > 1 {
client
.runtime_api()
.current_block(&id)
.map_err(|e| format!("{:?}", e))?
} else {
#[allow(deprecated)]
let legacy_block = client
.runtime_api()
.current_block_before_version_2(&id)
.map_err(|e| format!("{:?}", e))?;
legacy_block.map(|block| block.into())
};
let block_hash = block
.ok_or_else(|| "Ethereum genesis block not found".to_string())?
.header
Expand All @@ -93,7 +101,7 @@ where
backend.mapping().write_hashes(mapping_commitment)?;
} else {
backend.mapping().write_none(header.hash())?;
}
};

Ok(())
}
Expand Down

0 comments on commit e9c7743

Please sign in to comment.