@@ -15,8 +15,8 @@ use sha3::{digest::Update, Digest, Keccak256};
1515use tracing:: { info, instrument, warn} ;
1616
1717use hyperlane_core:: {
18- utils:: bytes_to_hex, CcipReadIsm , HyperlaneMessage , HyperlaneSignerExt , Metadata , ModuleType ,
19- RawHyperlaneMessage , Signable , H160 , H256 ,
18+ h512_to_bytes , utils:: bytes_to_hex, CcipReadIsm , HyperlaneMessage , HyperlaneSignerExt ,
19+ Metadata , ModuleType , RawHyperlaneMessage , Signable , H160 , H256 ,
2020} ;
2121use hyperlane_ethereum:: { OffchainLookup , Signers } ;
2222
@@ -37,6 +37,7 @@ struct OffchainLookupRequestBody {
3737 pub data : String ,
3838 pub sender : String ,
3939 pub signature : Option < String > ,
40+ pub origin_tx_hash : Option < String > ,
4041}
4142
4243#[ derive( Serialize , Deserialize ) ]
@@ -223,6 +224,24 @@ async fn metadata_build(
223224 . call_get_offchain_verify_info ( ism, message)
224225 . await ?;
225226
227+ let origin_tx_hash = ism_builder
228+ . base
229+ . base_builder ( )
230+ . retrieve_origin_tx_hash_by_message_id ( message. id ( ) )
231+ . await
232+ . map_err ( |err| {
233+ warn ! ( error = %err, "Error retrieving origin tx hash for message {:?}" , message. id( ) ) ;
234+ } )
235+ . ok ( )
236+ . flatten ( )
237+ . map ( |h| bytes_to_hex ( & h512_to_bytes ( & h) ) ) ;
238+ tracing:: debug!(
239+ message_id = ?message. id( ) ,
240+ origin_tx_hash = ?origin_tx_hash,
241+ found_in_db = origin_tx_hash. is_some( ) ,
242+ "Origin tx hash lookup result" ,
243+ ) ;
244+
226245 let ccip_url_regex = create_ccip_url_regex ( ) ;
227246
228247 for url in info. urls . iter ( ) {
@@ -232,7 +251,7 @@ async fn metadata_build(
232251 }
233252
234253 // if we fail, we want to try the other urls
235- match fetch_offchain_data ( ism_builder, & info, url) . await {
254+ match fetch_offchain_data ( ism_builder, & info, url, origin_tx_hash . clone ( ) ) . await {
236255 Ok ( data) => return Ok ( data) ,
237256 Err ( err) => {
238257 tracing:: warn!( ?ism_address, url, ?err, "Failed to fetch offchain data" ) ;
@@ -250,6 +269,7 @@ async fn fetch_offchain_data(
250269 ism_builder : & CcipReadIsmMetadataBuilder ,
251270 info : & OffchainLookup ,
252271 url : & str ,
272+ origin_tx_hash : Option < String > ,
253273) -> Result < Metadata , MetadataBuildError > {
254274 // Compute relayer authentication signature via EIP-191
255275 let maybe_signature_hex = if let Some ( signer) = ism_builder. base . base_builder ( ) . get_signer ( ) {
@@ -271,7 +291,13 @@ async fn fetch_offchain_data(
271291 sender : sender_as_bytes,
272292 data : data_as_bytes,
273293 signature : maybe_signature_hex,
294+ origin_tx_hash,
274295 } ;
296+ tracing:: debug!(
297+ url = interpolated_url,
298+ ?body,
299+ "Sending POST request to offchain lookup server"
300+ ) ;
275301 Client :: new ( )
276302 . request ( Method :: POST , interpolated_url)
277303 . header ( CONTENT_TYPE , "application/json" )
@@ -301,6 +327,10 @@ async fn fetch_offchain_data(
301327 let error_msg = format ! ( "Failed to read offchain lookup server response: ({err})" ) ;
302328 MetadataBuildError :: FailedToBuild ( error_msg)
303329 } ) ?;
330+ tracing:: debug!(
331+ response = response_body,
332+ "Received response from offchain lookup server"
333+ ) ;
304334 let json: OffchainResponse = serde_json:: from_str ( & response_body) . map_err ( |err| {
305335 let error_msg = format ! (
306336 "Failed to parse offchain lookup server json response: ({err}) ({response_body})"
0 commit comments