From c6c232bee6bf58f79b25af0b266af11388fbce4f Mon Sep 17 00:00:00 2001
From: Silas Davis <silas@monax.io>
Date: Thu, 28 Jun 2018 12:46:52 +0200
Subject: [PATCH] Fix latest bound off by one since end is exclusive

Signed-off-by: Silas Davis <silas@monax.io>
---
 execution/events/event.go                | 1 +
 execution/events/key.go                  | 4 ++++
 execution/events/pbevents/blocks.go      | 4 +++-
 execution/events/pbevents/blocks_test.go | 2 +-
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/execution/events/event.go b/execution/events/event.go
index 5830a129..508c9677 100644
--- a/execution/events/event.go
+++ b/execution/events/event.go
@@ -14,6 +14,7 @@ var cdc = txs.NewAminoCodec()
 var eventMessageTag = event.TagMap{event.MessageTypeKey: reflect.TypeOf(&Event{}).String()}
 
 type Provider interface {
+	// Get events between startKey (inclusive) and endKey (exclusive) - i.e. the half open interval [start, end)
 	GetEvents(startKey, endKey Key, consumer func(*Event) (stop bool)) (stopped bool, err error)
 	LatestEventKey() Key
 }
diff --git a/execution/events/key.go b/execution/events/key.go
index f78463e1..52371518 100644
--- a/execution/events/key.go
+++ b/execution/events/key.go
@@ -36,6 +36,10 @@ func (k Key) IsSuccessorOf(p Key) bool {
 	return ph == kh && pi+1 == ki || ph < kh && ki == 0
 }
 
+func (k Key) IncHeight() Key {
+	return NewKey(k.Height()+1, k.Index())
+}
+
 func (k Key) Bytes() []byte {
 	return k
 }
diff --git a/execution/events/pbevents/blocks.go b/execution/events/pbevents/blocks.go
index 5513ec34..b2df626d 100644
--- a/execution/events/pbevents/blocks.go
+++ b/execution/events/pbevents/blocks.go
@@ -2,8 +2,10 @@ package pbevents
 
 import "github.com/hyperledger/burrow/execution/events"
 
+// Get bounds suitable for events.Provider
 func (br *BlockRange) Bounds(latestBlockHeight uint64) (startKey, endKey events.Key, streaming bool) {
-	return br.GetStart().Key(latestBlockHeight), br.GetEnd().Key(latestBlockHeight),
+	// End bound is exclusive in state.GetEvents so we increment the height
+	return br.GetStart().Key(latestBlockHeight), br.GetEnd().Key(latestBlockHeight).IncHeight(),
 		br.GetEnd().GetType() == Bound_STREAM
 }
 
diff --git a/execution/events/pbevents/blocks_test.go b/execution/events/pbevents/blocks_test.go
index 62641f87..a7a05b47 100644
--- a/execution/events/pbevents/blocks_test.go
+++ b/execution/events/pbevents/blocks_test.go
@@ -12,6 +12,6 @@ func TestBlockRange_Bounds(t *testing.T) {
 	br := &BlockRange{}
 	start, end, streaming := br.Bounds(latestHeight)
 	assert.Equal(t, events.NewKey(latestHeight, 0), start)
-	assert.Equal(t, events.NewKey(latestHeight, 0), end)
+	assert.Equal(t, events.NewKey(latestHeight+1, 0), end)
 	assert.False(t, streaming)
 }
-- 
GitLab