internal/ethapi: make ext signer sign legacy (#23274)

This commit is contained in:
Daniel Liu 2024-05-29 18:18:40 +08:00
parent 206175fb43
commit 655fb584b3

View file

@ -80,40 +80,45 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
} }
// After london, default to 1559 unless gasPrice is set // After london, default to 1559 unless gasPrice is set
head := b.CurrentHeader() head := b.CurrentHeader()
if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil { // If user specifies both maxPriorityfee and maxFee, then we do not
if args.MaxPriorityFeePerGas == nil { // need to consult the chain for defaults. It's definitely a London tx.
tip, err := b.SuggestGasTipCap(ctx) if args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil {
if err != nil { // In this clause, user left some fields unspecified.
return err if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil {
if args.MaxPriorityFeePerGas == nil {
tip, err := b.SuggestGasTipCap(ctx)
if err != nil {
return err
}
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
} }
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip) if args.MaxFeePerGas == nil {
} gasFeeCap := new(big.Int).Add(
if args.MaxFeePerGas == nil { (*big.Int)(args.MaxPriorityFeePerGas),
gasFeeCap := new(big.Int).Add( new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
(*big.Int)(args.MaxPriorityFeePerGas), )
new(big.Int).Mul(head.BaseFee, big.NewInt(2)), args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
)
args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
}
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
}
} else {
if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
}
if args.GasPrice == nil {
price, err := b.SuggestGasTipCap(ctx)
if err != nil {
return err
} }
if b.ChainConfig().IsEIP1559(head.Number) { if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
// The legacy tx gas price suggestion should not add 2x base fee return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
// because all fees are consumed, so it would result in a spiral }
// upwards. } else {
price.Add(price, head.BaseFee) if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
}
if args.GasPrice == nil {
price, err := b.SuggestGasTipCap(ctx)
if err != nil {
return err
}
if b.ChainConfig().IsEIP1559(head.Number) {
// The legacy tx gas price suggestion should not add 2x base fee
// because all fees are consumed, so it would result in a spiral
// upwards.
price.Add(price, head.BaseFee)
}
args.GasPrice = (*hexutil.Big)(price)
} }
args.GasPrice = (*hexutil.Big)(price)
} }
} }
if args.Value == nil { if args.Value == nil {