Skip to content

Commit

Permalink
check BlockNotAvailableErrMsg in WS response
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Nov 6, 2023
1 parent c7e0d3e commit 4b8f748
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion catchup/universalFetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package catchup

import (
"bytes"
"context"
"encoding/binary"
"fmt"
Expand Down Expand Up @@ -173,7 +174,7 @@ func (w *wsFetcherClient) requestBlock(ctx context.Context, round basics.Round)
}

if errMsg, found := resp.Topics.GetValue(network.ErrorKey); found {
if latest, lfound := resp.Topics.GetValue(rpcs.LatestRoundKey); lfound {
if latest, lfound := resp.Topics.GetValue(rpcs.LatestRoundKey); lfound && bytes.Equal(errMsg, []byte(rpcs.BlockNotAvailableErrMsg)) {
return nil, noBlockForRoundError{round: round, latest: basics.Round(binary.BigEndian.Uint64(latest))}
}
return nil, makeErrWsFetcherRequestFailed(round, w.target.GetAddress(), string(errMsg))
Expand Down
7 changes: 4 additions & 3 deletions rpcs/blockService.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ func (bs *BlockService) listenForCatchupReq(reqs <-chan network.IncomingMessage,
}
}

// BlockNotAvailableErrMsg is returned if the requested round's block was not stored on this node.
const BlockNotAvailableErrMsg = "requested block is not available"
const noRoundNumberErrMsg = "can't find the round number"
const noDataTypeErrMsg = "can't find the data-type"
const roundNumberParseErrMsg = "unable to parse round number"
const blockNotAvailableErrMsg = "requested block is not available"
const datatypeUnsupportedErrMsg = "requested data type is unsupported"

// a blocking function for handling a catchup request
Expand Down Expand Up @@ -461,13 +462,13 @@ func topicBlockBytes(log logging.Logger, dataLedger LedgerForBlockService, round
switch lerr := err.(type) {
case ledgercore.ErrNoEntry:
return network.Topics{
network.MakeTopic(network.ErrorKey, []byte(blockNotAvailableErrMsg)),
network.MakeTopic(network.ErrorKey, []byte(BlockNotAvailableErrMsg)),
network.MakeTopic(LatestRoundKey, binary.BigEndian.AppendUint64([]byte{}, uint64(lerr.Latest))),
}, 0
default:
log.Infof("BlockService topicBlockBytes: %s", err)
}
return network.Topics{network.MakeTopic(network.ErrorKey, []byte(blockNotAvailableErrMsg))}, 0
return network.Topics{network.MakeTopic(network.ErrorKey, []byte(BlockNotAvailableErrMsg))}, 0
}
switch requestType {
case BlockAndCertValue:
Expand Down

0 comments on commit 4b8f748

Please sign in to comment.