Skip to content

Commit

Permalink
Merge branch 'devel' into e3_invalid_txnum
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Jan 9, 2023
2 parents 6b01dc5 + f3636c2 commit 147e6a9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 38 deletions.
8 changes: 4 additions & 4 deletions core/state/history_reader_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (hr *HistoryReaderV3) ReadAccountData(address common.Address) (*accounts.Ac
var ok bool
var err error
if hr.ttx != nil {
enc, ok, err = hr.ttx.DomainGet(temporal.AccountsDomain, address.Bytes(), hr.txNum)
enc, ok, err = hr.ttx.DomainGet(temporal.AccountsDomain, address.Bytes(), nil, hr.txNum)
if err != nil || !ok || len(enc) == 0 {
if hr.trace {
fmt.Printf("ReadAccountData [%x] => []\n", address)
Expand Down Expand Up @@ -101,7 +101,7 @@ func (hr *HistoryReaderV3) ReadAccountData(address common.Address) (*accounts.Ac

func (hr *HistoryReaderV3) ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error) {
if hr.ttx != nil {
enc, _, err := hr.ttx.DomainGet(temporal.StorageDomain, append(address.Bytes(), key.Bytes()...), hr.txNum)
enc, _, err := hr.ttx.DomainGet(temporal.StorageDomain, append(address.Bytes(), key.Bytes()...), nil, hr.txNum)
return enc, err
}

Expand Down Expand Up @@ -134,7 +134,7 @@ func (hr *HistoryReaderV3) ReadAccountCode(address common.Address, incarnation u
return nil, nil
}
if hr.ttx != nil {
enc, _, err := hr.ttx.DomainGet(temporal.CodeDomain, address.Bytes(), hr.txNum)
enc, _, err := hr.ttx.DomainGet(temporal.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
return enc, err
}

Expand All @@ -156,7 +156,7 @@ func (hr *HistoryReaderV3) ReadAccountCode(address common.Address, incarnation u

func (hr *HistoryReaderV3) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error) {
if hr.ttx != nil {
enc, _, err := hr.ttx.DomainGet(temporal.CodeDomain, address.Bytes(), hr.txNum)
enc, _, err := hr.ttx.DomainGet(temporal.CodeDomain, address.Bytes(), codeHash.Bytes(), hr.txNum)
return len(enc), err
}
enc, ok, err := hr.ac.ReadAccountCodeNoStateWithRecent(address.Bytes(), hr.txNum)
Expand Down
8 changes: 4 additions & 4 deletions core/state/plain_readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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 = ttx.DomainGet(temporal.AccountsDomain, addr[:], s.txNr)
accData, _, err = ttx.DomainGet(temporal.AccountsDomain, addr[:], nil, s.txNr)
if err != nil {
return err
}
Expand Down Expand Up @@ -192,7 +192,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 = ttx.DomainGet(temporal.AccountsDomain, address[:], s.txNr)
enc, _, err = ttx.DomainGet(temporal.AccountsDomain, address[:], nil, s.txNr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -238,7 +238,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 = ttx.DomainGet(temporal.StorageDomain, compositeKey, s.txNr)
enc, _, err = ttx.DomainGet(temporal.StorageDomain, compositeKey, nil, s.txNr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -280,7 +280,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 = ttx.DomainGet(temporal.AccountsDomain, address[:], s.txNr+1)
enc, _, err = ttx.DomainGet(temporal.AccountsDomain, address[:], nil, s.txNr+1)
if err != nil {
return 0, err
}
Expand Down
10 changes: 5 additions & 5 deletions core/state/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const (
TracesToIdx kv.InvertedIdx = "TracesToIdx"
)

func (tx *Tx) DomainGet(name kv.Domain, key []byte, ts uint64) (v []byte, ok bool, err error) {
func (tx *Tx) DomainGet(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 Expand Up @@ -160,10 +160,10 @@ func (tx *Tx) DomainGet(name kv.Domain, key []byte, ts uint64) (v []byte, ok boo
if ok {
return v, true, nil
}
v, err = tx.GetOne(kv.Code, key)
v, err = tx.GetOne(kv.Code, key2)
return v, v != nil, err
}
v, err = tx.GetOne(kv.Code, key)
v, err = tx.GetOne(kv.Code, key2)
return v, v != nil, err
default:
panic(fmt.Sprintf("unexpected: %s", name))
Expand Down Expand Up @@ -204,8 +204,8 @@ func (tx *Tx) HistoryGet(name kv.History, key []byte, ts uint64) (v []byte, ok b
if err != nil {
return nil, false, err
}
if !ok {
return nil, ok, nil
if !ok || len(v) == 0 {
return v, ok, nil
}
v, err = tx.db.restoreCodeHash(tx.Tx, key, v)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ func startHandlingForkChoice(
}
}

cfg.hd.UpdateTopSeenHeightPoS(headerNumber)
forkingPoint, err := forkingPoint(ctx, tx, headerInserter, cfg.blockReader, header)
if err != nil {
return nil, err
Expand Down Expand Up @@ -476,7 +475,6 @@ func handleNewPayload(
headerHash := block.Hash()

log.Info(fmt.Sprintf("[%s] Handling new payload", s.LogPrefix()), "height", headerNumber, "hash", headerHash)
cfg.hd.UpdateTopSeenHeightPoS(headerNumber)

parent, err := cfg.blockReader.HeaderByHash(ctx, tx, header.ParentHash)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions 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.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230106113245-1a33a0bd2931
github.com/ledgerwatch/erigon-lib v0.0.0-20230109081124-7cfe15344887
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230106211435-2670b273bb55
github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down Expand Up @@ -40,7 +40,6 @@ require (
github.com/golang-jwt/jwt/v4 v4.4.3
github.com/golang/snappy v0.0.4
github.com/google/btree v1.1.2
github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,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-20230106113245-1a33a0bd2931 h1:vC3Hgdb4AWx3hDsW83gcGU+XlT93/idzsLX+sTmY5pk=
github.com/ledgerwatch/erigon-lib v0.0.0-20230106113245-1a33a0bd2931/go.mod h1:+KUIITyYdMtGzEMQXdoI06o/w+Qin3Lf48PQQCqtHZ0=
github.com/ledgerwatch/erigon-lib v0.0.0-20230109081124-7cfe15344887 h1:p+Ay0Xdal6YAfEYF/WXXXKnnXrI0Z/vwBpy/8PxfGhg=
github.com/ledgerwatch/erigon-lib v0.0.0-20230109081124-7cfe15344887/go.mod h1:eVDPfeBk2LVY7IqJjddlMTAy7BxSZ9+DgZbu+ftVNtk=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230106211435-2670b273bb55 h1:4gY6eRXQiX0Te1oKTpsxj6MjXksQSSTHWiSh/j89sEY=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230106211435-2670b273bb55/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
Expand Down
18 changes: 0 additions & 18 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,24 +1063,6 @@ func (hd *HeaderDownload) SetFirstPoSHeight(blockHeight uint64) {
}
}

func (hd *HeaderDownload) TopSeenHeight() uint64 {
hd.lock.RLock()
defer hd.lock.RUnlock()
if hd.topSeenHeightPoW > hd.topSeenHeightPoS {
return hd.topSeenHeightPoW
} else {
return hd.topSeenHeightPoS
}
}

func (hd *HeaderDownload) UpdateTopSeenHeightPoS(blockHeight uint64) {
hd.lock.Lock()
defer hd.lock.Unlock()
if blockHeight > hd.topSeenHeightPoS {
hd.topSeenHeightPoS = blockHeight
}
}

func (hd *HeaderDownload) SetHeaderReader(headerReader consensus.ChainHeaderReader) {
hd.lock.Lock()
defer hd.lock.Unlock()
Expand Down
1 change: 0 additions & 1 deletion turbo/stages/headerdownload/header_data_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ type HeaderDownload struct {
headerReader services.HeaderReader

// Proof of Stake (PoS)
topSeenHeightPoS uint64
firstSeenHeightPoS *uint64
requestId int
posAnchor *Anchor
Expand Down

0 comments on commit 147e6a9

Please sign in to comment.