Skip to content

Commit 10092a4

Browse files
committed
feat(api, rawdb): batch clean skipped txs traces
1 parent 88349c6 commit 10092a4

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

core/rawdb/accessors_skipped_txs.go

+10
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ func WriteSkippedTransaction(db ethdb.Database, tx *types.Transaction, traces *t
199199
}
200200
}
201201

202+
// ResetSkippedTransactionTracesByHash resets the traces stored in local db, by reading the tx and its associated fields,
203+
// and overwritting it with empty trace
204+
func ResetSkippedTransactionTracesByHash(db ethdb.Database, txHash common.Hash) {
205+
stx := ReadSkippedTransaction(db, txHash)
206+
if stx == nil {
207+
return
208+
}
209+
writeSkippedTransaction(db, stx.Tx, nil, stx.Reason, stx.BlockNumber, stx.BlockHash)
210+
}
211+
202212
// SkippedTransactionIterator is a wrapper around ethdb.Iterator that
203213
// allows us to iterate over skipped transaction hashes in the database.
204214
// It implements an interface similar to ethdb.Iterator.

eth/api.go

+23
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,26 @@ func (api *ScrollAPI) GetSkippedTransactionHashes(ctx context.Context, from uint
817817

818818
return hashes, nil
819819
}
820+
821+
// ResetSkippedTransactionsTraces resets the traces for skipped txs stored in db, and returns the list of reset transaction hashes.
822+
// The skipped txs to reset are specified by the two indices provided (inclusive).
823+
func (api *ScrollAPI) ResetSkippedTransactionsTraces(ctx context.Context, from uint64, to uint64) ([]common.Hash, error) {
824+
hashes, err := api.GetSkippedTransactionHashes(ctx, from, to)
825+
if err != nil {
826+
return nil, err
827+
}
828+
829+
for _, hash := range hashes {
830+
log.Info("resetting skipped tx's traces", "txHash", hash)
831+
api.ResetSkippedTransactionTracesByHash(ctx, hash)
832+
log.Info("reset skipped tx's traces done", "txHash", hash)
833+
}
834+
835+
return hashes, nil
836+
}
837+
838+
// ResetSkippedTransactionTracesByHash resets a specified skipped tx's traces stored in db.
839+
func (api *ScrollAPI) ResetSkippedTransactionTracesByHash(ctx context.Context, hash common.Hash) error {
840+
rawdb.ResetSkippedTransactionTracesByHash(api.eth.ChainDb(), hash)
841+
return nil
842+
}

internal/web3ext/web3ext.go

+10
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,16 @@ web3._extend({
903903
call: 'scroll_getSkippedTransactionHashes',
904904
params: 2
905905
}),
906+
new web3._extend.Method({
907+
name: 'resetSkippedTransactionsTraces',
908+
call: 'scroll_resetSkippedTransactionsTraces',
909+
params: 2
910+
}),
911+
new web3._extend.Method({
912+
name: 'resetSkippedTransactionTracesByHash',
913+
call: 'scroll_resetSkippedTransactionTracesByHash',
914+
params: 1
915+
}),
906916
new web3._extend.Method({
907917
name: 'estimateL1DataFee',
908918
call: 'scroll_estimateL1DataFee',

0 commit comments

Comments
 (0)