@@ -214,7 +214,7 @@ where
214214
215215 /// Decodes a `FeedMessage` into a `BlockUpdate` containing the updated states of protocol
216216 /// components
217- pub async fn decode ( & self , msg : FeedMessage < H > ) -> Result < Update , StreamDecodeError > {
217+ pub async fn decode ( & self , msg : & FeedMessage < H > ) -> Result < Update , StreamDecodeError > {
218218 // stores all states updated in this tick/msg
219219 let mut updated_states = HashMap :: new ( ) ;
220220 let mut new_pairs = HashMap :: new ( ) ;
@@ -377,7 +377,8 @@ where
377377 Some ( storage_by_address) ,
378378 token_proxy_accounts,
379379 )
380- . await ;
380+ . await
381+ . map_err ( |e| StreamDecodeError :: Fatal ( e. to_string ( ) ) ) ?;
381382 info ! ( "Engine updated" ) ;
382383 drop ( state_guard) ;
383384 }
@@ -437,6 +438,8 @@ where
437438 continue ' outer;
438439 }
439440 } ;
441+ // TODO: Ok we deployed a proxy whenever we see a new token without
442+ // a implementation set.
440443 if !state_guard
441444 . proxy_token_addresses
442445 . contains_key ( & token_address)
@@ -474,7 +477,8 @@ where
474477 None ,
475478 new_tokens_accounts,
476479 )
477- . await ;
480+ . await
481+ . map_err ( |e| StreamDecodeError :: Fatal ( e. to_string ( ) ) ) ?;
478482 }
479483
480484 // collect contracts:ids mapping for states that should update on contract
@@ -562,6 +566,9 @@ where
562566 . map ( |( key, value) | {
563567 let mut update: AccountUpdate = value. clone ( ) . into ( ) ;
564568
569+ // TODO: Unify this different initialisation if we receive
570+ // state updates for the token with the usual case. Also
571+ // switch the if cases.
565572 if state_guard. tokens . contains_key ( key) {
566573 // If the account is a token, we need to handle it with a proxy contract
567574
@@ -599,6 +606,21 @@ where
599606 . unwrap ( )
600607 } ;
601608
609+ // TEMP PATCH (ENG-4993)
610+ //
611+ // The indexer emits deltas without code marked as creations,
612+ // which crashes TychoDB. Until fixed, treat them as updates
613+ // (since EVM code cannot be deleted).
614+ if update. code . is_none ( ) &&
615+ matches ! ( update. change, ChangeType :: Creation )
616+ {
617+ error ! (
618+ update = ?update,
619+ "FaultyCreationDelta"
620+ ) ;
621+ update. change = ChangeType :: Update ;
622+ }
623+
602624 // assign original token contract to new address
603625 update. address = proxy_addr;
604626 } ;
@@ -617,7 +639,8 @@ where
617639 None ,
618640 token_proxy_accounts,
619641 )
620- . await ;
642+ . await
643+ . map_err ( |e| StreamDecodeError :: Fatal ( e. to_string ( ) ) ) ?;
621644 info ! ( "Engine updated" ) ;
622645
623646 // Collect all pools related to the updated accounts
@@ -771,7 +794,7 @@ where
771794 // Send the tick with all updated states
772795 Ok ( Update :: new ( header. block_number_or_timestamp ( ) , updated_states, new_pairs)
773796 . set_removed_pairs ( removed_pairs)
774- . set_sync_states ( msg. sync_states ) )
797+ . set_sync_states ( msg. sync_states . clone ( ) ) )
775798 }
776799
777800 fn apply_update (
@@ -975,12 +998,12 @@ mod tests {
975998
976999 let msg = load_test_msg ( "uniswap_v2_snapshot" ) ;
9771000 let res1 = decoder
978- . decode ( msg)
1001+ . decode ( & msg)
9791002 . await
9801003 . expect ( "decode failure" ) ;
9811004 let msg = load_test_msg ( "uniswap_v2_delta" ) ;
9821005 let res2 = decoder
983- . decode ( msg)
1006+ . decode ( & msg)
9841007 . await
9851008 . expect ( "decode failure" ) ;
9861009
@@ -1007,7 +1030,7 @@ mod tests {
10071030
10081031 let msg = load_test_msg ( "uniswap_v2_snapshot" ) ;
10091032 let res1 = decoder
1010- . decode ( msg)
1033+ . decode ( & msg)
10111034 . await
10121035 . expect ( "decode failure" ) ;
10131036
@@ -1023,7 +1046,7 @@ mod tests {
10231046 decoder. skip_state_decode_failures = skip_failures;
10241047
10251048 let msg = load_test_msg ( "uniswap_v2_snapshot_broken_id" ) ;
1026- match decoder. decode ( msg) . await {
1049+ match decoder. decode ( & msg) . await {
10271050 Err ( StreamDecodeError :: Fatal ( msg) ) => {
10281051 if !skip_failures {
10291052 assert_eq ! (
@@ -1053,7 +1076,7 @@ mod tests {
10531076 decoder. skip_state_decode_failures = skip_failures;
10541077
10551078 let msg = load_test_msg ( "uniswap_v2_snapshot_broken_state" ) ;
1056- match decoder. decode ( msg) . await {
1079+ match decoder. decode ( & msg) . await {
10571080 Err ( StreamDecodeError :: Fatal ( msg) ) => {
10581081 if !skip_failures {
10591082 assert_eq ! ( msg, "Missing attributes reserve0" ) ;
@@ -1119,7 +1142,7 @@ mod tests {
11191142
11201143 // Decode the message
11211144 let _ = decoder
1122- . decode ( msg)
1145+ . decode ( & msg)
11231146 . await
11241147 . expect ( "decode failure" ) ;
11251148
0 commit comments