Skip to content

Commit

Permalink
e3: storageRangeAt fix NextPage value (erigontech#6676)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jan 24, 2023
1 parent 539eaf0 commit 71067a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 0 additions & 3 deletions cmd/rpcdaemon/commands/debug_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 13 additions & 9 deletions cmd/rpcdaemon/commands/storage_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
}
1 change: 0 additions & 1 deletion core/state/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 71067a6

Please sign in to comment.