@@ -108,14 +108,14 @@ pub fn eip1559_default_estimator(base_fee_per_gas: U256, rewards: Vec<Vec<U256>>
108108fn estimate_priority_fee ( rewards : Vec < Vec < U256 > > ) -> U256 {
109109 let mut rewards: Vec < U256 > = rewards
110110 . iter ( )
111- . map ( |r| r[ 0 ] )
111+ . map ( |r| r. first ( ) . copied ( ) . unwrap_or_default ( ) )
112112 . filter ( |r| * r > U256 :: zero ( ) )
113113 . collect ( ) ;
114114 if rewards. is_empty ( ) {
115115 return U256 :: zero ( ) ;
116116 }
117117 if rewards. len ( ) == 1 {
118- return rewards[ 0 ] ;
118+ return rewards. first ( ) . copied ( ) . unwrap_or_default ( ) ;
119119 }
120120 // Sort the rewards as we will eventually take the median.
121121 rewards. sort ( ) ;
@@ -129,32 +129,33 @@ fn estimate_priority_fee(rewards: Vec<Vec<U256>>) -> U256 {
129129 . iter ( )
130130 . zip ( rewards_copy. iter ( ) )
131131 . map ( |( a, b) | {
132- let a = I256 :: try_from ( * a) . expect ( "priority fee overflow" ) ;
133- let b = I256 :: try_from ( * b) . expect ( "priority fee overflow" ) ;
132+ let a = I256 :: try_from ( * a) . unwrap_or_default ( ) ;
133+ let b = I256 :: try_from ( * b) . unwrap_or_default ( ) ;
134134 ( ( b - a) * 100 ) / a
135135 } )
136136 . collect ( ) ;
137137 percentage_change. pop ( ) ;
138138
139139 // Fetch the max of the percentage change, and that element's index.
140- let max_change = percentage_change. iter ( ) . max ( ) . unwrap ( ) ;
140+ let zero = I256 :: zero ( ) ;
141+ let max_change = percentage_change. iter ( ) . max ( ) . unwrap_or ( & zero) ;
141142 let max_change_index = percentage_change
142143 . iter ( )
143144 . position ( |& c| c == * max_change)
144- . unwrap ( ) ;
145+ . unwrap_or ( 0 ) ;
145146
146147 // If we encountered a big change in fees at a certain position, then consider only
147148 // the values >= it.
148149 let values = if * max_change >= EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE . into ( )
149150 && ( max_change_index >= ( rewards. len ( ) / 2 ) )
150151 {
151- rewards[ max_change_index..] . to_vec ( )
152+ rewards. get ( max_change_index..) . unwrap_or ( & rewards ) . to_vec ( )
152153 } else {
153154 rewards
154155 } ;
155156
156157 // Return the median.
157- values[ values. len ( ) / 2 ]
158+ values. get ( values. len ( ) / 2 ) . copied ( ) . unwrap_or_default ( )
158159}
159160
160161fn base_fee_surged ( base_fee_per_gas : U256 ) -> U256 {
0 commit comments