From 3654fc9faef66c81d612dbcd28c2f675cbbad007 Mon Sep 17 00:00:00 2001 From: Jasmina Malicevic Date: Wed, 27 Apr 2022 15:34:51 +0200 Subject: [PATCH] blocksync/pool: reverted to PeekTwoBlocks --- internal/blocksync/pool.go | 10 ---------- internal/blocksync/pool_test.go | 8 ++++---- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/internal/blocksync/pool.go b/internal/blocksync/pool.go index 1f69a03e0..b662773f1 100644 --- a/internal/blocksync/pool.go +++ b/internal/blocksync/pool.go @@ -205,16 +205,6 @@ func (pool *BlockPool) IsCaughtUp() bool { return pool.height >= (pool.maxPeerHeight - 1) } -func (pool *BlockPool) PeekBlock() (first *types.Block) { - pool.mtx.RLock() - defer pool.mtx.RUnlock() - - if r := pool.requesters[pool.height]; r != nil { - first = r.getBlock() - } - return -} - // PeekTwoBlocks returns blocks at pool.height and pool.height+1. // We need to see the second block's Commit to validate the first block. // So we peek two blocks at a time. diff --git a/internal/blocksync/pool_test.go b/internal/blocksync/pool_test.go index ae29b205e..1cb8cca40 100644 --- a/internal/blocksync/pool_test.go +++ b/internal/blocksync/pool_test.go @@ -110,8 +110,8 @@ func TestBlockPoolBasic(t *testing.T) { if !pool.IsRunning() { return } - first := pool.PeekBlock() - if first != nil { + first, second := pool.PeekTwoBlocks() + if first != nil && second != nil { pool.PopRequest() } else { time.Sleep(1 * time.Second) @@ -164,8 +164,8 @@ func TestBlockPoolTimeout(t *testing.T) { if !pool.IsRunning() { return } - first := pool.PeekBlock() - if first != nil { + first, second := pool.PeekTwoBlocks() + if first != nil && second != nil { pool.PopRequest() } else { time.Sleep(1 * time.Second)