github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/synchronizer/interfaces.go (about)

     1  package synchronizer
     2  
     3  import (
     4  	"context"
     5  	"math/big"
     6  
     7  	"github.com/0xPolygon/supernets2-node/etherman"
     8  	"github.com/0xPolygon/supernets2-node/jsonrpc/types"
     9  	"github.com/0xPolygon/supernets2-node/state"
    10  	"github.com/0xPolygon/supernets2-node/state/metrics"
    11  	"github.com/0xPolygon/supernets2-node/state/runtime/executor/pb"
    12  	"github.com/ethereum/go-ethereum/common"
    13  	ethTypes "github.com/ethereum/go-ethereum/core/types"
    14  	"github.com/jackc/pgx/v4"
    15  )
    16  
    17  // ethermanInterface contains the methods required to interact with ethereum.
    18  type ethermanInterface interface {
    19  	HeaderByNumber(ctx context.Context, number *big.Int) (*ethTypes.Header, error)
    20  	GetRollupInfoByBlockRange(ctx context.Context, fromBlock uint64, toBlock *uint64) ([]etherman.Block, map[common.Hash][]etherman.Order, error)
    21  	EthBlockByNumber(ctx context.Context, blockNumber uint64) (*ethTypes.Block, error)
    22  	GetLatestBatchNumber() (uint64, error)
    23  	GetTrustedSequencerURL() (string, error)
    24  	VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error)
    25  	GetForks(ctx context.Context, genBlockNumber uint64) ([]state.ForkIDInterval, error)
    26  	GetLatestVerifiedBatchNum() (uint64, error)
    27  	GetCurrentDataCommittee() (*etherman.DataCommittee, error)
    28  }
    29  
    30  // stateInterface gathers the methods required to interact with the state.
    31  type stateInterface interface {
    32  	GetLastBlock(ctx context.Context, dbTx pgx.Tx) (*state.Block, error)
    33  	AddGlobalExitRoot(ctx context.Context, exitRoot *state.GlobalExitRoot, dbTx pgx.Tx) error
    34  	AddForcedBatch(ctx context.Context, forcedBatch *state.ForcedBatch, dbTx pgx.Tx) error
    35  	AddBlock(ctx context.Context, block *state.Block, dbTx pgx.Tx) error
    36  	Reset(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) error
    37  	GetPreviousBlock(ctx context.Context, offset uint64, dbTx pgx.Tx) (*state.Block, error)
    38  	GetLastBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
    39  	GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error)
    40  	GetBatchL2DataByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) ([]byte, error)
    41  	ResetTrustedState(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error
    42  	AddVirtualBatch(ctx context.Context, virtualBatch *state.VirtualBatch, dbTx pgx.Tx) error
    43  	GetNextForcedBatches(ctx context.Context, nextForcedBatches int, dbTx pgx.Tx) ([]state.ForcedBatch, error)
    44  	AddVerifiedBatch(ctx context.Context, verifiedBatch *state.VerifiedBatch, dbTx pgx.Tx) error
    45  	ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller metrics.CallerLabel) (common.Hash, error)
    46  	SetGenesis(ctx context.Context, block state.Block, genesis state.Genesis, dbTx pgx.Tx) ([]byte, error)
    47  	OpenBatch(ctx context.Context, processingContext state.ProcessingContext, dbTx pgx.Tx) error
    48  	CloseBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error
    49  	ProcessSequencerBatch(ctx context.Context, batchNumber uint64, batchL2Data []byte, caller metrics.CallerLabel, dbTx pgx.Tx) (*state.ProcessBatchResponse, error)
    50  	StoreTransactions(ctx context.Context, batchNum uint64, processedTxs []*state.ProcessTransactionResponse, dbTx pgx.Tx) error
    51  	GetStateRootByBatchNumber(ctx context.Context, batchNum uint64, dbTx pgx.Tx) (common.Hash, error)
    52  	ExecuteBatch(ctx context.Context, batch state.Batch, updateMerkleTree bool, dbTx pgx.Tx) (*pb.ProcessBatchResponse, error)
    53  	GetLastVerifiedBatch(ctx context.Context, dbTx pgx.Tx) (*state.VerifiedBatch, error)
    54  	GetLastVirtualBatchNum(ctx context.Context, dbTx pgx.Tx) (uint64, error)
    55  	AddSequence(ctx context.Context, sequence state.Sequence, dbTx pgx.Tx) error
    56  	AddAccumulatedInputHash(ctx context.Context, batchNum uint64, accInputHash common.Hash, dbTx pgx.Tx) error
    57  	AddTrustedReorg(ctx context.Context, trustedReorg *state.TrustedReorg, dbTx pgx.Tx) error
    58  	GetReorgedTransactions(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) ([]*ethTypes.Transaction, error)
    59  	ResetForkID(ctx context.Context, batchNumber, forkID uint64, version string, dbTx pgx.Tx) error
    60  	GetForkIDTrustedReorgCount(ctx context.Context, forkID uint64, version string, dbTx pgx.Tx) (uint64, error)
    61  	UpdateForkIDIntervals(intervals []state.ForkIDInterval)
    62  	SetLastBatchInfoSeenOnEthereum(ctx context.Context, lastBatchNumberSeen, lastBatchNumberVerified uint64, dbTx pgx.Tx) error
    63  	SetInitSyncBatch(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error
    64  	BeginStateTransaction(ctx context.Context) (pgx.Tx, error)
    65  }
    66  
    67  type ethTxManager interface {
    68  	Reorg(ctx context.Context, fromBlockNumber uint64, dbTx pgx.Tx) error
    69  }
    70  
    71  type poolInterface interface {
    72  	DeleteReorgedTransactions(ctx context.Context, txs []*ethTypes.Transaction) error
    73  	StoreTx(ctx context.Context, tx ethTypes.Transaction, ip string, isWIP bool) error
    74  }
    75  
    76  type zkEVMClientInterface interface {
    77  	BatchNumber(ctx context.Context) (uint64, error)
    78  	BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error)
    79  }