diff --git a/indexer/db/db.go b/indexer/db/db.go index 38fd5a63b0be7..bf024550ee100 100644 --- a/indexer/db/db.go +++ b/indexer/db/db.go @@ -292,36 +292,6 @@ func (d *Database) AddIndexedL2Block(block *IndexedL2Block) error { }) } -// AddStateBatch inserts the state batches into the known state batches -// database. -func (d *Database) AddStateBatch(batches []StateBatch) error { - const insertStateBatchStatement = ` - INSERT INTO state_batches - (index, root, size, prev_total, extra_data, block_hash) - VALUES - ($1, $2, $3, $4, $5, $6) - ` - - return txn(d.db, func(tx *sql.Tx) error { - for _, sb := range batches { - _, err := tx.Exec( - insertStateBatchStatement, - sb.Index.Uint64(), - sb.Root.String(), - sb.Size.Uint64(), - sb.PrevTotal.Uint64(), - sb.ExtraData, - sb.BlockHash.String(), - ) - if err != nil { - return err - } - } - - return nil - }) -} - // GetDepositsByAddress returns the list of Deposits indexed for the given // address paginated by the given params. func (d *Database) GetDepositsByAddress(address common.Address, page PaginationParam) (*PaginatedDeposits, error) { @@ -398,64 +368,6 @@ func (d *Database) GetDepositsByAddress(address common.Address, page PaginationP }, nil } -// GetWithdrawalBatch returns the StateBatch corresponding to the given -// withdrawal transaction hash. -func (d *Database) GetWithdrawalBatch(hash common.Hash) (*StateBatchJSON, error) { - const selectWithdrawalBatchStatement = ` - SELECT - state_batches.index, state_batches.root, state_batches.size, state_batches.prev_total, state_batches.extra_data, state_batches.block_hash, - l1_blocks.number, l1_blocks.timestamp - FROM state_batches - INNER JOIN l1_blocks ON state_batches.block_hash = l1_blocks.hash - WHERE size + prev_total >= ( - SELECT - number - FROM - withdrawals - INNER JOIN l2_blocks ON withdrawals.block_hash = l2_blocks.hash where tx_hash=$1 - ) ORDER BY "index" LIMIT 1; - ` - - var batch *StateBatchJSON - err := txn(d.db, func(tx *sql.Tx) error { - row := tx.QueryRow(selectWithdrawalBatchStatement, hash.String()) - if row.Err() != nil { - return row.Err() - } - - var index, size, prevTotal, blockNumber, blockTimestamp uint64 - var root, blockHash string - var extraData []byte - err := row.Scan(&index, &root, &size, &prevTotal, &extraData, &blockHash, - &blockNumber, &blockTimestamp) - if err != nil { - if errors.Is(err, sql.ErrNoRows) { - batch = nil - return nil - } - return err - } - - batch = &StateBatchJSON{ - Index: index, - Root: root, - Size: size, - PrevTotal: prevTotal, - ExtraData: extraData, - BlockHash: blockHash, - BlockNumber: blockNumber, - BlockTimestamp: blockTimestamp, - } - - return nil - }) - if err != nil { - return nil, err - } - - return batch, nil -} - // GetWithdrawalsByAddress returns the list of Withdrawals indexed for the given // address paginated by the given params. func (d *Database) GetWithdrawalsByAddress(address common.Address, page PaginationParam) (*PaginatedWithdrawals, error) { @@ -503,11 +415,6 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati return nil, err } - for i := range withdrawals { - batch, _ := d.GetWithdrawalBatch(common.HexToHash(withdrawals[i].TxHash)) - withdrawals[i].Batch = batch - } - const selectWithdrawalCountStatement = ` SELECT count(*) diff --git a/indexer/db/sql.go b/indexer/db/sql.go index 08a9c8547ee6c..b9a7f48c0a93f 100644 --- a/indexer/db/sql.go +++ b/indexer/db/sql.go @@ -51,20 +51,6 @@ CREATE TABLE IF NOT EXISTS l2_tokens ( ) ` -const createStateBatchesTable = ` -CREATE TABLE IF NOT EXISTS state_batches ( - index INTEGER NOT NULL PRIMARY KEY, - root VARCHAR NOT NULL, - size INTEGER NOT NULL, - prev_total INTEGER NOT NULL, - extra_data BYTEA NOT NULL, - block_hash VARCHAR NOT NULL REFERENCES l1_blocks(hash) -); -CREATE INDEX IF NOT EXISTS state_batches_block_hash ON state_batches(block_hash); -CREATE INDEX IF NOT EXISTS state_batches_size ON state_batches(size); -CREATE INDEX IF NOT EXISTS state_batches_prev_total ON state_batches(prev_total); -` - const createWithdrawalsTable = ` CREATE TABLE IF NOT EXISTS withdrawals ( guid VARCHAR PRIMARY KEY NOT NULL, @@ -77,7 +63,6 @@ CREATE TABLE IF NOT EXISTS withdrawals ( log_index INTEGER NOT NULL, block_hash VARCHAR NOT NULL REFERENCES l2_blocks(hash), tx_hash VARCHAR NOT NULL, - state_batch INTEGER REFERENCES state_batches(index) ) ` @@ -127,7 +112,6 @@ var schema = []string{ createL2BlocksTable, createL1TokensTable, createL2TokensTable, - createStateBatchesTable, insertETHL1Token, insertETHL2Token, createDepositsTable, diff --git a/indexer/db/state_batch.go b/indexer/db/state_batch.go deleted file mode 100644 index c8d820a4a1c2a..0000000000000 --- a/indexer/db/state_batch.go +++ /dev/null @@ -1,30 +0,0 @@ -package db - -import ( - "math/big" - - "github.com/ethereum/go-ethereum/common" -) - -// StateBatch is the state batch containing merkle root of the withdrawals -// periodically written to L1. -type StateBatch struct { - Index *big.Int - Root common.Hash - Size *big.Int - PrevTotal *big.Int - ExtraData []byte - BlockHash common.Hash -} - -// StateBatchJSON contains StateBatch data suitable for JSON serialization. -type StateBatchJSON struct { - Index uint64 `json:"index"` - Root string `json:"root"` - Size uint64 `json:"size"` - PrevTotal uint64 `json:"prevTotal"` - ExtraData []byte `json:"extraData"` - BlockHash string `json:"blockHash"` - BlockNumber uint64 `json:"blockNumber"` - BlockTimestamp uint64 `json:"blockTimestamp"` -} diff --git a/indexer/db/withdrawal.go b/indexer/db/withdrawal.go index 032b1d77101f1..d252b667ab21f 100644 --- a/indexer/db/withdrawal.go +++ b/indexer/db/withdrawal.go @@ -26,16 +26,15 @@ func (w Withdrawal) String() string { // WithdrawalJSON contains Withdrawal data suitable for JSON serialization. type WithdrawalJSON struct { - GUID string `json:"guid"` - FromAddress string `json:"from"` - ToAddress string `json:"to"` - L1Token string `json:"l1Token"` - L2Token *Token `json:"l2Token"` - Amount string `json:"amount"` - Data []byte `json:"data"` - LogIndex uint64 `json:"logIndex"` - BlockNumber uint64 `json:"blockNumber"` - BlockTimestamp string `json:"blockTimestamp"` - TxHash string `json:"transactionHash"` - Batch *StateBatchJSON `json:"batch"` + GUID string `json:"guid"` + FromAddress string `json:"from"` + ToAddress string `json:"to"` + L1Token string `json:"l1Token"` + L2Token *Token `json:"l2Token"` + Amount string `json:"amount"` + Data []byte `json:"data"` + LogIndex uint64 `json:"logIndex"` + BlockNumber uint64 `json:"blockNumber"` + BlockTimestamp string `json:"blockTimestamp"` + TxHash string `json:"transactionHash"` } diff --git a/indexer/indexer.go b/indexer/indexer.go index 8235f1a5903e6..1bd501b209d51 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -212,7 +212,6 @@ func (b *Indexer) Serve() error { b.router.HandleFunc("/v1/l1/status", b.l1IndexingService.GetIndexerStatus).Methods("GET") b.router.HandleFunc("/v1/l2/status", b.l2IndexingService.GetIndexerStatus).Methods("GET") b.router.HandleFunc("/v1/deposits/0x{address:[a-fA-F0-9]{40}}", b.l1IndexingService.GetDeposits).Methods("GET") - b.router.HandleFunc("/v1/withdrawal/0x{hash:[a-fA-F0-9]{64}}", b.l2IndexingService.GetWithdrawalBatch).Methods("GET") b.router.HandleFunc("/v1/withdrawals/0x{address:[a-fA-F0-9]{40}}", b.l2IndexingService.GetWithdrawals).Methods("GET") b.router.HandleFunc("/v1/airdrops/0x{address:[a-fA-F0-9]{40}}", b.airdropService.GetAirdrop) b.router.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { diff --git a/indexer/metrics/metrics.go b/indexer/metrics/metrics.go index 6027d13fd91e5..2a0e895ee9472 100644 --- a/indexer/metrics/metrics.go +++ b/indexer/metrics/metrics.go @@ -21,8 +21,6 @@ type Metrics struct { WithdrawalsCount *prometheus.CounterVec - StateBatchesCount prometheus.Counter - L1CatchingUp prometheus.Gauge L2CatchingUp prometheus.Gauge @@ -74,12 +72,6 @@ func NewMetrics(monitoredTokens map[string]string) *Metrics { "symbol", }), - StateBatchesCount: promauto.NewCounter(prometheus.CounterOpts{ - Name: "state_batches_count", - Help: "The number of state batches indexed.", - Namespace: metricsNamespace, - }), - L1CatchingUp: promauto.NewGauge(prometheus.GaugeOpts{ Name: "l1_catching_up", Help: "Whether or not L1 is far behind the chain tip.", @@ -168,10 +160,6 @@ func (m *Metrics) RecordWithdrawal(addr common.Address) { m.WithdrawalsCount.WithLabelValues(sym).Inc() } -func (m *Metrics) RecordStateBatches(count int) { - m.StateBatchesCount.Add(float64(count)) -} - func (m *Metrics) SetL1CatchingUp(state bool) { var catchingUp float64 if state { diff --git a/indexer/services/l2/service.go b/indexer/services/l2/service.go index ecd2e61332f9e..295d512a0401d 100644 --- a/indexer/services/l2/service.go +++ b/indexer/services/l2/service.go @@ -336,18 +336,6 @@ func (s *Service) GetIndexerStatus(w http.ResponseWriter, r *http.Request) { server.RespondWithJSON(w, http.StatusOK, status) } -func (s *Service) GetWithdrawalBatch(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - - batch, err := s.cfg.DB.GetWithdrawalBatch(common.HexToHash(vars["hash"])) - if err != nil { - server.RespondWithError(w, http.StatusInternalServerError, err.Error()) - return - } - - server.RespondWithJSON(w, http.StatusOK, batch) -} - func (s *Service) GetWithdrawals(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r)