From ec062fd1b5e53b54de696dbbe7635efac7d7b6e4 Mon Sep 17 00:00:00 2001 From: agnusmor Date: Wed, 9 Aug 2023 14:34:19 +0200 Subject: [PATCH 1/2] Sort txs in worker by GasPrice (remove efficiency sort) --- config/config_test.go | 40 ---- config/default.go | 11 -- .../environments/local/local.node.config.toml | 11 -- docs/config-file/node-config-schema.json | 57 ------ sequencer/addrqueue.go | 16 +- sequencer/config.go | 36 ---- sequencer/efficiencylist.go | 126 ------------ sequencer/efficiencylist_test.go | 94 --------- sequencer/finalizer.go | 10 +- sequencer/finalizer_test.go | 8 +- sequencer/interfaces.go | 2 +- sequencer/mock_worker.go | 4 +- sequencer/sequencer.go | 26 +-- sequencer/txsorted_list.go | 152 +++++++++++++++ sequencer/txsorted_list_test.go | 114 +++++++++++ sequencer/txtracker.go | 100 +--------- sequencer/txtracker_test.go | 100 ---------- sequencer/worker.go | 114 ++++------- sequencer/worker_test.go | 184 ++++++------------ test/config/debug.node.config.toml | 11 -- test/config/test.node.config.toml | 11 -- 21 files changed, 380 insertions(+), 847 deletions(-) delete mode 100644 sequencer/efficiencylist.go delete mode 100644 sequencer/efficiencylist_test.go create mode 100644 sequencer/txsorted_list.go create mode 100644 sequencer/txsorted_list_test.go delete mode 100644 sequencer/txtracker_test.go diff --git a/config/config_test.go b/config/config_test.go index d94ed5d603..58f0a8dfb5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -100,42 +100,6 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.MaxTxLifetime", expectedValue: types.NewDuration(3 * time.Hour), }, - { - path: "Sequencer.WeightBatchBytesSize", - expectedValue: 1, - }, - { - path: "Sequencer.WeightCumulativeGasUsed", - expectedValue: 1, - }, - { - path: "Sequencer.WeightKeccakHashes", - expectedValue: 1, - }, - { - path: "Sequencer.WeightPoseidonHashes", - expectedValue: 1, - }, - { - path: "Sequencer.WeightPoseidonPaddings", - expectedValue: 1, - }, - { - path: "Sequencer.WeightMemAligns", - expectedValue: 1, - }, - { - path: "Sequencer.WeightArithmetics", - expectedValue: 1, - }, - { - path: "Sequencer.WeightBinaries", - expectedValue: 1, - }, - { - path: "Sequencer.WeightSteps", - expectedValue: 1, - }, { path: "Sequencer.Finalizer.GERDeadlineTimeout", expectedValue: types.NewDuration(5 * time.Second), @@ -208,10 +172,6 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.DBManager.L2ReorgRetrievalInterval", expectedValue: types.NewDuration(5 * time.Second), }, - { - path: "Sequencer.Worker.ResourceCostMultiplier", - expectedValue: float64(1000), - }, { path: "SequenceSender.WaitPeriodSendSequence", expectedValue: types.NewDuration(5 * time.Second), diff --git a/config/default.go b/config/default.go index 132b6f3a90..e9e0243c03 100644 --- a/config/default.go +++ b/config/default.go @@ -85,15 +85,6 @@ MaxMemAligns = 236585 MaxArithmetics = 236585 MaxBinaries = 473170 MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -111,8 +102,6 @@ MaxTxLifetime = "3h" [Sequencer.DBManager] PoolRetrievalInterval = "500ms" L2ReorgRetrievalInterval = "5s" - [Sequencer.Worker] - ResourceCostMultiplier = 1000 [Sequencer.EffectiveGasPrice] MaxBreakEvenGasPriceDeviationPercentage = 10 L1GasPriceFactor = 0.25 diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index cc03b03701..5dbb7ef69a 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -69,15 +69,6 @@ MaxMemAligns = 236585 MaxArithmetics = 236585 MaxBinaries = 473170 MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -95,8 +86,6 @@ MaxTxLifetime = "3h" [Sequencer.DBManager] PoolRetrievalInterval = "500ms" L2ReorgRetrievalInterval = "5s" - [Sequencer.Worker] - ResourceCostMultiplier = 1000 [Sequencer.EffectiveGasPrice] MaxBreakEvenGasPriceDeviationPercentage = 10 L1GasPriceFactor = 0.25 diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index 64c4967768..8cd220280b 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -454,51 +454,6 @@ "description": "MaxSteps is max steps batch can handle", "default": 7570538 }, - "WeightBatchBytesSize": { - "type": "integer", - "description": "WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource", - "default": 1 - }, - "WeightCumulativeGasUsed": { - "type": "integer", - "description": "WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource", - "default": 1 - }, - "WeightKeccakHashes": { - "type": "integer", - "description": "WeightKeccakHashes is the cost weight for the KeccakHashes batch resource", - "default": 1 - }, - "WeightPoseidonHashes": { - "type": "integer", - "description": "WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource", - "default": 1 - }, - "WeightPoseidonPaddings": { - "type": "integer", - "description": "WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource", - "default": 1 - }, - "WeightMemAligns": { - "type": "integer", - "description": "WeightMemAligns is the cost weight for the MemAligns batch resource", - "default": 1 - }, - "WeightArithmetics": { - "type": "integer", - "description": "WeightArithmetics is the cost weight for the Arithmetics batch resource", - "default": 1 - }, - "WeightBinaries": { - "type": "integer", - "description": "WeightBinaries is the cost weight for the Binaries batch resource", - "default": 1 - }, - "WeightSteps": { - "type": "integer", - "description": "WeightSteps is the cost weight for the Steps batch resource", - "default": 1 - }, "TxLifetimeCheckTimeout": { "type": "string", "title": "Duration", @@ -641,18 +596,6 @@ "type": "object", "description": "DBManager's specific config properties" }, - "Worker": { - "properties": { - "ResourceCostMultiplier": { - "type": "number", - "description": "ResourceCostMultiplier is the multiplier for the resource cost", - "default": 1000 - } - }, - "additionalProperties": false, - "type": "object", - "description": "Worker's specific config properties" - }, "EffectiveGasPrice": { "properties": { "MaxBreakEvenGasPriceDeviationPercentage": { diff --git a/sequencer/addrqueue.go b/sequencer/addrqueue.go index 684a060aed..db69e5e2a7 100644 --- a/sequencer/addrqueue.go +++ b/sequencer/addrqueue.go @@ -185,29 +185,19 @@ func (a *addrQueue) updateCurrentNonceBalance(nonce *uint64, balance *big.Int) ( } // UpdateTxZKCounters updates the ZKCounters for the given tx (txHash) -// If the updated tx is the readyTx it returns a copy of the previous readyTx, nil otherwise -func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters, constraints batchConstraintsFloat64, weights batchResourceWeights) (newReadyTx, prevReadyTx *TxTracker) { +func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters) { txHashStr := txHash.String() if (a.readyTx != nil) && (a.readyTx.HashStr == txHashStr) { - // We need to assign the new readyTx as a new TxTracker copy of the previous one with the updated efficiency - // We need to do in this way because the efficiency value is changed and we use this value as key field to - // add/delete TxTrackers in the efficiencyList - prevReadyTx := a.readyTx - newReadyTx := *a.readyTx - newReadyTx.updateZKCounters(counters, constraints, weights) - a.readyTx = &newReadyTx log.Debugf("Updating readyTx %s with new ZKCounters from addrQueue %s", txHashStr, a.fromStr) - return a.readyTx, prevReadyTx + a.readyTx.updateZKCounters(counters) } else { - txHashStr := txHash.String() for _, txTracker := range a.notReadyTxs { if txTracker.HashStr == txHashStr { log.Debugf("Updating notReadyTx %s with new ZKCounters from addrQueue %s", txHashStr, a.fromStr) - txTracker.updateZKCounters(counters, constraints, weights) + txTracker.updateZKCounters(counters) break } } - return nil, nil } } diff --git a/sequencer/config.go b/sequencer/config.go index 9b99af333b..7a98925ca0 100644 --- a/sequencer/config.go +++ b/sequencer/config.go @@ -47,33 +47,6 @@ type Config struct { // MaxSteps is max steps batch can handle MaxSteps uint32 `mapstructure:"MaxSteps"` - // WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource - WeightBatchBytesSize int `mapstructure:"WeightBatchBytesSize"` - - // WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource - WeightCumulativeGasUsed int `mapstructure:"WeightCumulativeGasUsed"` - - // WeightKeccakHashes is the cost weight for the KeccakHashes batch resource - WeightKeccakHashes int `mapstructure:"WeightKeccakHashes"` - - // WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource - WeightPoseidonHashes int `mapstructure:"WeightPoseidonHashes"` - - // WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource - WeightPoseidonPaddings int `mapstructure:"WeightPoseidonPaddings"` - - // WeightMemAligns is the cost weight for the MemAligns batch resource - WeightMemAligns int `mapstructure:"WeightMemAligns"` - - // WeightArithmetics is the cost weight for the Arithmetics batch resource - WeightArithmetics int `mapstructure:"WeightArithmetics"` - - // WeightBinaries is the cost weight for the Binaries batch resource - WeightBinaries int `mapstructure:"WeightBinaries"` - - // WeightSteps is the cost weight for the Steps batch resource - WeightSteps int `mapstructure:"WeightSteps"` - // TxLifetimeCheckTimeout is the time the sequencer waits to check txs lifetime TxLifetimeCheckTimeout types.Duration `mapstructure:"TxLifetimeCheckTimeout"` @@ -86,9 +59,6 @@ type Config struct { // DBManager's specific config properties DBManager DBManagerCfg `mapstructure:"DBManager"` - // Worker's specific config properties - Worker WorkerCfg `mapstructure:"Worker"` - // EffectiveGasPrice is the config for the gas price EffectiveGasPrice EffectiveGasPriceCfg `mapstructure:"EffectiveGasPrice"` } @@ -129,12 +99,6 @@ type FinalizerCfg struct { StopSequencerOnBatchNum uint64 `mapstructure:"StopSequencerOnBatchNum"` } -// WorkerCfg contains the Worker's configuration properties -type WorkerCfg struct { - // ResourceCostMultiplier is the multiplier for the resource cost - ResourceCostMultiplier float64 `mapstructure:"ResourceCostMultiplier"` -} - // DBManagerCfg contains the DBManager's configuration properties type DBManagerCfg struct { PoolRetrievalInterval types.Duration `mapstructure:"PoolRetrievalInterval"` diff --git a/sequencer/efficiencylist.go b/sequencer/efficiencylist.go deleted file mode 100644 index 0508046b8d..0000000000 --- a/sequencer/efficiencylist.go +++ /dev/null @@ -1,126 +0,0 @@ -package sequencer - -import ( - "fmt" - "sort" - "sync" - - "github.com/0xPolygonHermez/zkevm-node/log" -) - -// efficiencyList represents a list of tx sorted by efficiency -type efficiencyList struct { - list map[string]*TxTracker - sorted []*TxTracker - mutex sync.Mutex -} - -// newEfficiencyList creates and init an efficiencyList -func newEfficiencyList() *efficiencyList { - return &efficiencyList{ - list: make(map[string]*TxTracker), - sorted: []*TxTracker{}, - } -} - -// add adds a tx to the efficiencyList -func (e *efficiencyList) add(tx *TxTracker) bool { - e.mutex.Lock() - defer e.mutex.Unlock() - - if _, found := e.list[tx.HashStr]; !found { - e.list[tx.HashStr] = tx - e.addSort(tx) - return true - } - return false -} - -// delete deletes the tx from the efficiencyList -func (e *efficiencyList) delete(tx *TxTracker) bool { - e.mutex.Lock() - defer e.mutex.Unlock() - - if tx, found := e.list[tx.HashStr]; found { - sLen := len(e.sorted) - i := sort.Search(sLen, func(i int) bool { - return e.isGreaterThan(tx, e.list[e.sorted[i].HashStr]) - }) - - if (e.sorted[i].HashStr != tx.HashStr) || i == sLen { - log.Errorf("Error deleting tx from efficiencyList: %s", tx.HashStr) - return false - } - - delete(e.list, tx.HashStr) - - copy(e.sorted[i:], e.sorted[i+1:]) - e.sorted[sLen-1] = nil - e.sorted = e.sorted[:sLen-1] - - return true - } - return false -} - -// getByIndex retrieves the tx at the i position in the sorted EfficiencyList -func (e *efficiencyList) getByIndex(i int) *TxTracker { - e.mutex.Lock() - defer e.mutex.Unlock() - - tx := e.sorted[i] - - return tx -} - -// len returns the length of the EfficiencyList -func (e *efficiencyList) len() int { - e.mutex.Lock() - defer e.mutex.Unlock() - - l := len(e.sorted) - - return l -} - -// print prints the contents of the EfficiencyList -func (e *efficiencyList) Print() { - e.mutex.Lock() - defer e.mutex.Unlock() - - fmt.Println("Len: ", len(e.sorted)) - for _, txi := range e.sorted { - fmt.Printf("Hash=%s, efficiency=%f\n", txi.HashStr, txi.Efficiency) - } -} - -// addSort adds the tx to the EfficiencyList in a sorted way -func (e *efficiencyList) addSort(tx *TxTracker) { - i := sort.Search(len(e.sorted), func(i int) bool { - return e.isGreaterThan(tx, e.list[e.sorted[i].HashStr]) - }) - - e.sorted = append(e.sorted, nil) - copy(e.sorted[i+1:], e.sorted[i:]) - e.sorted[i] = tx - log.Infof("Added tx(%s) to efficiencyList. With efficiency(%f) at index(%d) from total(%d)", tx.HashStr, tx.Efficiency, i, len(e.sorted)) -} - -// isGreaterThan returns true if the tx1 has best efficiency than tx2 -func (e *efficiencyList) isGreaterThan(tx1 *TxTracker, tx2 *TxTracker) bool { - if tx1.Efficiency > tx2.Efficiency { - return true - } else if tx1.Efficiency == tx2.Efficiency { - return tx1.HashStr >= tx2.HashStr - } else { - return false - } -} - -// GetSorted returns the sorted list of tx -func (e *efficiencyList) GetSorted() []*TxTracker { - e.mutex.Lock() - defer e.mutex.Unlock() - - return e.sorted -} diff --git a/sequencer/efficiencylist_test.go b/sequencer/efficiencylist_test.go deleted file mode 100644 index cd566edba8..0000000000 --- a/sequencer/efficiencylist_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package sequencer - -import ( - "crypto/rand" - "fmt" - "math/big" - "testing" - "time" -) - -// randomFloat64 is a shortcut for generating a random float between 0 and 1 using crypto/rand. -func randomFloat64() float64 { - nBig, err := rand.Int(rand.Reader, big.NewInt(1<<53)) - if err != nil { - panic(err) - } - return float64(nBig.Int64()) / (1 << 53) -} - -func TestEfficiencyListSort(t *testing.T) { - el := newEfficiencyList() - nItems := 100 - - for i := 0; i < nItems; i++ { - el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", i), Efficiency: randomFloat64()}) - } - - for i := 0; i < nItems-1; i++ { - if !(el.getByIndex(i).Efficiency > el.getByIndex(i+1).Efficiency) { - t.Fatalf("Sort error. [%d].Efficiency(%f) < [%d].Efficiency(%f)", i, el.getByIndex(i).Efficiency, i+1, el.getByIndex(i+1).Efficiency) - } - } - - // el.print() - - if el.len() != nItems { - t.Fatalf("Length error. Length %d. Expected %d", el.len(), nItems) - } -} - -func TestEfficiencyListDelete(t *testing.T) { - el := newEfficiencyList() - - el.add(&TxTracker{HashStr: "0x01", Efficiency: 1}) - el.add(&TxTracker{HashStr: "0x02", Efficiency: 2}) - el.add(&TxTracker{HashStr: "0x03", Efficiency: 2}) - el.add(&TxTracker{HashStr: "0x04", Efficiency: 3}) - el.add(&TxTracker{HashStr: "0x05", Efficiency: 10}) - el.add(&TxTracker{HashStr: "0x06", Efficiency: 1.5}) - el.add(&TxTracker{HashStr: "0x07", Efficiency: 1.5}) - - deltxs := []string{"0x03", "0x07", "0x01", "0x05"} - - for _, deltx := range deltxs { - count := el.len() - el.delete(&TxTracker{HashStr: deltx}) - - for i := 0; i < el.len(); i++ { - if el.getByIndex(i).HashStr == deltx { - t.Fatalf("Delete error. %s tx was not deleted", deltx) - } - } - - if el.len() != count-1 { - t.Fatalf("Length error. Length %d. Expected %d", el.len(), count) - } - } -} - -func TestEfficiencyListBench(t *testing.T) { - el := newEfficiencyList() - - start := time.Now() - for i := 0; i < 10000; i++ { - el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", i), Efficiency: randomFloat64()}) - } - elapsed := time.Since(start) - t.Logf("EfficiencyList adding 10000 items took %s", elapsed) - - start = time.Now() - el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", 10001), Efficiency: randomFloat64()}) - elapsed = time.Since(start) - t.Logf("EfficiencyList adding the 10001 item (efficiency=random) took %s", elapsed) - - start = time.Now() - el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", 10002), Efficiency: 0}) - elapsed = time.Since(start) - t.Logf("EfficiencyList adding the 10002 item (efficiency=0) took %s", elapsed) - - start = time.Now() - el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", 10003), Efficiency: 1000}) - elapsed = time.Since(start) - t.Logf("EfficiencyList adding the 10003 item (efficiency=1000) took %s", elapsed) -} diff --git a/sequencer/finalizer.go b/sequencer/finalizer.go index 52311e3bf5..4ade249382 100644 --- a/sequencer/finalizer.go +++ b/sequencer/finalizer.go @@ -755,9 +755,9 @@ func (f *finalizer) storeProcessedTx(ctx context.Context, txToStore transactionT } func (f *finalizer) updateWorkerAfterSuccessfulProcessing(ctx context.Context, tx *TxTracker, result *state.ProcessBatchResponse) { - // Delete the transaction from the efficiency list + // Delete the transaction from the txSorted list f.worker.DeleteTx(tx.Hash, tx.From) - log.Debug("tx deleted from efficiency list", "txHash", tx.Hash.String(), "from", tx.From.Hex()) + log.Debug("tx deleted from txSorted list", "txHash", tx.Hash.String(), "from", tx.From.Hex()) start := time.Now() txsToDelete := f.worker.UpdateAfterSingleSuccessfulTxExecution(tx.From, result.ReadWriteAddresses) @@ -822,9 +822,9 @@ func (f *finalizer) handleProcessTransactionError(ctx context.Context, result *s } metrics.WorkerProcessingTime(time.Since(start)) } else { - // Delete the transaction from the efficiency list + // Delete the transaction from the txSorted list f.worker.DeleteTx(tx.Hash, tx.From) - log.Debug("tx deleted from efficiency list", "txHash", tx.Hash.String(), "from", tx.From.Hex()) + log.Debug("tx deleted from txSorted list", "txHash", tx.Hash.String(), "from", tx.From.Hex()) wg.Add(1) go func() { @@ -1177,7 +1177,7 @@ func (f *finalizer) checkRemainingResources(result *state.ProcessBatchResponse, if err != nil { log.Infof("current transaction exceeds the batch limit, updating metadata for tx in worker and continuing") start := time.Now() - f.worker.UpdateTx(result.Responses[0].TxHash, tx.From, usedResources.ZKCounters) + f.worker.UpdateTxZKCounters(result.Responses[0].TxHash, tx.From, usedResources.ZKCounters) metrics.WorkerProcessingTime(time.Since(start)) return err } diff --git a/sequencer/finalizer_test.go b/sequencer/finalizer_test.go index 74751f453c..b60a8c5a94 100644 --- a/sequencer/finalizer_test.go +++ b/sequencer/finalizer_test.go @@ -288,7 +288,7 @@ func TestFinalizer_handleProcessTransactionResponse(t *testing.T) { workerMock.On("MoveTxToNotReady", txHash, senderAddr, addressInfo.Nonce, addressInfo.Balance).Return([]*TxTracker{}).Once() } if tc.expectedUpdateTxCall { - workerMock.On("UpdateTx", txTracker.Hash, txTracker.From, tc.executorResponse.UsedZkCounters).Return().Once() + workerMock.On("UpdateTxZKCounters", txTracker.Hash, txTracker.From, tc.executorResponse.UsedZkCounters).Return().Once() } if tc.expectedError == nil { //dbManagerMock.On("GetGasPrices", ctx).Return(pool.GasPrices{L1GasPrice: 0, L2GasPrice: 0}, nilErr).Once() @@ -1300,7 +1300,7 @@ func TestFinalizer_checkRemainingResources(t *testing.T) { f.batch.remainingResources = tc.remaining dbManagerMock.On("AddEvent", ctx, mock.Anything, nil).Return(nil) if tc.expectedWorkerUpdate { - workerMock.On("UpdateTx", txResponse.TxHash, tc.expectedTxTracker.From, result.UsedZkCounters).Return().Once() + workerMock.On("UpdateTxZKCounters", txResponse.TxHash, tc.expectedTxTracker.From, result.UsedZkCounters).Return().Once() } // act @@ -1314,9 +1314,9 @@ func TestFinalizer_checkRemainingResources(t *testing.T) { assert.NoError(t, err) } if tc.expectedWorkerUpdate { - workerMock.AssertCalled(t, "UpdateTx", txResponse.TxHash, tc.expectedTxTracker.From, result.UsedZkCounters) + workerMock.AssertCalled(t, "UpdateTxZKCounters", txResponse.TxHash, tc.expectedTxTracker.From, result.UsedZkCounters) } else { - workerMock.AssertNotCalled(t, "UpdateTx", mock.Anything, mock.Anything, mock.Anything) + workerMock.AssertNotCalled(t, "UpdateTxZKCounters", mock.Anything, mock.Anything, mock.Anything) } }) } diff --git a/sequencer/interfaces.go b/sequencer/interfaces.go index 181326eaaf..411570224b 100644 --- a/sequencer/interfaces.go +++ b/sequencer/interfaces.go @@ -86,7 +86,7 @@ type stateInterface interface { type workerInterface interface { GetBestFittingTx(resources state.BatchResources) *TxTracker UpdateAfterSingleSuccessfulTxExecution(from common.Address, touchedAddresses map[common.Address]*state.InfoReadWrite) []*TxTracker - UpdateTx(txHash common.Hash, from common.Address, ZKCounters state.ZKCounters) + UpdateTxZKCounters(txHash common.Hash, from common.Address, ZKCounters state.ZKCounters) AddTxTracker(ctx context.Context, txTracker *TxTracker) (replacedTx *TxTracker, dropReason error) MoveTxToNotReady(txHash common.Hash, from common.Address, actualNonce *uint64, actualBalance *big.Int) []*TxTracker DeleteTx(txHash common.Hash, from common.Address) diff --git a/sequencer/mock_worker.go b/sequencer/mock_worker.go index 1262c09023..c6c3d4648e 100644 --- a/sequencer/mock_worker.go +++ b/sequencer/mock_worker.go @@ -130,8 +130,8 @@ func (_m *WorkerMock) UpdateAfterSingleSuccessfulTxExecution(from common.Address return r0 } -// UpdateTx provides a mock function with given fields: txHash, from, ZKCounters -func (_m *WorkerMock) UpdateTx(txHash common.Hash, from common.Address, ZKCounters state.ZKCounters) { +// UpdateTxZKCounters provides a mock function with given fields: txHash, from, ZKCounters +func (_m *WorkerMock) UpdateTxZKCounters(txHash common.Hash, from common.Address, ZKCounters state.ZKCounters) { _m.Called(txHash, from, ZKCounters) } diff --git a/sequencer/sequencer.go b/sequencer/sequencer.go index ef41799b03..8644f7bdc7 100644 --- a/sequencer/sequencer.go +++ b/sequencer/sequencer.go @@ -42,19 +42,6 @@ type batchConstraints struct { MaxSteps uint32 } -// TODO: Add tests to config_test.go -type batchResourceWeights struct { - WeightBatchBytesSize int - WeightCumulativeGasUsed int - WeightKeccakHashes int - WeightPoseidonHashes int - WeightPoseidonPaddings int - WeightMemAligns int - WeightArithmetics int - WeightBinaries int - WeightSteps int -} - // L2ReorgEvent is the event that is triggered when a reorg happens in the L2 type L2ReorgEvent struct { TxHashes []common.Hash @@ -111,24 +98,13 @@ func (s *Sequencer) Start(ctx context.Context) { MaxBinaries: s.cfg.MaxBinaries, MaxSteps: s.cfg.MaxSteps, } - batchResourceWeights := batchResourceWeights{ - WeightBatchBytesSize: s.cfg.WeightBatchBytesSize, - WeightCumulativeGasUsed: s.cfg.WeightCumulativeGasUsed, - WeightKeccakHashes: s.cfg.WeightKeccakHashes, - WeightPoseidonHashes: s.cfg.WeightPoseidonHashes, - WeightPoseidonPaddings: s.cfg.WeightPoseidonPaddings, - WeightMemAligns: s.cfg.WeightMemAligns, - WeightArithmetics: s.cfg.WeightArithmetics, - WeightBinaries: s.cfg.WeightBinaries, - WeightSteps: s.cfg.WeightSteps, - } err := s.pool.MarkWIPTxsAsPending(ctx) if err != nil { log.Fatalf("failed to mark WIP txs as pending, err: %v", err) } - worker := NewWorker(s.cfg.Worker, s.state, batchConstraints, batchResourceWeights) + worker := NewWorker(s.state) dbManager := newDBManager(ctx, s.cfg.DBManager, s.pool, s.state, worker, closingSignalCh, batchConstraints) go dbManager.Start() diff --git a/sequencer/txsorted_list.go b/sequencer/txsorted_list.go new file mode 100644 index 0000000000..3b328671d2 --- /dev/null +++ b/sequencer/txsorted_list.go @@ -0,0 +1,152 @@ +package sequencer + +import ( + "fmt" + "sort" + "sync" + + "github.com/0xPolygonHermez/zkevm-node/log" +) + +// txSortedList represents a list of tx sorted by gasPrice +type txSortedList struct { + list map[string]*TxTracker + sorted []*TxTracker + mutex sync.Mutex +} + +// newTxSortedList creates and init an txSortedList +func newTxSortedList() *txSortedList { + return &txSortedList{ + list: make(map[string]*TxTracker), + sorted: []*TxTracker{}, + } +} + +// add adds a tx to the txSortedList +func (e *txSortedList) add(tx *TxTracker) bool { + e.mutex.Lock() + defer e.mutex.Unlock() + + if _, found := e.list[tx.HashStr]; !found { + e.list[tx.HashStr] = tx + e.addSort(tx) + return true + } + return false +} + +// delete deletes the tx from the txSortedList +func (e *txSortedList) delete(tx *TxTracker) bool { + e.mutex.Lock() + defer e.mutex.Unlock() + + if tx, found := e.list[tx.HashStr]; found { + sLen := len(e.sorted) + i := sort.Search(sLen, func(i int) bool { + return e.isGreaterOrEqualThan(tx, e.list[e.sorted[i].HashStr]) + }) + + // i is the index of the first tx that has equal (or lower) gasPrice than the tx. From here we need to go down in the list + // looking for the sorted[i].HashStr equal to tx.HashStr to get the index of tx in the sorted slice. + // We need to go down until we find the tx or we have a tx with different (lower) gasPrice or we reach the end of the list + for { + if i == sLen { + log.Errorf("Error deleting tx (%s) from txSortedList, we reach the end of the list", tx.HashStr) + return false + } + + if (e.sorted[i].GasPrice.Cmp(tx.GasPrice)) != 0 { + // we have a tx with different (lower) GasPrice than the tx we are looking for, therefore we haven't found the tx + log.Errorf("Error deleting tx (%s) from txSortedList, not found in the list of txs with same gasPrice: %s", tx.HashStr) + return false + } + + if e.sorted[i].HashStr == tx.HashStr { + break + } + + i = i + 1 + } + + delete(e.list, tx.HashStr) + + copy(e.sorted[i:], e.sorted[i+1:]) + e.sorted[sLen-1] = nil + e.sorted = e.sorted[:sLen-1] + + return true + } + return false +} + +// getByIndex retrieves the tx at the i position in the sorted txSortedList +func (e *txSortedList) getByIndex(i int) *TxTracker { + e.mutex.Lock() + defer e.mutex.Unlock() + + tx := e.sorted[i] + + return tx +} + +// len returns the length of the txSortedList +func (e *txSortedList) len() int { + e.mutex.Lock() + defer e.mutex.Unlock() + + l := len(e.sorted) + + return l +} + +// print prints the contents of the txSortedList +func (e *txSortedList) Print() { + e.mutex.Lock() + defer e.mutex.Unlock() + + fmt.Println("Len: ", len(e.sorted)) + for _, txi := range e.sorted { + fmt.Printf("Hash=%s, gasPrice=%d\n", txi.HashStr, txi.GasPrice) + } +} + +// addSort adds the tx to the txSortedList in a sorted way +func (e *txSortedList) addSort(tx *TxTracker) { + i := sort.Search(len(e.sorted), func(i int) bool { + return e.isGreaterThan(tx, e.list[e.sorted[i].HashStr]) + }) + + e.sorted = append(e.sorted, nil) + copy(e.sorted[i+1:], e.sorted[i:]) + e.sorted[i] = tx + log.Infof("Added tx(%s) to txSortedList. With gasPrice(%d) at index(%d) from total(%d)", tx.HashStr, tx.GasPrice, i, len(e.sorted)) +} + +// isGreaterThan returns true if the tx1 has greater gasPrice than tx2 +func (e *txSortedList) isGreaterThan(tx1 *TxTracker, tx2 *TxTracker) bool { + cmp := tx1.GasPrice.Cmp(tx2.GasPrice) + if cmp == 1 { + return true + } else { + return false + } +} + +// isGreaterOrEqualThan returns true if the tx1 has greater or equal gasPrice than tx2 +func (e *txSortedList) isGreaterOrEqualThan(tx1 *TxTracker, tx2 *TxTracker) bool { + cmp := tx1.GasPrice.Cmp(tx2.GasPrice) + if cmp >= 0 { + return true + } else { + return false + } +} + +// GetSorted returns the sorted list of tx +func (e *txSortedList) GetSorted() []*TxTracker { + e.mutex.Lock() + defer e.mutex.Unlock() + + return e.sorted +} diff --git a/sequencer/txsorted_list_test.go b/sequencer/txsorted_list_test.go new file mode 100644 index 0000000000..e3ae43dffb --- /dev/null +++ b/sequencer/txsorted_list_test.go @@ -0,0 +1,114 @@ +package sequencer + +import ( + "crypto/rand" + "fmt" + "math/big" + "testing" + "time" +) + +// randomBigInt is a shortcut for generating a random big.Int +func randomBigInt() *big.Int { + //Max random value, a 130-bits integer, i.e 2^130 - 1 + max := new(big.Int) + max.Exp(big.NewInt(2), big.NewInt(130), nil).Sub(max, big.NewInt(1)) + + //Generate cryptographically strong pseudo-random between 0 - max + n, err := rand.Int(rand.Reader, max) + if err != nil { + //error handling + return nil + } + + return n +} + +func TestTxSortedList(t *testing.T) { + el := newTxSortedList() + nItems := 100 + + for i := 0; i < nItems; i++ { + el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", i), GasPrice: randomBigInt()}) + } + + for i := 0; i < nItems-1; i++ { + if !(el.getByIndex(i).GasPrice.Cmp(el.getByIndex(i+1).GasPrice) == 1) { + t.Fatalf("Sort error. [%d].GasPrice(%f) < [%d].GasPrice(%f)", i, el.getByIndex(i).GasPrice, i+1, el.getByIndex(i+1).GasPrice) + } + } + + // el.print() + + if el.len() != nItems { + t.Fatalf("Length error. Length %d. Expected %d", el.len(), nItems) + } +} + +func TestTxSortedListDelete(t *testing.T) { + el := newTxSortedList() + + el.add(&TxTracker{HashStr: "0x01", GasPrice: new(big.Int).SetInt64(10)}) + el.add(&TxTracker{HashStr: "0x02", GasPrice: new(big.Int).SetInt64(20)}) + el.add(&TxTracker{HashStr: "0x03", GasPrice: new(big.Int).SetInt64(20)}) + el.add(&TxTracker{HashStr: "0x04", GasPrice: new(big.Int).SetInt64(40)}) + el.add(&TxTracker{HashStr: "0x05", GasPrice: new(big.Int).SetInt64(100)}) + el.add(&TxTracker{HashStr: "0x06", GasPrice: new(big.Int).SetInt64(15)}) + el.add(&TxTracker{HashStr: "0x07", GasPrice: new(big.Int).SetInt64(15)}) + el.add(&TxTracker{HashStr: "0x08", GasPrice: new(big.Int).SetInt64(10)}) + + sort := []string{"0x05", "0x04", "0x02", "0x03", "0x06", "0x07", "0x01", "0x08"} + + for index, tx := range el.sorted { + if sort[index] != tx.HashStr { + t.Fatalf("Sort error. Expected %s, Actual %s", sort[index], tx.HashStr) + } + } + + deltxs := []string{"0x03", "0x06", "0x08", "0x05"} + + for _, deltx := range deltxs { + count := el.len() + el.delete(&TxTracker{HashStr: deltx}) + + for i := 0; i < el.len(); i++ { + if el.getByIndex(i).HashStr == deltx { + t.Fatalf("Delete error. %s tx was not deleted", deltx) + } + } + + if el.len() != count-1 { + t.Fatalf("Length error. Length %d. Expected %d", el.len(), count) + } + } + + if el.delete(&TxTracker{HashStr: "0x08"}) { + t.Fatal("Delete error. 0x08 tx was deleted and should not exist in the list") + } +} + +func TestTxSortedListBench(t *testing.T) { + el := newTxSortedList() + + start := time.Now() + for i := 0; i < 10000; i++ { + el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", i), GasPrice: randomBigInt()}) + } + elapsed := time.Since(start) + t.Logf("TxSortedList adding 10000 items took %s", elapsed) + + start = time.Now() + el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", 10001), GasPrice: randomBigInt()}) + elapsed = time.Since(start) + t.Logf("TxSortedList adding the 10001 item (GasPrice=random) took %s", elapsed) + + start = time.Now() + el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", 10002), GasPrice: new(big.Int).SetInt64(0)}) + elapsed = time.Since(start) + t.Logf("TxSortedList adding the 10002 item (GasPrice=0) took %s", elapsed) + + start = time.Now() + el.add(&TxTracker{HashStr: fmt.Sprintf("0x%d", 10003), GasPrice: new(big.Int).SetInt64(1000)}) + elapsed = time.Since(start) + t.Logf("TxSortedList adding the 10003 item (GasPrice=1000) took %s", elapsed) +} diff --git a/sequencer/txtracker.go b/sequencer/txtracker.go index bfc67f5b7b..3a380d2301 100644 --- a/sequencer/txtracker.go +++ b/sequencer/txtracker.go @@ -4,7 +4,6 @@ import ( "math/big" "time" - "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -22,15 +21,10 @@ type TxTracker struct { Cost *big.Int // Cost = Amount + Benefit Benefit *big.Int // GasLimit * GasPrice BatchResources state.BatchResources // To check if it fits into a batch - Efficiency float64 RawTx []byte - ReceivedAt time.Time // To check if it has been in the efficiency list for too long + ReceivedAt time.Time // To check if it has been in the txSortedList for too long IP string // IP of the tx sender FailedReason *string // FailedReason is the reason why the tx failed, if it failed - Constraints batchConstraintsFloat64 - WeightMultipliers batchResourceWeightMultipliers - ResourceCostMultiplier float64 - TotalWeight float64 BreakEvenGasPrice *big.Int GasPriceEffectivePercentage uint8 EffectiveGasPriceProcessCount uint8 @@ -38,43 +32,13 @@ type TxTracker struct { L1GasPrice uint64 } -// batchResourceWeightMultipliers is a struct that contains the weight multipliers for each resource -type batchResourceWeightMultipliers struct { - cumulativeGasUsed float64 - arithmetics float64 - binaries float64 - keccakHashes float64 - memAligns float64 - poseidonHashes float64 - poseidonPaddings float64 - steps float64 - batchBytesSize float64 -} - -// batchConstraints represents the Constraints for a batch in float64 -type batchConstraintsFloat64 struct { - maxTxsPerBatch float64 - maxBatchBytesSize float64 - maxCumulativeGasUsed float64 - maxKeccakHashes float64 - maxPoseidonHashes float64 - maxPoseidonPaddings float64 - maxMemAligns float64 - maxArithmetics float64 - maxBinaries float64 - maxSteps float64 -} - // newTxTracker creates and inti a TxTracker -func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints batchConstraintsFloat64, weights batchResourceWeights, resourceCostMultiplier float64, ip string) (*TxTracker, error) { +func newTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) { addr, err := state.GetSender(tx) if err != nil { return nil, err } - totalWeight := float64(weights.WeightArithmetics + weights.WeightBatchBytesSize + weights.WeightBinaries + weights.WeightCumulativeGasUsed + - weights.WeightKeccakHashes + weights.WeightMemAligns + weights.WeightPoseidonHashes + weights.WeightPoseidonPaddings + weights.WeightSteps) - rawTx, err := state.EncodeTransactionWithoutEffectivePercentage(tx) if err != nil { return nil, err @@ -93,74 +57,18 @@ func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints b Bytes: tx.Size(), ZKCounters: counters, }, - Efficiency: 0, RawTx: rawTx, ReceivedAt: time.Now(), IP: ip, - Constraints: constraints, - WeightMultipliers: calculateWeightMultipliers(weights, totalWeight), - ResourceCostMultiplier: resourceCostMultiplier, - TotalWeight: totalWeight, BreakEvenGasPrice: new(big.Int).SetUint64(0), EffectiveGasPriceProcessCount: 0, IsEffectiveGasPriceFinalExecution: false, } - txTracker.calculateEfficiency(constraints, weights) return txTracker, nil } -// updateZKCounters updates the counters of the tx and recalculates the tx efficiency - -func (tx *TxTracker) updateZKCounters(counters state.ZKCounters, constraints batchConstraintsFloat64, weights batchResourceWeights) { +// updateZKCounters updates the counters of the tx +func (tx *TxTracker) updateZKCounters(counters state.ZKCounters) { tx.BatchResources.ZKCounters = counters - tx.calculateEfficiency(constraints, weights) -} - -// calculateEfficiency calculates the tx efficiency -func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, weights batchResourceWeights) { - totalWeight := float64(weights.WeightArithmetics + weights.WeightBatchBytesSize + weights.WeightBinaries + weights.WeightCumulativeGasUsed + - weights.WeightKeccakHashes + weights.WeightMemAligns + weights.WeightPoseidonHashes + weights.WeightPoseidonPaddings + weights.WeightSteps) - - // TODO: Optmize tx.Efficiency calculation (precalculate constansts values) - // TODO: Evaluate avoid type conversion (performance impact?) - resourceCost := (float64(tx.BatchResources.ZKCounters.CumulativeGasUsed)/constraints.maxCumulativeGasUsed)*float64(weights.WeightCumulativeGasUsed)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedArithmetics)/constraints.maxArithmetics)*float64(weights.WeightArithmetics)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedBinaries)/constraints.maxBinaries)*float64(weights.WeightBinaries)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedKeccakHashes)/constraints.maxKeccakHashes)*float64(weights.WeightKeccakHashes)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedMemAligns)/constraints.maxMemAligns)*float64(weights.WeightMemAligns)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedPoseidonHashes)/constraints.maxPoseidonHashes)*float64(weights.WeightPoseidonHashes)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedPoseidonPaddings)/constraints.maxPoseidonPaddings)*float64(weights.WeightPoseidonPaddings)/totalWeight + - (float64(tx.BatchResources.ZKCounters.UsedSteps)/constraints.maxSteps)*float64(weights.WeightSteps)/totalWeight + - (float64(tx.BatchResources.Bytes)/constraints.maxBatchBytesSize)*float64(weights.WeightBatchBytesSize)/totalWeight //Meto config - - resourceCost = resourceCost * tx.ResourceCostMultiplier - - var eff *big.Float - - ben := big.NewFloat(0).SetInt(tx.Benefit) - rc := big.NewFloat(0).SetFloat64(resourceCost) - eff = big.NewFloat(0).Quo(ben, rc) - - var accuracy big.Accuracy - tx.Efficiency, accuracy = eff.Float64() - log.Infof("CalculateEfficiency(%f) for tx(%s)", tx.Efficiency, tx.Hash.String()) - if accuracy != big.Exact { - log.Errorf("CalculateEfficiency accuracy warning (%s). Calculated=%s Assigned=%f", accuracy.String(), eff.String(), tx.Efficiency) - } -} - -// calculateWeightMultipliers calculates the weight multipliers for each resource -func calculateWeightMultipliers(weights batchResourceWeights, totalWeight float64) batchResourceWeightMultipliers { - return batchResourceWeightMultipliers{ - cumulativeGasUsed: float64(weights.WeightCumulativeGasUsed) / totalWeight, - arithmetics: float64(weights.WeightArithmetics) / totalWeight, - binaries: float64(weights.WeightBinaries) / totalWeight, - keccakHashes: float64(weights.WeightKeccakHashes) / totalWeight, - memAligns: float64(weights.WeightMemAligns) / totalWeight, - poseidonHashes: float64(weights.WeightPoseidonHashes) / totalWeight, - poseidonPaddings: float64(weights.WeightPoseidonPaddings) / totalWeight, - steps: float64(weights.WeightSteps) / totalWeight, - batchBytesSize: float64(weights.WeightBatchBytesSize) / totalWeight, - } } diff --git a/sequencer/txtracker_test.go b/sequencer/txtracker_test.go deleted file mode 100644 index e5663f78b2..0000000000 --- a/sequencer/txtracker_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package sequencer - -import ( - "fmt" - "math/big" - "testing" - - "github.com/0xPolygonHermez/zkevm-node/state" - "github.com/stretchr/testify/assert" -) - -type efficiencyCalcTestCase struct { - Name string - benefit int64 - counters state.ZKCounters - usedBytes uint64 - expectedResult float64 -} - -func TestTxTrackerEfficiencyCalculation(t *testing.T) { - // Init ZKEVM resourceCostWeight values - rcWeigth := batchResourceWeights{} - rcWeigth.WeightCumulativeGasUsed = 1 - rcWeigth.WeightArithmetics = 1 - rcWeigth.WeightBinaries = 1 - rcWeigth.WeightKeccakHashes = 1 - rcWeigth.WeightMemAligns = 1 - rcWeigth.WeightPoseidonHashes = 1 - rcWeigth.WeightPoseidonPaddings = 1 - rcWeigth.WeightSteps = 1 - rcWeigth.WeightBatchBytesSize = 2 - - // Init ZKEVM resourceCostMax values - rcMax := batchConstraintsFloat64{} - rcMax.maxCumulativeGasUsed = 10 - rcMax.maxArithmetics = 10 - rcMax.maxBinaries = 10 - rcMax.maxKeccakHashes = 10 - rcMax.maxMemAligns = 10 - rcMax.maxPoseidonHashes = 10 - rcMax.maxPoseidonPaddings = 10 - rcMax.maxSteps = 10 - rcMax.maxBatchBytesSize = 10 - - totalWeight := float64(rcWeigth.WeightArithmetics + rcWeigth.WeightBatchBytesSize + rcWeigth.WeightBinaries + rcWeigth.WeightCumulativeGasUsed + - rcWeigth.WeightKeccakHashes + rcWeigth.WeightMemAligns + rcWeigth.WeightPoseidonHashes + rcWeigth.WeightPoseidonPaddings + rcWeigth.WeightSteps) - - testCases := []efficiencyCalcTestCase{ - { - Name: "Using all of the resources", - benefit: 1000000, - counters: state.ZKCounters{CumulativeGasUsed: 10, UsedKeccakHashes: 10, UsedPoseidonHashes: 10, UsedPoseidonPaddings: 10, UsedMemAligns: 10, UsedArithmetics: 10, UsedBinaries: 10, UsedSteps: 10}, - usedBytes: 10, - expectedResult: 1000.00, - }, - { - Name: "Using half of the resources", - benefit: 1000000, - counters: state.ZKCounters{CumulativeGasUsed: 5, UsedKeccakHashes: 5, UsedPoseidonHashes: 5, UsedPoseidonPaddings: 5, UsedMemAligns: 5, UsedArithmetics: 5, UsedBinaries: 5, UsedSteps: 5}, - usedBytes: 5, - expectedResult: 2000.00, - }, - { - Name: "Using all the bytes and half of the remain resources", - benefit: 1000000, - counters: state.ZKCounters{CumulativeGasUsed: 5, UsedKeccakHashes: 5, UsedPoseidonHashes: 5, UsedPoseidonPaddings: 5, UsedMemAligns: 5, UsedArithmetics: 5, UsedBinaries: 5, UsedSteps: 5}, - usedBytes: 10, - expectedResult: 1666.67, - }, - { - Name: "Using all the steps and half of the remain resources", - benefit: 1000000, - counters: state.ZKCounters{CumulativeGasUsed: 5, UsedKeccakHashes: 5, UsedPoseidonHashes: 5, UsedPoseidonPaddings: 5, UsedMemAligns: 5, UsedArithmetics: 5, UsedBinaries: 5, UsedSteps: 10}, - usedBytes: 5, - expectedResult: 1818.18, - }, - { - Name: "Using 10% of all the resources", - benefit: 1000000, - counters: state.ZKCounters{CumulativeGasUsed: 1, UsedKeccakHashes: 1, UsedPoseidonHashes: 1, UsedPoseidonPaddings: 1, UsedMemAligns: 1, UsedArithmetics: 1, UsedBinaries: 1, UsedSteps: 1}, - usedBytes: 1, - expectedResult: 10000.00, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.Name, func(t *testing.T) { - tx := TxTracker{} - tx.Benefit = new(big.Int).SetInt64(testCase.benefit) - - tx.BatchResources.Bytes = testCase.usedBytes - tx.updateZKCounters(testCase.counters, rcMax, rcWeigth) - tx.WeightMultipliers = calculateWeightMultipliers(rcWeigth, totalWeight) - tx.ResourceCostMultiplier = 1000 - tx.updateZKCounters(testCase.counters, rcMax, rcWeigth) - t.Logf("%s=%s", testCase.Name, fmt.Sprintf("%.2f", tx.Efficiency)) - assert.Equal(t, fmt.Sprintf("%.2f", testCase.expectedResult), fmt.Sprintf("%.2f", tx.Efficiency), "Efficiency calculation err. Expected=%s, Actual=%s", fmt.Sprintf("%.2f", testCase.expectedResult), fmt.Sprintf("%.2f", tx.Efficiency)) - }) - } -} diff --git a/sequencer/worker.go b/sequencer/worker.go index cba6938f7c..ec596c7d56 100644 --- a/sequencer/worker.go +++ b/sequencer/worker.go @@ -16,24 +16,18 @@ import ( // Worker represents the worker component of the sequencer type Worker struct { - cfg WorkerCfg - pool map[string]*addrQueue - efficiencyList *efficiencyList - workerMutex sync.Mutex - state stateInterface - batchConstraints batchConstraintsFloat64 - batchResourceWeights batchResourceWeights + pool map[string]*addrQueue + txSortedList *txSortedList + workerMutex sync.Mutex + state stateInterface } // NewWorker creates an init a worker -func NewWorker(cfg WorkerCfg, state stateInterface, constraints batchConstraints, weights batchResourceWeights) *Worker { +func NewWorker(state stateInterface) *Worker { w := Worker{ - cfg: cfg, - pool: make(map[string]*addrQueue), - efficiencyList: newEfficiencyList(), - state: state, - batchConstraints: convertBatchConstraintsToFloat64(constraints), - batchResourceWeights: weights, + pool: make(map[string]*addrQueue), + txSortedList: newTxSortedList(), + state: state, } return &w @@ -41,7 +35,7 @@ func NewWorker(cfg WorkerCfg, state stateInterface, constraints batchConstraints // NewTxTracker creates and inits a TxTracker func (w *Worker) NewTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) { - return newTxTracker(tx, counters, w.batchConstraints, w.batchResourceWeights, w.cfg.ResourceCostMultiplier, ip) + return newTxTracker(tx, counters, ip) } // AddTxTracker adds a new Tx to the Worker @@ -92,14 +86,14 @@ func (w *Worker) AddTxTracker(ctx context.Context, tx *TxTracker) (replacedTx *T return repTx, dropReason } - // Update the EfficiencyList (if needed) + // Update the txSortedList (if needed) if prevReadyTx != nil { - log.Infof("AddTx prevReadyTx(%s) nonce(%d) cost(%s) deleted from EfficiencyList", prevReadyTx.HashStr, prevReadyTx.Nonce, prevReadyTx.Cost.String()) - w.efficiencyList.delete(prevReadyTx) + log.Infof("AddTx prevReadyTx(%s) nonce(%d) cost(%s) deleted from TxSortedList", prevReadyTx.HashStr, prevReadyTx.Nonce, prevReadyTx.Cost.String()) + w.txSortedList.delete(prevReadyTx) } if newReadyTx != nil { - log.Infof("AddTx newReadyTx(%s) nonce(%d) cost(%s) added to EfficiencyList", newReadyTx.HashStr, newReadyTx.Nonce, newReadyTx.Cost.String()) - w.efficiencyList.add(newReadyTx) + log.Infof("AddTx newReadyTx(%s) nonce(%d) cost(%s) added to TxSortedList", newReadyTx.HashStr, newReadyTx.Nonce, newReadyTx.Cost.String()) + w.txSortedList.add(newReadyTx) } if repTx != nil { @@ -115,14 +109,14 @@ func (w *Worker) applyAddressUpdate(from common.Address, fromNonce *uint64, from if found { newReadyTx, prevReadyTx, txsToDelete := addrQueue.updateCurrentNonceBalance(fromNonce, fromBalance) - // Update the EfficiencyList (if needed) + // Update the TxSortedList (if needed) if prevReadyTx != nil { - log.Infof("applyAddressUpdate prevReadyTx(%s) nonce(%d) cost(%s) deleted from EfficiencyList", prevReadyTx.Hash.String(), prevReadyTx.Nonce, prevReadyTx.Cost.String()) - w.efficiencyList.delete(prevReadyTx) + log.Infof("applyAddressUpdate prevReadyTx(%s) nonce(%d) cost(%s) deleted from TxSortedList", prevReadyTx.Hash.String(), prevReadyTx.Nonce, prevReadyTx.Cost.String()) + w.txSortedList.delete(prevReadyTx) } if newReadyTx != nil { - log.Infof("applyAddressUpdate newReadyTx(%s) nonce(%d) cost(%s) added to EfficiencyList", newReadyTx.Hash.String(), newReadyTx.Nonce, newReadyTx.Cost.String()) - w.efficiencyList.add(newReadyTx) + log.Infof("applyAddressUpdate newReadyTx(%s) nonce(%d) cost(%s) added to TxSortedList", newReadyTx.Hash.String(), newReadyTx.Nonce, newReadyTx.Cost.String()) + w.txSortedList.add(newReadyTx) } return newReadyTx, prevReadyTx, txsToDelete @@ -187,44 +181,35 @@ func (w *Worker) DeleteTx(txHash common.Hash, addr common.Address) { if found { deletedReadyTx := addrQueue.deleteTx(txHash) if deletedReadyTx != nil { - log.Infof("DeleteTx tx(%s) deleted from EfficiencyList", deletedReadyTx.Hash.String()) - w.efficiencyList.delete(deletedReadyTx) + log.Infof("DeleteTx tx(%s) deleted from TxSortedList", deletedReadyTx.Hash.String()) + w.txSortedList.delete(deletedReadyTx) } } else { log.Errorf("DeleteTx addrQueue(%s) not found", addr.String()) } } -// UpdateTx updates the ZKCounter of a tx and resort the tx in the efficiency list if needed -func (w *Worker) UpdateTx(txHash common.Hash, addr common.Address, counters state.ZKCounters) { +// UpdateTxZKCounters updates the ZKCounter of a tx +func (w *Worker) UpdateTxZKCounters(txHash common.Hash, addr common.Address, counters state.ZKCounters) { w.workerMutex.Lock() defer w.workerMutex.Unlock() - log.Infof("UpdateTx tx(%s) addr(%s)", txHash.String(), addr.String()) - log.Debugf("UpdateTx counters.CumulativeGasUsed: %d", counters.CumulativeGasUsed) - log.Debugf("UpdateTx counters.UsedKeccakHashes: %d", counters.UsedKeccakHashes) - log.Debugf("UpdateTx counters.UsedPoseidonHashes: %d", counters.UsedPoseidonHashes) - log.Debugf("UpdateTx counters.UsedPoseidonPaddings: %d", counters.UsedPoseidonPaddings) - log.Debugf("UpdateTx counters.UsedMemAligns: %d", counters.UsedMemAligns) - log.Debugf("UpdateTx counters.UsedArithmetics: %d", counters.UsedArithmetics) - log.Debugf("UpdateTx counters.UsedBinaries: %d", counters.UsedBinaries) - log.Debugf("UpdateTx counters.UsedSteps: %d", counters.UsedSteps) + + log.Infof("UpdateTxZKCounters tx(%s) addr(%s)", txHash.String(), addr.String()) + log.Debugf("UpdateTxZKCounters counters.CumulativeGasUsed: %d", counters.CumulativeGasUsed) + log.Debugf("UpdateTxZKCounters counters.UsedKeccakHashes: %d", counters.UsedKeccakHashes) + log.Debugf("UpdateTxZKCounters counters.UsedPoseidonHashes: %d", counters.UsedPoseidonHashes) + log.Debugf("UpdateTxZKCounters counters.UsedPoseidonPaddings: %d", counters.UsedPoseidonPaddings) + log.Debugf("UpdateTxZKCounters counters.UsedMemAligns: %d", counters.UsedMemAligns) + log.Debugf("UpdateTxZKCounters counters.UsedArithmetics: %d", counters.UsedArithmetics) + log.Debugf("UpdateTxZKCounters counters.UsedBinaries: %d", counters.UsedBinaries) + log.Debugf("UpdateTxZKCounters counters.UsedSteps: %d", counters.UsedSteps) addrQueue, found := w.pool[addr.String()] if found { - newReadyTx, prevReadyTx := addrQueue.UpdateTxZKCounters(txHash, counters, w.batchConstraints, w.batchResourceWeights) - - // Resort the newReadyTx in efficiencyList - if prevReadyTx != nil { - log.Infof("UpdateTx prevReadyTx(%s) nonce(%d) cost(%s) deleted from EfficiencyList", prevReadyTx.Hash.String(), prevReadyTx.Nonce, prevReadyTx.Cost.String()) - w.efficiencyList.delete(prevReadyTx) - } - if newReadyTx != nil { - log.Infof("UpdateTx newReadyTx(%s) nonce(%d) cost(%s) added to EfficiencyList", newReadyTx.Hash.String(), newReadyTx.Nonce, newReadyTx.Cost.String()) - w.efficiencyList.add(newReadyTx) - } + addrQueue.UpdateTxZKCounters(txHash, counters) } else { - log.Errorf("UpdateTx addrQueue(%s) not found", addr.String()) + log.Warnf("UpdateTxZKCounters addrQueue(%s) not found", addr.String()) } } @@ -248,7 +233,7 @@ func (w *Worker) GetBestFittingTx(resources state.BatchResources) *TxTracker { for i := 0; i < nGoRoutines; i++ { go func(n int, bresources state.BatchResources) { defer wg.Done() - for i := n; i < w.efficiencyList.len(); i += nGoRoutines { + for i := n; i < w.txSortedList.len(); i += nGoRoutines { foundMutex.RLock() if foundAt != -1 && i > foundAt { foundMutex.RUnlock() @@ -256,7 +241,7 @@ func (w *Worker) GetBestFittingTx(resources state.BatchResources) *TxTracker { } foundMutex.RUnlock() - txCandidate := w.efficiencyList.getByIndex(i) + txCandidate := w.txSortedList.getByIndex(i) err := bresources.Sub(txCandidate.BatchResources) if err != nil { // We don't add this Tx @@ -277,7 +262,7 @@ func (w *Worker) GetBestFittingTx(resources state.BatchResources) *TxTracker { wg.Wait() if foundAt != -1 { - log.Infof("GetBestFittingTx found tx(%s) at index(%d) with efficiency(%f)", tx.Hash.String(), foundAt, tx.Efficiency) + log.Infof("GetBestFittingTx found tx(%s) at index(%d) with gasPrice(%d)", tx.Hash.String(), foundAt, tx.GasPrice) } else { log.Debugf("GetBestFittingTx no tx found") } @@ -298,7 +283,7 @@ func (w *Worker) ExpireTransactions(maxTime time.Duration) []*TxTracker { txs = append(txs, subTxs...) if prevReadyTx != nil { - w.efficiencyList.delete(prevReadyTx) + w.txSortedList.delete(prevReadyTx) } if addrQueue.IsEmpty() { @@ -310,28 +295,7 @@ func (w *Worker) ExpireTransactions(maxTime time.Duration) []*TxTracker { return txs } -// GetEfficiencyList returns the efficiency list -func (w *Worker) GetEfficiencyList() *efficiencyList { - return w.efficiencyList -} - // HandleL2Reorg handles the L2 reorg signal func (w *Worker) HandleL2Reorg(txHashes []common.Hash) { log.Fatal("L2 Reorg detected. Restarting to sync with the new L2 state...") } - -// convertBatchConstraintsToFloat64 converts the batch Constraints to float64 -func convertBatchConstraintsToFloat64(constraints batchConstraints) batchConstraintsFloat64 { - return batchConstraintsFloat64{ - maxTxsPerBatch: float64(constraints.MaxTxsPerBatch), - maxBatchBytesSize: float64(constraints.MaxBatchBytesSize), - maxCumulativeGasUsed: float64(constraints.MaxCumulativeGasUsed), - maxKeccakHashes: float64(constraints.MaxKeccakHashes), - maxPoseidonHashes: float64(constraints.MaxPoseidonHashes), - maxPoseidonPaddings: float64(constraints.MaxPoseidonPaddings), - maxMemAligns: float64(constraints.MaxMemAligns), - maxArithmetics: float64(constraints.MaxArithmetics), - maxBinaries: float64(constraints.MaxBinaries), - maxSteps: float64(constraints.MaxSteps), - } -} diff --git a/sequencer/worker_test.go b/sequencer/worker_test.go index 51787f188c..98382898e5 100644 --- a/sequencer/worker_test.go +++ b/sequencer/worker_test.go @@ -2,7 +2,6 @@ package sequencer import ( "context" - "fmt" "math/big" "testing" @@ -11,23 +10,16 @@ import ( "github.com/stretchr/testify/assert" ) -var ( - workerCfg = WorkerCfg{ - ResourceCostMultiplier: 1000, - } -) - type workerAddTxTestCase struct { - name string - from common.Address - txHash common.Hash - nonce uint64 - // isClaim bool - benefit int64 - cost *big.Int - counters state.ZKCounters - usedBytes uint64 - expectedEfficiencyList []common.Hash + name string + from common.Address + txHash common.Hash + nonce uint64 + cost *big.Int + counters state.ZKCounters + usedBytes uint64 + gasPrice *big.Int + expectedTxSortedList []common.Hash } type workerAddrQueueInfo struct { @@ -36,43 +28,34 @@ type workerAddrQueueInfo struct { balance *big.Int } -func processWorkerAddTxTestCases(t *testing.T, worker *Worker, testCases []workerAddTxTestCase) { - totalWeight := float64(worker.batchResourceWeights.WeightArithmetics + - worker.batchResourceWeights.WeightBatchBytesSize + worker.batchResourceWeights.WeightBinaries + - worker.batchResourceWeights.WeightCumulativeGasUsed + worker.batchResourceWeights.WeightKeccakHashes + - worker.batchResourceWeights.WeightMemAligns + worker.batchResourceWeights.WeightPoseidonHashes + - worker.batchResourceWeights.WeightPoseidonPaddings + worker.batchResourceWeights.WeightSteps) - +func processWorkerAddTxTestCases(ctx context.Context, t *testing.T, worker *Worker, testCases []workerAddTxTestCase) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { tx := TxTracker{} - tx.WeightMultipliers = calculateWeightMultipliers(worker.batchResourceWeights, totalWeight) - tx.Constraints = worker.batchConstraints - tx.ResourceCostMultiplier = worker.cfg.ResourceCostMultiplier tx.Hash = testCase.txHash tx.HashStr = testCase.txHash.String() tx.From = testCase.from tx.FromStr = testCase.from.String() tx.Nonce = testCase.nonce - tx.Benefit = new(big.Int).SetInt64(testCase.benefit) tx.Cost = testCase.cost tx.BatchResources.Bytes = testCase.usedBytes - tx.updateZKCounters(testCase.counters, worker.batchConstraints, worker.batchResourceWeights) - t.Logf("%s=%s", testCase.name, fmt.Sprintf("%.2f", tx.Efficiency)) + tx.GasPrice = testCase.gasPrice + tx.updateZKCounters(testCase.counters) + t.Logf("%s=%d", testCase.name, tx.GasPrice) _, err := worker.AddTxTracker(ctx, &tx) if err != nil { return } - el := worker.efficiencyList - if el.len() != len(testCase.expectedEfficiencyList) { - t.Fatalf("Error efficiencylist.len(%d) != expectedEfficiencyList.len(%d)", el.len(), len(testCase.expectedEfficiencyList)) + el := worker.txSortedList + if el.len() != len(testCase.expectedTxSortedList) { + t.Fatalf("Error txSortedList.len(%d) != expectedTxSortedList.len(%d)", el.len(), len(testCase.expectedTxSortedList)) } for i := 0; i < el.len(); i++ { - if el.getByIndex(i).HashStr != string(testCase.expectedEfficiencyList[i].String()) { - t.Fatalf("Error efficiencylist(%d). Expected=%s, Actual=%s", i, testCase.expectedEfficiencyList[i].String(), el.getByIndex(i).HashStr) + if el.getByIndex(i).HashStr != string(testCase.expectedTxSortedList[i].String()) { + t.Fatalf("Error txSortedList(%d). Expected=%s, Actual=%s", i, testCase.expectedTxSortedList[i].String(), el.getByIndex(i).HashStr) } } }) @@ -82,32 +65,8 @@ func processWorkerAddTxTestCases(t *testing.T, worker *Worker, testCases []worke func TestWorkerAddTx(t *testing.T) { var nilErr error - // Init ZKEVM resourceCostWeight values - rcWeigth := batchResourceWeights{} - rcWeigth.WeightCumulativeGasUsed = 1 - rcWeigth.WeightArithmetics = 1 - rcWeigth.WeightBinaries = 1 - rcWeigth.WeightKeccakHashes = 1 - rcWeigth.WeightMemAligns = 1 - rcWeigth.WeightPoseidonHashes = 1 - rcWeigth.WeightPoseidonPaddings = 1 - rcWeigth.WeightSteps = 1 - rcWeigth.WeightBatchBytesSize = 2 - - // Init ZKEVM resourceCostMax values - rcMax := batchConstraints{} - rcMax.MaxCumulativeGasUsed = 10 - rcMax.MaxArithmetics = 10 - rcMax.MaxBinaries = 10 - rcMax.MaxKeccakHashes = 10 - rcMax.MaxMemAligns = 10 - rcMax.MaxPoseidonHashes = 10 - rcMax.MaxPoseidonPaddings = 10 - rcMax.MaxSteps = 10 - rcMax.MaxBatchBytesSize = 10 - stateMock := NewStateMock(t) - worker := initWorker(stateMock, rcMax, rcWeigth) + worker := initWorker(stateMock) ctx := context.Background() @@ -127,98 +86,65 @@ func TestWorkerAddTx(t *testing.T) { addTxsTC := []workerAddTxTestCase{ { - name: "Adding from:0x01, tx:0x01/ef:10", from: common.Address{1}, txHash: common.Hash{1}, nonce: 1, - benefit: 1000, cost: new(big.Int).SetInt64(5), + name: "Adding from:0x01, tx:0x01/gp:10", from: common.Address{1}, txHash: common.Hash{1}, nonce: 1, gasPrice: new(big.Int).SetInt64(10), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 1, UsedKeccakHashes: 1, UsedPoseidonHashes: 1, UsedPoseidonPaddings: 1, UsedMemAligns: 1, UsedArithmetics: 1, UsedBinaries: 1, UsedSteps: 1}, usedBytes: 1, - expectedEfficiencyList: []common.Hash{ + expectedTxSortedList: []common.Hash{ {1}, }, }, { - name: "Adding from:0x02, tx:0x02/ef:20", from: common.Address{2}, txHash: common.Hash{2}, nonce: 1, - benefit: 2000, cost: new(big.Int).SetInt64(5), + name: "Adding from:0x02, tx:0x02/gp:4", from: common.Address{2}, txHash: common.Hash{2}, nonce: 1, gasPrice: new(big.Int).SetInt64(4), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 1, UsedKeccakHashes: 1, UsedPoseidonHashes: 1, UsedPoseidonPaddings: 1, UsedMemAligns: 1, UsedArithmetics: 1, UsedBinaries: 1, UsedSteps: 1}, usedBytes: 1, - expectedEfficiencyList: []common.Hash{ - {2}, {1}, + expectedTxSortedList: []common.Hash{ + {1}, {2}, }, }, { - name: "Readding from:0x02, tx:0x02/ef:4", from: common.Address{2}, txHash: common.Hash{2}, nonce: 1, - benefit: 2000, cost: new(big.Int).SetInt64(5), + name: "Readding from:0x02, tx:0x02/gp:20", from: common.Address{2}, txHash: common.Hash{2}, nonce: 1, gasPrice: new(big.Int).SetInt64(20), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 5, UsedKeccakHashes: 5, UsedPoseidonHashes: 5, UsedPoseidonPaddings: 5, UsedMemAligns: 5, UsedArithmetics: 5, UsedBinaries: 5, UsedSteps: 5}, usedBytes: 5, - expectedEfficiencyList: []common.Hash{ - {1}, {2}, + expectedTxSortedList: []common.Hash{ + {2}, {1}, }, }, { - name: "Readding from:0x03, tx:0x03/ef:25", from: common.Address{3}, txHash: common.Hash{3}, nonce: 1, - benefit: 5000, cost: new(big.Int).SetInt64(5), + name: "Readding from:0x03, tx:0x03/gp:25", from: common.Address{3}, txHash: common.Hash{3}, nonce: 1, gasPrice: new(big.Int).SetInt64(25), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 2, UsedKeccakHashes: 2, UsedPoseidonHashes: 2, UsedPoseidonPaddings: 2, UsedMemAligns: 2, UsedArithmetics: 2, UsedBinaries: 2, UsedSteps: 2}, usedBytes: 2, - expectedEfficiencyList: []common.Hash{ - {3}, {1}, {2}, + expectedTxSortedList: []common.Hash{ + {3}, {2}, {1}, }, }, - } - - processWorkerAddTxTestCases(t, worker, addTxsTC) - - // Change counters fpr tx:0x03/ef:9.61 - counters := state.ZKCounters{CumulativeGasUsed: 6, UsedKeccakHashes: 6, UsedPoseidonHashes: 6, UsedPoseidonPaddings: 6, UsedMemAligns: 6, UsedArithmetics: 6, UsedBinaries: 6, UsedSteps: 6} - worker.UpdateTx(common.Hash{3}, common.Address{3}, counters) - - addTxsTC = []workerAddTxTestCase{ { - name: "Adding from:0x04, tx:0x04/ef:100", from: common.Address{4}, txHash: common.Hash{4}, nonce: 1, - benefit: 10000, cost: new(big.Int).SetInt64(5), + name: "Adding from:0x04, tx:0x04/gp:100", from: common.Address{4}, txHash: common.Hash{4}, nonce: 1, gasPrice: new(big.Int).SetInt64(100), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 1, UsedKeccakHashes: 1, UsedPoseidonHashes: 1, UsedPoseidonPaddings: 1, UsedMemAligns: 1, UsedArithmetics: 1, UsedBinaries: 1, UsedSteps: 1}, usedBytes: 1, - expectedEfficiencyList: []common.Hash{ - {4}, {1}, {3}, {2}, + expectedTxSortedList: []common.Hash{ + {4}, {3}, {2}, {1}, }, }, } - processWorkerAddTxTestCases(t, worker, addTxsTC) + processWorkerAddTxTestCases(ctx, t, worker, addTxsTC) } func TestWorkerGetBestTx(t *testing.T) { var nilErr error - // Init ZKEVM resourceCostWeight values - rcWeight := batchResourceWeights{} - rcWeight.WeightCumulativeGasUsed = 1 - rcWeight.WeightArithmetics = 1 - rcWeight.WeightBinaries = 1 - rcWeight.WeightKeccakHashes = 1 - rcWeight.WeightMemAligns = 1 - rcWeight.WeightPoseidonHashes = 1 - rcWeight.WeightPoseidonPaddings = 1 - rcWeight.WeightSteps = 1 - rcWeight.WeightBatchBytesSize = 2 - - // Init ZKEVM resourceCostMax values - rcMax := batchConstraints{} - rcMax.MaxCumulativeGasUsed = 10 - rcMax.MaxArithmetics = 10 - rcMax.MaxBinaries = 10 - rcMax.MaxKeccakHashes = 10 - rcMax.MaxMemAligns = 10 - rcMax.MaxPoseidonHashes = 10 - rcMax.MaxPoseidonPaddings = 10 - rcMax.MaxSteps = 10 - rcMax.MaxBatchBytesSize = 10 - rc := state.BatchResources{ ZKCounters: state.ZKCounters{CumulativeGasUsed: 10, UsedKeccakHashes: 10, UsedPoseidonHashes: 10, UsedPoseidonPaddings: 10, UsedMemAligns: 10, UsedArithmetics: 10, UsedBinaries: 10, UsedSteps: 10}, Bytes: 10, } stateMock := NewStateMock(t) - worker := initWorker(stateMock, rcMax, rcWeight) + worker := initWorker(stateMock) ctx := context.Background() @@ -238,44 +164,44 @@ func TestWorkerGetBestTx(t *testing.T) { addTxsTC := []workerAddTxTestCase{ { - name: "Adding from:0x01, tx:0x01/ef:10", from: common.Address{1}, txHash: common.Hash{1}, nonce: 1, - benefit: 1000, cost: new(big.Int).SetInt64(5), + name: "Adding from:0x01, tx:0x01/gp:10", from: common.Address{1}, txHash: common.Hash{1}, nonce: 1, gasPrice: new(big.Int).SetInt64(10), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 1, UsedKeccakHashes: 1, UsedPoseidonHashes: 1, UsedPoseidonPaddings: 1, UsedMemAligns: 1, UsedArithmetics: 1, UsedBinaries: 1, UsedSteps: 1}, usedBytes: 1, - expectedEfficiencyList: []common.Hash{ + expectedTxSortedList: []common.Hash{ {1}, }, }, { - name: "Adding from:0x02, tx:0x02/ef:12", from: common.Address{2}, txHash: common.Hash{2}, nonce: 1, - benefit: 6000, cost: new(big.Int).SetInt64(5), + name: "Adding from:0x02, tx:0x02/gp:12", from: common.Address{2}, txHash: common.Hash{2}, nonce: 1, gasPrice: new(big.Int).SetInt64(12), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 5, UsedKeccakHashes: 5, UsedPoseidonHashes: 5, UsedPoseidonPaddings: 5, UsedMemAligns: 5, UsedArithmetics: 5, UsedBinaries: 5, UsedSteps: 5}, usedBytes: 5, - expectedEfficiencyList: []common.Hash{ + expectedTxSortedList: []common.Hash{ {2}, {1}, }, }, { - name: "Readding from:0x03, tx:0x03/ef:25", from: common.Address{3}, txHash: common.Hash{3}, nonce: 1, - benefit: 5000, cost: new(big.Int).SetInt64(5), + name: "Readding from:0x03, tx:0x03/gp:25", from: common.Address{3}, txHash: common.Hash{3}, nonce: 1, gasPrice: new(big.Int).SetInt64(25), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 2, UsedKeccakHashes: 2, UsedPoseidonHashes: 2, UsedPoseidonPaddings: 2, UsedMemAligns: 2, UsedArithmetics: 2, UsedBinaries: 2, UsedSteps: 2}, usedBytes: 2, - expectedEfficiencyList: []common.Hash{ + expectedTxSortedList: []common.Hash{ {3}, {2}, {1}, }, }, { - name: "Adding from:0x04, tx:0x04/ef:100", from: common.Address{4}, txHash: common.Hash{4}, nonce: 1, - benefit: 40000, cost: new(big.Int).SetInt64(5), + name: "Adding from:0x04, tx:0x04/gp:100", from: common.Address{4}, txHash: common.Hash{4}, nonce: 1, gasPrice: new(big.Int).SetInt64(100), + cost: new(big.Int).SetInt64(5), counters: state.ZKCounters{CumulativeGasUsed: 4, UsedKeccakHashes: 4, UsedPoseidonHashes: 4, UsedPoseidonPaddings: 4, UsedMemAligns: 4, UsedArithmetics: 4, UsedBinaries: 4, UsedSteps: 4}, usedBytes: 4, - expectedEfficiencyList: []common.Hash{ + expectedTxSortedList: []common.Hash{ {4}, {3}, {2}, {1}, }, }, } - processWorkerAddTxTestCases(t, worker, addTxsTC) + processWorkerAddTxTestCases(ctx, t, worker, addTxsTC) expectedGetBestTx := []common.Hash{{4}, {3}, {1}} ct := 0 @@ -306,7 +232,7 @@ func TestWorkerGetBestTx(t *testing.T) { } } -func initWorker(stateMock *StateMock, rcMax batchConstraints, rcWeigth batchResourceWeights) *Worker { - worker := NewWorker(workerCfg, stateMock, rcMax, rcWeigth) +func initWorker(stateMock *StateMock) *Worker { + worker := NewWorker(stateMock) return worker } diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index 1fb57cb65b..d1ed26753d 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -69,15 +69,6 @@ MaxMemAligns = 236585 MaxArithmetics = 236585 MaxBinaries = 473170 MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -95,8 +86,6 @@ MaxTxLifetime = "3h" [Sequencer.DBManager] PoolRetrievalInterval = "500ms" L2ReorgRetrievalInterval = "5s" - [Sequencer.Worker] - ResourceCostMultiplier = 1000 [Sequencer.EffectiveGasPrice] MaxBreakEvenGasPriceDeviationPercentage = 10 L1GasPriceFactor = 0.25 diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index d5133f7b47..b1eb35e044 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -70,15 +70,6 @@ MaxMemAligns = 236585 MaxArithmetics = 236585 MaxBinaries = 473170 MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -96,8 +87,6 @@ MaxTxLifetime = "3h" [Sequencer.DBManager] PoolRetrievalInterval = "500ms" L2ReorgRetrievalInterval = "5s" - [Sequencer.Worker] - ResourceCostMultiplier = 1000 [Sequencer.EffectiveGasPrice] MaxBreakEvenGasPriceDeviationPercentage = 10 L1GasPriceFactor = 0.25 From e95c341d4deca50475638fd81dca61805ae77e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Ram=C3=ADrez?= Date: Wed, 9 Aug 2023 15:23:42 +0200 Subject: [PATCH 2/2] update config docs --- docs/config-file/node-config-doc.html | 4 +- docs/config-file/node-config-doc.md | 207 +++----------------------- 2 files changed, 26 insertions(+), 185 deletions(-) diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 55fb39748c..571e5e0bd7 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -20,7 +20,7 @@
"300ms"
 

Default: 100Type: integer

BlocksAmountForTxsToBeDeleted is blocks amount after which txs will be deleted from the pool


Default: "12h0m0s"Type: string

FrequencyToCheckTxsForDelete is frequency with which txs will be checked for deleting


Examples:

"1m"
 
"300ms"
-

Default: 300Type: integer

MaxTxsPerBatch is the maximum amount of transactions in the batch


Default: 120000Type: integer

MaxBatchBytesSize is the maximum batch size in bytes
(subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1)


Default: 30000000Type: integer

MaxCumulativeGasUsed is max gas amount used by batch


Default: 2145Type: integer

MaxKeccakHashes is max keccak hashes used by batch


Default: 252357Type: integer

MaxPoseidonHashes is max poseidon hashes batch can handle


Default: 135191Type: integer

MaxPoseidonPaddings is max poseidon paddings batch can handle


Default: 236585Type: integer

MaxMemAligns is max mem aligns batch can handle


Default: 236585Type: integer

MaxArithmetics is max arithmetics batch can handle


Default: 473170Type: integer

MaxBinaries is max binaries batch can handle


Default: 7570538Type: integer

MaxSteps is max steps batch can handle


Default: 1Type: integer

WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource


Default: 1Type: integer

WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource


Default: 1Type: integer

WeightKeccakHashes is the cost weight for the KeccakHashes batch resource


Default: 1Type: integer

WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource


Default: 1Type: integer

WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource


Default: 1Type: integer

WeightMemAligns is the cost weight for the MemAligns batch resource


Default: 1Type: integer

WeightArithmetics is the cost weight for the Arithmetics batch resource


Default: 1Type: integer

WeightBinaries is the cost weight for the Binaries batch resource


Default: 1Type: integer

WeightSteps is the cost weight for the Steps batch resource


Default: "10m0s"Type: string

TxLifetimeCheckTimeout is the time the sequencer waits to check txs lifetime


Examples:

"1m"
+

Default: 300Type: integer

MaxTxsPerBatch is the maximum amount of transactions in the batch


Default: 120000Type: integer

MaxBatchBytesSize is the maximum batch size in bytes
(subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1)


Default: 30000000Type: integer

MaxCumulativeGasUsed is max gas amount used by batch


Default: 2145Type: integer

MaxKeccakHashes is max keccak hashes used by batch


Default: 252357Type: integer

MaxPoseidonHashes is max poseidon hashes batch can handle


Default: 135191Type: integer

MaxPoseidonPaddings is max poseidon paddings batch can handle


Default: 236585Type: integer

MaxMemAligns is max mem aligns batch can handle


Default: 236585Type: integer

MaxArithmetics is max arithmetics batch can handle


Default: 473170Type: integer

MaxBinaries is max binaries batch can handle


Default: 7570538Type: integer

MaxSteps is max steps batch can handle


Default: "10m0s"Type: string

TxLifetimeCheckTimeout is the time the sequencer waits to check txs lifetime


Examples:

"1m"
 
"300ms"
 

Default: "3h0m0s"Type: string

MaxTxLifetime is the time a tx can be in the sequencer memory


Examples:

"1m"
 
"300ms"
@@ -42,7 +42,7 @@
 
"300ms"
 

Default: "5s"Type: string

Examples:

"1m"
 
"300ms"
-

Worker's specific config properties
Default: 1000Type: number

ResourceCostMultiplier is the multiplier for the resource cost


EffectiveGasPrice is the config for the gas price
Default: 10Type: integer

MaxBreakEvenGasPriceDeviationPercentage is the max allowed deviation percentage BreakEvenGasPrice on re-calculation


Default: 0.25Type: number

L1GasPriceFactor is the percentage of the L1 gas price that will be used as the L2 min gas price


Default: 16Type: integer

ByteGasCost is the gas cost per byte


Default: 1Type: number

MarginFactor is the margin factor percentage to be added to the L2 min gas price


Default: falseType: boolean

Enabled is a flag to enable/disable the effective gas price


Default: 0Type: integer

DefaultMinGasPriceAllowed is the default min gas price to suggest
This value is assigned from [Pool].DefaultMinGasPriceAllowed


Configuration of the sequence sender service
Default: "5s"Type: string

WaitPeriodSendSequence is the time the sequencer waits until
trying to send a sequence to L1


Examples:

"1m"
+

EffectiveGasPrice is the config for the gas price
Default: 10Type: integer

MaxBreakEvenGasPriceDeviationPercentage is the max allowed deviation percentage BreakEvenGasPrice on re-calculation


Default: 0.25Type: number

L1GasPriceFactor is the percentage of the L1 gas price that will be used as the L2 min gas price


Default: 16Type: integer

ByteGasCost is the gas cost per byte


Default: 1Type: number

MarginFactor is the margin factor percentage to be added to the L2 min gas price


Default: falseType: boolean

Enabled is a flag to enable/disable the effective gas price


Default: 0Type: integer

DefaultMinGasPriceAllowed is the default min gas price to suggest
This value is assigned from [Pool].DefaultMinGasPriceAllowed


Configuration of the sequence sender service
Default: "5s"Type: string

WaitPeriodSendSequence is the time the sequencer waits until
trying to send a sequence to L1


Examples:

"1m"
 
"300ms"
 

Default: "5s"Type: string

LastBatchVirtualizationTimeMaxWaitPeriod is time since sequences should be sent


Examples:

"1m"
 
"300ms"
diff --git a/docs/config-file/node-config-doc.md b/docs/config-file/node-config-doc.md
index 211cd0e1c7..4d93c64e69 100644
--- a/docs/config-file/node-config-doc.md
+++ b/docs/config-file/node-config-doc.md
@@ -1010,20 +1010,10 @@ TrustedSequencerURL=""
 | - [MaxArithmetics](#Sequencer_MaxArithmetics )                               | No      | integer | No         | -          | MaxArithmetics is max arithmetics batch can handle                                                                                                 |
 | - [MaxBinaries](#Sequencer_MaxBinaries )                                     | No      | integer | No         | -          | MaxBinaries is max binaries batch can handle                                                                                                       |
 | - [MaxSteps](#Sequencer_MaxSteps )                                           | No      | integer | No         | -          | MaxSteps is max steps batch can handle                                                                                                             |
-| - [WeightBatchBytesSize](#Sequencer_WeightBatchBytesSize )                   | No      | integer | No         | -          | WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource                                                                      |
-| - [WeightCumulativeGasUsed](#Sequencer_WeightCumulativeGasUsed )             | No      | integer | No         | -          | WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource                                                                |
-| - [WeightKeccakHashes](#Sequencer_WeightKeccakHashes )                       | No      | integer | No         | -          | WeightKeccakHashes is the cost weight for the KeccakHashes batch resource                                                                          |
-| - [WeightPoseidonHashes](#Sequencer_WeightPoseidonHashes )                   | No      | integer | No         | -          | WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource                                                                      |
-| - [WeightPoseidonPaddings](#Sequencer_WeightPoseidonPaddings )               | No      | integer | No         | -          | WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource                                                                  |
-| - [WeightMemAligns](#Sequencer_WeightMemAligns )                             | No      | integer | No         | -          | WeightMemAligns is the cost weight for the MemAligns batch resource                                                                                |
-| - [WeightArithmetics](#Sequencer_WeightArithmetics )                         | No      | integer | No         | -          | WeightArithmetics is the cost weight for the Arithmetics batch resource                                                                            |
-| - [WeightBinaries](#Sequencer_WeightBinaries )                               | No      | integer | No         | -          | WeightBinaries is the cost weight for the Binaries batch resource                                                                                  |
-| - [WeightSteps](#Sequencer_WeightSteps )                                     | No      | integer | No         | -          | WeightSteps is the cost weight for the Steps batch resource                                                                                        |
 | - [TxLifetimeCheckTimeout](#Sequencer_TxLifetimeCheckTimeout )               | No      | string  | No         | -          | Duration                                                                                                                                           |
 | - [MaxTxLifetime](#Sequencer_MaxTxLifetime )                                 | No      | string  | No         | -          | Duration                                                                                                                                           |
 | - [Finalizer](#Sequencer_Finalizer )                                         | No      | object  | No         | -          | Finalizer's specific config properties                                                                                                             |
 | - [DBManager](#Sequencer_DBManager )                                         | No      | object  | No         | -          | DBManager's specific config properties                                                                                                             |
-| - [Worker](#Sequencer_Worker )                                               | No      | object  | No         | -          | Worker's specific config properties                                                                                                                |
 | - [EffectiveGasPrice](#Sequencer_EffectiveGasPrice )                         | No      | object  | No         | -          | EffectiveGasPrice is the config for the gas price                                                                                                  |
 
 ### 10.1. `Sequencer.WaitPeriodPoolIsEmpty`
@@ -1234,133 +1224,7 @@ MaxBinaries=473170
 MaxSteps=7570538
 ```
 
-### 10.14. `Sequencer.WeightBatchBytesSize`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightBatchBytesSize=1
-```
-
-### 10.15. `Sequencer.WeightCumulativeGasUsed`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightCumulativeGasUsed=1
-```
-
-### 10.16. `Sequencer.WeightKeccakHashes`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightKeccakHashes is the cost weight for the KeccakHashes batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightKeccakHashes=1
-```
-
-### 10.17. `Sequencer.WeightPoseidonHashes`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightPoseidonHashes=1
-```
-
-### 10.18. `Sequencer.WeightPoseidonPaddings`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightPoseidonPaddings=1
-```
-
-### 10.19. `Sequencer.WeightMemAligns`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightMemAligns is the cost weight for the MemAligns batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightMemAligns=1
-```
-
-### 10.20. `Sequencer.WeightArithmetics`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightArithmetics is the cost weight for the Arithmetics batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightArithmetics=1
-```
-
-### 10.21. `Sequencer.WeightBinaries`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightBinaries is the cost weight for the Binaries batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightBinaries=1
-```
-
-### 10.22. `Sequencer.WeightSteps`
-
-**Type:** : `integer`
-
-**Default:** `1`
-
-**Description:** WeightSteps is the cost weight for the Steps batch resource
-
-**Example setting the default value** (1):
-```
-[Sequencer]
-WeightSteps=1
-```
-
-### 10.23. `Sequencer.TxLifetimeCheckTimeout`
+### 10.14. `Sequencer.TxLifetimeCheckTimeout`
 
 **Title:** Duration
 
@@ -1386,7 +1250,7 @@ WeightSteps=1
 TxLifetimeCheckTimeout="10m0s"
 ```
 
-### 10.24. `Sequencer.MaxTxLifetime`
+### 10.15. `Sequencer.MaxTxLifetime`
 
 **Title:** Duration
 
@@ -1412,7 +1276,7 @@ TxLifetimeCheckTimeout="10m0s"
 MaxTxLifetime="3h0m0s"
 ```
 
-### 10.25. `[Sequencer.Finalizer]`
+### 10.16. `[Sequencer.Finalizer]`
 
 **Type:** : `object`
 **Description:** Finalizer's specific config properties
@@ -1431,7 +1295,7 @@ MaxTxLifetime="3h0m0s"
 | - [TimestampResolution](#Sequencer_Finalizer_TimestampResolution )                                                             | No      | string  | No         | -          | Duration                                                                                                                                                                                                       |
 | - [StopSequencerOnBatchNum](#Sequencer_Finalizer_StopSequencerOnBatchNum )                                                     | No      | integer | No         | -          | StopSequencerOnBatchNum specifies the batch number where the Sequencer will stop to process more transactions and generate new batches. The Sequencer will halt after it closes the batch equal to this number |
 
-#### 10.25.1. `Sequencer.Finalizer.GERDeadlineTimeout`
+#### 10.16.1. `Sequencer.Finalizer.GERDeadlineTimeout`
 
 **Title:** Duration
 
@@ -1457,7 +1321,7 @@ MaxTxLifetime="3h0m0s"
 GERDeadlineTimeout="5s"
 ```
 
-#### 10.25.2. `Sequencer.Finalizer.ForcedBatchDeadlineTimeout`
+#### 10.16.2. `Sequencer.Finalizer.ForcedBatchDeadlineTimeout`
 
 **Title:** Duration
 
@@ -1483,7 +1347,7 @@ GERDeadlineTimeout="5s"
 ForcedBatchDeadlineTimeout="1m0s"
 ```
 
-#### 10.25.3. `Sequencer.Finalizer.SleepDuration`
+#### 10.16.3. `Sequencer.Finalizer.SleepDuration`
 
 **Title:** Duration
 
@@ -1509,7 +1373,7 @@ ForcedBatchDeadlineTimeout="1m0s"
 SleepDuration="100ms"
 ```
 
-#### 10.25.4. `Sequencer.Finalizer.ResourcePercentageToCloseBatch`
+#### 10.16.4. `Sequencer.Finalizer.ResourcePercentageToCloseBatch`
 
 **Type:** : `integer`
 
@@ -1523,7 +1387,7 @@ SleepDuration="100ms"
 ResourcePercentageToCloseBatch=10
 ```
 
-#### 10.25.5. `Sequencer.Finalizer.GERFinalityNumberOfBlocks`
+#### 10.16.5. `Sequencer.Finalizer.GERFinalityNumberOfBlocks`
 
 **Type:** : `integer`
 
@@ -1537,7 +1401,7 @@ ResourcePercentageToCloseBatch=10
 GERFinalityNumberOfBlocks=64
 ```
 
-#### 10.25.6. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingL1Timeout`
+#### 10.16.6. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingL1Timeout`
 
 **Title:** Duration
 
@@ -1563,7 +1427,7 @@ GERFinalityNumberOfBlocks=64
 ClosingSignalsManagerWaitForCheckingL1Timeout="10s"
 ```
 
-#### 10.25.7. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingGER`
+#### 10.16.7. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingGER`
 
 **Title:** Duration
 
@@ -1589,7 +1453,7 @@ ClosingSignalsManagerWaitForCheckingL1Timeout="10s"
 ClosingSignalsManagerWaitForCheckingGER="10s"
 ```
 
-#### 10.25.8. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingForcedBatches`
+#### 10.16.8. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingForcedBatches`
 
 **Title:** Duration
 
@@ -1615,7 +1479,7 @@ ClosingSignalsManagerWaitForCheckingGER="10s"
 ClosingSignalsManagerWaitForCheckingForcedBatches="10s"
 ```
 
-#### 10.25.9. `Sequencer.Finalizer.ForcedBatchesFinalityNumberOfBlocks`
+#### 10.16.9. `Sequencer.Finalizer.ForcedBatchesFinalityNumberOfBlocks`
 
 **Type:** : `integer`
 
@@ -1629,7 +1493,7 @@ ClosingSignalsManagerWaitForCheckingForcedBatches="10s"
 ForcedBatchesFinalityNumberOfBlocks=64
 ```
 
-#### 10.25.10. `Sequencer.Finalizer.TimestampResolution`
+#### 10.16.10. `Sequencer.Finalizer.TimestampResolution`
 
 **Title:** Duration
 
@@ -1655,7 +1519,7 @@ ForcedBatchesFinalityNumberOfBlocks=64
 TimestampResolution="10s"
 ```
 
-#### 10.25.11. `Sequencer.Finalizer.StopSequencerOnBatchNum`
+#### 10.16.11. `Sequencer.Finalizer.StopSequencerOnBatchNum`
 
 **Type:** : `integer`
 
@@ -1669,7 +1533,7 @@ TimestampResolution="10s"
 StopSequencerOnBatchNum=0
 ```
 
-### 10.26. `[Sequencer.DBManager]`
+### 10.17. `[Sequencer.DBManager]`
 
 **Type:** : `object`
 **Description:** DBManager's specific config properties
@@ -1679,7 +1543,7 @@ StopSequencerOnBatchNum=0
 | - [PoolRetrievalInterval](#Sequencer_DBManager_PoolRetrievalInterval )       | No      | string | No         | -          | Duration          |
 | - [L2ReorgRetrievalInterval](#Sequencer_DBManager_L2ReorgRetrievalInterval ) | No      | string | No         | -          | Duration          |
 
-#### 10.26.1. `Sequencer.DBManager.PoolRetrievalInterval`
+#### 10.17.1. `Sequencer.DBManager.PoolRetrievalInterval`
 
 **Title:** Duration
 
@@ -1703,7 +1567,7 @@ StopSequencerOnBatchNum=0
 PoolRetrievalInterval="500ms"
 ```
 
-#### 10.26.2. `Sequencer.DBManager.L2ReorgRetrievalInterval`
+#### 10.17.2. `Sequencer.DBManager.L2ReorgRetrievalInterval`
 
 **Title:** Duration
 
@@ -1727,30 +1591,7 @@ PoolRetrievalInterval="500ms"
 L2ReorgRetrievalInterval="5s"
 ```
 
-### 10.27. `[Sequencer.Worker]`
-
-**Type:** : `object`
-**Description:** Worker's specific config properties
-
-| Property                                                              | Pattern | Type   | Deprecated | Definition | Title/Description                                              |
-| --------------------------------------------------------------------- | ------- | ------ | ---------- | ---------- | -------------------------------------------------------------- |
-| - [ResourceCostMultiplier](#Sequencer_Worker_ResourceCostMultiplier ) | No      | number | No         | -          | ResourceCostMultiplier is the multiplier for the resource cost |
-
-#### 10.27.1. `Sequencer.Worker.ResourceCostMultiplier`
-
-**Type:** : `number`
-
-**Default:** `1000`
-
-**Description:** ResourceCostMultiplier is the multiplier for the resource cost
-
-**Example setting the default value** (1000):
-```
-[Sequencer.Worker]
-ResourceCostMultiplier=1000
-```
-
-### 10.28. `[Sequencer.EffectiveGasPrice]`
+### 10.18. `[Sequencer.EffectiveGasPrice]`
 
 **Type:** : `object`
 **Description:** EffectiveGasPrice is the config for the gas price
@@ -1764,7 +1605,7 @@ ResourceCostMultiplier=1000
 | - [Enabled](#Sequencer_EffectiveGasPrice_Enabled )                                                                 | No      | boolean | No         | -          | Enabled is a flag to enable/disable the effective gas price                                                                         |
 | - [DefaultMinGasPriceAllowed](#Sequencer_EffectiveGasPrice_DefaultMinGasPriceAllowed )                             | No      | integer | No         | -          | DefaultMinGasPriceAllowed is the default min gas price to suggest
This value is assigned from [Pool].DefaultMinGasPriceAllowed | -#### 10.28.1. `Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage` +#### 10.18.1. `Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage` **Type:** : `integer` @@ -1778,7 +1619,7 @@ ResourceCostMultiplier=1000 MaxBreakEvenGasPriceDeviationPercentage=10 ``` -#### 10.28.2. `Sequencer.EffectiveGasPrice.L1GasPriceFactor` +#### 10.18.2. `Sequencer.EffectiveGasPrice.L1GasPriceFactor` **Type:** : `number` @@ -1792,7 +1633,7 @@ MaxBreakEvenGasPriceDeviationPercentage=10 L1GasPriceFactor=0.25 ``` -#### 10.28.3. `Sequencer.EffectiveGasPrice.ByteGasCost` +#### 10.18.3. `Sequencer.EffectiveGasPrice.ByteGasCost` **Type:** : `integer` @@ -1806,7 +1647,7 @@ L1GasPriceFactor=0.25 ByteGasCost=16 ``` -#### 10.28.4. `Sequencer.EffectiveGasPrice.MarginFactor` +#### 10.18.4. `Sequencer.EffectiveGasPrice.MarginFactor` **Type:** : `number` @@ -1820,7 +1661,7 @@ ByteGasCost=16 MarginFactor=1 ``` -#### 10.28.5. `Sequencer.EffectiveGasPrice.Enabled` +#### 10.18.5. `Sequencer.EffectiveGasPrice.Enabled` **Type:** : `boolean` @@ -1834,7 +1675,7 @@ MarginFactor=1 Enabled=false ``` -#### 10.28.6. `Sequencer.EffectiveGasPrice.DefaultMinGasPriceAllowed` +#### 10.18.6. `Sequencer.EffectiveGasPrice.DefaultMinGasPriceAllowed` **Type:** : `integer`