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

fix: Solve the mismatch validator bug with final solution #135

Merged
merged 1 commit into from
Jun 20, 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
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