Skip to content

fix(oracle): fix wrong nil check in ValidateFeeder function#255

Merged
jhelison merged 2 commits into
KiiChain:mainfrom
catsmile100:fix/oracle-nil-check
Jan 27, 2026
Merged

fix(oracle): fix wrong nil check in ValidateFeeder function#255
jhelison merged 2 commits into
KiiChain:mainfrom
catsmile100:fix/oracle-nil-check

Conversation

@catsmile100

Copy link
Copy Markdown
Contributor

Description

Fixed wrong nil check in ValidateFeeder function.

The bug: code checks valAddr == nil but this never happens because valAddr is a function parameter. Should check validator == nil instead.

Changed line 188 in x/oracle/keeper/keeper.go from checking valAddr to checking validator.

Fixes #250

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added TestValidateFeederNilCheckBug test case to verify the bug exists
  • Confirmed test passes with the fix applied
  • Ran existing oracle module tests to ensure no regression

Test configuration: Go 1.23, kiichain v6.1.1

PR Checklist:

  • Updated changelog with PR's intent
  • Added test case to verify fix

@catsmile100 catsmile100 requested a review from jhelison as a code owner January 26, 2026 15:08
@coderabbitai

coderabbitai Bot commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request corrects a logic error in the ValidateFeeder function within the oracle module's keeper. The fix changes a nil check from validating valAddr (a function parameter) to validating validator (a return value from the staking keeper query). The original condition was dead code that could not execute. The corrected condition now properly validates whether the validator object exists before calling its IsBonded() method, eliminating a potential nil pointer dereference. A changelog entry documents this bug fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(oracle): fix wrong nil check in ValidateFeeder function' clearly and specifically describes the main change in the PR—fixing an incorrect nil check in the oracle module's ValidateFeeder function.
Description check ✅ Passed The description provides relevant context for the changeset, explaining the bug (checking valAddr == nil instead of validator == nil), the fix applied (line 188), testing performed, and the issue reference (#250).
Linked Issues check ✅ Passed The PR addresses all key requirements from issue #250: replaces the dead check 'valAddr == nil' with 'validator == nil' in x/oracle/keeper/keeper.go line 188, adds a test case TestValidateFeederNilCheckBug, updates the changelog, and ensures consistency with other code paths.
Out of Scope Changes check ✅ Passed All changes in the PR are in scope: the primary fix to keeper.go line 188, the new test case, and the CHANGELOG.md update directly support the objectives of issue #250 with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Around line 128-129: The changelog bug fix entry "* **oracle:** fix wrong nil
check in ValidateFeeder function
([`#250`](https://github.com/KiiChain/kiichain/issues/250))" is currently under
v2.0.0's "### Changed" section; move that exact entry out of lines shown and add
it into the existing "## Fixed" subsection under "## UNRELEASED" (place it after
the other entries in that section) so the fix is recorded in the unreleased
fixed list.

In `@x/oracle/validate_feeder_test.go`:
- Around line 38-39: The test misrepresents the original buggy pattern in
ValidateFeeder: update the test so keeperPattern mirrors the actual buggy
conditional used in ValidateFeeder (which directly calls validator.IsBonded()
without a nil check) by removing the guarded check involving validator != nil
and making the condition use valAddr and validator.IsBonded() exactly as in the
bug; reference the ValidateFeeder logic, the keeperPattern variable, valAddr and
validator.IsBonded() so the test will reproduce the nil-validator panic scenario
and fail when validator is nil.
🧹 Nitpick comments (1)
x/oracle/validate_feeder_test.go (1)

14-31: Tests document the bug but don't provide regression protection.

These tests demonstrate the bug conceptually but don't actually invoke ValidateFeeder with a mock StakingKeeper that returns (nil, nil). Consider adding an integration test that:

  1. Sets up a keeper with a mock StakingKeeper
  2. Configures the mock to return (nil, nil) for a valid valAddr
  3. Calls ValidateFeeder and asserts it returns ErrNoValidatorFound

This would catch regressions if the nil check is accidentally reverted.

Comment thread CHANGELOG.md Outdated
Comment thread x/oracle/validate_feeder_test.go Outdated
Fixes KiiChain#250

- Change valAddr == nil to validator == nil check
- Add test case to verify fix and demonstrate bug
- valAddr is function parameter, never nil
- validator can be nil from StakingKeeper.Validator()
- Update CHANGELOG.md with proper UNRELEASED entry
- Address CodeRabbit actionable comments

@Thaleszh Thaleszh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge once AI test is removed

Comment thread x/oracle/validate_feeder_test.go Outdated
@codecov

codecov Bot commented Jan 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
x/oracle/keeper/keeper.go 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@jhelison jhelison merged commit c076468 into KiiChain:main Jan 27, 2026
8 of 9 checks passed
@catsmile100 catsmile100 deleted the fix/oracle-nil-check branch January 27, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Wrong Nil Check in ValidateFeeder - Dead Code

3 participants