1ded097733
* implement block process part of light sync * add difflayer protocol * handle difflayer and refine light processor * add testcase for diff protocol * make it faster * allow validator to light sync * change into diff sync * ligth sync: download difflayer (#2) * ligth sync: download difflayer Signed-off-by: kyrie-yl <lei.y@binance.com> * download diff layer: fix according to the comments Signed-off-by: kyrie-yl <lei.y@binance.com> * download diff layer: update Signed-off-by: kyrie-yl <lei.y@binance.com> * download diff layer: fix accroding comments Signed-off-by: kyrie-yl <lei.y@binance.com> Co-authored-by: kyrie-yl <lei.y@binance.com> * update light sync to diff sync * raise the max diff limit * add switcher of snap protocol * fix test case * make commit concurrently * remove peer for diff cache when peer closed * consensus tuning * add test code * remove extra message * fix testcase and lint make diff block configable wait code write fix testcase resolve comments resolve comment * resolve comments * resolve comments * resolve comment * fix mistake Co-authored-by: kyrie-yl <83150977+kyrie-yl@users.noreply.github.com> Co-authored-by: kyrie-yl <lei.y@binance.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package parlia
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
)
|
|
|
|
const (
|
|
wiggleTimeBeforeFork = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers
|
|
fixedBackOffTimeBeforeFork = 200 * time.Millisecond
|
|
)
|
|
|
|
func (p *Parlia) delayForRamanujanFork(snap *Snapshot, header *types.Header) time.Duration {
|
|
delay := time.Until(time.Unix(int64(header.Time), 0)) // nolint: gosimple
|
|
if p.chainConfig.IsRamanujan(header.Number) {
|
|
return delay
|
|
}
|
|
if header.Difficulty.Cmp(diffNoTurn) == 0 {
|
|
// It's not our turn explicitly to sign, delay it a bit
|
|
wiggle := time.Duration(len(snap.Validators)/2+1) * wiggleTimeBeforeFork
|
|
delay += fixedBackOffTimeBeforeFork + time.Duration(rand.Int63n(int64(wiggle)))
|
|
}
|
|
return delay
|
|
}
|
|
|
|
func (p *Parlia) blockTimeForRamanujanFork(snap *Snapshot, header, parent *types.Header) uint64 {
|
|
blockTime := parent.Time + p.config.Period
|
|
if p.chainConfig.IsRamanujan(header.Number) {
|
|
blockTime = blockTime + backOffTime(snap, p.val)
|
|
}
|
|
return blockTime
|
|
}
|
|
|
|
func (p *Parlia) blockTimeVerifyForRamanujanFork(snap *Snapshot, header, parent *types.Header) error {
|
|
if p.chainConfig.IsRamanujan(header.Number) {
|
|
if header.Time < parent.Time+p.config.Period+backOffTime(snap, header.Coinbase) {
|
|
return consensus.ErrFutureBlock
|
|
}
|
|
}
|
|
return nil
|
|
}
|