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

parlia urgent: BEP-131 bug. Cause new validators on blockNumber%Epoch = 11 are slashed often. #1145

Merged
merged 1 commit into from
Oct 28, 2022

Conversation

Jolly23
Copy link
Contributor

@Jolly23 Jolly23 commented Oct 19, 2022

Please review and merge this PR ASAP. It continually makes mistake for all validators.

Description

Inside parlia snapshot, BEP-131 validator set is updated at number%s.config.Epoch == uint64(len(snap.Validators)/2).

Simplify it is blockNumber%200 = 10

parlia.SignRecently() is the first function be called when miner.worker getting NewChainHead signal, which controls the starting of the packing tasks.

            case head := <-w.chainHeadCh:
			if !w.isRunning() {
				continue
			}
			clearPending(head.Block.NumberU64())
			timestamp = time.Now().Unix()
			if p, ok := w.engine.(*parlia.Parlia); ok {
				signedRecent, err := p.SignRecently(w.chain, head.Block.Header())
				if err != nil {
					log.Info("Not allowed to propose block", "err", err)
					continue
				}
				if signedRecent {
					log.Info("Signed recently, must wait")
					continue
				}
			}
			commit(true, commitInterruptNewHead)

But there is bug inside the parlia.SignRecently() causes the newValidatorSet is not updated on blockNumber%200 = 10

func (p *Parlia) SignRecently(chain consensus.ChainReader, parent *types.Header) (bool, error) {
	snap, err := p.snapshot(chain, parent.Number.Uint64(), parent.ParentHash, nil)

Obviously we cannot find a block by mismatched blockNumber and blockHash. In the line above they are parent.Number.Uint64() and parent.ParentHash.

However the parent.ParentHash hits a cache of parlia.Snapshot. The cached snapshot cannot snap.apply the latest chain head.

Thus the very import part ChangeValidatorSet doesn't run on a RecentSigned validator and new imported validator of current Epoch.

Rationale

BNB48 Club reported some related cases.

Example

slashlist

recent slash list, blockNumber%Epoch = 11 occur frequently

slashrecord

The slashed validator

epoch

This was a new imported validator on Epoch of 22243800, it was a candidate in last Epoch. He was in-turn at 22243811.

But he didn't loaded the newValidatorSet at 22243810 so he missed 22243811.

Changes

func (p *Parlia) SignRecently(chain consensus.ChainReader, parent *types.Block) (bool, error) {
	snap, err := p.snapshot(chain, parent.NumberU64(), parent.Hash(), nil)

@Jolly23 Jolly23 changed the title parlia urgent: BEP-131 bug. Cause new validators on blockNumber%Epoch = 11 are slashed often. parlia urgent: BEP-131 bug. Cause new validators on _blockNumber%Epoch = 11_ are slashed often. Oct 19, 2022
@Jolly23 Jolly23 changed the title parlia urgent: BEP-131 bug. Cause new validators on _blockNumber%Epoch = 11_ are slashed often. parlia urgent: BEP-131 bug. Cause new validators on blockNumber%Epoch = 11 are slashed often. Oct 19, 2022
brilliant-lx
brilliant-lx previously approved these changes Oct 19, 2022
Copy link
Collaborator

@brilliant-lx brilliant-lx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thank you for your contribution.

qinglin89
qinglin89 previously approved these changes Oct 19, 2022
@Jolly23
Copy link
Contributor Author

Jolly23 commented Oct 19, 2022

related issue #1133

unclezoro
unclezoro previously approved these changes Oct 28, 2022
@unclezoro unclezoro changed the base branch from master to develop October 28, 2022 03:26
@unclezoro unclezoro dismissed stale reviews from qinglin89, brilliant-lx, and themself October 28, 2022 03:26

The base branch was changed.

@unclezoro unclezoro changed the base branch from develop to master October 28, 2022 03:27
@brilliant-lx brilliant-lx merged commit c46671d into bnb-chain:master Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants