From 284cd8a85be7cb756cdad99888299f928c415a90 Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Fri, 10 Mar 2023 15:23:42 +0800 Subject: [PATCH 1/2] consensus: fix delete the 1st validator from snapshot.recents list --- consensus/parlia/parlia.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index f3e051691b..22054cfa0d 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1326,7 +1326,11 @@ func (p *Parlia) backOffTime(snap *Snapshot, header *types.Header, val common.Ad if p.chainConfig.IsPlanck(header.Number) { // reverse the key/value of snap.Recents to get recentsMap recentsMap := make(map[common.Address]uint64, len(snap.Recents)) + bound := header.Number.Uint64() - uint64(len(validators)/2+1) for seen, recent := range snap.Recents { + if seen <= bound { + continue + } recentsMap[recent] = seen } From 94afd8106c81650a358b225bd29b2ab4ce53ef6c Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Sun, 12 Mar 2023 12:06:40 +0800 Subject: [PATCH 2/2] consensus:fix uint sub error with negative --- consensus/parlia/parlia.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 22054cfa0d..693a9e28b3 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1326,7 +1326,10 @@ func (p *Parlia) backOffTime(snap *Snapshot, header *types.Header, val common.Ad if p.chainConfig.IsPlanck(header.Number) { // reverse the key/value of snap.Recents to get recentsMap recentsMap := make(map[common.Address]uint64, len(snap.Recents)) - bound := header.Number.Uint64() - uint64(len(validators)/2+1) + bound := uint64(0) + if n, limit := header.Number.Uint64(), uint64(len(validators)/2+1); n > limit { + bound = n - limit + } for seen, recent := range snap.Recents { if seen <= bound { continue