This commit is contained in:
Marko Baricevic
2021-03-22 11:22:14 +00:00
parent bcf49ed8e7
commit 57ac518b66
3 changed files with 11 additions and 8 deletions

View File

@@ -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}

View File

@@ -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
}

View File

@@ -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)
}
}
}