Skip to content

Commit ef48cb5

Browse files
committed
internal/ethapi: make ext signer sign legacy (ethereum#23274)
1 parent 8eb56b1 commit ef48cb5

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

internal/ethapi/transaction_args.go

+36-31
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,45 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
8080
}
8181
// After london, default to 1559 unless gasPrice is set
8282
head := b.CurrentHeader()
83-
if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil {
84-
if args.MaxPriorityFeePerGas == nil {
85-
tip, err := b.SuggestGasTipCap(ctx)
86-
if err != nil {
87-
return err
83+
// If user specifies both maxPriorityfee and maxFee, then we do not
84+
// need to consult the chain for defaults. It's definitely a London tx.
85+
if args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil {
86+
// In this clause, user left some fields unspecified.
87+
if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil {
88+
if args.MaxPriorityFeePerGas == nil {
89+
tip, err := b.SuggestGasTipCap(ctx)
90+
if err != nil {
91+
return err
92+
}
93+
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
8894
}
89-
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
90-
}
91-
if args.MaxFeePerGas == nil {
92-
gasFeeCap := new(big.Int).Add(
93-
(*big.Int)(args.MaxPriorityFeePerGas),
94-
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
95-
)
96-
args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
97-
}
98-
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
99-
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
100-
}
101-
} else {
102-
if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
103-
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
104-
}
105-
if args.GasPrice == nil {
106-
price, err := b.SuggestGasTipCap(ctx)
107-
if err != nil {
108-
return err
95+
if args.MaxFeePerGas == nil {
96+
gasFeeCap := new(big.Int).Add(
97+
(*big.Int)(args.MaxPriorityFeePerGas),
98+
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
99+
)
100+
args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
101+
}
102+
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
103+
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
104+
}
105+
} else {
106+
if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
107+
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
109108
}
110-
if b.ChainConfig().IsEIP1559(head.Number) {
111-
// The legacy tx gas price suggestion should not add 2x base fee
112-
// because all fees are consumed, so it would result in a spiral
113-
// upwards.
114-
price.Add(price, head.BaseFee)
109+
if args.GasPrice == nil {
110+
price, err := b.SuggestGasTipCap(ctx)
111+
if err != nil {
112+
return err
113+
}
114+
if b.ChainConfig().IsEIP1559(head.Number) {
115+
// The legacy tx gas price suggestion should not add 2x base fee
116+
// because all fees are consumed, so it would result in a spiral
117+
// upwards.
118+
price.Add(price, head.BaseFee)
119+
}
120+
args.GasPrice = (*hexutil.Big)(price)
115121
}
116-
args.GasPrice = (*hexutil.Big)(price)
117122
}
118123
}
119124
if args.Value == nil {

0 commit comments

Comments
 (0)