Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use gas_price index/order/limit when load pending tx from pool #3510

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ StateConsistencyCheckInterval = "5s"
Version = 0
WriteTimeout = "5s"
Enabled = false
LoadPendingTxsLimit = 0

[SequenceSender]
WaitPeriodSendSequence = "5s"
Expand Down
5 changes: 5 additions & 0 deletions db/migrations/pool/0014.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up
CREATE INDEX IF NOT EXISTS idx_transaction_gas_price ON pool.transaction (gas_price);

-- +migrate Down
DROP INDEX IF EXISTS pool.idx_transaction_gas_price;
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</pre></div> </div><div id=Sequencer_Finalizer_Metrics_Interval_ex2 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;300ms&quot;</span>
</pre></div> </div> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><!-- None --><a href=#Sequencer.Finalizer.Metrics.EnableLog onclick="anchorLink('Sequencer.Finalizer.Metrics.EnableLog')">Sequencer.Finalizer.Metrics.EnableLog=</a> </div> <span class="badge badge-success default-value">Default: true</span><span class="badge badge-dark value-type">Type: boolean</span><br> <span class=description><p>EnableLog is a flag to enable/disable metrics logs</p> </span> <hr> </div> </div> </div> </div> </div> </div> </div> </div> <div class=accordion id=accordionSequencer_StreamServer> <div class=card> <div class=card-header id=headingSequencer_StreamServer> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#Sequencer_StreamServer aria-expanded aria-controls=Sequencer_StreamServer onclick="setAnchor('#Sequencer_StreamServer')"><span class=property-name> <div class=breadcrumbs>[<a href=#Sequencer onclick="anchorLink('Sequencer')">Sequencer</a> . <a href=#Sequencer_StreamServer onclick="anchorLink('Sequencer_StreamServer')">StreamServer</a>] </div></span></button> </h2> StreamServerCfg is the config for the stream server </div> <div id=Sequencer_StreamServer class="collapse property-definition-div" aria-labelledby=headingSequencer_StreamServer data-parent=#accordionSequencer_StreamServer> <div class="card-body pl-5"> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Port onclick="anchorLink('Sequencer.StreamServer.Port')">Sequencer.StreamServer.Port=</a> </div> <span class="badge badge-success default-value">Default: 0</span><span class="badge badge-dark value-type">Type: integer</span><br> <span class=description><p>Port to listen on</p> </span> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Filename onclick="anchorLink('Sequencer.StreamServer.Filename')">Sequencer.StreamServer.Filename=</a> </div> <span class="badge badge-success default-value">Default: ""</span><span class="badge badge-dark value-type">Type: string</span><br> <span class=description><p>Filename of the binary data file</p> </span> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Version onclick="anchorLink('Sequencer.StreamServer.Version')">Sequencer.StreamServer.Version=</a> </div> <span class="badge badge-success default-value">Default: 0</span><span class="badge badge-dark value-type">Type: integer</span><br> <span class=description><p>Version of the binary data file</p> </span> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.ChainID onclick="anchorLink('Sequencer.StreamServer.ChainID')">Sequencer.StreamServer.ChainID=</a> </div> <span class="badge badge-success default-value">Default: 0</span><span class="badge badge-dark value-type">Type: integer</span><br> <span class=description><p>ChainID is the chain ID</p> </span> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Enabled onclick="anchorLink('Sequencer.StreamServer.Enabled')">Sequencer.StreamServer.Enabled=</a> </div> <span class="badge badge-success default-value">Default: false</span><span class="badge badge-dark value-type">Type: boolean</span><br> <span class=description><p>Enabled is a flag to enable/disable the data streamer</p> </span> <hr> <div class=accordion id=accordionSequencer_StreamServer_Log> <div class=card> <div class=card-header id=headingSequencer_StreamServer_Log> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#Sequencer_StreamServer_Log aria-expanded aria-controls=Sequencer_StreamServer_Log onclick="setAnchor('#Sequencer_StreamServer_Log')"><span class=property-name> <div class=breadcrumbs>[<a href=#Sequencer onclick="anchorLink('Sequencer')">Sequencer</a> . <a href=#Sequencer_StreamServer onclick="anchorLink('Sequencer_StreamServer')">StreamServer</a> . <a href=#Sequencer_StreamServer_Log onclick="anchorLink('Sequencer_StreamServer_Log')">Log</a>] </div></span></button> </h2> Log is the log configuration </div> <div id=Sequencer_StreamServer_Log class="collapse property-definition-div" aria-labelledby=headingSequencer_StreamServer_Log data-parent=#accordionSequencer_StreamServer_Log> <div class="card-body pl-5"> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Log.Environment onclick="anchorLink('Sequencer.StreamServer.Log.Environment')">Sequencer.StreamServer.Log.Environment=</a> </div> <span class="badge badge-success default-value">Default: ""</span><span class="badge badge-dark value-type">Type: enum (of string)</span><br> <div class=enum-value id=Sequencer_StreamServer_Log_Environment_enum> <h4>Must be one of:</h4> <ul class=list-group><li class="list-group-item enum-item">"production"</li><li class="list-group-item enum-item">"development"</li></ul> </div> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Log.Level onclick="anchorLink('Sequencer.StreamServer.Log.Level')">Sequencer.StreamServer.Log.Level=</a> </div> <span class="badge badge-success default-value">Default: ""</span><span class="badge badge-dark value-type">Type: enum (of string)</span><br> <div class=enum-value id=Sequencer_StreamServer_Log_Level_enum> <h4>Must be one of:</h4> <ul class=list-group><li class="list-group-item enum-item">"debug"</li><li class="list-group-item enum-item">"info"</li><li class="list-group-item enum-item">"warn"</li><li class="list-group-item enum-item">"error"</li><li class="list-group-item enum-item">"dpanic"</li><li class="list-group-item enum-item">"panic"</li><li class="list-group-item enum-item">"fatal"</li></ul> </div> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.Log.Outputs onclick="anchorLink('Sequencer.StreamServer.Log.Outputs')">Sequencer.StreamServer.Log.Outputs=</a> </div><span class="badge badge-dark value-type">Type: array of string</span><br> <h4>Each item of this array must be:</h4> <div class=card> <div class="card-body items-definition" id=Sequencer_StreamServer_Log_Outputs_items> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><!-- None --><!-- None --><a href="#Sequencer.StreamServer.Log.Outputs.Outputs items" onclick="anchorLink('Sequencer.StreamServer.Log.Outputs.Outputs items')">Sequencer.StreamServer.Log.Outputs.Outputs items=</a> </div><span class="badge badge-dark value-type">Type: string</span><br> </div> </div> <hr> </div> </div> </div> </div> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.UpgradeEtrogBatchNumber onclick="anchorLink('Sequencer.StreamServer.UpgradeEtrogBatchNumber')">Sequencer.StreamServer.UpgradeEtrogBatchNumber=</a> </div> <span class="badge badge-success default-value">Default: 0</span><span class="badge badge-dark value-type">Type: integer</span><br> <span class=description><p>UpgradeEtrogBatchNumber is the batch number of the upgrade etrog</p> </span> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><!-- None --><a href=#Sequencer.StreamServer.WriteTimeout onclick="anchorLink('Sequencer.StreamServer.WriteTimeout')">Sequencer.StreamServer.WriteTimeout=</a> </div> <span class="badge badge-success default-value">Default: "5s"</span><span class="badge badge-dark value-type">Type: string</span><br> <span class=description><p>WriteTimeout is the TCP write timeout when sending data to a datastream client</p> </span> <br> <div class="badge badge-secondary">Examples:</div> <br><div id=Sequencer_StreamServer_WriteTimeout_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;1m&quot;</span>
</pre></div> </div><div id=Sequencer_StreamServer_WriteTimeout_ex2 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;300ms&quot;</span>
</pre></div> </div> <hr> </div> </div> </div> </div> </div> </div> </div> </div> <div class=accordion id=accordionSequenceSender> <div class=card> <div class=card-header id=headingSequenceSender> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#SequenceSender aria-expanded aria-controls=SequenceSender onclick="setAnchor('#SequenceSender')"><span class=property-name> <div class=breadcrumbs>[<a href=#SequenceSender onclick="anchorLink('SequenceSender')">SequenceSender</a>] </div></span></button> </h2> Configuration of the sequence sender service </div> <div id=SequenceSender class="collapse property-definition-div" aria-labelledby=headingSequenceSender data-parent=#accordionSequenceSender> <div class="card-body pl-5"> <div class=breadcrumbs> <!-- None --><!-- None --><a href=#SequenceSender.WaitPeriodSendSequence onclick="anchorLink('SequenceSender.WaitPeriodSendSequence')">SequenceSender.WaitPeriodSendSequence=</a> </div> <span class="badge badge-success default-value">Default: "5s"</span><span class="badge badge-dark value-type">Type: string</span><br> <span class=description><p>WaitPeriodSendSequence is the time the sequencer waits until<br> trying to send a sequence to L1</p> </span> <br> <div class="badge badge-secondary">Examples:</div> <br><div id=SequenceSender_WaitPeriodSendSequence_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;1m&quot;</span>
</pre></div> </div> <hr> </div> </div> </div> </div> <div class=breadcrumbs> <!-- None --><!-- None --><a href=#Sequencer.LoadPendingTxsLimit onclick="anchorLink('Sequencer.LoadPendingTxsLimit')">Sequencer.LoadPendingTxsLimit=</a> </div> <span class="badge badge-success default-value">Default: 0</span><span class="badge badge-dark value-type">Type: integer</span><br> <span class=description><p>LoadPendingTxsLimit is used to limit amount txs from the db</p> </span> <hr> </div> </div> </div> </div> <div class=accordion id=accordionSequenceSender> <div class=card> <div class=card-header id=headingSequenceSender> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#SequenceSender aria-expanded aria-controls=SequenceSender onclick="setAnchor('#SequenceSender')"><span class=property-name> <div class=breadcrumbs>[<a href=#SequenceSender onclick="anchorLink('SequenceSender')">SequenceSender</a>] </div></span></button> </h2> Configuration of the sequence sender service </div> <div id=SequenceSender class="collapse property-definition-div" aria-labelledby=headingSequenceSender data-parent=#accordionSequenceSender> <div class="card-body pl-5"> <div class=breadcrumbs> <!-- None --><!-- None --><a href=#SequenceSender.WaitPeriodSendSequence onclick="anchorLink('SequenceSender.WaitPeriodSendSequence')">SequenceSender.WaitPeriodSendSequence=</a> </div> <span class="badge badge-success default-value">Default: "5s"</span><span class="badge badge-dark value-type">Type: string</span><br> <span class=description><p>WaitPeriodSendSequence is the time the sequencer waits until<br> trying to send a sequence to L1</p> </span> <br> <div class="badge badge-secondary">Examples:</div> <br><div id=SequenceSender_WaitPeriodSendSequence_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;1m&quot;</span>
</pre></div> </div><div id=SequenceSender_WaitPeriodSendSequence_ex2 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;300ms&quot;</span>
</pre></div> </div> <hr> <div class=breadcrumbs> <!-- None --><!-- None --><a href=#SequenceSender.LastBatchVirtualizationTimeMaxWaitPeriod onclick="anchorLink('SequenceSender.LastBatchVirtualizationTimeMaxWaitPeriod')">SequenceSender.LastBatchVirtualizationTimeMaxWaitPeriod=</a> </div> <span class="badge badge-success default-value">Default: "5s"</span><span class="badge badge-dark value-type">Type: string</span><br> <span class=description><p>LastBatchVirtualizationTimeMaxWaitPeriod is time since sequences should be sent</p> </span> <br> <div class="badge badge-secondary">Examples:</div> <br><div id=SequenceSender_LastBatchVirtualizationTimeMaxWaitPeriod_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;1m&quot;</span>
</pre></div> </div><div id=SequenceSender_LastBatchVirtualizationTimeMaxWaitPeriod_ex2 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;300ms&quot;</span>
Expand Down
15 changes: 15 additions & 0 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ CheckLastL2BlockHashOnCloseBatch=true
| - [L2Coinbase](#Sequencer_L2Coinbase ) | No | array of integer | No | - | L2Coinbase defines which address is going to receive the fees. It gets the config value from SequenceSender.L2Coinbase |
| - [Finalizer](#Sequencer_Finalizer ) | No | object | No | - | Finalizer's specific config properties |
| - [StreamServer](#Sequencer_StreamServer ) | No | object | No | - | StreamServerCfg is the config for the stream server |
| - [LoadPendingTxsLimit](#Sequencer_LoadPendingTxsLimit ) | No | integer | No | - | LoadPendingTxsLimit is used to limit amount txs from the db |

### <a name="Sequencer_DeletePoolTxsL1BlockConfirmations"></a>10.1. `Sequencer.DeletePoolTxsL1BlockConfirmations`

Expand Down Expand Up @@ -2666,6 +2667,20 @@ UpgradeEtrogBatchNumber=0
WriteTimeout="5s"
```

### <a name="Sequencer_LoadPendingTxsLimit"></a>10.10. `Sequencer.LoadPendingTxsLimit`

**Type:** : `integer`

**Default:** `0`

**Description:** LoadPendingTxsLimit is used to limit amount txs from the db

**Example setting the default value** (0):
```
[Sequencer]
LoadPendingTxsLimit=0
```

## <a name="SequenceSender"></a>11. `[SequenceSender]`

**Type:** : `object`
Expand Down
5 changes: 5 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,11 @@
"additionalProperties": false,
"type": "object",
"description": "StreamServerCfg is the config for the stream server"
},
"LoadPendingTxsLimit": {
"type": "integer",
"description": "LoadPendingTxsLimit is used to limit amount txs from the db",
"default": 0
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion pool/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type storage interface {
GetPendingTxHashesSince(ctx context.Context, since time.Time) ([]common.Hash, error)
GetTxsByFromAndNonce(ctx context.Context, from common.Address, nonce uint64) ([]Transaction, error)
GetTxsByStatus(ctx context.Context, state TxStatus, limit uint64) ([]Transaction, error)
GetNonWIPPendingTxs(ctx context.Context) ([]Transaction, error)
GetNonWIPPendingTxs(ctx context.Context, limit uint64) ([]Transaction, error)
IsTxPending(ctx context.Context, hash common.Hash) (bool, error)
SetGasPrices(ctx context.Context, l2GasPrice uint64, l1GasPrice uint64) error
DeleteGasPricesHistoryOlderThan(ctx context.Context, date time.Time) error
Expand Down
14 changes: 10 additions & 4 deletions pool/pgpoolstorage/pgpoolstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,22 @@ func (p *PostgresPoolStorage) GetTxsByStatus(ctx context.Context, status pool.Tx
}

// GetNonWIPPendingTxs returns an array of transactions
func (p *PostgresPoolStorage) GetNonWIPPendingTxs(ctx context.Context) ([]pool.Transaction, error) {
func (p *PostgresPoolStorage) GetNonWIPPendingTxs(ctx context.Context, limit uint64) ([]pool.Transaction, error) {
var (
rows pgx.Rows
err error
sql string
)

sql = `SELECT encoded, status, received_at, is_wip, ip, cumulative_gas_used, used_keccak_hashes, used_poseidon_hashes, used_poseidon_paddings, used_mem_aligns,
used_arithmetics, used_binaries, used_steps, used_sha256_hashes, failed_reason, reserved_zkcounters FROM pool.transaction WHERE is_wip IS FALSE and status = $1`
rows, err = p.db.Query(ctx, sql, pool.TxStatusPending)
if limit == 0 {
sql = `SELECT encoded, status, received_at, is_wip, ip, cumulative_gas_used, used_keccak_hashes, used_poseidon_hashes, used_poseidon_paddings, used_mem_aligns,
used_arithmetics, used_binaries, used_steps, used_sha256_hashes, failed_reason, reserved_zkcounters FROM pool.transaction WHERE is_wip IS FALSE and status = $1 ORDER BY gas_price DESC`
rows, err = p.db.Query(ctx, sql, pool.TxStatusPending)
} else {
sql = `SELECT encoded, status, received_at, is_wip, ip, cumulative_gas_used, used_keccak_hashes, used_poseidon_hashes, used_poseidon_paddings, used_mem_aligns,
used_arithmetics, used_binaries, used_steps, used_sha256_hashes, failed_reason, reserved_zkcounters FROM pool.transaction WHERE is_wip IS FALSE and status = $1 ORDER BY gas_price DESC LIMIT $2`
rows, err = p.db.Query(ctx, sql, pool.TxStatusPending, limit)
}

if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ func (p *Pool) GetPendingTxs(ctx context.Context, limit uint64) ([]Transaction,
}

// GetNonWIPPendingTxs from the pool
func (p *Pool) GetNonWIPPendingTxs(ctx context.Context) ([]Transaction, error) {
return p.storage.GetNonWIPPendingTxs(ctx)
func (p *Pool) GetNonWIPPendingTxs(ctx context.Context, limit uint64) ([]Transaction, error) {
return p.storage.GetNonWIPPendingTxs(ctx, limit)
}

// GetSelectedTxs gets selected txs from the pool db
Expand Down
3 changes: 3 additions & 0 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type Config struct {

// StreamServerCfg is the config for the stream server
StreamServer StreamServerCfg `mapstructure:"StreamServer"`

// LoadPendingTxsLimit is used to limit amount txs from the db
LoadPendingTxsLimit uint64 `mapstructure:"LoadPendingTxsLimit"`
}

// StreamServerCfg contains the data streamer's configuration properties
Expand Down
2 changes: 1 addition & 1 deletion sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type txPool interface {
DeleteFailedTransactionsOlderThan(ctx context.Context, date time.Time) error
DeleteTransactionByHash(ctx context.Context, hash common.Hash) error
MarkWIPTxsAsPending(ctx context.Context) error
GetNonWIPPendingTxs(ctx context.Context) ([]pool.Transaction, error)
GetNonWIPPendingTxs(ctx context.Context, limit uint64) ([]pool.Transaction, error)
UpdateTxStatus(ctx context.Context, hash common.Hash, newStatus pool.TxStatus, isWIP bool, failedReason *string) error
GetTxZkCountersByHash(ctx context.Context, hash common.Hash) (*state.ZKCounters, *state.ZKCounters, error)
UpdateTxWIPStatus(ctx context.Context, hash common.Hash, isWIP bool) error
Expand Down
2 changes: 1 addition & 1 deletion sequencer/mock_pool.go

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

2 changes: 1 addition & 1 deletion sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *Sequencer) loadFromPool(ctx context.Context) {
return
}

poolTransactions, err := s.pool.GetNonWIPPendingTxs(ctx)
poolTransactions, err := s.pool.GetNonWIPPendingTxs(ctx, s.cfg.LoadPendingTxsLimit)
if err != nil && err != pool.ErrNotFound {
log.Errorf("error loading txs from pool, error: %v", err)
}
Expand Down