Skip to content

Commit

Permalink
solve the mismatch validator bug with final solution (node-real#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmbeing committed Jun 20, 2023
1 parent 2dcfdfd commit 10a1057
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ docker-compose.*.yml
coverage.out

dist
__debug_bin
__debug_bin
cmd/erigon/Users/
7 changes: 5 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/willf/bitset"

"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto/cryptopool"

Expand All @@ -38,7 +39,6 @@ import (
"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/forkid"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/crypto"
Expand Down Expand Up @@ -876,6 +876,7 @@ func (p *Parlia) verifyValidators(header, parentHeader *types.Header, state *sta
}
} else {
if uint8(validatorsNumber) != header.Extra[extraVanity] {
log.Error("verifyValidators failed", "len(validatorsNumber)", validatorsNumber, "header.Extra[extraVanity]", header.Extra[extraVanity])
return errMismatchingEpochValidators
}
validatorsBytes = make([]byte, validatorsNumber*validatorBytesLength)
Expand Down Expand Up @@ -949,6 +950,7 @@ func (p *Parlia) finalize(header *types.Header, state *state.IntraBlockState, tx
// If the block is an epoch end block, verify the validator list
// The verification can only be done when the state is ready, it can't be done in VerifyHeader.
parentHeader := chain.GetHeader(header.ParentHash, number-1)

if err := p.verifyValidators(header, parentHeader, state); err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -1339,7 +1341,8 @@ func (p *Parlia) getCurrentValidators(header *types.Header, ibs *state.IntraBloc
}

msgData := hexutility.Bytes(data)
_, returnData, err := p.systemCall(header.Coinbase, systemcontracts.ValidatorContract, msgData[:], ibs, header, u256.Num0)
ibsWithoutCache := state.New(ibs.StateReader)
_, returnData, err := p.systemCall(header.Coinbase, systemcontracts.ValidatorContract, msgData[:], ibsWithoutCache, header, u256.Num0)
if err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type BalanceIncrease struct {
// that occur during block's execution.
// NOT THREAD SAFE!
type IntraBlockState struct {
stateReader StateReader
StateReader StateReader

// This map holds 'live' objects, which will get modified while processing a state transition.
stateObjects map[libcommon.Address]*stateObject
Expand Down Expand Up @@ -88,7 +88,7 @@ type IntraBlockState struct {
// Create a new state from a given trie
func New(stateReader StateReader) *IntraBlockState {
return &IntraBlockState{
stateReader: stateReader,
StateReader: stateReader,
stateObjects: map[libcommon.Address]*stateObject{},
stateObjectsDirty: map[libcommon.Address]struct{}{},
nilAccounts: map[libcommon.Address]struct{}{},
Expand Down Expand Up @@ -235,7 +235,7 @@ func (sdb *IntraBlockState) GetCodeSize(addr libcommon.Address) int {
if stateObject.code != nil {
return len(stateObject.code)
}
l, err := sdb.stateReader.ReadAccountCodeSize(addr, stateObject.data.Incarnation, stateObject.data.CodeHash)
l, err := sdb.StateReader.ReadAccountCodeSize(addr, stateObject.data.Incarnation, stateObject.data.CodeHash)
if err != nil {
sdb.setErrorUnsafe(err)
}
Expand Down Expand Up @@ -427,7 +427,7 @@ func (sdb *IntraBlockState) getStateObject(addr libcommon.Address) (stateObject
}
return nil
}
account, err := sdb.stateReader.ReadAccountData(addr)
account, err := sdb.StateReader.ReadAccountData(addr)
if err != nil {
sdb.setErrorUnsafe(err)
return nil
Expand Down Expand Up @@ -503,7 +503,7 @@ func (sdb *IntraBlockState) CreateAccount(addr libcommon.Address, contractCreati
if previous != nil && previous.selfdestructed {
prevInc = previous.data.Incarnation
} else {
if inc, err := sdb.stateReader.ReadAccountIncarnation(addr); err == nil {
if inc, err := sdb.StateReader.ReadAccountIncarnation(addr); err == nil {
prevInc = inc
} else {
sdb.savedErr = err
Expand Down
4 changes: 2 additions & 2 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (so *stateObject) GetCommittedState(key *libcommon.Hash, out *uint256.Int)
return
}
// Load from DB in case it is missing.
enc, err := so.db.stateReader.ReadAccountStorage(so.address, so.data.GetIncarnation(), key)
enc, err := so.db.StateReader.ReadAccountStorage(so.address, so.data.GetIncarnation(), key)
if err != nil {
so.setError(err)
out.Clear()
Expand Down Expand Up @@ -328,7 +328,7 @@ func (so *stateObject) Code() []byte {
if bytes.Equal(so.CodeHash(), emptyCodeHash) {
return nil
}
code, err := so.db.stateReader.ReadAccountCode(so.Address(), so.data.Incarnation, libcommon.BytesToHash(so.CodeHash()))
code, err := so.db.StateReader.ReadAccountCode(so.Address(), so.data.Incarnation, libcommon.BytesToHash(so.CodeHash()))
if err != nil {
so.setError(fmt.Errorf("can't load code hash %x: %w", so.CodeHash(), err))
}
Expand Down

0 comments on commit 10a1057

Please sign in to comment.