Skip to content

fix error casting #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2020
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
3 changes: 1 addition & 2 deletions common/blocker/blocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ type (
)

var (
ServiceErr TypeBlocker = "ServiceErr"
InternalErr TypeBlocker = "InternalErr"
DBErr TypeBlocker = "DBErr"
DBRowNotFound TypeBlocker = "DBRowNotFound"
BlockErr TypeBlocker = "BlockErr"
Expand All @@ -33,6 +31,7 @@ var (
SmithingErr TypeBlocker = "SmithingErr"
ZeroParticipationScoreErr TypeBlocker = "ZeroParticipationScoreErr"
ChainValidationErr TypeBlocker = "ChainValidationErr"
P2PPeerError TypeBlocker = "P2PPeerError"
P2PNetworkConnectionErr TypeBlocker = "P2PNetworkConnectionErr"
SmithingPending TypeBlocker = "SmithingPending"
TimeoutExceeded TypeBlocker = "TimeoutExceeded"
Expand Down
7 changes: 5 additions & 2 deletions core/blockchainsync/blockchainSync.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@ func (bss *BlockchainSyncService) getMoreBlocks() {
if err != nil {
monitoring.IncrementMainchainDownloadCycleDebugger(bss.ChainType, 3)
needDownloadBlock = false
errCasted := err.(blocker.Blocker)
errCasted, ok := err.(blocker.Blocker)
if !ok {
errCasted = blocker.NewBlocker(blocker.P2PNetworkConnectionErr, err.Error()).(blocker.Blocker)
}
monitoring.IncrementMainchainDownloadCycleDebugger(bss.ChainType, 4)
switch errCasted.Type {
case blocker.P2PNetworkConnectionErr:
case blocker.P2PPeerError:
// this will allow the node to start smithing if it fails to connect to the p2p network,
// eg. he is the first node. if later on he can connect, it will try resolve the fork normally
monitoring.IncrementMainchainDownloadCycleDebugger(bss.ChainType, 5)
Expand Down
2 changes: 1 addition & 1 deletion core/blockchainsync/downloadBlockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (bd *BlockchainDownloader) GetPeerBlockchainInfo() (*PeerBlockchainInfo, er
bd.PeerHasMore = true
peer := bd.PeerExplorer.GetAnyResolvedPeer()
if peer == nil {
return nil, blocker.NewBlocker(blocker.P2PNetworkConnectionErr, "no connected peer can be found")
return nil, blocker.NewBlocker(blocker.P2PPeerError, "no connected peer can be found")
}
peerCumulativeDifficultyResponse, err = bd.PeerServiceClient.GetCumulativeDifficulty(peer, bd.ChainType)
monitoring.IncrementMainchainDownloadCycleDebugger(bd.ChainType, 31)
Expand Down
2 changes: 1 addition & 1 deletion p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (s *Peer2PeerService) DownloadFilesFromPeer(fileChunksNames []string, maxRe
)
// Retry downloading from different peers until all chunks are downloaded or retry limit is reached
if len(resolvedPeers) < 1 {
return nil, blocker.NewBlocker(blocker.P2PNetworkConnectionErr, "no resolved peer can be found")
return nil, blocker.NewBlocker(blocker.P2PPeerError, "no resolved peer can be found")
}
// convert the slice to a map to make it easier to find elements in it
fileChunkNamesMap := make(map[string]string)
Expand Down
Loading