Skip to content

Commit

Permalink
feat(api, rawdb): batch clean skipped txs traces
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop committed Feb 26, 2024
1 parent 88349c6 commit 10092a4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/rawdb/accessors_skipped_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ func WriteSkippedTransaction(db ethdb.Database, tx *types.Transaction, traces *t
}
}

// ResetSkippedTransactionTracesByHash resets the traces stored in local db, by reading the tx and its associated fields,
// and overwritting it with empty trace
func ResetSkippedTransactionTracesByHash(db ethdb.Database, txHash common.Hash) {
stx := ReadSkippedTransaction(db, txHash)
if stx == nil {
return
}
writeSkippedTransaction(db, stx.Tx, nil, stx.Reason, stx.BlockNumber, stx.BlockHash)
}

// SkippedTransactionIterator is a wrapper around ethdb.Iterator that
// allows us to iterate over skipped transaction hashes in the database.
// It implements an interface similar to ethdb.Iterator.
Expand Down
23 changes: 23 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,26 @@ func (api *ScrollAPI) GetSkippedTransactionHashes(ctx context.Context, from uint

return hashes, nil
}

// ResetSkippedTransactionsTraces resets the traces for skipped txs stored in db, and returns the list of reset transaction hashes.
// The skipped txs to reset are specified by the two indices provided (inclusive).
func (api *ScrollAPI) ResetSkippedTransactionsTraces(ctx context.Context, from uint64, to uint64) ([]common.Hash, error) {
hashes, err := api.GetSkippedTransactionHashes(ctx, from, to)
if err != nil {
return nil, err
}

for _, hash := range hashes {
log.Info("resetting skipped tx's traces", "txHash", hash)
api.ResetSkippedTransactionTracesByHash(ctx, hash)
log.Info("reset skipped tx's traces done", "txHash", hash)
}

return hashes, nil
}

// ResetSkippedTransactionTracesByHash resets a specified skipped tx's traces stored in db.
func (api *ScrollAPI) ResetSkippedTransactionTracesByHash(ctx context.Context, hash common.Hash) error {
rawdb.ResetSkippedTransactionTracesByHash(api.eth.ChainDb(), hash)
return nil
}
10 changes: 10 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,16 @@ web3._extend({
call: 'scroll_getSkippedTransactionHashes',
params: 2
}),
new web3._extend.Method({
name: 'resetSkippedTransactionsTraces',
call: 'scroll_resetSkippedTransactionsTraces',
params: 2
}),
new web3._extend.Method({
name: 'resetSkippedTransactionTracesByHash',
call: 'scroll_resetSkippedTransactionTracesByHash',
params: 1
}),
new web3._extend.Method({
name: 'estimateL1DataFee',
call: 'scroll_estimateL1DataFee',
Expand Down

0 comments on commit 10092a4

Please sign in to comment.