From f2d99f9d852c12c6cf2d63028e6ad6db42b04aa2 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Mon, 13 Mar 2023 15:06:50 +0700 Subject: [PATCH] e3: split "changed keys" iterator to simplify (#7086) --- cmd/rpcdaemon/commands/debug_api.go | 6 +++++- core/state/temporal/kv_temporal.go | 16 ++++++++++------ go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/rpcdaemon/commands/debug_api.go b/cmd/rpcdaemon/commands/debug_api.go index 682c6a6e524..d757ddce2c2 100644 --- a/cmd/rpcdaemon/commands/debug_api.go +++ b/cmd/rpcdaemon/commands/debug_api.go @@ -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 { diff --git a/core/state/temporal/kv_temporal.go b/core/state/temporal/kv_temporal.go index 38cad43c2e5..fc86d125337 100644 --- a/core/state/temporal/kv_temporal.go +++ b/core/state/temporal/kv_temporal.go @@ -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 } diff --git a/go.mod b/go.mod index a901300830a..d8cbf5632d5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon go 1.18 require ( - github.com/ledgerwatch/erigon-lib v0.0.0-20230313023514-6f17999b1f89 + github.com/ledgerwatch/erigon-lib v0.0.0-20230313075942-ae07c2744483 github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 github.com/ledgerwatch/log/v3 v3.7.0 github.com/ledgerwatch/secp256k1 v1.0.0 diff --git a/go.sum b/go.sum index 353eee6c4ad..4c1f3d288a8 100644 --- a/go.sum +++ b/go.sum @@ -517,8 +517,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v0.0.0-20230313023514-6f17999b1f89 h1:VavyYnW8r5wyjxM+lU4nH3BKOEUyDr/nuNiLPJrvlDs= -github.com/ledgerwatch/erigon-lib v0.0.0-20230313023514-6f17999b1f89/go.mod h1:sKLWgIyFuajTu7nu+cahKhReP+CZW57R5jFUYtzvn44= +github.com/ledgerwatch/erigon-lib v0.0.0-20230313075942-ae07c2744483 h1:59UeMgiynV+JflMPfQCH+I4qxVIer0wSgtEJvX+sUV8= +github.com/ledgerwatch/erigon-lib v0.0.0-20230313075942-ae07c2744483/go.mod h1:sKLWgIyFuajTu7nu+cahKhReP+CZW57R5jFUYtzvn44= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=