Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIP-64 / CIP-66 compatible TransactionArgs #123

Merged
merged 11 commits into from
Jun 12, 2024
22 changes: 11 additions & 11 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ func toWordSize(size uint64) uint64 {
// A Message contains the data derived from a single transaction that is relevant to state
// processing.
type Message struct {
To *common.Address
From common.Address
Nonce uint64
Value *big.Int
GasLimit uint64
GasPrice *big.Int
GasFeeCap *big.Int
GasTipCap *big.Int
To *common.Address
From common.Address
Nonce uint64
Value *big.Int
GasLimit uint64
GasPrice *big.Int
GasFeeCap *big.Int
GasTipCap *big.Int

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an unnecessary change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dbb2c57

Data []byte
AccessList types.AccessList
BlobGasFeeCap *big.Int
Expand All @@ -182,8 +183,7 @@ type Message struct {
// FeeCurrency specifies the currency for gas fees.
// `nil` corresponds to Celo Gold (native currency).
// All other values should correspond to ERC20 contract addresses.
FeeCurrency *common.Address

FeeCurrency *common.Address
MaxFeeInFeeCurrency *big.Int // MaxFeeInFeeCurrency is the maximum fee that can be charged in the fee currency.
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.In
}
// If baseFee provided, set gasPrice to effectiveGasPrice.
if baseFee != nil {
if msg.FeeCurrency != nil {
if tx.Type() == types.CeloDynamicFeeTxType {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change safe for the case where tx.Type() == types.CeloDynamicFeeTxType but msg.FeeCurrency == nil? Unfortunately, we didn't forbid nil currencies for CIP-64.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the ConvertGoldToCurrency function just returns the passed in value in that case (here baseFee, which has the same effect as omitting the if case).

var err error
baseFee, err = exchange.ConvertGoldToCurrency(exchangeRates, msg.FeeCurrency, baseFee)
if err != nil {
Expand Down
39 changes: 22 additions & 17 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int, ex
gas = globalGasCap
}
var (
gasPrice *big.Int
gasFeeCap *big.Int
gasTipCap *big.Int
blobFeeCap *big.Int
gasPrice *big.Int
gasFeeCap *big.Int
gasTipCap *big.Int
blobFeeCap *big.Int
maxFeeInFeeCurrency *big.Int
Comment on lines +441 to +445
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a // Celo specific comment in between will reduce the diff size because it breaks the formatter's alignment into two parts. Not sure if that is overall better in this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dbb2c57

)
if baseFee == nil {
// If there's no basefee, then it must be a non-1559 execution
Expand Down Expand Up @@ -501,20 +502,24 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int, ex
if args.AccessList != nil {
accessList = *args.AccessList
}
if args.MaxFeeInFeeCurrency != nil {
maxFeeInFeeCurrency = args.MaxFeeInFeeCurrency.ToInt()
}
msg := &core.Message{
From: addr,
To: args.To,
Value: value,
GasLimit: gas,
GasPrice: gasPrice,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: data,
AccessList: accessList,
BlobGasFeeCap: blobFeeCap,
BlobHashes: args.BlobHashes,
SkipAccountChecks: true,
FeeCurrency: args.FeeCurrency,
From: addr,
To: args.To,
Value: value,
GasLimit: gas,
GasPrice: gasPrice,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: data,
AccessList: accessList,
BlobGasFeeCap: blobFeeCap,
BlobHashes: args.BlobHashes,
SkipAccountChecks: true,
FeeCurrency: args.FeeCurrency,
MaxFeeInFeeCurrency: maxFeeInFeeCurrency,
}
return msg, nil
}
Expand Down