Skip to content

Commit 16c912a

Browse files
authored
Merge pull request bnb-chain#59 from node-real/improve-block-proposer-layer-liveness
imporve liveness of block proposal layer
2 parents cab13f2 + a622aae commit 16c912a

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

consensus/parlia/parlia.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,6 @@ func getVoteAttestationFromHeader(header *types.Header, chainConfig *params.Chai
389389
return &attestation, nil
390390
}
391391

392-
func getSignRecentlyLimit(blockNumber *big.Int, validatorsNumber int, chainConfig *params.ChainConfig) int {
393-
limit := validatorsNumber/2 + 1
394-
if chainConfig.IsBoneh(blockNumber) {
395-
limit = cmath.CeilDiv(validatorsNumber*2, 3)
396-
}
397-
return limit
398-
}
399-
400392
// verifyVoteAttestation checks whether the vote attestation in the header is valid.
401393
func (p *Parlia) verifyVoteAttestation(chain consensus.ChainHeaderReader, header *types.Header, parents []*types.Header) error {
402394
attestation, err := getVoteAttestationFromHeader(header, p.chainConfig, p.config)
@@ -757,7 +749,7 @@ func (p *Parlia) verifySeal(chain consensus.ChainHeaderReader, header *types.Hea
757749
for seen, recent := range snap.Recents {
758750
if recent == signer {
759751
// Signer is among recents, only fail if the current block doesn't shift it out
760-
if limit := getSignRecentlyLimit(header.Number, len(snap.Validators), p.chainConfig); seen > number-uint64(limit) {
752+
if limit := uint64(len(snap.Validators)/2 + 1); seen > number-limit {
761753
return errRecentlySigned
762754
}
763755
}
@@ -1291,7 +1283,7 @@ func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
12911283
for seen, recent := range snap.Recents {
12921284
if recent == val {
12931285
// Signer is among recents, only wait if the current block doesn't shift it out
1294-
if limit := getSignRecentlyLimit(header.Number, len(snap.Validators), p.chainConfig); number < uint64(limit) || seen > number-uint64(limit) {
1286+
if limit := uint64(len(snap.Validators)/2 + 1); number < limit || seen > number-limit {
12951287
log.Info("Signed recently, must wait for others")
12961288
return nil
12971289
}
@@ -1406,8 +1398,7 @@ func (p *Parlia) SignRecently(chain consensus.ChainReader, parent *types.Block)
14061398
}
14071399

14081400
// Signer is among recents, only wait if the current block doesn't shift it out
1409-
limit := getSignRecentlyLimit(parent.Number(), len(snap.Validators), p.chainConfig)
1410-
if number < uint64(limit) || seen > number-uint64(limit) {
1401+
if limit := uint64(len(snap.Validators)/2 + 1); number < limit || seen > number-limit {
14111402
return true, nil
14121403
}
14131404
}
@@ -1849,7 +1840,7 @@ func (p *Parlia) backOffTime(snap *Snapshot, header *types.Header, val common.Ad
18491840

18501841
// Exclude the recently signed validators first, and then compute the backOffTime.
18511842
recentVals := make(map[common.Address]struct{}, len(snap.Recents))
1852-
limit := getSignRecentlyLimit(header.Number, len(snap.Validators), p.chainConfig)
1843+
limit := len(snap.Validators)/2 + 1
18531844
for seen, recent := range snap.Recents {
18541845
if header.Number.Uint64() < uint64(limit) || seen > header.Number.Uint64()-uint64(limit) {
18551846
if val == recent {

consensus/parlia/snapshot.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
219219
for _, header := range headers {
220220
number := header.Number.Uint64()
221221
// Delete the oldest validator from the recent list to allow it signing again
222-
if limit := getSignRecentlyLimit(header.Number, len(snap.Validators), chainConfig); number >= uint64(limit) {
223-
delete(snap.Recents, number-uint64(limit))
222+
if limit := uint64(len(snap.Validators)/2 + 1); number >= limit {
223+
delete(snap.Recents, number-limit)
224224
}
225225
if limit := uint64(len(snap.Validators)); number >= limit {
226226
delete(snap.RecentForkHashes, number-limit)
@@ -261,8 +261,8 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
261261
}
262262
}
263263
}
264-
oldLimit := getSignRecentlyLimit(header.Number, len(snap.Validators), chainConfig)
265-
newLimit := getSignRecentlyLimit(header.Number, len(newVals), chainConfig)
264+
oldLimit := len(snap.Validators)/2 + 1
265+
newLimit := len(newVals)/2 + 1
266266
if newLimit < oldLimit {
267267
for i := 0; i < oldLimit-newLimit; i++ {
268268
delete(snap.Recents, number-uint64(newLimit)-uint64(i))

0 commit comments

Comments
 (0)