This commit is contained in:
alex.sharov 2022-12-29 10:09:09 +07:00
parent 0fdd60a0d1
commit 9efb8e838b
2 changed files with 9 additions and 6 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/kvcfg" "github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/dbutils" "github.com/ledgerwatch/erigon/common/dbutils"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state/historyv2read" "github.com/ledgerwatch/erigon/core/state/historyv2read"
"github.com/ledgerwatch/erigon/core/types/accounts" "github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/log/v3"
@ -54,7 +55,7 @@ type PlainState struct {
accHistoryC, storageHistoryC kv.Cursor accHistoryC, storageHistoryC kv.Cursor
accChangesC, storageChangesC kv.CursorDupSort accChangesC, storageChangesC kv.CursorDupSort
tx kv.Tx tx kv.Tx
blockNr uint64 blockNr, txNr uint64
histV3 bool histV3 bool
storage map[common.Address]*btree.BTree storage map[common.Address]*btree.BTree
trace bool trace bool
@ -83,6 +84,9 @@ func NewPlainState(tx kv.Tx, blockNr uint64, systemContractLookup map[common.Add
ps.storageChangesC = c4 ps.storageChangesC = c4
} }
if histV3 {
ps.txNr, _ = rawdb.TxNums.Min(tx, blockNr)
}
return ps return ps
} }
@ -105,7 +109,7 @@ func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Ha
var accData []byte var accData []byte
var err error var err error
if ttx, ok := s.tx.(kv.TemporalTx); ok { 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 { if err != nil {
return err return err
} }
@ -187,7 +191,7 @@ func (s *PlainState) ReadAccountData(address common.Address) (*accounts.Account,
var enc []byte var enc []byte
var err error var err error
if ttx, ok := s.tx.(kv.TemporalTx); ok { 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 { if err != nil {
return nil, err return nil, err
} }
@ -233,7 +237,7 @@ func (s *PlainState) ReadAccountStorage(address common.Address, incarnation uint
var enc []byte var enc []byte
var err error var err error
if ttx, ok := s.tx.(kv.TemporalTx); ok { 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 { if err != nil {
return nil, err return nil, err
} }
@ -275,7 +279,7 @@ func (s *PlainState) ReadAccountIncarnation(address common.Address) (uint64, err
var enc []byte var enc []byte
var err error var err error
if ttx, ok := s.tx.(kv.TemporalTx); ok { 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 { if err != nil {
return 0, err return 0, err
} }

View File

@ -127,7 +127,6 @@ func CreateHistoryStateReader(tx kv.Tx, blockNumber, txnIndex uint64, agg *state
if err != nil { if err != nil {
return nil, err return nil, err
} }
fmt.Printf("hist reader v3: bn=%d, txNum=%d\n", tx, blockNumber)
r.SetTxNum(minTxNum + txnIndex) r.SetTxNum(minTxNum + txnIndex)
return r, nil return r, nil
} }