@ -9,7 +9,7 @@ use async_trait::async_trait;
use eyre ::Result ;
use hyperlane_base ::settings ::IndexSettings ;
use hyperlane_core ::{
unwrap_or_none_result , BlockInfo , Delivery , HyperlaneDomain , HyperlaneLogStore ,
unwrap_or_none_result , BlockId , BlockI nfo , Delivery , HyperlaneDomain , HyperlaneLogStore ,
HyperlaneMessage , HyperlaneProvider , HyperlaneSequenceAwareIndexerStoreReader ,
HyperlaneWatermarkedLogStore , Indexed , InterchainGasPayment , LogMeta , H256 ,
} ;
@ -78,13 +78,13 @@ impl HyperlaneSqlDb {
& self ,
log_meta : impl Iterator < Item = & LogMeta > ,
) -> Result < impl Iterator < Item = TxnWithId > > {
let block_hash _by_txn_hash : HashMap < H256 , H256 > = log_meta
let block_id _by_txn_hash : HashMap < H256 , BlockId > = log_meta
. map ( | meta | {
(
meta . transaction_id
. try_into ( )
. expect ( "256-bit transaction ids are the maximum supported at this time" ) ,
meta . block_hash ,
BlockId ::new ( meta . block_hash , meta . block_number ) ,
)
} )
. collect ( ) ;
@ -92,16 +92,16 @@ impl HyperlaneSqlDb {
// all blocks we care about
// hash of block maps to the block id and timestamp
let blocks : HashMap < _ , _ > = self
. ensure_blocks ( block_hash _by_txn_hash . values ( ) . copied ( ) )
. ensure_blocks ( block_id _by_txn_hash . values ( ) . copied ( ) )
. await ?
. map ( | block | ( block . hash , block ) )
. collect ( ) ;
trace ! ( ? blocks , "Ensured blocks" ) ;
// We ensure transactions only from blocks which are inserted into database
let txn_hash_with_block_ids = block_hash _by_txn_hash
let txn_hash_with_block_ids = block_id _by_txn_hash
. into_iter ( )
. filter_map ( move | ( txn , block ) | blocks . get ( & block ) . map ( | b | ( txn , b . id ) ) )
. filter_map ( move | ( txn , block ) | blocks . get ( & block . hash ) . map ( | b | ( txn , b . id ) ) )
. map ( | ( txn_hash , block_id ) | TxnWithBlockId { txn_hash , block_id } ) ;
let txns_with_ids = self . ensure_txns ( txn_hash_with_block_ids ) . await ? ;
@ -195,11 +195,17 @@ impl HyperlaneSqlDb {
/// this method.
async fn ensure_blocks (
& self ,
block_hashe s : impl Iterator < Item = H256 > ,
block_id s : impl Iterator < Item = BlockId > ,
) -> Result < impl Iterator < Item = BasicBlock > > {
// Mapping from block hash to block ids (hash and height)
let block_hash_to_block_id_map : HashMap < H256 , BlockId > =
block_ids . map ( | b | ( b . hash , b ) ) . collect ( ) ;
// Mapping of block hash to `BasicBlock` which contains database block id and block hash.
let mut blocks : HashMap < H256 , Option < BasicBlock > > =
block_hashes . map ( | b | ( b , None ) ) . collect ( ) ;
let mut blocks : HashMap < H256 , Option < BasicBlock > > = block_hash_to_block_id_map
. keys ( )
. map ( | hash | ( * hash , None ) )
. collect ( ) ;
let db_blocks : Vec < BasicBlock > = if ! blocks . is_empty ( ) {
// check database to see which blocks we already know and fetch their IDs
@ -230,10 +236,14 @@ impl HyperlaneSqlDb {
for chunk in as_chunks ( blocks_to_fetch , CHUNK_SIZE ) {
debug_assert! ( ! chunk . is_empty ( ) ) ;
for ( hash , block_info ) in chunk {
let info = match self . provider . get_block_by_hash ( hash ) . await {
// We should have block_id in this map for every hashes
let block_id = block_hash_to_block_id_map [ hash ] ;
let block_height = block_id . height ;
let info = match self . provider . get_block_by_height ( block_height ) . await {
Ok ( info ) = > info ,
Err ( e ) = > {
warn ! ( ? hash , ? e , "error fetching and parsing block" ) ;
warn ! ( block_hash = ? hash , ? block_height , ? e , "error fetching and parsing block" ) ;
continue ;
}
} ;