summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Vanahalli <ganesh.vanahalli@algorand.com>2022-08-16 15:05:15 -0400
committerGanesh Vanahalli <ganesh.vanahalli@algorand.com>2022-08-16 15:05:15 -0400
commitd3d9591307e3d88e1d4f31f4421d7b58c2f36a34 (patch)
tree6783efcbadf985d94bdf6d26c880a15e106c912b
parent70ba2c3d39124dea582c837aac21f3cd08dd6803 (diff)
-rw-r--r--catchup/networkFetcher.go4
-rw-r--r--catchup/networkFetcher_test.go87
2 files changed, 79 insertions, 12 deletions
diff --git a/catchup/networkFetcher.go b/catchup/networkFetcher.go
index 85beef678..d64c327c8 100644
--- a/catchup/networkFetcher.go
+++ b/catchup/networkFetcher.go
@@ -52,7 +52,7 @@ func MakeNetworkFetcher(log logging.Logger, net network.GossipNode, cfg config.L
}
func (netFetcher *NetworkFetcher) getHTTPPeer() (network.HTTPPeer, *peerSelectorPeer, error) {
- for retryCount := 0; retryCount < netFetcher.cfg.CatchupBlockDownloadRetryAttempts; retryCount++ {
+ for retryCount := 1; retryCount <= netFetcher.cfg.CatchupBlockDownloadRetryAttempts; retryCount++ {
psp, err := netFetcher.peerSelector.getNextPeer()
if err != nil {
if err != errPeerSelectorNoPeerPoolsAvailable {
@@ -79,7 +79,7 @@ func (netFetcher *NetworkFetcher) getHTTPPeer() (network.HTTPPeer, *peerSelector
func (netFetcher *NetworkFetcher) FetchBlock(ctx context.Context, round basics.Round) (*bookkeeping.Block,
*agreement.Certificate, time.Duration, error) {
// internal retry attempt to fetch the block
- for retryCount := 0; retryCount < netFetcher.cfg.CatchupBlockDownloadRetryAttempts; retryCount++ {
+ for retryCount := 1; retryCount <= netFetcher.cfg.CatchupBlockDownloadRetryAttempts; retryCount++ {
httpPeer, psp, err := netFetcher.getHTTPPeer()
if err != nil {
return nil, nil, time.Duration(0), err
diff --git a/catchup/networkFetcher_test.go b/catchup/networkFetcher_test.go
index 8fd5fae7c..7c6a2c885 100644
--- a/catchup/networkFetcher_test.go
+++ b/catchup/networkFetcher_test.go
@@ -45,11 +45,11 @@ func TestFetchBlock(t *testing.T) {
net := &httpTestPeerSource{}
ls := rpcs.MakeBlockService(logging.Base(), blockServiceConfig, ledger, net, "test genesisID")
- nodeA := basicRPCNode{}
- nodeA.RegisterHTTPHandler(rpcs.BlockServiceBlockPath, ls)
- nodeA.start()
- defer nodeA.stop()
- rootURL := nodeA.rootURL()
+ node := basicRPCNode{}
+ node.RegisterHTTPHandler(rpcs.BlockServiceBlockPath, ls)
+ node.start()
+ defer node.stop()
+ rootURL := node.rootURL()
net.addPeer(rootURL)
@@ -89,11 +89,11 @@ func TestConcurrentAttemptsToFetchBlockSuccess(t *testing.T) {
net := &httpTestPeerSource{}
ls := rpcs.MakeBlockService(logging.Base(), blockServiceConfig, ledger, net, "test genesisID")
- nodeA := basicRPCNode{}
- nodeA.RegisterHTTPHandler(rpcs.BlockServiceBlockPath, ls)
- nodeA.start()
- defer nodeA.stop()
- rootURL := nodeA.rootURL()
+ node := basicRPCNode{}
+ node.RegisterHTTPHandler(rpcs.BlockServiceBlockPath, ls)
+ node.start()
+ defer node.stop()
+ rootURL := node.rootURL()
net.addPeer(rootURL)
@@ -121,3 +121,70 @@ func TestConcurrentAttemptsToFetchBlockSuccess(t *testing.T) {
close(start)
wg.Wait()
}
+
+func TestHTTPPeerNotAvailable(t *testing.T) {
+ partitiontest.PartitionTest(t)
+
+ net := &httpTestPeerSource{}
+
+ // Disable block authentication
+ cfg := config.GetDefaultLocal()
+ cfg.CatchupBlockValidateMode = 1
+ cfg.CatchupBlockDownloadRetryAttempts = 1
+
+ fetcher := MakeNetworkFetcher(logging.TestingLog(t), net, cfg, nil, false)
+
+ _, _, _, err := fetcher.FetchBlock(context.Background(), 1)
+ require.Contains(t, err.Error(), "recurring non-HTTP peer was provided by the peer selector")
+}
+
+func TestFetchBlockFailed(t *testing.T) {
+ partitiontest.PartitionTest(t)
+
+ net := &httpTestPeerSource{}
+ wsPeer := makeTestUnicastPeer(net, t)
+ net.addPeer(wsPeer.GetAddress())
+
+ // Disable block authentication
+ cfg := config.GetDefaultLocal()
+ cfg.CatchupBlockValidateMode = 1
+ cfg.CatchupBlockDownloadRetryAttempts = 1
+
+ fetcher := MakeNetworkFetcher(logging.TestingLog(t), net, cfg, nil, false)
+
+ _, _, _, err := fetcher.FetchBlock(context.Background(), 1)
+ require.Contains(t, err.Error(), "FetchBlock failed after multiple blocks download attempts")
+}
+
+func TestFetchBlockAuthenticationFailed(t *testing.T) {
+ partitiontest.PartitionTest(t)
+
+ ledger, next, _, err := buildTestLedger(t, bookkeeping.Block{})
+ if err != nil {
+ t.Fatal(err)
+ return
+ }
+
+ blockServiceConfig := config.GetDefaultLocal()
+ blockServiceConfig.EnableBlockService = true
+ blockServiceConfig.EnableBlockServiceFallbackToArchiver = false
+
+ net := &httpTestPeerSource{}
+ ls := rpcs.MakeBlockService(logging.Base(), blockServiceConfig, ledger, net, "test genesisID")
+
+ node := basicRPCNode{}
+ node.RegisterHTTPHandler(rpcs.BlockServiceBlockPath, ls)
+ node.start()
+ defer node.stop()
+ rootURL := node.rootURL()
+
+ net.addPeer(rootURL)
+
+ cfg := config.GetDefaultLocal()
+ cfg.CatchupBlockDownloadRetryAttempts = 1
+
+ fetcher := MakeNetworkFetcher(logging.TestingLog(t), net, cfg, &mockedAuthenticator{errorRound: int(next)}, false)
+
+ _, _, _, err = fetcher.FetchBlock(context.Background(), next)
+ require.Contains(t, err.Error(), "FetchBlock failed after multiple blocks download attempts")
+}