Skip to content

Commit

Permalink
e3: DomainGetAsOf, DomainRange (erigontech#7177)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored and calmbeing committed Apr 24, 2023
1 parent 7449b27 commit f5dbb44
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (api *PrivateDebugAPIImpl) AccountAt(ctx context.Context, blockHash common.
return nil, err
}
ttx := tx.(kv.TemporalTx)
v, ok, err := ttx.DomainGet(temporal.AccountsDomain, address[:], nil, minTxNum+txIndex+1)
v, ok, err := ttx.DomainGetAsOf(temporal.AccountsDomain, address[:], nil, minTxNum+txIndex+1)
if err != nil {
return nil, err
}
Expand All @@ -362,7 +362,7 @@ func (api *PrivateDebugAPIImpl) AccountAt(ctx context.Context, blockHash common.
result.Nonce = hexutil.Uint64(a.Nonce)
result.CodeHash = a.CodeHash

code, _, err := ttx.DomainGet(temporal.CodeDomain, address[:], a.CodeHash[:], minTxNum+txIndex)
code, _, err := ttx.DomainGetAsOf(temporal.CodeDomain, address[:], a.CodeHash[:], minTxNum+txIndex)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/debug_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestMapTxNum2BlockNum(t *testing.T) {
}
}
t.Run("descend", func(t *testing.T) {
tx, err := m.DB.(kv.TemporalRoDb).BeginTemporalRo(m.Ctx)
tx, err := m.DB.(kv.TemporalRoDB).BeginTemporalRo(m.Ctx)
require.NoError(t, err)
defer tx.Rollback()

Expand All @@ -440,7 +440,7 @@ func TestMapTxNum2BlockNum(t *testing.T) {
checkIter(t, expectTxNums, txNumsIter)
})
t.Run("ascend", func(t *testing.T) {
tx, err := m.DB.(kv.TemporalRoDb).BeginTemporalRo(m.Ctx)
tx, err := m.DB.(kv.TemporalRoDB).BeginTemporalRo(m.Ctx)
require.NoError(t, err)
defer tx.Rollback()

Expand All @@ -452,7 +452,7 @@ func TestMapTxNum2BlockNum(t *testing.T) {
checkIter(t, expectTxNums, txNumsIter)
})
t.Run("ascend limit", func(t *testing.T) {
tx, err := m.DB.(kv.TemporalRoDb).BeginTemporalRo(m.Ctx)
tx, err := m.DB.(kv.TemporalRoDB).BeginTemporalRo(m.Ctx)
require.NoError(t, err)
defer tx.Rollback()

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 @@ -32,7 +32,7 @@ func (hr *HistoryReaderV3) SetTxNum(txNum uint64) { hr.txNum = txNum }
func (hr *HistoryReaderV3) SetTrace(trace bool) { hr.trace = trace }

func (hr *HistoryReaderV3) ReadAccountData(address libcommon.Address) (*accounts.Account, error) {
enc, ok, err := hr.ttx.DomainGet(temporal.AccountsDomain, address.Bytes(), nil, hr.txNum)
enc, ok, err := hr.ttx.DomainGetAsOf(temporal.AccountsDomain, address.Bytes(), nil, hr.txNum)
if err != nil || !ok || len(enc) == 0 {
if hr.trace {
fmt.Printf("ReadAccountData [%x] => []\n", address)
Expand All @@ -53,7 +53,7 @@ func (hr *HistoryReaderV3) ReadAccountStorage(address libcommon.Address, incarna
acc := make([]byte, 20+8)
copy(acc, address.Bytes())
binary.BigEndian.PutUint64(acc[20:], incarnation)
enc, _, err := hr.ttx.DomainGet(temporal.StorageDomain, acc, key.Bytes(), hr.txNum)
enc, _, err := hr.ttx.DomainGetAsOf(temporal.StorageDomain, acc, key.Bytes(), hr.txNum)
if hr.trace {
fmt.Printf("ReadAccountStorage [%x] [%x] => [%x]\n", address, *key, enc)
}
Expand All @@ -64,20 +64,20 @@ func (hr *HistoryReaderV3) ReadAccountCode(address libcommon.Address, incarnatio
if codeHash == emptyCodeHashH {
return nil, nil
}
code, _, err := hr.ttx.DomainGet(temporal.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
code, _, err := hr.ttx.DomainGetAsOf(temporal.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
if hr.trace {
fmt.Printf("ReadAccountCode [%x %x] => [%x]\n", address, codeHash, code)
}
return code, err
}

func (hr *HistoryReaderV3) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error) {
enc, _, err := hr.ttx.DomainGet(temporal.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
enc, _, err := hr.ttx.DomainGetAsOf(temporal.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
return len(enc), err
}

func (hr *HistoryReaderV3) ReadAccountIncarnation(address libcommon.Address) (uint64, error) {
enc, ok, err := hr.ttx.DomainGet(temporal.AccountsDomain, address.Bytes(), nil, hr.txNum)
enc, ok, err := hr.ttx.DomainGetAsOf(temporal.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
17 changes: 16 additions & 1 deletion core/state/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,22 @@ func (tx *Tx) DomainRange(name kv.Domain, fromKey, toKey []byte, asOfTs uint64,

return it, nil
}
func (tx *Tx) DomainGet(name kv.Domain, key, key2 []byte, ts uint64) (v []byte, ok bool, err error) {
func (tx *Tx) DomainGet(name kv.Domain, key, key2 []byte) (v []byte, ok bool, err error) {
switch name {
case AccountsDomain:
v, err = tx.GetOne(kv.PlainState, key)
return v, v != nil, err
case StorageDomain:
v, err = tx.GetOne(kv.PlainState, append(common.Copy(key), key2...))
return v, v != nil, err
case CodeDomain:
v, err = tx.GetOne(kv.Code, key2)
return v, v != nil, err
default:
panic(fmt.Sprintf("unexpected: %s", name))
}
}
func (tx *Tx) DomainGetAsOf(name kv.Domain, key, key2 []byte, ts uint64) (v []byte, ok bool, err error) {
switch name {
case AccountsDomain:
v, ok, err = tx.HistoryGet(AccountsHistory, key, ts)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.19

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230324081547-7a281bca0c7c
github.com/ledgerwatch/erigon-lib v0.0.0-20230325033216-5ae3af617b53
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3
github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230324081547-7a281bca0c7c h1:3TOKHeGE1DpoYbCe/K8USRA0IV7MjRyE9OzRWKlxI3Y=
github.com/ledgerwatch/erigon-lib v0.0.0-20230324081547-7a281bca0c7c/go.mod h1:dagOLJlpxlMcQX4a2KIdzyCBIMtk6+ccqikNQf2uDwA=
github.com/ledgerwatch/erigon-lib v0.0.0-20230325033216-5ae3af617b53 h1:FTIeWRzOoUqVMyJPKR91NJWG0THkfYAsss6SarUt7PI=
github.com/ledgerwatch/erigon-lib v0.0.0-20230325033216-5ae3af617b53/go.mod h1:CkP5qnLv68u1AAHHamS7TBgPmlPBn0aVcPrHi7njrIU=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
Expand Down

0 comments on commit f5dbb44

Please sign in to comment.