Skip to content

Commit

Permalink
e3: split "changed keys" iterator to simplify (erigontech#7086)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored and ty-sentio-xyz committed Mar 16, 2023
1 parent 2137697 commit 7db77c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion cmd/rpcdaemon/commands/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ func (api *PrivateDebugAPIImpl) GetModifiedAccountsByNumber(ctx context.Context,
// getModifiedAccountsV3 returns a list of addresses that were modified in the block range
// [startNum:endNum)
func getModifiedAccountsV3(tx kv.TemporalTx, startTxNum, endTxNum uint64) ([]common.Address, error) {
it, err := tx.HistoryRange(temporal.AccountsHistory, int(startTxNum), int(endTxNum), order.Asc, -1)
if err != nil {
return nil, err
}

changedAddrs := make(map[common.Address]struct{})
it, _ := tx.HistoryRange(temporal.AccountsHistory, int(startTxNum), int(endTxNum), order.Asc, -1)
for it.HasNext() {
k, _, err := it.Next()
if err != nil {
Expand Down
16 changes: 10 additions & 6 deletions core/state/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,19 @@ func (tx *Tx) HistoryRange(name kv.History, fromTs, toTs int, asc order.By, limi
}
switch name {
case AccountsHistory:
it = tx.agg.AccountHistoryIterateChanged(fromTs, toTs, asc, limit, tx)
return it, nil
it, err = tx.agg.AccountHistoryIterateChanged(fromTs, toTs, asc, limit, tx)
case StorageHistory:
it = tx.agg.StorageHistoryIterateChanged(fromTs, toTs, asc, limit, tx)
return it, nil
it, err = tx.agg.StorageHistoryIterateChanged(fromTs, toTs, asc, limit, tx)
case CodeHistory:
it = tx.agg.CodeHistoryIterateChanged(fromTs, toTs, asc, limit, tx)
return it, nil
it, err = tx.agg.CodeHistoryIterateChanged(fromTs, toTs, asc, limit, tx)
default:
return nil, fmt.Errorf("unexpected history name: %s", name)
}
if err != nil {
return nil, err
}
if closer, ok := it.(kv.Closer); ok {
tx.resourcesToClose = append(tx.resourcesToClose, closer)
}
return it, err
}

0 comments on commit 7db77c7

Please sign in to comment.