diff --git a/beacon/light/api/light_api.go b/beacon/light/api/light_api.go
index 7e5ac38420b2..1bba220d3129 100755
--- a/beacon/light/api/light_api.go
+++ b/beacon/light/api/light_api.go
@@ -146,7 +146,7 @@ func (api *BeaconLightApi) httpGetf(format string, params ...any) ([]byte, error
return api.httpGet(fmt.Sprintf(format, params...))
}
-// GetBestUpdateAndCommittee fetches and validates LightClientUpdate for given
+// GetBestUpdatesAndCommittees fetches and validates LightClientUpdate for given
// period and full serialized committee for the next period (committee root hash
// equals update.NextSyncCommitteeRoot).
// Note that the results are validated but the update signature should be verified
diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go
index 1d885bd58d20..4e91a4ff25ed 100644
--- a/cmd/geth/dbcmd.go
+++ b/cmd/geth/dbcmd.go
@@ -33,11 +33,14 @@ import (
"github.com/ethereum/go-ethereum/console/prompt"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state/snapshot"
+ "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
+ "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
+ "github.com/ethereum/go-ethereum/triedb"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)
@@ -79,6 +82,7 @@ Remove blockchain and state databases`,
dbExportCmd,
dbMetadataCmd,
dbCheckStateContentCmd,
+ dbInspectHistoryCmd,
},
}
dbInspectCmd = &cli.Command{
@@ -203,6 +207,28 @@ WARNING: This is a low-level operation which may cause database corruption!`,
}, utils.NetworkFlags, utils.DatabaseFlags),
Description: "Shows metadata about the chain status.",
}
+ dbInspectHistoryCmd = &cli.Command{
+ Action: inspectHistory,
+ Name: "inspect-history",
+ Usage: "Inspect the state history within block range",
+ ArgsUsage: "
[OPTIONAL ]",
+ Flags: flags.Merge([]cli.Flag{
+ utils.SyncModeFlag,
+ &cli.Uint64Flag{
+ Name: "start",
+ Usage: "block number of the range start, zero means earliest history",
+ },
+ &cli.Uint64Flag{
+ Name: "end",
+ Usage: "block number of the range end(included), zero means latest history",
+ },
+ &cli.BoolFlag{
+ Name: "raw",
+ Usage: "display the decoded raw state value (otherwise shows rlp-encoded value)",
+ },
+ }, utils.NetworkFlags, utils.DatabaseFlags),
+ Description: "This command queries the history of the account or storage slot within the specified block range",
+ }
)
func removeDB(ctx *cli.Context) error {
@@ -759,3 +785,145 @@ func showMetaData(ctx *cli.Context) error {
table.Render()
return nil
}
+
+func inspectAccount(db *triedb.Database, start uint64, end uint64, address common.Address, raw bool) error {
+ stats, err := db.AccountHistory(address, start, end)
+ if err != nil {
+ return err
+ }
+ fmt.Printf("Account history:\n\taddress: %s\n\tblockrange: [#%d-#%d]\n", address.Hex(), stats.Start, stats.End)
+
+ from := stats.Start
+ for i := 0; i < len(stats.Blocks); i++ {
+ var content string
+ if len(stats.Origins[i]) == 0 {
+ content = ""
+ } else {
+ if !raw {
+ content = fmt.Sprintf("%#x", stats.Origins[i])
+ } else {
+ account := new(types.SlimAccount)
+ if err := rlp.DecodeBytes(stats.Origins[i], account); err != nil {
+ panic(err)
+ }
+ code := ""
+ if len(account.CodeHash) > 0 {
+ code = fmt.Sprintf("%#x", account.CodeHash)
+ }
+ root := ""
+ if len(account.Root) > 0 {
+ root = fmt.Sprintf("%#x", account.Root)
+ }
+ content = fmt.Sprintf("nonce: %d, balance: %d, codeHash: %s, root: %s", account.Nonce, account.Balance, code, root)
+ }
+ }
+ fmt.Printf("#%d - #%d: %s\n", from, stats.Blocks[i], content)
+ from = stats.Blocks[i]
+ }
+ return nil
+}
+
+func inspectStorage(db *triedb.Database, start uint64, end uint64, address common.Address, slot common.Hash, raw bool) error {
+ // The hash of storage slot key is utilized in the history
+ // rather than the raw slot key, make the conversion.
+ slotHash := crypto.Keccak256Hash(slot.Bytes())
+ stats, err := db.StorageHistory(address, slotHash, start, end)
+ if err != nil {
+ return err
+ }
+ fmt.Printf("Storage history:\n\taddress: %s\n\tslot: %s\n\tblockrange: [#%d-#%d]\n", address.Hex(), slot.Hex(), stats.Start, stats.End)
+
+ from := stats.Start
+ for i := 0; i < len(stats.Blocks); i++ {
+ var content string
+ if len(stats.Origins[i]) == 0 {
+ content = ""
+ } else {
+ if !raw {
+ content = fmt.Sprintf("%#x", stats.Origins[i])
+ } else {
+ _, data, _, err := rlp.Split(stats.Origins[i])
+ if err != nil {
+ fmt.Printf("Failed to decode storage slot, %v", err)
+ return err
+ }
+ content = fmt.Sprintf("%#x", data)
+ }
+ }
+ fmt.Printf("#%d - #%d: %s\n", from, stats.Blocks[i], content)
+ from = stats.Blocks[i]
+ }
+ return nil
+}
+
+func inspectHistory(ctx *cli.Context) error {
+ if ctx.NArg() == 0 || ctx.NArg() > 2 {
+ return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage)
+ }
+ var (
+ address common.Address
+ slot common.Hash
+ )
+ if err := address.UnmarshalText([]byte(ctx.Args().Get(0))); err != nil {
+ return err
+ }
+ if ctx.NArg() > 1 {
+ if err := slot.UnmarshalText([]byte(ctx.Args().Get(1))); err != nil {
+ return err
+ }
+ }
+ // Load the databases.
+ stack, _ := makeConfigNode(ctx)
+ defer stack.Close()
+
+ db := utils.MakeChainDatabase(ctx, stack, true)
+ defer db.Close()
+
+ triedb := utils.MakeTrieDatabase(ctx, db, false, false, false)
+ defer triedb.Close()
+
+ var (
+ err error
+ start uint64 // the id of first history object to query
+ end uint64 // the id (included) of last history object to query
+ )
+ // State histories are identified by state ID rather than block number.
+ // To address this, load the corresponding block header and perform the
+ // conversion by this function.
+ blockToID := func(blockNumber uint64) (uint64, error) {
+ header := rawdb.ReadHeader(db, rawdb.ReadCanonicalHash(db, blockNumber), blockNumber)
+ if header == nil {
+ return 0, fmt.Errorf("block #%d is not existent", blockNumber)
+ }
+ id := rawdb.ReadStateID(db, header.Root)
+ if id == nil {
+ first, last, err := triedb.HistoryRange()
+ if err == nil {
+ return 0, fmt.Errorf("history of block #%d is not existent, available history range: [#%d-#%d]", blockNumber, first, last)
+ }
+ return 0, fmt.Errorf("history of block #%d is not existent", blockNumber)
+ }
+ return *id, nil
+ }
+ // Parse the starting block number for inspection.
+ startNumber := ctx.Uint64("start")
+ if startNumber != 0 {
+ start, err = blockToID(startNumber)
+ if err != nil {
+ return err
+ }
+ }
+ // Parse the ending block number for inspection.
+ endBlock := ctx.Uint64("end")
+ if endBlock != 0 {
+ end, err = blockToID(endBlock)
+ if err != nil {
+ return err
+ }
+ }
+ // Inspect the state history.
+ if slot == (common.Hash{}) {
+ return inspectAccount(triedb, start, end, address, ctx.Bool("raw"))
+ }
+ return inspectStorage(triedb, start, end, address, slot, ctx.Bool("raw"))
+}
diff --git a/crypto/bn256/google/bn256.go b/crypto/bn256/google/bn256.go
index 93953e23a95f..aca9cf62de1b 100644
--- a/crypto/bn256/google/bn256.go
+++ b/crypto/bn256/google/bn256.go
@@ -29,7 +29,7 @@ import (
)
// BUG(agl): this implementation is not constant time.
-// TODO(agl): keep GF(p²) elements in Mongomery form.
+// TODO(agl): keep GF(p²) elements in Montgomery form.
// G1 is an abstract cyclic group. The zero value is suitable for use as the
// output of an operation, but cannot be used as an input.
diff --git a/eth/downloader/queue_test.go b/eth/downloader/queue_test.go
index 50b9031a27c6..857ac4813a7d 100644
--- a/eth/downloader/queue_test.go
+++ b/eth/downloader/queue_test.go
@@ -18,6 +18,7 @@ package downloader
import (
"fmt"
+ "log/slog"
"math/big"
"math/rand"
"os"
@@ -32,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
- "golang.org/x/exp/slog"
)
// makeChain creates a chain of n blocks starting at and including parent.
diff --git a/internal/debug/api.go b/internal/debug/api.go
index 482989e0d0f3..c262201e3b7f 100644
--- a/internal/debug/api.go
+++ b/internal/debug/api.go
@@ -24,6 +24,7 @@ import (
"bytes"
"errors"
"io"
+ "log/slog"
"os"
"os/user"
"path/filepath"
@@ -37,7 +38,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/hashicorp/go-bexpr"
- "golang.org/x/exp/slog"
)
// Handler is the global debugging handler.
diff --git a/internal/debug/flags.go b/internal/debug/flags.go
index dac878a7b1ff..19222c8325f9 100644
--- a/internal/debug/flags.go
+++ b/internal/debug/flags.go
@@ -19,6 +19,7 @@ package debug
import (
"fmt"
"io"
+ "log/slog"
"net"
"net/http"
_ "net/http/pprof"
@@ -34,7 +35,6 @@ import (
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
- "golang.org/x/exp/slog"
"gopkg.in/natefinch/lumberjack.v2"
)
diff --git a/internal/testlog/testlog.go b/internal/testlog/testlog.go
index e5ddf9cfeb0b..3740dd1f242c 100644
--- a/internal/testlog/testlog.go
+++ b/internal/testlog/testlog.go
@@ -21,11 +21,11 @@ import (
"bytes"
"context"
"fmt"
+ "log/slog"
"sync"
"testing"
"github.com/ethereum/go-ethereum/log"
- "golang.org/x/exp/slog"
)
const (
diff --git a/log/format.go b/log/format.go
index 391e9a8dbbba..515ae66e98fc 100644
--- a/log/format.go
+++ b/log/format.go
@@ -3,6 +3,7 @@ package log
import (
"bytes"
"fmt"
+ "log/slog"
"math/big"
"reflect"
"strconv"
@@ -10,7 +11,6 @@ import (
"unicode/utf8"
"github.com/holiman/uint256"
- "golang.org/x/exp/slog"
)
const (
diff --git a/log/handler.go b/log/handler.go
index 7459aad8913b..248e3813fc2c 100644
--- a/log/handler.go
+++ b/log/handler.go
@@ -4,13 +4,13 @@ import (
"context"
"fmt"
"io"
+ "log/slog"
"math/big"
"reflect"
"sync"
"time"
"github.com/holiman/uint256"
- "golang.org/x/exp/slog"
)
type discardHandler struct{}
diff --git a/log/handler_glog.go b/log/handler_glog.go
index f51bae2a4a5b..608d955572ad 100644
--- a/log/handler_glog.go
+++ b/log/handler_glog.go
@@ -20,14 +20,13 @@ import (
"context"
"errors"
"fmt"
+ "log/slog"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
-
- "golang.org/x/exp/slog"
)
// errVmoduleSyntax is returned when a user vmodule pattern is invalid.
diff --git a/log/logger.go b/log/logger.go
index c28bbde56840..5672344b0c5c 100644
--- a/log/logger.go
+++ b/log/logger.go
@@ -2,12 +2,11 @@ package log
import (
"context"
+ "log/slog"
"math"
"os"
"runtime"
"time"
-
- "golang.org/x/exp/slog"
)
const errorKey = "LOG_ERROR"
diff --git a/log/logger_test.go b/log/logger_test.go
index ff981fd018ca..d23e16e57241 100644
--- a/log/logger_test.go
+++ b/log/logger_test.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
+ "log/slog"
"math/big"
"os"
"strings"
@@ -12,7 +13,6 @@ import (
"time"
"github.com/holiman/uint256"
- "golang.org/x/exp/slog"
)
// TestLoggingWithVmodule checks that vmodule works.
diff --git a/log/root.go b/log/root.go
index 8662d870637b..91209c46ad1c 100644
--- a/log/root.go
+++ b/log/root.go
@@ -1,10 +1,9 @@
package log
import (
+ "log/slog"
"os"
"sync/atomic"
-
- "golang.org/x/exp/slog"
)
var root atomic.Value
diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go
index 17e0f75d5ab9..5df2d7649cd8 100644
--- a/p2p/simulations/adapters/exec.go
+++ b/p2p/simulations/adapters/exec.go
@@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"io"
+ "log/slog"
"net"
"net/http"
"os"
@@ -41,7 +42,6 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rpc"
"github.com/gorilla/websocket"
- "golang.org/x/exp/slog"
)
func init() {
diff --git a/p2p/simulations/adapters/types.go b/p2p/simulations/adapters/types.go
index fb8463d221eb..a26dff7a8229 100644
--- a/p2p/simulations/adapters/types.go
+++ b/p2p/simulations/adapters/types.go
@@ -21,6 +21,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
+ "log/slog"
"net"
"os"
"strconv"
@@ -34,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/rpc"
"github.com/gorilla/websocket"
- "golang.org/x/exp/slog"
)
// Node represents a node in a simulation network which is created by a
diff --git a/p2p/simulations/http_test.go b/p2p/simulations/http_test.go
index c04308fe0bf8..460ed72d7fc8 100644
--- a/p2p/simulations/http_test.go
+++ b/p2p/simulations/http_test.go
@@ -20,6 +20,7 @@ import (
"context"
"flag"
"fmt"
+ "log/slog"
"math/rand"
"net/http/httptest"
"os"
@@ -37,7 +38,6 @@ import (
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/rpc"
"github.com/mattn/go-colorable"
- "golang.org/x/exp/slog"
)
func TestMain(m *testing.M) {
diff --git a/signer/core/auditlog.go b/signer/core/auditlog.go
index d2207c9eb8d5..78785a3b02e8 100644
--- a/signer/core/auditlog.go
+++ b/signer/core/auditlog.go
@@ -19,6 +19,7 @@ package core
import (
"context"
"encoding/json"
+ "log/slog"
"os"
"github.com/ethereum/go-ethereum/common"
@@ -26,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
- "golang.org/x/exp/slog"
)
type AuditLogger struct {
diff --git a/signer/storage/aes_gcm_storage_test.go b/signer/storage/aes_gcm_storage_test.go
index a223b1a6b4e7..b895269f9597 100644
--- a/signer/storage/aes_gcm_storage_test.go
+++ b/signer/storage/aes_gcm_storage_test.go
@@ -20,13 +20,13 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "log/slog"
"os"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/mattn/go-colorable"
- "golang.org/x/exp/slog"
)
func TestEncryption(t *testing.T) {
diff --git a/triedb/hashdb/database.go b/triedb/hashdb/database.go
index e45ccdba32ca..7d5499eb693a 100644
--- a/triedb/hashdb/database.go
+++ b/triedb/hashdb/database.go
@@ -619,7 +619,6 @@ func (db *Database) Size() (common.StorageSize, common.StorageSize) {
func (db *Database) Close() error {
if db.cleans != nil {
db.cleans.Reset()
- db.cleans = nil
}
return nil
}
diff --git a/triedb/history.go b/triedb/history.go
new file mode 100644
index 000000000000..f663cdd7c248
--- /dev/null
+++ b/triedb/history.go
@@ -0,0 +1,72 @@
+// Copyright 2023 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see .
+
+package triedb
+
+import (
+ "errors"
+
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/triedb/pathdb"
+)
+
+// AccountHistory inspects the account history within the specified range.
+//
+// Start: State ID of the first history object for the query. 0 implies the first
+// available object is selected as the starting point.
+//
+// End: State ID of the last history for the query. 0 implies the last available
+// object is selected as the starting point. Note end is included for query.
+//
+// This function is only supported by path mode database.
+func (db *Database) AccountHistory(address common.Address, start, end uint64) (*pathdb.HistoryStats, error) {
+ pdb, ok := db.backend.(*pathdb.Database)
+ if !ok {
+ return nil, errors.New("not supported")
+ }
+ return pdb.AccountHistory(address, start, end)
+}
+
+// StorageHistory inspects the storage history within the specified range.
+//
+// Start: State ID of the first history object for the query. 0 implies the first
+// available object is selected as the starting point.
+//
+// End: State ID of the last history for the query. 0 implies the last available
+// object is selected as the starting point. Note end is included for query.
+//
+// Note, slot refers to the hash of the raw slot key.
+//
+// This function is only supported by path mode database.
+func (db *Database) StorageHistory(address common.Address, slot common.Hash, start uint64, end uint64) (*pathdb.HistoryStats, error) {
+ pdb, ok := db.backend.(*pathdb.Database)
+ if !ok {
+ return nil, errors.New("not supported")
+ }
+ return pdb.StorageHistory(address, slot, start, end)
+}
+
+// HistoryRange returns the block numbers associated with earliest and latest
+// state history in the local store.
+//
+// This function is only supported by path mode database.
+func (db *Database) HistoryRange() (uint64, uint64, error) {
+ pdb, ok := db.backend.(*pathdb.Database)
+ if !ok {
+ return 0, 0, errors.New("not supported")
+ }
+ return pdb.HistoryRange()
+}
diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go
index 7bdb6132bb57..34941a274d4c 100644
--- a/triedb/pathdb/database.go
+++ b/triedb/pathdb/database.go
@@ -487,3 +487,33 @@ func (db *Database) modifyAllowed() error {
}
return nil
}
+
+// AccountHistory inspects the account history within the specified range.
+//
+// Start: State ID of the first history object for the query. 0 implies the first
+// available object is selected as the starting point.
+//
+// End: State ID of the last history for the query. 0 implies the last available
+// object is selected as the ending point. Note end is included in the query.
+func (db *Database) AccountHistory(address common.Address, start, end uint64) (*HistoryStats, error) {
+ return accountHistory(db.freezer, address, start, end)
+}
+
+// StorageHistory inspects the storage history within the specified range.
+//
+// Start: State ID of the first history object for the query. 0 implies the first
+// available object is selected as the starting point.
+//
+// End: State ID of the last history for the query. 0 implies the last available
+// object is selected as the ending point. Note end is included in the query.
+//
+// Note, slot refers to the hash of the raw slot key.
+func (db *Database) StorageHistory(address common.Address, slot common.Hash, start uint64, end uint64) (*HistoryStats, error) {
+ return storageHistory(db.freezer, address, slot, start, end)
+}
+
+// HistoryRange returns the block numbers associated with earliest and latest
+// state history in the local store.
+func (db *Database) HistoryRange() (uint64, uint64, error) {
+ return historyRange(db.freezer)
+}
diff --git a/triedb/pathdb/history_inspect.go b/triedb/pathdb/history_inspect.go
new file mode 100644
index 000000000000..d8a761b91689
--- /dev/null
+++ b/triedb/pathdb/history_inspect.go
@@ -0,0 +1,151 @@
+// Copyright 2024 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see first {
+ first = start
+ }
+ // Load the id of the last history object in local store.
+ head, err := freezer.Ancients()
+ if err != nil {
+ return 0, 0, err
+ }
+ last := head - 1
+ if end != 0 && end < last {
+ last = end
+ }
+ // Make sure the range is valid
+ if first >= last {
+ return 0, 0, fmt.Errorf("range is invalid, first: %d, last: %d", first, last)
+ }
+ return first, last, nil
+}
+
+func inspectHistory(freezer *rawdb.ResettableFreezer, start, end uint64, onHistory func(*history, *HistoryStats)) (*HistoryStats, error) {
+ var (
+ stats = &HistoryStats{}
+ init = time.Now()
+ logged = time.Now()
+ )
+ start, end, err := sanitizeRange(start, end, freezer)
+ if err != nil {
+ return nil, err
+ }
+ for id := start; id <= end; id += 1 {
+ // The entire history object is decoded, although it's unnecessary for
+ // account inspection. TODO(rjl493456442) optimization is worthwhile.
+ h, err := readHistory(freezer, id)
+ if err != nil {
+ return nil, err
+ }
+ if id == start {
+ stats.Start = h.meta.block
+ }
+ if id == end {
+ stats.End = h.meta.block
+ }
+ onHistory(h, stats)
+
+ if time.Since(logged) > time.Second*8 {
+ logged = time.Now()
+ eta := float64(time.Since(init)) / float64(id-start+1) * float64(end-id)
+ log.Info("Inspecting state history", "checked", id-start+1, "left", end-id, "elapsed", common.PrettyDuration(time.Since(init)), "eta", common.PrettyDuration(eta))
+ }
+ }
+ log.Info("Inspected state history", "total", end-start+1, "elapsed", common.PrettyDuration(time.Since(init)))
+ return stats, nil
+}
+
+// accountHistory inspects the account history within the range.
+func accountHistory(freezer *rawdb.ResettableFreezer, address common.Address, start, end uint64) (*HistoryStats, error) {
+ return inspectHistory(freezer, start, end, func(h *history, stats *HistoryStats) {
+ blob, exists := h.accounts[address]
+ if !exists {
+ return
+ }
+ stats.Blocks = append(stats.Blocks, h.meta.block)
+ stats.Origins = append(stats.Origins, blob)
+ })
+}
+
+// storageHistory inspects the storage history within the range.
+func storageHistory(freezer *rawdb.ResettableFreezer, address common.Address, slot common.Hash, start uint64, end uint64) (*HistoryStats, error) {
+ return inspectHistory(freezer, start, end, func(h *history, stats *HistoryStats) {
+ slots, exists := h.storages[address]
+ if !exists {
+ return
+ }
+ blob, exists := slots[slot]
+ if !exists {
+ return
+ }
+ stats.Blocks = append(stats.Blocks, h.meta.block)
+ stats.Origins = append(stats.Origins, blob)
+ })
+}
+
+// historyRange returns the block number range of local state histories.
+func historyRange(freezer *rawdb.ResettableFreezer) (uint64, uint64, error) {
+ // Load the id of the first history object in local store.
+ tail, err := freezer.Tail()
+ if err != nil {
+ return 0, 0, err
+ }
+ first := tail + 1
+
+ // Load the id of the last history object in local store.
+ head, err := freezer.Ancients()
+ if err != nil {
+ return 0, 0, err
+ }
+ last := head - 1
+
+ fh, err := readHistory(freezer, first)
+ if err != nil {
+ return 0, 0, err
+ }
+ lh, err := readHistory(freezer, last)
+ if err != nil {
+ return 0, 0, err
+ }
+ return fh.meta.block, lh.meta.block, nil
+}