Skip to content

Commit

Permalink
e3: Rename domain methods (#12676)
Browse files Browse the repository at this point in the history
Rename: 
- `DomainRange` to `RangeAsOf`
- `DomainGetAsOf` to `GetAsOf`
-  `DomainGet` to `GetLatest`
all this methods do accept typed `kv.Domain` as a parameter

merge after #12621
  • Loading branch information
AskAlexSharov authored Nov 16, 2024
1 parent 3733391 commit 736da1c
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 79 deletions.
6 changes: 3 additions & 3 deletions core/rawdb/rawtemporaldb/accessors_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func ReceiptAsOf(tx kv.TemporalTx, txNum uint64) (cumGasUsed uint64, cumBlobGasu
var v []byte
var ok bool

v, ok, err = tx.DomainGetAsOf(kv.ReceiptDomain, CumulativeGasUsedInBlockKey, nil, txNum)
v, ok, err = tx.GetAsOf(kv.ReceiptDomain, CumulativeGasUsedInBlockKey, nil, txNum)
if err != nil {
return
}
if ok && v != nil {
cumGasUsed = uvarint(v)
}

v, ok, err = tx.DomainGetAsOf(kv.ReceiptDomain, CumulativeBlobGasUsedInBlockKey, nil, txNum)
v, ok, err = tx.GetAsOf(kv.ReceiptDomain, CumulativeBlobGasUsedInBlockKey, nil, txNum)
if err != nil {
return
}
Expand All @@ -61,7 +61,7 @@ func ReceiptAsOf(tx kv.TemporalTx, txNum uint64) (cumGasUsed uint64, cumBlobGasu
//logIndex always 0
//}

v, ok, err = tx.DomainGetAsOf(kv.ReceiptDomain, FirstLogIndexKey, nil, txNum)
v, ok, err = tx.GetAsOf(kv.ReceiptDomain, FirstLogIndexKey, nil, txNum)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions core/state/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (d *Dumper) DumpToCollector(c DumpCollector, excludeCode, excludeStorage bo
}

var nextKey []byte
it, err := ttx.DomainRange(kv.AccountsDomain, startAddress[:], nil, txNum, order.Asc, kv.Unlim) //unlim because need skip empty vals
it, err := ttx.RangeAsOf(kv.AccountsDomain, startAddress[:], nil, txNum, order.Asc, kv.Unlim) //unlim because need skip empty vals
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func (d *Dumper) DumpToCollector(c DumpCollector, excludeCode, excludeStorage bo
account.CodeHash = hexutility.Bytes(acc.CodeHash.Bytes())

if !excludeCode {
r, _, err := ttx.DomainGet(kv.CodeDomain, k, nil)
r, _, err := ttx.GetLatest(kv.CodeDomain, k, nil)
if err != nil {
return nil, err
}
Expand All @@ -214,7 +214,7 @@ func (d *Dumper) DumpToCollector(c DumpCollector, excludeCode, excludeStorage bo
if !excludeStorage {
t := trie.New(libcommon.Hash{})
nextAcc, _ := kv.NextSubtree(addr[:])
r, err := ttx.DomainRange(kv.StorageDomain, addr[:], nextAcc, txNumForStorage, order.Asc, kv.Unlim) //unlim because need skip empty vals
r, err := ttx.RangeAsOf(kv.StorageDomain, addr[:], nextAcc, txNumForStorage, order.Asc, kv.Unlim) //unlim because need skip empty vals
if err != nil {
return nil, fmt.Errorf("walking over storage for %x: %w", addr, err)
}
Expand Down
12 changes: 6 additions & 6 deletions core/state/history_reader_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (hr *HistoryReaderV3) ResetReadSet() {}
func (hr *HistoryReaderV3) DiscardReadList() {}

func (hr *HistoryReaderV3) ReadAccountData(address common.Address) (*accounts.Account, error) {
enc, ok, err := hr.ttx.DomainGetAsOf(kv.AccountsDomain, address[:], nil, hr.txNum)
enc, ok, err := hr.ttx.GetAsOf(kv.AccountsDomain, address[:], nil, hr.txNum)
if err != nil || !ok || len(enc) == 0 {
if hr.trace {
fmt.Printf("ReadAccountData [%x] => []\n", address)
Expand All @@ -74,7 +74,7 @@ func (hr *HistoryReaderV3) ReadAccountData(address common.Address) (*accounts.Ac

func (hr *HistoryReaderV3) ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error) {
k := append(address[:], key.Bytes()...)
enc, _, err := hr.ttx.DomainGetAsOf(kv.StorageDomain, k, nil, hr.txNum)
enc, _, err := hr.ttx.GetAsOf(kv.StorageDomain, k, nil, hr.txNum)
if hr.trace {
fmt.Printf("ReadAccountStorage [%x] [%x] => [%x]\n", address, *key, enc)
}
Expand All @@ -86,21 +86,21 @@ func (hr *HistoryReaderV3) ReadAccountCode(address common.Address, incarnation u
return nil, nil
}
// must pass key2=Nil here: because Erigon4 does concatinate key1+key2 under the hood
//code, _, err := hr.ttx.DomainGetAsOf(kv.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
code, _, err := hr.ttx.DomainGetAsOf(kv.CodeDomain, address[:], nil, hr.txNum)
//code, _, err := hr.ttx.GetAsOf(kv.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
code, _, err := hr.ttx.GetAsOf(kv.CodeDomain, address[:], nil, hr.txNum)
if hr.trace {
fmt.Printf("ReadAccountCode [%x %x] => [%x]\n", address, codeHash, code)
}
return code, err
}

func (hr *HistoryReaderV3) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error) {
enc, _, err := hr.ttx.DomainGetAsOf(kv.CodeDomain, address[:], nil, hr.txNum)
enc, _, err := hr.ttx.GetAsOf(kv.CodeDomain, address[:], nil, hr.txNum)
return len(enc), err
}

func (hr *HistoryReaderV3) ReadAccountIncarnation(address common.Address) (uint64, error) {
enc, ok, err := hr.ttx.DomainGetAsOf(kv.AccountsDomain, address.Bytes(), nil, hr.txNum)
enc, ok, err := hr.ttx.GetAsOf(kv.AccountsDomain, address.Bytes(), nil, hr.txNum)
if err != nil || !ok || len(enc) == 0 {
if hr.trace {
fmt.Printf("ReadAccountIncarnation [%x] => [0]\n", address)
Expand Down
18 changes: 9 additions & 9 deletions core/state/rw_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (rs *StateV3) applyState(txTask *TxTask, domains *libstate.SharedDomains) e
for addr, increase := range txTask.BalanceIncreaseSet {
increase := increase
addrBytes := addr.Bytes()
enc0, step0, err := domains.DomainGet(kv.AccountsDomain, addrBytes, nil)
enc0, step0, err := domains.GetLatest(kv.AccountsDomain, addrBytes, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -590,7 +590,7 @@ func (r *ReaderV3) SetTrace(trace bool) { r.trace = trace }
func (r *ReaderV3) ResetReadSet() {}

func (r *ReaderV3) ReadAccountData(address common.Address) (*accounts.Account, error) {
enc, _, err := r.tx.DomainGet(kv.AccountsDomain, address[:], nil)
enc, _, err := r.tx.GetLatest(kv.AccountsDomain, address[:], nil)
if err != nil {
return nil, err
}
Expand All @@ -613,7 +613,7 @@ func (r *ReaderV3) ReadAccountData(address common.Address) (*accounts.Account, e

func (r *ReaderV3) ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error) {
r.composite = append(append(r.composite[:0], address[:]...), key.Bytes()...)
enc, _, err := r.tx.DomainGet(kv.StorageDomain, r.composite, nil)
enc, _, err := r.tx.GetLatest(kv.StorageDomain, r.composite, nil)
if err != nil {
return nil, err
}
Expand All @@ -631,7 +631,7 @@ func (r *ReaderV3) ReadAccountCode(address common.Address, incarnation uint64, c
//if codeHash == emptyCodeHashH { // TODO: how often do we have this case on mainnet/bor-mainnet?
// return nil, nil
//}
enc, _, err := r.tx.DomainGet(kv.CodeDomain, address[:], nil)
enc, _, err := r.tx.GetLatest(kv.CodeDomain, address[:], nil)
if err != nil {
return nil, err
}
Expand All @@ -642,7 +642,7 @@ func (r *ReaderV3) ReadAccountCode(address common.Address, incarnation uint64, c
}

func (r *ReaderV3) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error) {
enc, _, err := r.tx.DomainGet(kv.CodeDomain, address[:], nil)
enc, _, err := r.tx.GetLatest(kv.CodeDomain, address[:], nil)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -684,7 +684,7 @@ func (r *ReaderParallelV3) SetTrace(trace bool) { r.trace = tra
func (r *ReaderParallelV3) ResetReadSet() { r.readLists = newReadList() }

func (r *ReaderParallelV3) ReadAccountData(address common.Address) (*accounts.Account, error) {
enc, _, err := r.sd.DomainGet(kv.AccountsDomain, address[:], nil)
enc, _, err := r.sd.GetLatest(kv.AccountsDomain, address[:], nil)
if err != nil {
return nil, err
}
Expand All @@ -711,7 +711,7 @@ func (r *ReaderParallelV3) ReadAccountData(address common.Address) (*accounts.Ac

func (r *ReaderParallelV3) ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error) {
r.composite = append(append(r.composite[:0], address[:]...), key.Bytes()...)
enc, _, err := r.sd.DomainGet(kv.StorageDomain, r.composite, nil)
enc, _, err := r.sd.GetLatest(kv.StorageDomain, r.composite, nil)
if err != nil {
return nil, err
}
Expand All @@ -729,7 +729,7 @@ func (r *ReaderParallelV3) ReadAccountStorage(address common.Address, incarnatio
}

func (r *ReaderParallelV3) ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) ([]byte, error) {
enc, _, err := r.sd.DomainGet(kv.CodeDomain, address[:], nil)
enc, _, err := r.sd.GetLatest(kv.CodeDomain, address[:], nil)
if err != nil {
return nil, err
}
Expand All @@ -744,7 +744,7 @@ func (r *ReaderParallelV3) ReadAccountCode(address common.Address, incarnation u
}

func (r *ReaderParallelV3) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error) {
enc, _, err := r.sd.DomainGet(kv.CodeDomain, address[:], nil)
enc, _, err := r.sd.GetLatest(kv.CodeDomain, address[:], nil)
if err != nil {
return 0, err
}
Expand Down
8 changes: 4 additions & 4 deletions erigon-lib/gointerfaces/remoteproto/kv.pb.go

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

8 changes: 4 additions & 4 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.

12 changes: 6 additions & 6 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.

8 changes: 4 additions & 4 deletions erigon-lib/kv/kv_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ type (
)

type TemporalGetter interface {
DomainGet(name Domain, k, k2 []byte) (v []byte, step uint64, err error)
GetLatest(name Domain, k, k2 []byte) (v []byte, step uint64, err error)
}
type TemporalTx interface {
Tx
Expand All @@ -515,8 +515,8 @@ type TemporalTx interface {
// Example: GetAsOf(Account, key, txNum) - retuns account's value before `txNum` transaction changed it
// Means if you want re-execute `txNum` on historical state - do `DomainGetAsOf(key, txNum)` to read state
// `ok = false` means: key not found. or "future txNum" passed.
DomainGetAsOf(name Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error)
DomainRange(name Domain, fromKey, toKey []byte, ts uint64, asc order.By, limit int) (it stream.KV, err error)
GetAsOf(name Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error)
RangeAsOf(name Domain, fromKey, toKey []byte, ts uint64, asc order.By, limit int) (it stream.KV, err error)

// IndexRange - return iterator over range of inverted index for given key `k`
// Asc semantic: [from, to) AND from > to
Expand All @@ -527,7 +527,7 @@ type TemporalTx interface {
// Example: IndexRange("IndexName", -1, -1, order.Asc, 10)
IndexRange(name InvertedIdx, k []byte, fromTs, toTs int, asc order.By, limit int) (timestamps stream.U64, err error)

// HistorySeek - like `DomainGetAsOf` but without latest state - only for `History`
// HistorySeek - like `GetAsOf` but without latest state - only for `History`
// `ok == true && v != nil && len(v) == 0` means key-creation even
HistorySeek(name Domain, k []byte, ts uint64) (v []byte, ok bool, err error)

Expand Down
6 changes: 3 additions & 3 deletions erigon-lib/kv/kvcache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ func (c *Coherent) Get(k []byte, tx kv.Tx, id uint64) (v []byte, err error) {

if c.cfg.StateV3 {
if len(k) == 20 {
v, _, err = tx.(kv.TemporalTx).DomainGet(kv.AccountsDomain, k, nil)
v, _, err = tx.(kv.TemporalTx).GetLatest(kv.AccountsDomain, k, nil)
} else {
v, _, err = tx.(kv.TemporalTx).DomainGet(kv.StorageDomain, k, nil)
v, _, err = tx.(kv.TemporalTx).GetLatest(kv.StorageDomain, k, nil)
}
} else {
v, err = tx.GetOne(kv.PlainState, k)
Expand Down Expand Up @@ -443,7 +443,7 @@ func (c *Coherent) GetCode(k []byte, tx kv.Tx, id uint64) (v []byte, err error)
c.codeMiss.Inc()

if c.cfg.StateV3 {
v, _, err = tx.(kv.TemporalTx).DomainGet(kv.CodeDomain, k, nil)
v, _, err = tx.(kv.TemporalTx).GetLatest(kv.CodeDomain, k, nil)
} else {
v, err = tx.GetOne(kv.Code, k)
}
Expand Down
6 changes: 3 additions & 3 deletions erigon-lib/kv/kvcache/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ func (c *DummyCache) Len() int { return 0 }
func (c *DummyCache) Get(k []byte, tx kv.Tx, id uint64) ([]byte, error) {
if c.stateV3 {
if len(k) == 20 {
v, _, err := tx.(kv.TemporalTx).DomainGet(kv.AccountsDomain, k, nil)
v, _, err := tx.(kv.TemporalTx).GetLatest(kv.AccountsDomain, k, nil)
return v, err
}
v, _, err := tx.(kv.TemporalTx).DomainGet(kv.StorageDomain, k, nil)
v, _, err := tx.(kv.TemporalTx).GetLatest(kv.StorageDomain, k, nil)
return v, err
}
return tx.GetOne(kv.PlainState, k)
}
func (c *DummyCache) GetCode(k []byte, tx kv.Tx, id uint64) ([]byte, error) {
if c.stateV3 {
v, _, err := tx.(kv.TemporalTx).DomainGet(kv.CodeDomain, k, nil)
v, _, err := tx.(kv.TemporalTx).GetLatest(kv.CodeDomain, k, nil)
return v, err
}
return tx.GetOne(kv.Code, k)
Expand Down
8 changes: 4 additions & 4 deletions erigon-lib/kv/membatchwithdb/memory_mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,14 @@ func (m *MemoryMutation) AggTx() any {
return m.db.(hasAggCtx).AggTx()
}

func (m *MemoryMutation) DomainGet(name kv.Domain, k, k2 []byte) (v []byte, step uint64, err error) {
func (m *MemoryMutation) GetLatest(name kv.Domain, k, k2 []byte) (v []byte, step uint64, err error) {
panic("not supported")
//return m.db.(kv.TemporalTx).DomainGet(name, k, k2)
//return m.db.(kv.TemporalTx).GetLatest(name, k, k2)
}

func (m *MemoryMutation) GetAsOf(name kv.Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error) {
panic("not supported")
//return m.db.(kv.TemporalTx).DomainGetAsOf(name, k, k2, ts)
//return m.db.(kv.TemporalTx).GetAsOf(name, k, k2, ts)
}
func (m *MemoryMutation) HistorySeek(name kv.History, k []byte, ts uint64) (v []byte, ok bool, err error) {
panic("not supported")
Expand All @@ -738,5 +738,5 @@ func (m *MemoryMutation) HistoryRange(name kv.History, fromTs, toTs int, asc ord

func (m *MemoryMutation) DomainRange(name kv.Domain, fromKey, toKey []byte, ts uint64, asc order.By, limit int) (it stream.KV, err error) {
panic("not supported")
//return m.db.(kv.TemporalTx).DomainRange(name, fromKey, toKey, ts, asc, limit)
//return m.db.(kv.TemporalTx).RangeAsOf(name, fromKey, toKey, ts, asc, limit)
}
Loading

0 comments on commit 736da1c

Please sign in to comment.