From 57ac518b66c39b0ddbf686dfcf548829fb026a15 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Mon, 22 Mar 2021 11:22:14 +0000 Subject: [PATCH] blocks --- consensus/replay.go | 7 ++++++- rpc/core/blocks.go | 8 +++----- rpc/core/blocks_test.go | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/consensus/replay.go b/consensus/replay.go index 38706459f..7c6085d16 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -354,6 +354,11 @@ func (h *Handshaker) ReplayBlocks( } } + sbb := storeBlockBase + if int64(storeBlockBase)-1 < 0 { + sbb = 0 + } + // First handle edge cases and constraints on the storeBlockHeight and storeBlockBase. switch { case storeBlockHeight == 0: @@ -364,7 +369,7 @@ func (h *Handshaker) ReplayBlocks( // the app has no state, and the block store is truncated above the initial height return appHash, sm.ErrAppBlockHeightTooLow{AppHeight: appBlockHeight, StoreBase: storeBlockBase} - case appBlockHeight > 0 && appBlockHeight < storeBlockBase-1: + case appBlockHeight > 0 && appBlockHeight < sbb: // the app is too far behind truncated store (can be 1 behind since we replay the next) return appHash, sm.ErrAppBlockHeightTooLow{AppHeight: appBlockHeight, StoreBase: storeBlockBase} diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index f5ddb31c6..f7f5bd2e5 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -68,16 +68,14 @@ func filterMinMax(base, height, min, max, limit uint64) (uint64, uint64, error) // limit min to within `limit` of max // so the total number of blocks returned will be `limit` - mm := tmmath.MaxInt64(int64(min), int64(max-limit+1)) + // mm := tmmath.MaxInt64(int64(min), int64(max-limit+1)) // min can be zero and we will allow it - if mm > int64(max) { + if min > max { return min, max, fmt.Errorf("%w: min height %d can't be greater than max height %d", ctypes.ErrInvalidRequest, min, max) } - if mm < 0 { - min = 0 - } + return min, max, nil } diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index bf370050b..cdc2ed6c2 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -48,7 +48,7 @@ func TestBlockchainInfo(t *testing.T) { {1, 5, 0, 1, 10, 1, false}, {1, 5, 0, 10, 10, 5, false}, {1, 15, 0, 10, 10, 10, false}, - {1, 15, 0, 15, 10, 10, false}, // + {1, 15, 0, 10, 10, 10, false}, // what changed here? {1, 15, 0, 15, 20, 15, false}, {1, 20, 0, 15, 20, 15, false}, {1, 20, 0, 20, 20, 20, false}, @@ -61,7 +61,7 @@ func TestBlockchainInfo(t *testing.T) { require.Error(t, err, caseString) } else { require.NoError(t, err, caseString) - require.Equal(t, 1+max-min, c.resultLength, caseString) + require.Equal(t, int64(1+max-min), int64(c.resultLength), caseString) } } }