Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit cbdc79f

Browse files
authored
fix: allow negative threshold for MinBlockHeight (#195)
Negative values are used to disable the threshold and currently appear in unit tests: there is no reason not to allow them. Signed-off-by: Matthieu Blottière <[email protected]>
1 parent 5c3f546 commit cbdc79f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pkg/fab/events/client/peerresolver/minblockheight/minblockheight_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,19 @@ func TestOpts(t *testing.T) {
169169
assert.Equal(t, 9, params.reconnectBlockHeightLagThreshold)
170170
})
171171

172+
t.Run("No filter", func(t *testing.T) {
173+
policy := fab.EventServicePolicy{
174+
BlockHeightLagThreshold: -1,
175+
MinBlockHeightResolverMode: fab.ResolveByThreshold,
176+
}
177+
config.SetCustomChannelConfig(channelID, &fab.ChannelEndpointConfig{
178+
Policies: fab.ChannelPolicies{
179+
EventService: policy,
180+
},
181+
})
182+
183+
params := defaultParams(context, channelID)
184+
require.NotNil(t, params)
185+
assert.Equal(t, -1, params.blockHeightLagThreshold)
186+
})
172187
}

pkg/fab/events/client/peerresolver/minblockheight/opts.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ func getBlockHeightLagThreshold(policy fab.EventServicePolicy) int {
104104
threshold = 0
105105
case fab.ResolveByThreshold:
106106
threshold = policy.BlockHeightLagThreshold
107-
if threshold <= 0 {
108-
logger.Warnf("Invalid BlockHeightLagThreshold: %d. Using default: %d", threshold, defaultBlockHeightLagThreshold)
109-
threshold = defaultBlockHeightLagThreshold
110-
}
111107
default:
112108
logger.Warnf("Invalid MinBlockHeightResolverMode: [%s]. Using default: [%s]", policy.MinBlockHeightResolverMode, fab.ResolveByThreshold)
113109
threshold = policy.BlockHeightLagThreshold

0 commit comments

Comments
 (0)