⚠️ Potential issue | 🟠 Major
Incorrect voting period calculation may cause premature return.
Line 48 calculates targetHeight := height + int64(uint64(height)%params.Params.VotePeriod), which adds the remainder to the current height. This appears incorrect.
To wait for the next voting period, you should add the distance to the next period boundary: VotePeriod - (height % VotePeriod).
Apply this diff:
func (s *IntegrationSuite) waitNextVotePeriod() {
params, err := s.pricePosterClient.GetOracleClient().(oracletypes.QueryClient).Params(context.Background(), &oracletypes.QueryParamsRequest{})
require.NoError(s.T(), err)
height, err := s.network.LatestHeight()
require.NoError(s.T(), err)
- targetHeight := height + int64(uint64(height)%params.Params.VotePeriod)
+ votePeriod := params.Params.VotePeriod
+ targetHeight := height + int64(votePeriod - uint64(height)%votePeriod)
_, err = s.network.WaitForHeight(targetHeight)
require.NoError(s.T(), err)
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func (s *IntegrationSuite) waitNextVotePeriod() {
params, err := s.pricePosterClient.GetOracleClient().(oracletypes.QueryClient).Params(context.Background(), &oracletypes.QueryParamsRequest{})
require.NoError(s.T(), err)
height, err := s.network.LatestHeight()
require.NoError(s.T(), err)
votePeriod := params.Params.VotePeriod
targetHeight := height + int64(votePeriod - uint64(height)%votePeriod)
_, err = s.network.WaitForHeight(targetHeight)
require.NoError(s.T(), err)
}
🤖 Prompt for AI Agents
In feeder/priceposter_integration_test.go around lines 43 to 51, the calculation
of targetHeight uses the remainder (height % VotePeriod) instead of the distance
to the next period boundary; replace the current line with one that computes
distance := int64(params.Params.VotePeriod -
uint64(height)%params.Params.VotePeriod) and set targetHeight := height +
distance (casting as needed) so we wait until the next vote period boundary
(this also naturally yields VotePeriod when currently on a boundary).
Originally posted by @coderabbitai[bot] in #81 (comment)
Incorrect voting period calculation may cause premature return.
Line 48 calculates
targetHeight := height + int64(uint64(height)%params.Params.VotePeriod), which adds the remainder to the current height. This appears incorrect.To wait for the next voting period, you should add the distance to the next period boundary:
VotePeriod - (height % VotePeriod).Apply this diff:
func (s *IntegrationSuite) waitNextVotePeriod() { params, err := s.pricePosterClient.GetOracleClient().(oracletypes.QueryClient).Params(context.Background(), &oracletypes.QueryParamsRequest{}) require.NoError(s.T(), err) height, err := s.network.LatestHeight() require.NoError(s.T(), err) - targetHeight := height + int64(uint64(height)%params.Params.VotePeriod) + votePeriod := params.Params.VotePeriod + targetHeight := height + int64(votePeriod - uint64(height)%votePeriod) _, err = s.network.WaitForHeight(targetHeight) require.NoError(s.T(), err) }📝 Committable suggestion
🤖 Prompt for AI Agents
Originally posted by @coderabbitai[bot] in #81 (comment)