Skip to content

Commit 2d33800

Browse files
authored
add CurrentTipHeight and CurrentTipView to get epoch progress response (#746)
* add CurrentTipHeight and CurrentTipView to get epoch progress response * trigger build * adjustment for current leader returned in get current epoch progress for validator nodes
1 parent cfdd15a commit 2d33800

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

routes/validators.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ type GetEpochProgressResponse struct {
366366

367367
CurrentView uint64 `safeForLogging:"true"`
368368
CurrentTipHeight uint64 `safeForLogging:"true"`
369+
CurrentTipView uint64 `safeForLogging:"true"`
370+
CurrentBlockHash string `safeForLogging:"true"`
369371
CurrentLeader UserInfoBasic `safeForLogging:"true"`
370372
}
371373

@@ -382,16 +384,15 @@ func (fes *APIServer) GetCurrentEpochProgress(ww http.ResponseWriter, req *http.
382384
return
383385
}
384386

387+
timeoutIntervallMilliseconds := utxoView.GetCurrentGlobalParamsEntry().TimeoutIntervalMillisecondsPoS
388+
385389
// Get the current epoch number.
386390
currentEpochEntry, err := utxoView.GetCurrentEpochEntry()
387391
if err != nil {
388392
_AddInternalServerError(ww, "GetCurrentEpochProgress: problem fetching current epoch number")
389393
return
390394
}
391395

392-
// Get the current uncommitted tip.
393-
currentTip := fes.backendServer.GetBlockchain().BlockTip()
394-
395396
// Get the leader schedule for the current snapshot epoch.
396397
leaderSchedulePKIDs, err := utxoView.GetCurrentSnapshotLeaderSchedule()
397398
if err != nil {
@@ -416,29 +417,38 @@ func (fes *APIServer) GetCurrentEpochProgress(ww http.ResponseWriter, req *http.
416417
return UserInfoBasic{PublicKeyBase58Check: publicKeyBase58Check, Username: string(profileEntry.Username)}
417418
})
418419

420+
// Get the current uncommitted tip.
421+
currentTip := fes.backendServer.GetBlockchain().BlockTip()
422+
419423
// By default, set the current View to the tip block's view. The GetView() function is safe to use
420424
// whether we are on PoW or PoS.
421-
currentView := currentTip.Header.GetView()
425+
currentTipView := currentTip.Header.GetView()
422426

423427
// Try to fetch the current Fast-HotStuff view. If the server is running the Fast-HotStuff consensus,
424428
// then this will return a non-zero value. This value always overrides the tip block's current view.
425429
fastHotStuffConsensusView := fes.backendServer.GetLatestView()
430+
currentView := currentTipView
431+
leaderIdxAdjustmentForValidators := uint64(0)
426432
if fastHotStuffConsensusView != 0 {
427433
currentView = fastHotStuffConsensusView
434+
if currentView > currentTipView {
435+
leaderIdxAdjustmentForValidators = 1
436+
}
428437
}
429438

430439
// If the current tip is at or past the final PoW block height, but we don't have a view returned by the
431440
// Fast-HotStuff consensus, then we can estimate the current view based on the Fast-HotStuff rules. This
432441
// is the best fallback value we can use once the chain has transitioned to PoS.
433442
if currentView == 0 && currentTip.Header.Height >= fes.Params.GetFinalPoWBlockHeight() {
434-
timeoutDuration := time.Duration(utxoView.GetCurrentGlobalParamsEntry().TimeoutIntervalMillisecondsPoS) * time.Millisecond
443+
timeoutDuration := time.Duration(timeoutIntervallMilliseconds) * time.Millisecond
435444
currentTipTimestamp := time.Unix(0, currentTip.Header.TstampNanoSecs)
436445
currentView = currentTip.Header.GetView() + estimateNumTimeoutsSinceTip(time.Now(), currentTipTimestamp, timeoutDuration)
437446
}
438447

439448
currentLeaderIdx := (currentEpochEntry.InitialLeaderIndexOffset +
440449
(currentView - currentEpochEntry.InitialView) -
441-
(currentTip.Header.Height - currentEpochEntry.InitialBlockHeight)) % uint64(len(leaderSchedule))
450+
(currentTip.Header.Height - currentEpochEntry.InitialBlockHeight) -
451+
leaderIdxAdjustmentForValidators) % uint64(len(leaderSchedule))
442452
currentLeader := leaderSchedule[currentLeaderIdx]
443453

444454
// Construct the response
@@ -447,6 +457,8 @@ func (fes *APIServer) GetCurrentEpochProgress(ww http.ResponseWriter, req *http.
447457
LeaderSchedule: leaderSchedule,
448458
CurrentView: currentView,
449459
CurrentTipHeight: currentTip.Header.Height,
460+
CurrentTipView: currentTipView,
461+
CurrentBlockHash: currentTip.Hash.String(),
450462
CurrentLeader: currentLeader,
451463
}
452464

0 commit comments

Comments
 (0)