From 2726902ef2e62251a4dadc9454b677ce5437c56d Mon Sep 17 00:00:00 2001 From: chengzhinei Date: Thu, 18 Apr 2024 17:06:12 +0800 Subject: [PATCH] use latest gp of sortedlist for claimTx (#181) * use latest gp of sortedlist for claimTx * del unusable code * add comment * use cache --- sequencer/sequencer.go | 6 ++++-- sequencer/txtracker.go | 1 + sequencer/worker.go | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sequencer/sequencer.go b/sequencer/sequencer.go index 00457712f1..b321ad616f 100644 --- a/sequencer/sequencer.go +++ b/sequencer/sequencer.go @@ -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) diff --git a/sequencer/txtracker.go b/sequencer/txtracker.go index 33789d7d08..0740dfd948 100644 --- a/sequencer/txtracker.go +++ b/sequencer/txtracker.go @@ -32,6 +32,7 @@ type TxTracker struct { EGPLog state.EffectiveGasPriceLog L1GasPrice uint64 L2GasPrice uint64 + IsClaimTx bool } // newTxTracker creates and inti a TxTracker diff --git a/sequencer/worker.go b/sequencer/worker.go index 04f026867b..ad65b25c82 100644 --- a/sequencer/worker.go +++ b/sequencer/worker.go @@ -22,6 +22,7 @@ type Worker struct { state stateInterface batchConstraints state.BatchConstraintsCfg readyTxsCond *timeoutCond + claimGp *big.Int } // NewWorker creates an init a worker @@ -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 @@ -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 +}