Skip to content

Commit

Permalink
GetAsOf: single key param (#13021)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Dec 6, 2024
1 parent f44167d commit 1e67f70
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 24 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.GetAsOf(kv.ReceiptDomain, CumulativeGasUsedInBlockKey, nil, txNum)
v, ok, err = tx.GetAsOf(kv.ReceiptDomain, CumulativeGasUsedInBlockKey, txNum)
if err != nil {
return
}
if ok && v != nil {
cumGasUsed = uvarint(v)
}

v, ok, err = tx.GetAsOf(kv.ReceiptDomain, CumulativeBlobGasUsedInBlockKey, nil, txNum)
v, ok, err = tx.GetAsOf(kv.ReceiptDomain, CumulativeBlobGasUsedInBlockKey, 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.GetAsOf(kv.ReceiptDomain, FirstLogIndexKey, nil, txNum)
v, ok, err = tx.GetAsOf(kv.ReceiptDomain, FirstLogIndexKey, txNum)
if err != nil {
return
}
Expand Down
10 changes: 5 additions & 5 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.GetAsOf(kv.AccountsDomain, address[:], nil, hr.txNum)
enc, ok, err := hr.ttx.GetAsOf(kv.AccountsDomain, address[:], hr.txNum)
if err != nil || !ok || len(enc) == 0 {
if hr.trace {
fmt.Printf("ReadAccountData [%x] => []\n", address)
Expand All @@ -80,7 +80,7 @@ func (hr *HistoryReaderV3) ReadAccountDataForDebug(address common.Address) (*acc

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

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

func (hr *HistoryReaderV3) ReadAccountIncarnation(address common.Address) (uint64, error) {
enc, ok, err := hr.ttx.GetAsOf(kv.AccountsDomain, address.Bytes(), nil, hr.txNum)
enc, ok, err := hr.ttx.GetAsOf(kv.AccountsDomain, address.Bytes(), hr.txNum)
if err != nil || !ok || len(enc) == 0 {
if hr.trace {
fmt.Printf("ReadAccountIncarnation [%x] => [0]\n", address)
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/kv_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ 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.
GetAsOf(name Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error)
GetAsOf(name Domain, k []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`
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 @@ -717,9 +717,9 @@ func (m *MemoryMutation) GetLatest(name kv.Domain, k, k2 []byte) (v []byte, step
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) {
func (m *MemoryMutation) GetAsOf(name kv.Domain, k []byte, ts uint64) (v []byte, ok bool, err error) {
// panic("not supported")
return m.db.(kv.TemporalTx).GetAsOf(name, k, k2, ts)
return m.db.(kv.TemporalTx).GetAsOf(name, k, ts)
}

func (m *MemoryMutation) RangeAsOf(name kv.Domain, fromKey, toKey []byte, ts uint64, asc order.By, limit int) (it stream.KV, err error) {
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/kv/remotedb/kv_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ func (c *remoteCursorDupSort) PrevNoDup() ([]byte, []byte, error) { return c.pre
func (c *remoteCursorDupSort) LastDup() ([]byte, error) { return c.lastDup() }

// Temporal Methods
func (tx *tx) GetAsOf(name kv.Domain, k, k2 []byte, ts uint64) (v []byte, ok bool, err error) {
reply, err := tx.db.remoteKV.GetLatest(tx.ctx, &remote.GetLatestReq{TxId: tx.id, Table: name.String(), K: k, K2: k2, Ts: ts})
func (tx *tx) GetAsOf(name kv.Domain, k []byte, ts uint64) (v []byte, ok bool, err error) {
reply, err := tx.db.remoteKV.GetLatest(tx.ctx, &remote.GetLatestReq{TxId: tx.id, Table: name.String(), K: k, Ts: ts})
if err != nil {
return nil, false, err
}
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/remotedbserver/remotedbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (s *KvServer) GetLatest(_ context.Context, req *remote.GetLatestReq) (reply
return err
}
} else {
reply.V, reply.Ok, err = ttx.GetAsOf(domainName, req.K, req.K2, req.Ts)
reply.V, reply.Ok, err = ttx.GetAsOf(domainName, req.K, req.Ts)
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions erigon-lib/kv/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package temporal
import (
"context"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/kv/mdbx"
"github.com/erigontech/erigon-lib/kv/order"
Expand Down Expand Up @@ -214,11 +213,8 @@ func (tx *Tx) GetLatest(name kv.Domain, k, k2 []byte) (v []byte, step uint64, er
}
return v, step, nil
}
func (tx *Tx) GetAsOf(name kv.Domain, key, key2 []byte, ts uint64) (v []byte, ok bool, err error) {
if key2 != nil {
key = append(common.Copy(key), key2...)
}
return tx.filesTx.GetAsOf(tx.MdbxTx, name, key, ts)
func (tx *Tx) GetAsOf(name kv.Domain, k []byte, ts uint64) (v []byte, ok bool, err error) {
return tx.filesTx.GetAsOf(tx.MdbxTx, name, k, ts)
}

func (tx *Tx) HistorySeek(name kv.Domain, key []byte, ts uint64) (v []byte, ok bool, err error) {
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/state/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1850,8 +1850,8 @@ func (ac *AggregatorRoTx) getAsOfFile(name kv.Domain, key []byte, ts uint64) (v
return ac.d[name].GetAsOfFile(key, ts)
}

func (ac *AggregatorRoTx) GetAsOf(tx kv.Tx, name kv.Domain, key []byte, ts uint64) (v []byte, ok bool, err error) {
return ac.d[name].GetAsOf(key, ts, tx)
func (ac *AggregatorRoTx) GetAsOf(tx kv.Tx, name kv.Domain, k []byte, ts uint64) (v []byte, ok bool, err error) {
return ac.d[name].GetAsOf(k, ts, tx)
}
func (ac *AggregatorRoTx) GetLatest(domain kv.Domain, k, k2 []byte, tx kv.Tx) (v []byte, step uint64, ok bool, err error) {
return ac.d[domain].GetLatest(k, k2, tx)
Expand Down
4 changes: 2 additions & 2 deletions turbo/jsonrpc/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (api *PrivateDebugAPIImpl) AccountAt(ctx context.Context, blockHash common.
return nil, err
}
ttx := tx.(kv.TemporalTx)
v, ok, err := ttx.GetAsOf(kv.AccountsDomain, address[:], nil, minTxNum+txIndex+1)
v, ok, err := ttx.GetAsOf(kv.AccountsDomain, address[:], minTxNum+txIndex+1)
if err != nil {
return nil, err
}
Expand All @@ -339,7 +339,7 @@ func (api *PrivateDebugAPIImpl) AccountAt(ctx context.Context, blockHash common.
result.Nonce = hexutil.Uint64(a.Nonce)
result.CodeHash = a.CodeHash

code, _, err := ttx.GetAsOf(kv.CodeDomain, address[:], nil, minTxNum+txIndex)
code, _, err := ttx.GetAsOf(kv.CodeDomain, address[:], minTxNum+txIndex)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1e67f70

Please sign in to comment.