diff --git a/execution/events/event.go b/execution/events/event.go index 5830a1298cbd7894c5cf209fd07880f9eb3570b2..508c96776e19b5e360c61830ffa2ccae90ac8525 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 f78463e16d8f521ee4fdbf9dc3389b05b0443121..52371518fb6c5ac7a6a3f4cb53fa32f9289f90b0 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 5513ec34c6310f815f7ad7ab57128431c79fd7e5..b2df626d2783d1b50472d693864bf5d811170b1b 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 62641f876048dbe8ec9f24d30cb452433347153c..a7a05b47e1e44e7ecb9b0b2418c17962b90d01f3 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) }