Skip to content

Commit 3b03f1f

Browse files
authored
Changes required for consensus capability duplicate outcomes protection (#1622)
* changes to prevent consensus capability duplicate outcome
1 parent d142c49 commit 3b03f1f

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

pkg/capabilities/consensus/ocr3/types/ocr3_config_types.pb.go

Lines changed: 21 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/capabilities/consensus/ocr3/types/ocr3_config_types.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ message ReportingPluginConfig {
1818
uint32 maxBatchSize = 6;
1919
uint64 outcomePruningThreshold = 7;
2020
google.protobuf.Duration requestTimeout = 8;
21+
uint64 historical_outcome_expiry_seq_nr_span = 9;
2122
}

pkg/capabilities/consensus/requests/store.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func (s *Store[T]) GetByIDs(requestIDs []string) []T {
6868
func (s *Store[T]) FirstN(batchSize int) ([]T, error) {
6969
s.mu.RLock()
7070
defer s.mu.RUnlock()
71+
72+
return s.firstN(batchSize)
73+
}
74+
75+
func (s *Store[T]) firstN(batchSize int) ([]T, error) {
7176
if batchSize == 0 {
7277
return nil, errors.New("batchsize cannot be 0")
7378
}
@@ -91,6 +96,19 @@ func (s *Store[T]) FirstN(batchSize int) ([]T, error) {
9196
return got, nil
9297
}
9398

99+
// All retrieves all requests.
100+
// The method deep-copies requests before returning them.
101+
func (s *Store[T]) All() ([]T, error) {
102+
s.mu.RLock()
103+
defer s.mu.RUnlock()
104+
allRequestsCnt := len(s.requestIDs)
105+
if allRequestsCnt == 0 {
106+
return []T{}, nil
107+
}
108+
109+
return s.firstN(allRequestsCnt)
110+
}
111+
94112
// RangeN retrieves up to `batchSize` requests starting at index `start`.
95113
// It deep-copies each request before returning.
96114
func (s *Store[T]) RangeN(start, batchSize int) ([]T, error) {

pkg/capabilities/consensus/requests/store_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ func TestOCR3Store(t *testing.T) {
2525
ExpiresAt: n.Add(10 * time.Second),
2626
}
2727

28+
t.Run("all with 0 requests", func(t *testing.T) {
29+
items, err := s.All()
30+
require.NoError(t, err)
31+
assert.Len(t, items, 0)
32+
})
33+
2834
t.Run("Add", func(t *testing.T) {
2935
err := s.Add(req)
3036
require.NoError(t, err)
@@ -64,6 +70,12 @@ func TestOCR3Store(t *testing.T) {
6470
assert.Len(t, items, 10)
6571
})
6672

73+
t.Run("all with 10 requests", func(t *testing.T) {
74+
items, err := s.All()
75+
require.NoError(t, err)
76+
assert.Len(t, items, 10)
77+
})
78+
6779
t.Run("rangeN", func(t *testing.T) {
6880
err := s.Add(&ocr3.ReportRequest{WorkflowExecutionID: uuid.New().String(), ExpiresAt: n.Add(1 * time.Hour)})
6981
r, err := s.RangeN(0, 1)

0 commit comments

Comments
 (0)