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

Gas limit 150K + tests #1551

Merged
merged 5 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions pool/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const (
TxStatusSelected TxStatus = "selected"
// TxStatusFailed represents a tx that has been failed after processing, but can be processed in the future
TxStatusFailed TxStatus = "failed"

// freeClaimGasLimit is the max gas allowed use to do a free claim
freeClaimGasLimit uint64 = 150000
ARR552 marked this conversation as resolved.
Show resolved Hide resolved
)

// TxStatus represents the state of a tx
Expand Down Expand Up @@ -79,6 +82,11 @@ func (tx *Transaction) IsClaimTx(l2BridgeAddr common.Address) bool {
return false
}

txGas := tx.Gas()
if txGas > freeClaimGasLimit || txGas == 0 {
return false
}

if *tx.To() == l2BridgeAddr &&
strings.HasPrefix("0x"+common.Bytes2Hex(tx.Data()), bridgeClaimMethodSignature) {
return true
Expand Down
23 changes: 20 additions & 3 deletions pool/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
func Test_IsClaimTx(t *testing.T) {
l2BridgeAddr := common.HexToAddress("0x00000000000000000000000000000001")
differentAddr := common.HexToAddress("0x00000000000000000000000000000002")
claimData := hex.DecodeHexToBig(bridgeClaimMethodSignature).Bytes()
claimData, err := hex.DecodeHex(bridgeClaimMethodSignature)
if err != nil {
panic(err)
}

testCases := []struct {
Name string
Expand Down Expand Up @@ -41,7 +44,7 @@ func Test_IsClaimTx(t *testing.T) {
expectedResult: false,
},
{
Name: "To address as l2BridgeAddr address",
Name: "To address as l2BridgeAddr address with 0 gas",
Tx: Transaction{
Transaction: *types.NewTx(&types.LegacyTx{Nonce: 1, To: &l2BridgeAddr, Value: big.NewInt(0), Gas: 0, GasPrice: big.NewInt(0), Data: claimData}),
},
Expand All @@ -50,10 +53,24 @@ func Test_IsClaimTx(t *testing.T) {
{
Name: "To address as l2BridgeAddr address",
Tx: Transaction{
Transaction: *types.NewTx(&types.LegacyTx{Nonce: 1, To: &l2BridgeAddr, Value: big.NewInt(0), Gas: 0, GasPrice: big.NewInt(0), Data: claimData}),
Transaction: *types.NewTx(&types.LegacyTx{Nonce: 1, To: &l2BridgeAddr, Value: big.NewInt(0), Gas: 50000, GasPrice: big.NewInt(0), Data: claimData}),
},
expectedResult: true,
},
{
Name: "More Gas than 150K",
Tx: Transaction{
Transaction: *types.NewTx(&types.LegacyTx{Nonce: 1, To: &l2BridgeAddr, Value: big.NewInt(0), Gas: 160000, GasPrice: big.NewInt(0), Data: claimData}),
},
expectedResult: false,
},
{
Name: "Tx with Gas 150K",
Tx: Transaction{
Transaction: *types.NewTx(&types.LegacyTx{Nonce: 1, To: &l2BridgeAddr, Value: big.NewInt(0), Gas: 150000, GasPrice: big.NewInt(0), Data: claimData}),
},
expectedResult: true,
},
}

for _, testCase := range testCases {
Expand Down