Skip to content

Commit

Permalink
suport free gas to claim asset (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzhinei authored and scf0220 committed Nov 26, 2023
1 parent 80e01ce commit c21f41e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions config/environments/testnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ AccountQueue = 64
MaxSteps = 7570538

[Pool]
FreeClaimGasLimit = 1500000
IntervalToRefreshBlockedAddresses = "5m"
IntervalToRefreshGasPrices = "5s"
MaxTxBytesSize=100132
MaxTxDataBytesSize=100000
DefaultMinGasPriceAllowed = 1000000000
MinAllowedGasPriceInterval = "5m"
PollMinAllowedGasPriceInterval = "15s"
FreeGasAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
[Pool.DB]
User = "pool_user"
Password = "pool_password"
Expand Down
24 changes: 23 additions & 1 deletion pool/transaction.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pool

import (
"strings"
"time"

"github.com/0xPolygonHermez/zkevm-node/state"
Expand Down Expand Up @@ -45,10 +46,11 @@ type Transaction struct {
IsWIP bool
IP string
FailedReason *string
IsClaims bool
}

// NewTransaction creates a new transaction
func NewTransaction(tx types.Transaction, ip string, isWIP bool) *Transaction {
func NewTransaction(tx types.Transaction, ip string, isWIP bool, p *Pool) *Transaction {
poolTx := Transaction{
Transaction: tx,
Status: TxStatusPending,
Expand All @@ -57,5 +59,25 @@ func NewTransaction(tx types.Transaction, ip string, isWIP bool) *Transaction {
IP: ip,
}

poolTx.IsClaims = poolTx.IsClaimTx(p.l2BridgeAddr, p.cfg.FreeClaimGasLimit)

return &poolTx
}

// IsClaimTx checks, if tx is a claim tx
func (tx *Transaction) IsClaimTx(l2BridgeAddr common.Address, freeClaimGasLimit uint64) bool {
if tx.To() == nil {
return false
}

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

if *tx.To() == l2BridgeAddr &&
strings.HasPrefix("0x"+common.Bytes2Hex(tx.Data()), BridgeClaimMethodSignature) {
return true
}
return false
}
2 changes: 1 addition & 1 deletion sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (d *dbManager) sendDataToStreamer() {
}

func (d *dbManager) addTxToWorker(tx pool.Transaction) error {
txTracker, err := d.worker.NewTxTracker(tx.Transaction, tx.ZKCounters, tx.IP)
txTracker, err := d.worker.NewTxTracker(tx, tx.ZKCounters, tx.IP)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type workerInterface interface {
AddPendingTxToStore(txHash common.Hash, addr common.Address)
DeletePendingTxToStore(txHash common.Hash, addr common.Address)
HandleL2Reorg(txHashes []common.Hash)
NewTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error)
NewTxTracker(tx pool.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error)
AddForcedTx(txHash common.Hash, addr common.Address)
DeleteForcedTx(txHash common.Hash, addr common.Address)
}
Expand Down
9 changes: 5 additions & 4 deletions sequencer/mock_worker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions sequencer/txtracker.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package sequencer

import (
"github.com/0xPolygonHermez/zkevm-node/pool"
"math/big"
"time"

"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

// TxTracker is a struct that contains all the tx data needed to be managed by the worker
Expand All @@ -32,7 +32,8 @@ type TxTracker struct {
}

// newTxTracker creates and inti a TxTracker
func newTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) {
func newTxTracker(ptx pool.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) {
tx := ptx.Transaction
addr, err := state.GetSender(tx)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions sequencer/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sequencer
import (
"context"
"fmt"
"github.com/0xPolygonHermez/zkevm-node/pool"
"math/big"
"runtime"
"sync"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

// Worker represents the worker component of the sequencer
Expand All @@ -37,7 +37,7 @@ func NewWorker(state stateInterface, constraints state.BatchConstraintsCfg) *Wor
}

// NewTxTracker creates and inits a TxTracker
func (w *Worker) NewTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) {
func (w *Worker) NewTxTracker(tx pool.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) {
return newTxTracker(tx, counters, ip)
}

Expand Down

0 comments on commit c21f41e

Please sign in to comment.