Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
}
if ctx.IsSet(utils.OverrideMinBlocksForBlobRequests.Name) {
params.MinBlocksForBlobRequests = ctx.Uint64(utils.OverrideMinBlocksForBlobRequests.Name)
params.MinTimeDurationForBlobRequests = uint64(float64(params.MinBlocksForBlobRequests) * 1.5 /*lorentzBlockInterval*/)
params.MinTimeDurationForBlobRequests = uint64(float64(params.MinBlocksForBlobRequests) * 0.75 /*maxwellBlockInterval*/)
}
if ctx.IsSet(utils.OverrideDefaultExtraReserveForBlobRequests.Name) {
params.DefaultExtraReserveForBlobRequests = ctx.Uint64(utils.OverrideDefaultExtraReserveForBlobRequests.Name)
Expand Down
27 changes: 17 additions & 10 deletions cmd/jsutils/getchainstatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,10 @@ async function getPerformanceData() {
let gasUsedTotal = 0;
let inturnBlocks = 0;
let justifiedBlocks = 0;
let turnLength = 1;
let turnLength = 4;
let lastTimestamp = null;
let parliaEnabled = true;

try {
turnLength = await provider.send("parlia_getTurnLength", [ethers.toQuantity(program.startNum)]);
} catch (error) {
Expand All @@ -426,14 +428,7 @@ async function getPerformanceData() {
inturnBlocks += 1;
}
let timestamp = eval(eval(header.milliTimestamp).toString(10));
if (parliaEnabled) {
let justifiedNumber = await provider.send("parlia_getJustifiedNumber", [ethers.toQuantity(i)]);
if (justifiedNumber + 1 == i) {
justifiedBlocks += 1;
} else {
console.log("justified unexpected", "BlockNumber =", i, "justifiedNumber", justifiedNumber);
}
}
let blockInterval = lastTimestamp !== null ? timestamp - lastTimestamp : null;
console.log(
"BlockNumber =",
i,
Expand All @@ -448,8 +443,20 @@ async function getPerformanceData() {
"gasUsed",
gasUsed,
"timestamp",
timestamp
timestamp,
"blockInterval",
blockInterval !== null ? blockInterval : "N/A"
);
lastTimestamp = timestamp;

if (parliaEnabled) {
let justifiedNumber = await provider.send("parlia_getJustifiedNumber", [ethers.toQuantity(i)]);
if (justifiedNumber + 1 == i) {
justifiedBlocks += 1;
} else {
console.log("justified unexpected", "BlockNumber =", i, "justifiedNumber", justifiedNumber);
}
}
}
let blockCount = program.endNum - program.startNum;
let txCountPerBlock = txCountTotal / blockCount;
Expand Down
9 changes: 7 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
maxwellEpochLength uint64 = 1000 // Epoch length starting from the Maxwell hard fork
defaultBlockInterval uint64 = 3000 // Default block interval in milliseconds
lorentzBlockInterval uint64 = 1500 // Block interval starting from the Lorentz hard fork
maxwellBlockInterval uint64 = 750 // Block interval starting from the Maxwell hard fork
defaultTurnLength uint8 = 1 // Default consecutive number of blocks a validator receives priority for block production

extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
Expand Down Expand Up @@ -795,14 +796,18 @@ func (p *Parlia) snapshot(chain consensus.ChainHeaderReader, number uint64, hash
blockHeader := chain.GetHeaderByNumber(number)
if blockHeader != nil {
blockHash = blockHeader.Hash()
if p.chainConfig.IsLorentz(blockHeader.Number, blockHeader.Time) {
if p.chainConfig.IsMaxwell(blockHeader.Number, blockHeader.Time) {
blockInterval = maxwellBlockInterval
} else if p.chainConfig.IsLorentz(blockHeader.Number, blockHeader.Time) {
blockInterval = lorentzBlockInterval
}
}
if number > offset { // exclude `number == 200`
blockBeforeCheckpoint := chain.GetHeaderByNumber(number - offset - 1)
if blockBeforeCheckpoint != nil {
if p.chainConfig.IsLorentz(blockBeforeCheckpoint.Number, blockBeforeCheckpoint.Time) {
if p.chainConfig.IsMaxwell(blockBeforeCheckpoint.Number, blockBeforeCheckpoint.Time) {
epochLength = maxwellEpochLength
} else if p.chainConfig.IsLorentz(blockBeforeCheckpoint.Number, blockBeforeCheckpoint.Time) {
epochLength = lorentzEpochLength
}
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/parlia/ramanujanfork.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const (
wiggleTimeBeforeFork = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers
fixedBackOffTimeBeforeFork = 200 * time.Millisecond
millisecondsUnit = 500 // Set to 250 if block interval is 750ms; not enforced at the consensus level
millisecondsUnit = 250 // not enforced at the consensus level
)

func (p *Parlia) delayForRamanujanFork(snap *Snapshot, header *types.Header) time.Duration {
Expand Down
47 changes: 39 additions & 8 deletions consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ func (s *Snapshot) isMajorityFork(forkHash string) bool {
return ally > len(s.RecentForkHashes)/2
}

func (s *Snapshot) updateAttestation(header *types.Header, chainConfig *params.ChainConfig, epochLength uint64) {
func (s *Snapshot) updateAttestation(header *types.Header, chainConfig *params.ChainConfig) {
if !chainConfig.IsLuban(header.Number) {
return
}

// The attestation should have been checked in verify header, update directly
attestation, _ := getVoteAttestationFromHeader(header, chainConfig, epochLength)
attestation, _ := getVoteAttestationFromHeader(header, chainConfig, s.EpochLength)
if attestation == nil {
return
}
Expand Down Expand Up @@ -269,6 +269,13 @@ func (s *Snapshot) SignRecently(validator common.Address) bool {
return s.signRecentlyByCounts(validator, s.countRecents())
}

func (s *Snapshot) getFinalizedNumber() uint64 {
if s.Attestation != nil {
return s.Attestation.SourceNumber
}
return 0
}

func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderReader, parents []*types.Header, chainConfig *params.ChainConfig) (*Snapshot, error) {
// Allow passing in no headers for cleaner code
if len(headers) == 0 {
Expand Down Expand Up @@ -320,16 +327,40 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
}
}
}

snap.updateAttestation(header, chainConfig)

snap.Recents[number] = validator
if chainConfig.IsMaxwell(header.Number, header.Time) {
latestFinalizedBlockNumber := snap.getFinalizedNumber()
// BEP-524: Clear entries up to the latest finalized block
for blockNumber := range snap.Recents {
if blockNumber <= latestFinalizedBlockNumber {
delete(snap.Recents, blockNumber)
}
}
}

snap.RecentForkHashes[number] = hex.EncodeToString(header.Extra[extraVanity-nextForkHashSize : extraVanity])

if chainConfig.IsMaxwell(header.Number, header.Time) {
snap.BlockInterval = maxwellBlockInterval
} else if chainConfig.IsLorentz(header.Number, header.Time) {
snap.BlockInterval = lorentzBlockInterval
}

epochLength := snap.EpochLength
snap.updateAttestation(header, chainConfig, epochLength)
if chainConfig.IsLorentz(header.Number, header.Time) {
nextBlockNumber := header.Number.Uint64() + 1
if snap.EpochLength == defaultEpochLength &&
chainConfig.IsLorentz(header.Number, header.Time) &&
// Without this condition, an incorrect block might be used to parse validators for certain blocks after the Lorentz hard fork.
if (header.Number.Uint64()+1)%lorentzEpochLength == 0 {
snap.EpochLength = lorentzEpochLength
}
snap.BlockInterval = lorentzBlockInterval
nextBlockNumber%lorentzEpochLength == 0 {
snap.EpochLength = lorentzEpochLength
}
if snap.EpochLength == lorentzEpochLength &&
chainConfig.IsMaxwell(header.Number, header.Time) &&
nextBlockNumber%maxwellEpochLength == 0 {
snap.EpochLength = maxwellEpochLength
}
// change validator set
if number > 0 && number%epochLength == snap.minerHistoryCheckLen() {
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func (api *BlockChainAPI) getFinalizedNumber(ctx context.Context, verifiedValida
lastHeader := latestHeader
confirmedValSet := make(map[common.Address]struct{}, valLen)
confirmedValSet[lastHeader.Coinbase] = struct{}{}
epochLength := int(500) // TODO(Nathan)(BEP-524 Phase Two): use `maxwellEpochLength` instead
epochLength := int(1000) // maxwellEpochLength
for count := 1; int64(len(confirmedValSet)) < verifiedValidatorNum && count <= epochLength && lastHeader.Number.Int64() > max(fastFinalizedHeader.Number.Int64(), 1); count++ {
lastHeader, err = api.b.HeaderByHash(ctx, lastHeader.ParentHash)
if err != nil { // impossible
Expand Down
2 changes: 1 addition & 1 deletion miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (b *bidSimulator) newBidLoop() {
// get block interval for current block by using parent header
func (b *bidSimulator) getBlockInterval(parentHeader *types.Header) uint64 {
if parentHeader == nil {
return 1500 // lorentzBlockInterval
return 750 // maxwellBlockInterval
}
parlia, _ := b.engine.(*parlia.Parlia)
// only `Number` and `ParentHash` are used when `BlockInterval`
Expand Down
8 changes: 4 additions & 4 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ const (
)

var (
// lorentzBlockInterval = 1.5
MinTimeDurationForBlobRequests uint64 = uint64(float64(24*3600) * 18.2) // it keeps blob data available for 18.2 days in local
MinBlocksForBlobRequests uint64 = uint64(float64(MinTimeDurationForBlobRequests) / 1.5) // ref: https://github.com/bnb-chain/BEPs/blob/master/BEPs/BEP-524.md#421-change-table.
DefaultExtraReserveForBlobRequests uint64 = uint64(24 * 3600 / 1.5) // it adds more time for expired blobs for some request cases, like expiry blob when remote peer is syncing, default 1 day.
// maxwellBlockInterval = 0.75
MinTimeDurationForBlobRequests uint64 = uint64(float64(24*3600) * 18.2) // it keeps blob data available for 18.2 days in local
MinBlocksForBlobRequests uint64 = uint64(float64(MinTimeDurationForBlobRequests) / 0.75) // ref: https://github.com/bnb-chain/BEPs/blob/master/BEPs/BEP-524.md#421-change-table.
DefaultExtraReserveForBlobRequests uint64 = uint64(24 * 3600 / 0.75) // it adds more time for expired blobs for some request cases, like expiry blob when remote peer is syncing, default 1 day.

BreatheBlockInterval uint64 = 24 * 3600 // Controls the interval for updateValidatorSetV2

Expand Down