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
1 change: 1 addition & 0 deletions daemon/algod/api/server/v1/handlers/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ var (
errTransactionNotFound = "couldn't find the required transaction in the required range"
errServiceShuttingDown = "operation aborted as server is shutting down"
errUnknownTransactionType = "found a transaction with an unknown type"
errRequestedRoundInUnsupportedRound = "requested round would reach only after the protocol upgrade which isn't supported"
)
19 changes: 18 additions & 1 deletion daemon/algod/api/server/v1/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,29 @@ func WaitForBlock(ctx lib.ReqContext, w http.ResponseWriter, r *http.Request) {
return
}

ledger := ctx.Node.Ledger()
latestBlkHdr, err := ledger.BlockHdr(ledger.Latest())
if err != nil {
lib.ErrorResponse(w, http.StatusInternalServerError, err, errFailedRetrievingNodeStatus, ctx.Log)
return
}
if latestBlkHdr.NextProtocol != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check necessary? Please add a comment to describe when the NextProtocol can be an empty string.

if _, nextProtocolSupported := config.Consensus[latestBlkHdr.NextProtocol]; !nextProtocolSupported {
// see if the desired protocol switch is expect to happen before or after the above point.
if latestBlkHdr.NextProtocolSwitchOn <= basics.Round(queryRound+1) {
// we would never reach to this round, since this round would happen after the (unsupported) protocol upgrade.
lib.ErrorResponse(w, http.StatusBadRequest, err, errRequestedRoundInUnsupportedRound, ctx.Log)
return
}
}
}

select {
case <-ctx.Shutdown:
lib.ErrorResponse(w, http.StatusInternalServerError, err, errServiceShuttingDown, ctx.Log)
return
case <-time.After(1 * time.Minute):
case <-ctx.Node.Ledger().Wait(basics.Round(queryRound + 1)):
case <-ledger.Wait(basics.Round(queryRound + 1)):
}

nodeStatus, err := nodeStatus(ctx.Node)
Expand Down