Skip to content

Commit

Permalink
use latest gp of sortedlist for claimTx (#181)
Browse files Browse the repository at this point in the history
* use latest gp of sortedlist for claimTx

* del unusable code

* add comment

* use cache
  • Loading branch information
chengzhinei authored Apr 18, 2024
1 parent b5923f1 commit 2726902
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ func (s *Sequencer) addTxToWorker(ctx context.Context, tx pool.Transaction) erro

addrs := getPackBatchSpacialList(s.cfg.PackBatchSpacialList)
if addrs[txTracker.FromStr] {
txTracker.IsClaimTx = true
_, l2gp := s.pool.GetL1AndL2GasPrice()
newGp := uint64(float64(l2gp) * getGasPriceMultiple(s.cfg.GasPriceMultiple))
txTracker.GasPrice = new(big.Int).SetUint64(newGp)
defaultGp := new(big.Int).SetUint64(l2gp)
baseGp := s.worker.getBaseClaimGp(defaultGp)
txTracker.GasPrice = baseGp.Mul(baseGp, new(big.Int).SetUint64(uint64(getGasPriceMultiple(s.cfg.GasPriceMultiple))))
}

replacedTx, dropReason := s.worker.AddTxTracker(ctx, txTracker)
Expand Down
1 change: 1 addition & 0 deletions sequencer/txtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type TxTracker struct {
EGPLog state.EffectiveGasPriceLog
L1GasPrice uint64
L2GasPrice uint64
IsClaimTx bool
}

// newTxTracker creates and inti a TxTracker
Expand Down
14 changes: 14 additions & 0 deletions sequencer/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Worker struct {
state stateInterface
batchConstraints state.BatchConstraintsCfg
readyTxsCond *timeoutCond
claimGp *big.Int
}

// NewWorker creates an init a worker
Expand Down Expand Up @@ -341,6 +342,9 @@ func (w *Worker) GetBestFittingTx(resources state.BatchResources) (*TxTracker, e

if foundAt != -1 {
log.Debugf("best fitting tx %s found at index %d with gasPrice %d", tx.HashStr, foundAt, tx.GasPrice)
if !tx.IsClaimTx {
w.claimGp = tx.GasPrice
}
return tx, nil
} else {
return nil, ErrNoFittingTransaction
Expand Down Expand Up @@ -381,3 +385,13 @@ func (w *Worker) addTxToSortedList(readyTx *TxTracker) {
w.readyTxsCond.L.Unlock()
}
}

func (w *Worker) getBaseClaimGp(defaultGp *big.Int) *big.Int {
w.workerMutex.Lock()
defer w.workerMutex.Unlock()

if w.claimGp.Cmp(defaultGp) < 0 {
w.claimGp = defaultGp
}
return w.claimGp
}

0 comments on commit 2726902

Please sign in to comment.