Skip to content

Commit 08016f5

Browse files
authored
pkg/types/llo/ChannelDefinition: add AllowNilStreamValues (#1900)
aa
1 parent 9c2ada8 commit 08016f5

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

pkg/types/llo/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ type ChannelDefinition struct {
260260
// Streams is the list of streams to be observed and aggregated
261261
// by the protocol.
262262
Streams []Stream `json:"streams"`
263+
// AllowNilStreamValues controls whether channels with nil stream values
264+
// are considered reportable.
265+
// When true, nil stream values are allowed
266+
// and the report codec needs to handle them accordingly.
267+
AllowNilStreamValues bool `json:"allowNilStreamValues"`
263268
// Opts contains configuration data for use in report generation
264269
// for this channel, e.g. feed ID, expiry window, USD base fee etc
265270
//
@@ -290,14 +295,21 @@ func (a ChannelDefinition) Equals(b ChannelDefinition) bool {
290295
if a.ReportFormat != b.ReportFormat {
291296
return false
292297
}
298+
299+
if a.AllowNilStreamValues != b.AllowNilStreamValues {
300+
return false
301+
}
302+
293303
if len(a.Streams) != len(b.Streams) {
294304
return false
295305
}
306+
296307
for i, strm := range a.Streams {
297308
if strm != b.Streams[i] {
298309
return false
299310
}
300311
}
312+
301313
return bytes.Equal(a.Opts, b.Opts)
302314
}
303315

pkg/types/llo/types_test.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ func Test_ChannelDefinitions_Serialization(t *testing.T) {
1919
],
2020
"opts": null,
2121
"tombstone": false,
22-
"source": 1
22+
"source": 1,
23+
"allowNilStreamValues": false
2324
},
2425
"1": {
2526
"reportFormat": "evm_premium_legacy",
@@ -35,7 +36,8 @@ func Test_ChannelDefinitions_Serialization(t *testing.T) {
3536
"baseUSDFee": "0.1"
3637
},
3738
"tombstone": false,
38-
"source": 2
39+
"source": 2,
40+
"allowNilStreamValues": true
3941
}
4042
}`
4143
var channelDefinitions ChannelDefinitions
@@ -132,6 +134,22 @@ func Test_ChannelDefinition_Equals(t *testing.T) {
132134
assert.False(t, a.Equals(b))
133135
})
134136

137+
t.Run("different AllowNilStreamValues", func(t *testing.T) {
138+
a := ChannelDefinition{
139+
ReportFormat: ReportFormatJSON,
140+
Streams: []Stream{{0, AggregatorMedian}, {1, AggregatorMode}},
141+
Opts: nil,
142+
AllowNilStreamValues: false,
143+
}
144+
b := ChannelDefinition{
145+
ReportFormat: ReportFormatJSON,
146+
Streams: []Stream{{0, AggregatorMedian}, {1, AggregatorMode}},
147+
Opts: nil,
148+
AllowNilStreamValues: true,
149+
}
150+
assert.False(t, a.Equals(b))
151+
})
152+
135153
t.Run("equal", func(t *testing.T) {
136154
a := ChannelDefinition{
137155
ReportFormat: ReportFormatJSON,
@@ -190,16 +208,18 @@ func Test_ChannelDefinitions_Value(t *testing.T) {
190208
t.Run("valid JSON", func(t *testing.T) {
191209
c := ChannelDefinitions{
192210
0: {
193-
ReportFormat: ReportFormatJSON,
194-
Streams: []Stream{{1, AggregatorMedian}, {2, AggregatorMode}},
195-
Opts: nil,
196-
Source: 1,
211+
ReportFormat: ReportFormatJSON,
212+
Streams: []Stream{{1, AggregatorMedian}, {2, AggregatorMode}},
213+
Opts: nil,
214+
Source: 1,
215+
AllowNilStreamValues: false,
197216
},
198217
1: {
199-
ReportFormat: ReportFormatEVMPremiumLegacy,
200-
Streams: []Stream{{1, AggregatorMedian}, {2, AggregatorMedian}, {3, AggregatorQuote}},
201-
Opts: []byte(`{"baseUSDFee":"0.1","expirationWindow":86400,"feedId":"0x0003aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","multiplier":"1000000000000000000"}`),
202-
Source: 2,
218+
ReportFormat: ReportFormatEVMPremiumLegacy,
219+
Streams: []Stream{{1, AggregatorMedian}, {2, AggregatorMedian}, {3, AggregatorQuote}},
220+
Opts: []byte(`{"baseUSDFee":"0.1","expirationWindow":86400,"feedId":"0x0003aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","multiplier":"1000000000000000000"}`),
221+
Source: 2,
222+
AllowNilStreamValues: true,
203223
},
204224
}
205225
v, err := c.Value()
@@ -213,7 +233,8 @@ func Test_ChannelDefinitions_Value(t *testing.T) {
213233
],
214234
"opts": null,
215235
"tombstone": false,
216-
"source": 1
236+
"source": 1,
237+
"allowNilStreamValues": false
217238
},
218239
"1": {
219240
"reportFormat": "evm_premium_legacy",
@@ -229,7 +250,8 @@ func Test_ChannelDefinitions_Value(t *testing.T) {
229250
"multiplier": "1000000000000000000"
230251
},
231252
"tombstone": false,
232-
"source": 2
253+
"source": 2,
254+
"allowNilStreamValues": true
233255
}
234256
}`
235257
assert.JSONEq(t, expectedJSON, string(v.([]byte)))

0 commit comments

Comments
 (0)