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

Refactor sequencer state interfaces #2002

Merged
merged 2 commits into from
Apr 12, 2023
Merged
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
4 changes: 2 additions & 2 deletions sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
type dbManager struct {
cfg DBManagerCfg
txPool txPool
state dbManagerStateInterface
state stateInterface
worker workerInterface
txsStore TxsStore
l2ReorgCh chan L2ReorgEvent
Expand All @@ -43,7 +43,7 @@ type ClosingBatchParameters struct {
Txs []types.Transaction
}

func newDBManager(ctx context.Context, config DBManagerCfg, txPool txPool, state dbManagerStateInterface, worker *Worker, closingSignalCh ClosingSignalCh, txsStore TxsStore, batchConstraints batchConstraints) *dbManager {
func newDBManager(ctx context.Context, config DBManagerCfg, txPool txPool, state stateInterface, worker *Worker, closingSignalCh ClosingSignalCh, txsStore TxsStore, batchConstraints batchConstraints) *dbManager {
numberOfReorgs, err := state.CountReorgs(ctx, nil)
if err != nil {
log.Error("failed to get number of reorgs: %v", err)
Expand Down
30 changes: 0 additions & 30 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,6 @@ type dbManagerInterface interface {
FlushMerkleTree(ctx context.Context) error
}

type dbManagerStateInterface interface {
BeginStateTransaction(ctx context.Context) (pgx.Tx, error)
OpenBatch(ctx context.Context, processingContext state.ProcessingContext, dbTx pgx.Tx) error
GetLastVirtualBatchNum(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetLastNBatches(ctx context.Context, numBatches uint, dbTx pgx.Tx) ([]*state.Batch, error)
StoreTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, coinbase common.Address, timestamp uint64, dbTx pgx.Tx) error
CloseBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error
IsBatchClosed(ctx context.Context, batchNum uint64, dbTx pgx.Tx) (bool, error)
GetTransactionsByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (txs []types.Transaction, err error)
GetLastClosedBatch(ctx context.Context, dbTx pgx.Tx) (*state.Batch, error)
GetLastBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetLastBatch(ctx context.Context, dbTx pgx.Tx) (*state.Batch, error)
GetLatestGlobalExitRoot(ctx context.Context, maxBlockNumber uint64, dbTx pgx.Tx) (state.GlobalExitRoot, time.Time, error)
GetLastStateRoot(ctx context.Context, dbTx pgx.Tx) (common.Hash, error)
GetLastL2BlockHeader(ctx context.Context, dbTx pgx.Tx) (*types.Header, error)
GetLastBlock(ctx context.Context, dbTx pgx.Tx) (*state.Block, error)
ExecuteBatch(ctx context.Context, batch state.Batch, updateMerkleTree bool, dbTx pgx.Tx) (*pb.ProcessBatchResponse, error)
GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error)
UpdateBatchL2Data(ctx context.Context, batchNumber uint64, batchL2Data []byte, dbTx pgx.Tx) error
GetForcedBatch(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) (*state.ForcedBatch, error)
ProcessSequencerBatch(ctx context.Context, batchNumber uint64, batchL2Data []byte, caller metrics.CallerLabel, dbTx pgx.Tx) (*state.ProcessBatchResponse, error)
GetForcedBatchesSince(ctx context.Context, forcedBatchNumber, maxBlockNumber uint64, dbTx pgx.Tx) ([]*state.ForcedBatch, error)
GetLastTrustedForcedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetBalanceByStateRoot(ctx context.Context, address common.Address, root common.Hash) (*big.Int, error)
GetLatestVirtualBatchTimestamp(ctx context.Context, dbTx pgx.Tx) (time.Time, error)
CountReorgs(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetLatestGer(ctx context.Context, maxBlockNumber uint64) (state.GlobalExitRoot, time.Time, error)
FlushMerkleTree(ctx context.Context) error
}

type ethTxManager interface {
Add(ctx context.Context, owner, id string, from common.Address, to *common.Address, value *big.Int, data []byte, dbTx pgx.Tx) error
Result(ctx context.Context, owner, id string, dbTx pgx.Tx) (ethtxmanager.MonitoredTxResult, error)
Expand Down