From 71067a69d11847e9edff28dccf3080b3a96fd67c Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Tue, 24 Jan 2023 11:22:50 +0700 Subject: [PATCH] e3: storageRangeAt fix NextPage value (#6676) --- cmd/rpcdaemon/commands/debug_api_test.go | 3 --- cmd/rpcdaemon/commands/storage_range.go | 22 +++++++++++++--------- core/state/temporal/kv_temporal.go | 1 - 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/rpcdaemon/commands/debug_api_test.go b/cmd/rpcdaemon/commands/debug_api_test.go index aa05b1782ec..f4d4058d13d 100644 --- a/cmd/rpcdaemon/commands/debug_api_test.go +++ b/cmd/rpcdaemon/commands/debug_api_test.go @@ -202,9 +202,6 @@ func TestTraceTransactionNoRefund(t *testing.T) { func TestStorageRangeAt(t *testing.T) { m, _, _ := rpcdaemontest.CreateTestSentry(t) - if m.HistoryV3 { - t.Skip() - } br := snapshotsync.NewBlockReaderWithSnapshots(m.BlockSnapshots) agg := m.HistoryV3Components() api := NewPrivateDebugAPI( diff --git a/cmd/rpcdaemon/commands/storage_range.go b/cmd/rpcdaemon/commands/storage_range.go index 954b044734a..6aaacb20e4c 100644 --- a/cmd/rpcdaemon/commands/storage_range.go +++ b/cmd/rpcdaemon/commands/storage_range.go @@ -40,7 +40,7 @@ func storageRangeAt(stateReader walker, contractAddress libcommon.Address, start result.NextKey = &key } resultCount++ - return resultCount <= maxResult + return resultCount < maxResult }, maxResult+1); err != nil { return StorageRangeResult{}, fmt.Errorf("error walking over storage: %w", err) } @@ -49,13 +49,12 @@ func storageRangeAt(stateReader walker, contractAddress libcommon.Address, start func storageRangeAtV3(ttx kv.TemporalTx, contractAddress libcommon.Address, start []byte, txNum uint64, maxResult int) (StorageRangeResult, error) { result := StorageRangeResult{Storage: storageMap{}} - resultCount := 0 - r, err := ttx.(*temporal.Tx).DomainRangeAscend(temporal.StorageDomain, contractAddress.Bytes(), start, txNum, maxResult) + r, err := ttx.(*temporal.Tx).DomainRangeAscend(temporal.StorageDomain, contractAddress.Bytes(), start, txNum, maxResult+1) if err != nil { return StorageRangeResult{}, err } - for r.HasNext() { + for i := 0; i < maxResult && r.HasNext(); i++ { k, v, err := r.Next() if err != nil { return StorageRangeResult{}, err @@ -70,13 +69,18 @@ func storageRangeAtV3(ttx kv.TemporalTx, contractAddress libcommon.Address, star } var value uint256.Int value.SetBytes(v) - if resultCount < maxResult { - result.Storage[seckey] = StorageEntry{Key: &key, Value: value.Bytes32()} - } else { + result.Storage[seckey] = StorageEntry{Key: &key, Value: value.Bytes32()} + } + + if r.HasNext() { + k, v, err := r.Next() + if err != nil { + return StorageRangeResult{}, err + } + if len(v) > 0 { + key := libcommon.BytesToHash(k[20:]) result.NextKey = &key - break } - resultCount++ } return result, nil } diff --git a/core/state/temporal/kv_temporal.go b/core/state/temporal/kv_temporal.go index 0b748ef391e..b950b0065cc 100644 --- a/core/state/temporal/kv_temporal.go +++ b/core/state/temporal/kv_temporal.go @@ -147,7 +147,6 @@ func (tx *Tx) DomainRangeAscend(name kv.Domain, k1, fromKey []byte, asOfTs uint6 case AccountsDomain: panic("not implemented yet") case StorageDomain: - //it := tx.agg.StorageHistoryRIterateChanged(asOfTs, math.MaxUint64, tx) toKey, _ := kv.NextSubtree(k1) fromKey2 := append(common.Copy(k1), fromKey...) it := tx.agg.StorageHistoricalStateRange(asOfTs, fromKey2, toKey, limit, tx)