Skip to content

Commit

Permalink
[action] enable dynamic fee tx (#4393)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Sep 18, 2024
1 parent 9f068ae commit d4c454f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
11 changes: 11 additions & 0 deletions action/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ func (elp *envelope) ToEthTx(evmNetworkID uint32, encoding iotextypes.Encoding)
Data: data,
AccessList: common.AccessList(),
}
case DynamicFeeTxType:
txdata = &types.DynamicFeeTx{
Nonce: common.Nonce(),
GasTipCap: common.GasTipCap(),
GasFeeCap: common.GasFeeCap(),
Gas: common.Gas(),
To: to,
Value: tx.Value(),
Data: data,
AccessList: common.AccessList(),
}
default:
return nil, errors.Wrapf(ErrInvalidAct, "unsupported type = %v", common.Version())
}
Expand Down
12 changes: 11 additions & 1 deletion action/rlp_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func NewEthSigner(txType iotextypes.Encoding, chainID uint32) (types.Signer, err
return types.HomesteadSigner{}, nil
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_ACCESSLIST:
return types.NewEIP2930Signer(big.NewInt(int64(chainID))), nil
case iotextypes.Encoding_ETHEREUM_DYNAMICFEE:
return types.NewLondonSigner(big.NewInt(int64(chainID))), nil
default:
return nil, ErrInvalidAct
}
Expand Down Expand Up @@ -85,7 +87,7 @@ func DecodeEtherTx(rawData string) (*types.Transaction, error) {
func ExtractTypeSigPubkey(tx *types.Transaction) (iotextypes.Encoding, []byte, crypto.PublicKey, error) {
var (
encoding iotextypes.Encoding
signer = types.NewEIP2930Signer(tx.ChainId()) // by default assume latest signer
signer types.Signer
V, R, S = tx.RawSignatureValues()
)
// extract correct V value
Expand All @@ -96,6 +98,7 @@ func ExtractTypeSigPubkey(tx *types.Transaction) (iotextypes.Encoding, []byte, c
V = new(big.Int).Sub(V, new(big.Int).Lsh(chainIDMul, 1))
V.Sub(V, big.NewInt(8))
encoding = iotextypes.Encoding_ETHEREUM_EIP155
signer = types.NewEIP155Signer(tx.ChainId())
} else {
// tx has pre-EIP155 signature
encoding = iotextypes.Encoding_ETHEREUM_UNPROTECTED
Expand All @@ -106,6 +109,13 @@ func ExtractTypeSigPubkey(tx *types.Transaction) (iotextypes.Encoding, []byte, c
// id, add 27 to become equivalent to unprotected Homestead signatures.
V = new(big.Int).Add(V, big.NewInt(27))
encoding = iotextypes.Encoding_ETHEREUM_ACCESSLIST
signer = types.NewEIP2930Signer(tx.ChainId())
case types.DynamicFeeTxType:
// DynamicFee txs are defined to use 0 and 1 as their recovery
// id, add 27 to become equivalent to unprotected Homestead signatures.
V = new(big.Int).Add(V, big.NewInt(27))
encoding = iotextypes.Encoding_ETHEREUM_DYNAMICFEE
signer = types.NewLondonSigner(tx.ChainId())
default:
return encoding, nil, nil, ErrNotSupported
}
Expand Down
27 changes: 25 additions & 2 deletions action/rlp_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ var (
nil,
"b30463d727248560e17d82764604fa64b2161f3bdb53434a6afd15fc64a42918",
},
{
"dynamicfee", 120, 21000, "1000000000", "0",
"0x3141df3f2e4415533bb6d6be2A351B2db9ee84EF",
_evmNetworkID,
iotextypes.Encoding_ETHEREUM_DYNAMICFEE,
nil,
"0dd507264fcc092c6430c248e48ac525e334e3699852e44451a376c4744e09af",
},
}
)

Expand Down Expand Up @@ -835,7 +843,7 @@ func convertToNativeProto(tx *types.Transaction, actType string) (*iotextypes.Ac
switch actType {
case "transfer":
elp, err = elpBuilder.BuildTransfer(tx)
case "execution", "unprotected", "accesslist":
case "execution", "unprotected", "accesslist", "dynamicfee":
elp, err = elpBuilder.BuildExecution(tx)
case "stakeCreate", "stakeAddDeposit", "changeCandidate", "unstake", "withdrawStake", "restake",
"transferStake", "candidateRegister", "candidateUpdate", "candidateActivate", "candidateEndorsement", "candidateTransferOwnership",
Expand Down Expand Up @@ -877,7 +885,7 @@ func checkContract(to string, actType string) func(context.Context, *common.Addr
return func(context.Context, *common.Address) (bool, bool, bool, error) {
return false, false, false, nil
}
case "execution", "unprotected", "accesslist":
case "execution", "unprotected", "accesslist", "dynamicfee":
return func(context.Context, *common.Address) (bool, bool, bool, error) {
return true, false, false, nil
}
Expand Down Expand Up @@ -977,6 +985,21 @@ func generateRLPTestRaw(sk *ecdsa.PrivateKey, test *rlpTest) string {
{Address: _c2, StorageKeys: []common.Hash{_k2, _k3, _k4, _k1}},
},
}
case "dynamicfee":
tx = &types.DynamicFeeTx{
Nonce: test.nonce,
GasTipCap: MustBeTrueV(new(big.Int).SetString(test.price, 10)),
GasFeeCap: MustBeTrueV(new(big.Int).SetString(test.price, 10)),
Gas: test.limit,
To: to,
Value: MustBeTrueV(new(big.Int).SetString(test.amount, 10)),
Data: test.data,
AccessList: types.AccessList{
{Address: common.Address{}, StorageKeys: nil},
{Address: _c1, StorageKeys: []common.Hash{_k1, {}, _k3}},
{Address: _c2, StorageKeys: []common.Hash{_k2, _k3, _k4, _k1}},
},
}
default:
panic("not supported")
}
Expand Down
9 changes: 6 additions & 3 deletions action/sealedenvelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (sealed *SealedEnvelope) envelopeHash() (hash.Hash256, error) {
return hash.ZeroHash256, err
}
return rlpRawHash(act.tx, signer)
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_UNPROTECTED, iotextypes.Encoding_ETHEREUM_ACCESSLIST:
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_UNPROTECTED, iotextypes.Encoding_ETHEREUM_ACCESSLIST,
iotextypes.Encoding_ETHEREUM_DYNAMICFEE:
tx, err := sealed.ToEthTx()
if err != nil {
return hash.ZeroHash256, err
Expand Down Expand Up @@ -83,7 +84,8 @@ func (sealed *SealedEnvelope) calcHash() (hash.Hash256, error) {
return hash.ZeroHash256, ErrInvalidAct
}
return act.hash(), nil
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_UNPROTECTED, iotextypes.Encoding_ETHEREUM_ACCESSLIST:
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_UNPROTECTED, iotextypes.Encoding_ETHEREUM_ACCESSLIST,
iotextypes.Encoding_ETHEREUM_DYNAMICFEE:
tx, err := sealed.ToEthTx()
if err != nil {
return hash.ZeroHash256, err
Expand Down Expand Up @@ -168,7 +170,8 @@ func (sealed *SealedEnvelope) loadProto(pbAct *iotextypes.Action, evmID uint32)
return ErrInvalidAct
}
sealed.evmNetworkID = evmID
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_UNPROTECTED, iotextypes.Encoding_ETHEREUM_ACCESSLIST:
case iotextypes.Encoding_ETHEREUM_EIP155, iotextypes.Encoding_ETHEREUM_UNPROTECTED, iotextypes.Encoding_ETHEREUM_ACCESSLIST,
iotextypes.Encoding_ETHEREUM_DYNAMICFEE:
// verify action type can support RLP-encoding
tx, err := elp.ToEthTx(evmID, encoding)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion action/sealedenvelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestSealedEnvelope_Proto(t *testing.T) {
err string
}{
{0, _signByte, "invalid signature length ="},
{iotextypes.Encoding_ETHEREUM_ACCESSLIST + 1, _validSig, "unknown encoding type"},
{iotextypes.Encoding_ETHEREUM_DYNAMICFEE + 1, _validSig, "unknown encoding type"},
} {
se.encoding = v.encoding
se.signature = v.sig
Expand Down
2 changes: 2 additions & 0 deletions action/tx_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func (etx *txContainer) typeToEncoding() (iotextypes.Encoding, error) {
}
case types.AccessListTxType:
return iotextypes.Encoding_ETHEREUM_ACCESSLIST, nil
case types.DynamicFeeTxType:
return iotextypes.Encoding_ETHEREUM_DYNAMICFEE, nil
default:
return 0, ErrNotSupported
}
Expand Down

0 comments on commit d4c454f

Please sign in to comment.