From 9efb8e838b153d8ac4c8d77123a19dff99c2efea Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Thu, 29 Dec 2022 10:09:09 +0700 Subject: [PATCH] save --- core/state/plain_readonly.go | 14 +++++++++----- turbo/rpchelper/helper.go | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/state/plain_readonly.go b/core/state/plain_readonly.go index 5de26fff1..968e323e0 100644 --- a/core/state/plain_readonly.go +++ b/core/state/plain_readonly.go @@ -29,6 +29,7 @@ import ( "github.com/ledgerwatch/erigon-lib/kv/kvcfg" "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/common/dbutils" + "github.com/ledgerwatch/erigon/core/rawdb" "github.com/ledgerwatch/erigon/core/state/historyv2read" "github.com/ledgerwatch/erigon/core/types/accounts" "github.com/ledgerwatch/log/v3" @@ -54,7 +55,7 @@ type PlainState struct { accHistoryC, storageHistoryC kv.Cursor accChangesC, storageChangesC kv.CursorDupSort tx kv.Tx - blockNr uint64 + blockNr, txNr uint64 histV3 bool storage map[common.Address]*btree.BTree trace bool @@ -83,6 +84,9 @@ func NewPlainState(tx kv.Tx, blockNr uint64, systemContractLookup map[common.Add ps.storageChangesC = c4 } + if histV3 { + ps.txNr, _ = rawdb.TxNums.Min(tx, blockNr) + } return ps } @@ -105,7 +109,7 @@ func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Ha var accData []byte var err error if ttx, ok := s.tx.(kv.TemporalTx); ok { - accData, err = historyv2read.GetAsOfV3(ttx, false /* storage */, addr[:], s.blockNr, s.histV3) + accData, err = historyv2read.GetAsOfV3(ttx, false /* storage */, addr[:], s.txNr, s.histV3) if err != nil { return err } @@ -187,7 +191,7 @@ func (s *PlainState) ReadAccountData(address common.Address) (*accounts.Account, var enc []byte var err error if ttx, ok := s.tx.(kv.TemporalTx); ok { - enc, err = historyv2read.GetAsOfV3(ttx, false /* storage */, address[:], s.blockNr, s.histV3) + enc, err = historyv2read.GetAsOfV3(ttx, false /* storage */, address[:], s.txNr, s.histV3) if err != nil { return nil, err } @@ -233,7 +237,7 @@ func (s *PlainState) ReadAccountStorage(address common.Address, incarnation uint var enc []byte var err error if ttx, ok := s.tx.(kv.TemporalTx); ok { - enc, err = historyv2read.GetAsOfV3(ttx, true /* storage */, compositeKey, s.blockNr, s.histV3) + enc, err = historyv2read.GetAsOfV3(ttx, true /* storage */, compositeKey, s.txNr, s.histV3) if err != nil { return nil, err } @@ -275,7 +279,7 @@ func (s *PlainState) ReadAccountIncarnation(address common.Address) (uint64, err var enc []byte var err error if ttx, ok := s.tx.(kv.TemporalTx); ok { - enc, err = historyv2read.GetAsOfV3(ttx, false /* storage */, address[:], s.blockNr+1, s.histV3) + enc, err = historyv2read.GetAsOfV3(ttx, false /* storage */, address[:], s.txNr+1, s.histV3) if err != nil { return 0, err } diff --git a/turbo/rpchelper/helper.go b/turbo/rpchelper/helper.go index 94759117a..d29a13112 100644 --- a/turbo/rpchelper/helper.go +++ b/turbo/rpchelper/helper.go @@ -127,7 +127,6 @@ func CreateHistoryStateReader(tx kv.Tx, blockNumber, txnIndex uint64, agg *state if err != nil { return nil, err } - fmt.Printf("hist reader v3: bn=%d, txNum=%d\n", tx, blockNumber) r.SetTxNum(minTxNum + txnIndex) return r, nil }