@@ -136,27 +136,42 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
136
136
if args .GasPrice != nil && (args .MaxFeePerGas != nil || args .MaxPriorityFeePerGas != nil ) {
137
137
return errors .New ("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified" )
138
138
}
139
- // If the tx has completely specified a fee mechanism, no default is needed. This allows users
140
- // who are not yet synced past London to get defaults for other tx values. See
141
- // https://github.com/ethereum/go-ethereum/pull/23274 for more information.
139
+ // If the tx has completely specified a fee mechanism, no default is needed.
140
+ // This allows users who are not yet synced past London to get defaults for
141
+ // other tx values. See https://github.com/ethereum/go-ethereum/pull/23274
142
+ // for more information.
142
143
eip1559ParamsSet := args .MaxFeePerGas != nil && args .MaxPriorityFeePerGas != nil
143
- if (args .GasPrice != nil && ! eip1559ParamsSet ) || (args .GasPrice == nil && eip1559ParamsSet ) {
144
- // Sanity check the EIP-1559 fee parameters if present.
145
- if args .GasPrice == nil && args .MaxFeePerGas .ToInt ().Cmp (args .MaxPriorityFeePerGas .ToInt ()) < 0 {
144
+
145
+ // Sanity check the EIP-1559 fee parameters if present.
146
+ if args .GasPrice == nil && eip1559ParamsSet {
147
+ if args .MaxFeePerGas .ToInt ().Sign () == 0 {
148
+ return errors .New ("maxFeePerGas must be non-zero" )
149
+ }
150
+ if args .MaxFeePerGas .ToInt ().Cmp (args .MaxPriorityFeePerGas .ToInt ()) < 0 {
146
151
return fmt .Errorf ("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)" , args .MaxFeePerGas , args .MaxPriorityFeePerGas )
147
152
}
148
- return nil
153
+ return nil // No need to set anything, user already set MaxFeePerGas and MaxPriorityFeePerGas
149
154
}
150
- // Now attempt to fill in default value depending on whether London is active or not .
155
+ // Sanity check the non-EIP-1559 fee parameters .
151
156
head := b .CurrentHeader ()
152
- if b .ChainConfig ().IsEIP1559 (head .Number ) {
157
+ isEIP1559 := b .ChainConfig ().IsEIP1559 (head .Number )
158
+ if args .GasPrice != nil && ! eip1559ParamsSet {
159
+ // Zero gas-price is not allowed after London fork
160
+ if args .GasPrice .ToInt ().Sign () == 0 && isEIP1559 {
161
+ return errors .New ("gasPrice must be non-zero after london fork" )
162
+ }
163
+ return nil // No need to set anything, user already set GasPrice
164
+ }
165
+
166
+ // Now attempt to fill in default value depending on whether London is active or not.
167
+ if isEIP1559 {
153
168
// London is active, set maxPriorityFeePerGas and maxFeePerGas.
154
169
if err := args .setLondonFeeDefaults (ctx , head , b ); err != nil {
155
170
return err
156
171
}
157
172
} else {
158
173
if args .MaxFeePerGas != nil || args .MaxPriorityFeePerGas != nil {
159
- return fmt . Errorf ("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active" )
174
+ return errors . New ("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active" )
160
175
}
161
176
// London not active, set gas price.
162
177
price , err := b .SuggestGasTipCap (ctx )
0 commit comments