Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e3: DomainGetAsOf, DomainRange #7177

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,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 @@ -321,7 +321,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