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

feat(api, rawdb): batch clean skipped txs traces #501

Closed
wants to merge 2 commits into from
Closed
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
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stx := ReadSkippedTransaction(db, txHash)
stx := ReadSkippedTransaction(db, txHash)
if stx == nil {
return
}

Sorry, forgot about the nil case

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return error can be better can let the caller know stx value is empty.

Copy link
Author

@0xmountaintop 0xmountaintop Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 108ddc8

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
Loading