Skip to content

Commit

Permalink
e3: rename HistoryGet to HistorySeek (#10270)
Browse files Browse the repository at this point in the history
- rename HistoryGet to HistorySeek
- ii.Seek to ii.seekInFiles
- h.GetNoState to h.historySeekInFiles
- h.GetNoStateWithRecent to h.HistorySeek
- h.getNoStateFromDB to h.historySeekInDB
  • Loading branch information
AskAlexSharov authored May 10, 2024
1 parent e75d359 commit 683537e
Show file tree
Hide file tree
Showing 31 changed files with 346 additions and 338 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ mocks: mocks-clean

## mocks-clean: cleans all generated test mocks
mocks-clean:
grep -r -l --exclude-dir="erigon-lib" --exclude-dir="*$(GOBINREL)*" "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r
grep -r -l --exclude-dir="erigon-lib" --exclude-dir="tests" --exclude-dir="*$(GOBINREL)*" "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r

## solc: generate all solidity contracts
solc:
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/erigontech/mdbx-go v0.38.0
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20240509080801-633688230242
github.com/ledgerwatch/interfaces v0.0.0-20240502103437-1e84e26799a6
github.com/ledgerwatch/interfaces v0.0.0-20240510032129-13f644ca2307
github.com/ledgerwatch/log/v3 v3.9.0
github.com/ledgerwatch/secp256k1 v1.0.0
)
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20240509080801-633688230242 h1:EvaRNRzZc8OXCWutZnq93kdSSP9AiVuozwI8nTjeEYA=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20240509080801-633688230242/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20240502103437-1e84e26799a6 h1:snFpr1kpUlT/ffEa29S9tGgu2uIaLJqA2wv9PuOlBvU=
github.com/ledgerwatch/interfaces v0.0.0-20240502103437-1e84e26799a6/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/interfaces v0.0.0-20240510032129-13f644ca2307 h1:v2syJaHSCTSEnzwFUW4F6FL92ZAnKEoyBesnm2E/IEU=
github.com/ledgerwatch/interfaces v0.0.0-20240510032129-13f644ca2307/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=
github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=
Expand Down
331 changes: 166 additions & 165 deletions erigon-lib/gointerfaces/remoteproto/kv.pb.go

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions erigon-lib/gointerfaces/remoteproto/kv_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions erigon-lib/gointerfaces/remoteproto/kv_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions erigon-lib/kv/kv_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ type BucketMigrator interface {
// Cursor - class for navigating through a database
// CursorDupSort are inherit this class
//
// If methods (like First/Next/Seek) return error, then returned key SHOULD not be nil (can be []byte{} for example).
// If methods (like First/Next/seekInFiles) return error, then returned key SHOULD not be nil (can be []byte{} for example).
// Then looping code will look as:
// c := kv.Cursor(bucketName)
//
Expand Down Expand Up @@ -545,7 +545,7 @@ type TemporalTx interface {
Tx
TemporalGetter
DomainGetAsOf(name Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error)
HistoryGet(name History, k []byte, ts uint64) (v []byte, ok bool, err error)
HistorySeek(name History, k []byte, ts uint64) (v []byte, ok bool, err error)

// IndexRange - return iterator over range of inverted index for given key `k`
// Asc semantic: [from, to) AND from > to
Expand All @@ -564,6 +564,12 @@ type TemporalTx interface {
type TemporalCommitment interface {
ComputeCommitment(ctx context.Context, saveStateAfter, trace bool) (rootHash []byte, err error)
}

type TemporalRwTx interface {
RwTx
TemporalTx
}

type TemporalPutDel interface {
// DomainPut
// Optimizations:
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/mdbx/kv_abstract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func testMultiCursor(t *testing.T, db kv.RwDB, bucket1, bucket2 string) {
// }
//
// c3 := tx.Cursor(dbutils.ChaindataTables[0])
// k, v, err := c3.Seek([]byte{5})
// k, v, err := c3.seekInFiles([]byte{5})
// if err != nil {
// return err
// }
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/mdbx/kv_mdbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ func (c *MdbxCursor) Seek(seek []byte) (k, v []byte, err error) {
if mdbx.IsNotFound(err) {
return nil, nil, nil
}
err = fmt.Errorf("failed MdbxKV cursor.Seek(): %w, bucket: %s, key: %x", err, c.bucketName, seek)
err = fmt.Errorf("failed MdbxKV cursor.seekInFiles(): %w, bucket: %s, key: %x", err, c.bucketName, seek)
return []byte{}, nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/kv/membatchwithdb/memory_mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ func (m *MemoryMutation) DomainGet(name kv.Domain, k, k2 []byte) (v []byte, step
func (m *MemoryMutation) DomainGetAsOf(name kv.Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error) {
return m.db.(kv.TemporalTx).DomainGetAsOf(name, k, k2, ts)
}
func (m *MemoryMutation) HistoryGet(name kv.History, k []byte, ts uint64) (v []byte, ok bool, err error) {
return m.db.(kv.TemporalTx).HistoryGet(name, k, ts)
func (m *MemoryMutation) HistorySeek(name kv.History, k []byte, ts uint64) (v []byte, ok bool, err error) {
return m.db.(kv.TemporalTx).HistorySeek(name, k, ts)
}

func (m *MemoryMutation) IndexRange(name kv.InvertedIdx, k []byte, fromTs, toTs int, asc order.By, limit int) (timestamps iter.U64, err error) {
Expand Down
6 changes: 3 additions & 3 deletions erigon-lib/kv/remotedb/kv_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (c *remoteCursor) Current() ([]byte, []byte, error) {
return c.getCurrent()
}

// Seek - doesn't start streaming (because much of code does only several .Seek calls without reading sequence of data)
// Seek - doesn't start streaming (because much of code does only several .seekInFiles calls without reading sequence of data)
// .Next() - does request streaming (if configured by user)
func (c *remoteCursor) Seek(seek []byte) ([]byte, []byte, error) {
return c.setRange(seek)
Expand Down Expand Up @@ -674,8 +674,8 @@ func (tx *tx) DomainRange(name kv.Domain, fromKey, toKey []byte, ts uint64, asc
return reply.Keys, reply.Values, reply.NextPageToken, nil
}), nil
}
func (tx *tx) HistoryGet(name kv.History, k []byte, ts uint64) (v []byte, ok bool, err error) {
reply, err := tx.db.remoteKV.HistoryGet(tx.ctx, &remote.HistoryGetReq{TxId: tx.id, Table: string(name), K: k, Ts: ts})
func (tx *tx) HistorySeek(name kv.History, k []byte, ts uint64) (v []byte, ok bool, err error) {
reply, err := tx.db.remoteKV.HistorySeek(tx.ctx, &remote.HistorySeekReq{TxId: tx.id, Table: string(name), K: k, Ts: ts})
if err != nil {
return nil, false, err
}
Expand Down
8 changes: 4 additions & 4 deletions erigon-lib/kv/remotedbserver/remotedbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const MaxTxTTL = 60 * time.Second
// 5.0 - BlockTransaction table now has canonical ids (txs of non-canonical blocks moving to NonCanonicalTransaction table)
// 5.1.0 - Added blockGasLimit to the StateChangeBatch
// 6.0.0 - Blocks now have system-txs - in the begin/end of block
// 6.1.0 - Add methods Range, IndexRange, HistoryGet, HistoryRange
// 6.1.0 - Add methods Range, IndexRange, HistorySeek, HistoryRange
// 6.2.0 - Add HistoryFiles to reply of Snapshots() method
var KvServiceAPIVersion = &types.VersionReply{Major: 6, Minor: 2, Patch: 0}

Expand Down Expand Up @@ -561,14 +561,14 @@ func (s *KvServer) DomainGet(_ context.Context, req *remote.DomainGetReq) (reply
}
return reply, nil
}
func (s *KvServer) HistoryGet(_ context.Context, req *remote.HistoryGetReq) (reply *remote.HistoryGetReply, err error) {
reply = &remote.HistoryGetReply{}
func (s *KvServer) HistorySeek(_ context.Context, req *remote.HistorySeekReq) (reply *remote.HistorySeekReply, err error) {
reply = &remote.HistorySeekReply{}
if err := s.with(req.TxId, func(tx kv.Tx) error {
ttx, ok := tx.(kv.TemporalTx)
if !ok {
return fmt.Errorf("server DB doesn't implement kv.Temporal interface")
}
reply.V, reply.Ok, err = ttx.HistoryGet(kv.History(req.Table), req.K, req.Ts)
reply.V, reply.Ok, err = ttx.HistorySeek(kv.History(req.Table), req.K, req.Ts)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions erigon-lib/kv/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ AccountsHistory and StorageHistory - indices designed to serve next 2 type of re
2. get last shard of A - to append there new block numbers
Task 1. is part of "get historical state" operation (see `core/state:GetAsOf`):
If `db.Seek(A+bigEndian(X))` returns non-last shard -
If `db.seekInFiles(A+bigEndian(X))` returns non-last shard -
then get block number from shard value Y := RoaringBitmap(shard_value).GetGte(X)
and with Y go to ChangeSets: db.Get(ChangeSets, Y+A)
If `db.Seek(A+bigEndian(X))` returns last shard -
If `db.seekInFiles(A+bigEndian(X))` returns last shard -
then we go to PlainState: db.Get(PlainState, A)
Expand All @@ -143,7 +143,7 @@ Format:
- if shard is last - then key has suffix 8 bytes = 0xFF
It allows:
- server task 1. by 1 db operation db.Seek(A+bigEndian(X))
- server task 1. by 1 db operation db.seekInFiles(A+bigEndian(X))
- server task 2. by 1 db operation db.Get(A+0xFF)
see also: docs/programmers_guide/db_walkthrough.MD#table-change-sets
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/kv/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func (tx *Tx) DomainGetAsOf(name kv.Domain, key, key2 []byte, ts uint64) (v []by
return tx.aggCtx.DomainGetAsOf(tx.MdbxTx, name, key, ts)
}

func (tx *Tx) HistoryGet(name kv.History, key []byte, ts uint64) (v []byte, ok bool, err error) {
return tx.aggCtx.HistoryGet(name, key, ts, tx.MdbxTx)
func (tx *Tx) HistorySeek(name kv.History, key []byte, ts uint64) (v []byte, ok bool, err error) {
return tx.aggCtx.HistorySeek(name, key, ts, tx.MdbxTx)
}

func (tx *Tx) IndexRange(name kv.InvertedIdx, k []byte, fromTs, toTs int, asc order.By, limit int) (timestamps iter.U64, err error) {
Expand Down
Loading

0 comments on commit 683537e

Please sign in to comment.