Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Nov 7, 2024
1 parent 0c4e0ad commit 49f96cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
14 changes: 13 additions & 1 deletion erigon-lib/kv/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func FromBool(v bool) By {
return Desc
}

func Must(asc By, k1, k2 []byte) {
func (asc By) Assert(k1, k2 []byte) {
if !dbg.AssertEnabled {
return
}
Expand All @@ -54,3 +54,15 @@ func Must(asc By, k1, k2 []byte) {
panic(fmt.Sprintf("epect: %x >= %x", k1, k2))
}
}

func (asc By) AssertList(keys [][]byte) {
if !dbg.AssertEnabled {
return
}
if len(keys) < 2 {
return
}
for i := 0; i < len(keys)-2; i++ {
asc.Assert(keys[i], keys[i+1])
}
}
7 changes: 3 additions & 4 deletions erigon-lib/state/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,6 @@ func (hi *DomainLatestIterFile) advanceInFiles() error {
}
}

fmt.Printf("[dbg] advInFiles2: %x\n", k)
if len(k) > 0 && (hi.to == nil || bytes.Compare(k[:len(k)-8], hi.to) < 0) {
stepBytes := k[len(k)-8:]
k = k[:len(k)-8]
Expand All @@ -2370,7 +2369,6 @@ func (hi *DomainLatestIterFile) advanceInFiles() error {
return err
}

fmt.Printf("[dbg] advInFiles3: %x\n", k)
if len(k) > 0 && (hi.to == nil || bytes.Compare(k, hi.to) < 0) {
stepBytes := stepBytesWithValue[:8]
v := stepBytesWithValue[8:]
Expand Down Expand Up @@ -2408,8 +2406,9 @@ func (hi *DomainLatestIterFile) Next() ([]byte, []byte, error) {
if err := hi.advanceInFiles(); err != nil {
return nil, nil, err
}
order.Must(order.Asc, hi.kBackup, hi.nextKey)
return hi.kBackup, hi.vBackup, nil
order.Assert(order.Asc, hi.kBackup, hi.nextKey)

Check failure on line 2409 in erigon-lib/state/domain.go

View workflow job for this annotation

GitHub Actions / tests-windows (windows-2022)

undefined: order.Assert
// TODO: remove `common.Copy`. it protecting from some existing bug.
return common.Copy(hi.kBackup), hi.vBackup, nil
}

func (d *Domain) stepsRangeInDBAsStr(tx kv.Tx) string {
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/state/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,8 +1519,8 @@ func TestDomainRange(t *testing.T) {
it, err := dc.ht.WalkAsOf(context.Background(), 190, nil, nil, order.Asc, -1, tx)
require.NoError(err)
keys, vals, err := stream.ToArrayKV(it)
fmt.Printf("keys: %x\n", keys)
require.NoError(err)
order.Asc.AssertList(keys)
require.Equal(3, len(keys))
require.Equal(3, len(vals))
}
Expand All @@ -1529,8 +1529,8 @@ func TestDomainRange(t *testing.T) {
it, err := dc.DomainRangeLatest(tx, nil, nil, -1)
require.NoError(err)
keys, vals, err := stream.ToArrayKV(it)
fmt.Printf("keys: %x\n", keys)
require.NoError(err)
order.Asc.AssertList(keys)
require.Equal(3, len(keys))
require.Equal(3, len(vals))
}
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/state/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ func (hi *StateAsOfIterF) Next() ([]byte, []byte, error) {
if err := hi.advanceInFiles(); err != nil {
return nil, nil, err
}
order.Must(hi.orderAscend, hi.kBackup, hi.nextKey)
order.Assert(hi.orderAscend, hi.kBackup, hi.nextKey)

Check failure on line 1518 in erigon-lib/state/history.go

View workflow job for this annotation

GitHub Actions / tests-windows (windows-2022)

undefined: order.Assert
return hi.kBackup, hi.vBackup, nil
}

Expand Down Expand Up @@ -1679,7 +1679,7 @@ func (hi *StateAsOfIterDB) Next() ([]byte, []byte, error) {
if err := hi.advance(); err != nil {
return nil, nil, err
}
order.Must(hi.orderAscend, hi.kBackup, hi.nextKey)
hi.orderAscend.Assert(hi.kBackup, hi.nextKey)
return hi.kBackup, hi.vBackup, nil
}

Expand Down

0 comments on commit 49f96cd

Please sign in to comment.