mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-01 00:31:21 +00:00
ee99f17fbe
* Add Parlia consensus engine for Binance Smart Chain support * Leave RamanujanBlock as nil in params/config.go * Run `go fmt` on files needing it * Add comment for PoSA * Remove empty branches and ineffectual assignments in parlia.go * Remove commented imports * Fix compilation error * Remove EIP155Signer in transaction_signing.go * Fix compilation issue * Fix go fmt issues * Remove Ramanujan from print statement * Remove references to EthAPIBackend approach * Fix Finalize method across consensus engines * Run go fmt * More linting * Remove more changes * remove a comment * Remove unneeded hashing function * Remove bytes check and fix actual vs expected mistake
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package parlia
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/ledgerwatch/erigon/consensus"
|
|
"github.com/ledgerwatch/erigon/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.IsRamanujanBigInt(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 += time.Duration(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.IsRamanujanBigInt(header.Number) {
|
|
blockTime = blockTime + backOffTime(snap, p.val)
|
|
}
|
|
return blockTime
|
|
}
|
|
|
|
func (p *Parlia) blockTimeVerifyForRamanujanFork(snap *Snapshot, header, parent *types.Header) error {
|
|
if p.chainConfig.IsRamanujanBigInt(header.Number) {
|
|
if header.Time < parent.Time+p.config.Period+backOffTime(snap, header.Coinbase) {
|
|
return consensus.ErrFutureBlock
|
|
}
|
|
}
|
|
return nil
|
|
}
|