From 6d52defe8ff0d157fd4e8c6bab280baaf97c7df0 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Fri, 16 Aug 2024 15:46:34 +0400 Subject: [PATCH 1/2] fix: u64 convert panic --- .../src/indexer/v06/mod.rs | 18 +++--- .../src/indexer/v07/mod.rs | 13 ++--- .../src/types/user_op.rs | 56 +++++++++---------- .../proto/user-ops-indexer.proto | 18 +++--- .../swagger/user-ops-indexer.swagger.yaml | 9 --- 5 files changed, 49 insertions(+), 65 deletions(-) diff --git a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/mod.rs b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/mod.rs index 614fe6a3c..1090a4028 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/mod.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/mod.rs @@ -151,10 +151,6 @@ fn build_user_op_model( .map(|e| e.account) .collect(); - let call_gas_limit = user_op.user_op.call_gas_limit.as_u64(); - let verification_gas_limit = user_op.user_op.verification_gas_limit.as_u64(); - let pre_verification_gas = user_op.user_op.pre_verification_gas.as_u64(); - let factory = extract_address(&user_op.user_op.init_code); let paymaster = extract_address(&user_op.user_op.paymaster_and_data); let sender = user_op.user_op.sender; @@ -166,9 +162,9 @@ fn build_user_op_model( nonce: H256::from_uint(&user_op.user_op.nonce), init_code: none_if_empty(user_op.user_op.init_code), call_data: user_op.user_op.call_data, - call_gas_limit, - verification_gas_limit, - pre_verification_gas, + call_gas_limit: user_op.user_op.call_gas_limit, + verification_gas_limit: user_op.user_op.verification_gas_limit, + pre_verification_gas: user_op.user_op.pre_verification_gas, max_fee_per_gas: user_op.user_op.max_fee_per_gas, max_priority_fee_per_gas: user_op.user_op.max_priority_fee_per_gas, paymaster_and_data: none_if_empty(user_op.user_op.paymaster_and_data), @@ -187,13 +183,13 @@ fn build_user_op_model( paymaster, status: user_op_event.success, revert_reason: revert_event.map(|e| e.revert_reason), - gas: call_gas_limit - + verification_gas_limit * if paymaster.is_none() { 1 } else { 3 } - + pre_verification_gas, + gas: user_op.user_op.call_gas_limit + + user_op.user_op.verification_gas_limit * if paymaster.is_none() { 1 } else { 3 } + + user_op.user_op.pre_verification_gas, gas_price: user_op_event .actual_gas_cost .div(user_op_event.actual_gas_used), - gas_used: user_op_event.actual_gas_used.as_u64(), + gas_used: user_op_event.actual_gas_used, sponsor_type: extract_sponsor_type(sender, paymaster, &tx_deposits), user_logs_start_index, user_logs_count, diff --git a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v07/mod.rs b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v07/mod.rs index 1e48c2b5d..0d2f29205 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v07/mod.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v07/mod.rs @@ -14,7 +14,7 @@ use ethers::prelude::{ abi::{AbiDecode, Address}, abigen, types::{Bytes, Log, TransactionReceipt, H256}, - BigEndianHash, EthEvent, + BigEndianHash, EthEvent, U256, }; use lazy_static::lazy_static; use std::ops::Div; @@ -154,15 +154,12 @@ fn build_user_op_model( let (verification_gas_limit, call_gas_limit) = unpack_uints(&user_op.user_op.account_gas_limits[..]); - let verification_gas_limit = verification_gas_limit.as_u64(); - let call_gas_limit = call_gas_limit.as_u64(); - let pre_verification_gas = user_op.user_op.pre_verification_gas.as_u64(); + let pre_verification_gas = user_op.user_op.pre_verification_gas; let (paymaster_verification_gas_limit, paymaster_post_op_gas_limit) = if user_op.user_op.paymaster_and_data.len() >= 52 { - let (a, b) = unpack_uints(&user_op.user_op.paymaster_and_data[20..52]); - (a.as_u64(), b.as_u64()) + unpack_uints(&user_op.user_op.paymaster_and_data[20..52]) } else { - (0, 0) + (U256::zero(), U256::zero()) }; let gas = call_gas_limit + verification_gas_limit @@ -208,7 +205,7 @@ fn build_user_op_model( gas_price: user_op_event .actual_gas_cost .div(user_op_event.actual_gas_used), - gas_used: user_op_event.actual_gas_used.as_u64(), + gas_used: user_op_event.actual_gas_used, sponsor_type: extract_sponsor_type(sender, paymaster, &tx_deposits), user_logs_start_index, user_logs_count, diff --git a/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs b/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs index 8a8f57d88..f05048547 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs @@ -5,10 +5,10 @@ use crate::{ pub use entity::sea_orm_active_enums::{EntryPointVersion, SponsorType}; use entity::user_operations::Model; use ethers::prelude::{ - abi::AbiEncode, core::utils::to_checksum, Address, BigEndianHash, Bytes, H128, H256, U256, + abi::AbiEncode, core::utils::to_checksum, Address, BigEndianHash, Bytes, H256, U256, }; use num_traits::cast::ToPrimitive; -use sea_orm::{prelude::BigDecimal, ActiveEnum}; +use sea_orm::ActiveEnum; use std::ops::Mul; #[derive(Clone, Debug, PartialEq)] @@ -18,9 +18,9 @@ pub struct UserOp { pub nonce: H256, pub init_code: Option, pub call_data: Bytes, - pub call_gas_limit: u64, - pub verification_gas_limit: u64, - pub pre_verification_gas: u64, + pub call_gas_limit: U256, + pub verification_gas_limit: U256, + pub pre_verification_gas: U256, pub max_fee_per_gas: U256, pub max_priority_fee_per_gas: U256, pub paymaster_and_data: Option, @@ -39,9 +39,9 @@ pub struct UserOp { pub paymaster: Option
, pub status: bool, pub revert_reason: Option, - pub gas: u64, + pub gas: U256, pub gas_price: U256, - pub gas_used: u64, + pub gas_used: U256, pub sponsor_type: SponsorType, pub user_logs_start_index: u32, pub user_logs_count: u32, @@ -72,9 +72,9 @@ impl From for Model { nonce: v.nonce.as_bytes().to_vec(), init_code: v.init_code.clone().map(|a| a.to_vec()), call_data: v.call_data.to_vec(), - call_gas_limit: BigDecimal::from(v.call_gas_limit), - verification_gas_limit: BigDecimal::from(v.verification_gas_limit), - pre_verification_gas: BigDecimal::from(v.pre_verification_gas), + call_gas_limit: u256_to_decimal(v.call_gas_limit), + verification_gas_limit: u256_to_decimal(v.verification_gas_limit), + pre_verification_gas: u256_to_decimal(v.pre_verification_gas), max_fee_per_gas: u256_to_decimal(v.max_fee_per_gas), max_priority_fee_per_gas: u256_to_decimal(v.max_priority_fee_per_gas), paymaster_and_data: v.paymaster_and_data.clone().map(|a| a.to_vec()), @@ -93,9 +93,9 @@ impl From for Model { paymaster: v.paymaster.map(|a| a.as_bytes().to_vec()), status: v.status, revert_reason: v.revert_reason.clone().map(|a| a.to_vec()), - gas: BigDecimal::from(v.gas), + gas: u256_to_decimal(v.gas), gas_price: u256_to_decimal(v.gas_price), - gas_used: BigDecimal::from(v.gas_used), + gas_used: u256_to_decimal(v.gas_used), sponsor_type: v.sponsor_type.clone(), user_logs_start_index: v.user_logs_start_index as i32, user_logs_count: v.user_logs_count as i32, @@ -113,9 +113,9 @@ impl From for UserOp { nonce: H256::from_slice(&v.nonce), init_code: v.init_code.clone().map(Bytes::from), call_data: Bytes::from(v.call_data.clone()), - call_gas_limit: v.call_gas_limit.to_u64().unwrap_or(0), - verification_gas_limit: v.verification_gas_limit.to_u64().unwrap_or(0), - pre_verification_gas: v.pre_verification_gas.to_u64().unwrap_or(0), + call_gas_limit: U256::from(v.call_gas_limit.to_u128().unwrap_or(0)), + verification_gas_limit: U256::from(v.verification_gas_limit.to_u128().unwrap_or(0)), + pre_verification_gas: U256::from(v.pre_verification_gas.to_u128().unwrap_or(0)), max_fee_per_gas: U256::from(v.max_fee_per_gas.to_u128().unwrap_or(0)), max_priority_fee_per_gas: U256::from(v.max_priority_fee_per_gas.to_u128().unwrap_or(0)), paymaster_and_data: v.paymaster_and_data.clone().map(Bytes::from), @@ -134,9 +134,9 @@ impl From for UserOp { paymaster: v.paymaster.clone().map(|a| Address::from_slice(&a)), status: v.status, revert_reason: v.revert_reason.clone().map(Bytes::from), - gas: v.gas.to_u64().unwrap_or(0), + gas: U256::from(v.gas.to_u128().unwrap_or(0)), gas_price: U256::from(v.gas_price.to_u128().unwrap_or(0)), - gas_used: v.gas_used.to_u64().unwrap_or(0), + gas_used: U256::from(v.gas_used.to_u128().unwrap_or(0)), sponsor_type: v.sponsor_type.clone(), user_logs_start_index: v.user_logs_start_index as u32, user_logs_count: v.user_logs_count as u32, @@ -158,9 +158,9 @@ impl From for user_ops_indexer_proto::blockscout::user_ops_indexer::v1:: nonce: U256::from(v.nonce.as_fixed_bytes()).to_string(), init_code: v.init_code.map_or("0x".to_string(), |b| b.to_string()), call_data: v.call_data.to_string(), - call_gas_limit: v.call_gas_limit, - verification_gas_limit: v.verification_gas_limit, - pre_verification_gas: v.pre_verification_gas, + call_gas_limit: v.call_gas_limit.to_string(), + verification_gas_limit: v.verification_gas_limit.to_string(), + pre_verification_gas: v.pre_verification_gas.to_string(), max_fee_per_gas: v.max_fee_per_gas.to_string(), max_priority_fee_per_gas: v.max_priority_fee_per_gas.to_string(), paymaster_and_data: v @@ -179,14 +179,14 @@ impl From for user_ops_indexer_proto::blockscout::user_ops_indexer::v1:: call_data: v.call_data.to_string(), account_gas_limits: H256::from_slice( [ - H128::from_low_u64_be(v.verification_gas_limit).as_bytes(), - H128::from_low_u64_be(v.call_gas_limit).as_bytes(), + &H256::from_uint(&v.verification_gas_limit).as_bytes()[16..], + &H256::from_uint(&v.call_gas_limit).as_bytes()[16..], ] .concat() .as_slice(), ) .encode_hex(), - pre_verification_gas: v.pre_verification_gas, + pre_verification_gas: v.pre_verification_gas.to_string(), gas_fees: H256::from_slice( [ &H256::from_uint(&v.max_fee_per_gas).as_bytes()[16..], @@ -212,9 +212,9 @@ impl From for user_ops_indexer_proto::blockscout::user_ops_indexer::v1:: sender: to_checksum(&v.sender, None), nonce: v.nonce.encode_hex(), call_data: v.call_data.to_string(), - call_gas_limit: v.call_gas_limit, - verification_gas_limit: v.verification_gas_limit, - pre_verification_gas: v.pre_verification_gas, + call_gas_limit: v.call_gas_limit.to_string(), + verification_gas_limit: v.verification_gas_limit.to_string(), + pre_verification_gas: v.pre_verification_gas.to_string(), max_fee_per_gas: v.max_fee_per_gas.to_string(), max_priority_fee_per_gas: v.max_priority_fee_per_gas.to_string(), signature: v.signature.to_string(), @@ -233,9 +233,9 @@ impl From for user_ops_indexer_proto::blockscout::user_ops_indexer::v1:: paymaster: v.paymaster.map(|a| to_checksum(&a, None)), status: v.status, revert_reason: v.revert_reason.map(|b| b.to_string()), - gas: v.gas, + gas: v.gas.to_string(), gas_price: v.gas_price.to_string(), - gas_used: v.gas_used, + gas_used: v.gas_used.to_string(), sponsor_type: v.sponsor_type.to_value().to_string(), user_logs_start_index: v.user_logs_start_index, user_logs_count: v.user_logs_count, diff --git a/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto b/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto index 94940c439..54c12b9d4 100644 --- a/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto +++ b/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto @@ -156,9 +156,9 @@ message RawUserOpV06 { string nonce = 2; string init_code = 3; string call_data = 4; - uint64 call_gas_limit = 5; - uint64 verification_gas_limit = 6; - uint64 pre_verification_gas = 7; + string call_gas_limit = 5; + string verification_gas_limit = 6; + string pre_verification_gas = 7; string max_fee_per_gas = 8; string max_priority_fee_per_gas = 9; string paymaster_and_data = 10; @@ -171,7 +171,7 @@ message RawUserOpV07 { string init_code = 3; string call_data = 4; string account_gas_limits = 5; // call_gas_limit + verification_gas_limit - uint64 pre_verification_gas = 6; + string pre_verification_gas = 6; string gas_fees = 7; // max_fee_per_gas + max_priority_fee_per_gas string paymaster_and_data = 8; // paymaster + paymaster_verification_gas_limit + post_op_gas_limit + paymaster_data string signature = 9; @@ -182,9 +182,9 @@ message UserOp { string sender = 2; string nonce = 3; string call_data = 4; - uint64 call_gas_limit = 5; - uint64 verification_gas_limit = 6; - uint64 pre_verification_gas = 7; + string call_gas_limit = 5; + string verification_gas_limit = 6; + string pre_verification_gas = 7; string max_fee_per_gas = 8; string max_priority_fee_per_gas = 9; string signature = 10; @@ -206,9 +206,9 @@ message UserOp { optional string paymaster = 23; bool status = 24; optional string revert_reason = 25; - uint64 gas = 26; + string gas = 26; string gas_price = 27; - uint64 gas_used = 28; + string gas_used = 28; string sponsor_type = 29; uint32 user_logs_start_index = 30; uint32 user_logs_count = 31; diff --git a/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml b/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml index ecdffb3c5..18ae38d8b 100644 --- a/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml +++ b/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml @@ -508,13 +508,10 @@ definitions: type: string call_gas_limit: type: string - format: uint64 verification_gas_limit: type: string - format: uint64 pre_verification_gas: type: string - format: uint64 max_fee_per_gas: type: string max_priority_fee_per_gas: @@ -539,7 +536,6 @@ definitions: title: call_gas_limit + verification_gas_limit pre_verification_gas: type: string - format: uint64 gas_fees: type: string title: max_fee_per_gas + max_priority_fee_per_gas @@ -561,13 +557,10 @@ definitions: type: string call_gas_limit: type: string - format: uint64 verification_gas_limit: type: string - format: uint64 pre_verification_gas: type: string - format: uint64 max_fee_per_gas: type: string max_priority_fee_per_gas: @@ -611,12 +604,10 @@ definitions: type: string gas: type: string - format: uint64 gas_price: type: string gas_used: type: string - format: uint64 sponsor_type: type: string user_logs_start_index: From f5c5a9c587195a3232c0bfe9ac557301368c383d Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Fri, 16 Aug 2024 16:26:22 +0400 Subject: [PATCH 2/2] chore: cargo clippy --- .../src/indexer/base_indexer.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/user-ops-indexer/user-ops-indexer-logic/src/indexer/base_indexer.rs b/user-ops-indexer/user-ops-indexer-logic/src/indexer/base_indexer.rs index 49efc819d..d02348655 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/indexer/base_indexer.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/indexer/base_indexer.rs @@ -412,9 +412,9 @@ mod tests { nonce: H256::zero(), init_code: None, call_data: Bytes::from_str("0x70641a22000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000001e0049783f008a0085193e00003d00cd54003c71ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000").unwrap(), - call_gas_limit: 92599, - verification_gas_limit: 87149, - pre_verification_gas: 49900, + call_gas_limit: U256::from(92599), + verification_gas_limit: U256::from(87149), + pre_verification_gas: U256::from(49900), max_fee_per_gas: U256::from(53825000000u64), max_priority_fee_per_gas: U256::from(500000000u64), paymaster_and_data: None, @@ -433,9 +433,9 @@ mod tests { paymaster: None, status: true, revert_reason: None, - gas: 229648, + gas: U256::from(229648), gas_price: U256::from(37400206579u64), - gas_used: 165030, + gas_used: U256::from(165030), sponsor_type: SponsorType::WalletDeposit, user_logs_start_index: 268, user_logs_count: 1, @@ -480,9 +480,9 @@ mod tests { nonce: H256::zero(), init_code: Some(Bytes::from_str("0x1f5806eafab78028b6e29ab65208f54cfdd4ce45a1aafc9e0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000244ac27308a000000000000000000000000000000000000000000000000000000000000008000000000000000000000000080ee560d57f4b1d2acfeb2174d09d54879c7408800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000598991c9d726cbac7eb023ca974fe6e7e7a57ce80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000003479096622cf141e3cc93126bbccc3ef10b952c1ef000000000000000000000000000000000000000000000000000000000002a3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074115cff9c5b847b402c382f066cf275ab6440b75aaa1b881c164e5d43131cfb3895759573bc597baf526002f8d1943f1aaa67dbf7fa99cd30d12a235169eef4f3d5c96fc1619c60bc9d8028dfea0f89c7ec5e3f27000000000000000000000000000000000000000000000000000000000002a300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()), call_data: Bytes::from_str("0x34fcd5be00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000094a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000001b637a3008dc1f86d92031a97fc4b5ac0803329e00000000000000000000000000000000000000000000000000000002540be40000000000000000000000000000000000000000000000000000000000").unwrap(), - call_gas_limit: 2000000, - verification_gas_limit: 1000000, - pre_verification_gas: 500000, + call_gas_limit: U256::from(2000000), + verification_gas_limit: U256::from(1000000), + pre_verification_gas: U256::from(500000), max_fee_per_gas: U256::from(1), max_priority_fee_per_gas: U256::from(1), paymaster_and_data: Some(Bytes::from_str("0x1b637a3008dc1f86d92031a97fc4b5ac0803329e00000000000000000000000000061a8000000000000000000000000000061a8000000000000000000000000094a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c800000000000000000000000000000000000000000000000000000002540be400").unwrap()), @@ -501,9 +501,9 @@ mod tests { paymaster: Some(Address::from_str("0x1b637a3008dc1f86d92031a97FC4B5aC0803329e").unwrap()), status: true, revert_reason: None, - gas: 4300000, + gas: U256::from(4300000), gas_price: U256::from(1), - gas_used: 1534051, + gas_used: U256::from(1534051), sponsor_type: SponsorType::PaymasterSponsor, user_logs_start_index: 42, user_logs_count: 3,