-
Notifications
You must be signed in to change notification settings - Fork 29
chore: consumer interface refactor #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…to lazar/consumer-interface-ref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the ConsumerController interface into three focused interfaces (RandomnessCommitter, BlockQuerier, FinalityOperator), adds context.Context parameters to all consumer API methods, and updates mocks/tests accordingly.
- Split the monolithic
ConsumerControllerinto smaller interfaces and introduced new request/response structs. - Propagated
context.Contextthrough nearly all consumer, controller, service, and test methods. - Updated GoMock usage (switched to Uber’s fork), regenerated mocks, and adapted
go.mod/Makefile.
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| clientcontroller/api/interface.go | New RandomnessCommitter, BlockQuerier, FinalityOperator interfaces with context-based methods |
| testutil/utils.go | Changed import from github.com/golang/mock/gomock to go.uber.org/mock/gomock |
| testutil/mocks/clientcontroller.go | Regenerated mocks with Uber’s mockgen and context params |
| itest//*.go & test-manager//*.go | Added context.Context to all consumer calls in integration and E2E tests |
| finality-provider/service/**/*.go | Updated service methods to accept and propagate context.Context |
| clientcontroller/{opstackl2,cosmwasm,babylon}/*.go | Refactored each consumer implementation to use context-aware request structs |
| go.mod, Makefile | Bumped go.uber.org/mock dependency and updated mockgen commands |
| CHANGELOG.md | Added entry for consumer interface refactor (#512) |
Comments suppressed due to low confidence (1)
| // | ||
| // Generated by this command: | ||
| // | ||
| // mockgen -source=clientcontroller/api/interface.go -package mocks -destination /Users/lazar/work/finality-provider/testutil/mocks/clientcontroller.go |
Copilot
AI
Jul 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The generated‐by comment uses an absolute local path. Consider updating it to a project‐relative path (e.g., ./testutil/mocks/clientcontroller.go) for better portability.
| // mockgen -source=clientcontroller/api/interface.go -package mocks -destination /Users/lazar/work/finality-provider/testutil/mocks/clientcontroller.go | |
| // mockgen -source=clientcontroller/api/interface.go -package mocks -destination ./testutil/mocks/clientcontroller.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is annoying, not sure if this can be omitted when generating
| case req := <-app.unjailFinalityProviderRequestChan: | ||
| pkHex := req.btcPubKey.MarshalHex() | ||
| isSlashed, isJailed, err := app.consumerCon.QueryFinalityProviderSlashedOrJailed(req.btcPubKey.MustToBTCPK()) | ||
| status, err := app.consumerCon.QueryFinalityProviderStatus(context.Background(), req.btcPubKey.MustToBTCPK()) |
Copilot
AI
Jul 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using context.Background() here prevents cancellation propagation from the surrounding loop. Consider adding a ctx parameter to unjailFpLoop and passing it instead of using Background().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing bot, proper ctx control will be done in future PR.
KonradStaniec
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codewise it looks good 👍
|
|
||
| // QueryLatestBlockHeight queries the tip block height of the consumer chain | ||
| QueryLatestBlockHeight() (uint64, error) | ||
| type SubmitBatchFinalitySigsRequest struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have constructors for those request likle func NewSubmitBatchFinalitySigsRequest(..). (though this can be done in following tickets)
| } | ||
|
|
||
| func (wc *CosmwasmConsumerController) UnjailFinalityProvider(_ context.Context, _ *btcec.PublicKey) (*fptypes.TxResponse, error) { | ||
| // TODO: implement unjail feature in OP stack L2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I do not think L2s have concept of jailing. Given that those were here already I wonder wheter we can remove those todos cc: @SebastianElvis ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK none of the existing ones has but we will need to double check again (cc @0xAleksaOpacic ) We can remove those TODOs and pick those up once the jailing in BSNs becomes relevant again
Wait for #512 to be merged. closes #513 --- bot generated: --- This pull request refactors the randomness commitment logic in the finality-provider by extracting it into a new, dedicated component (RandomnessCommitter), improving modularity and testability. The main changes include: - Introduction of a new interface types.RandomnessCommitter and its implementation DefaultRandomnessCommitter (service/rand_committ.go), encapsulating the logic for determining when and how to commit public randomness. - Refactoring FinalityProviderInstance and FinalityProviderApp to accept and use a RandomnessCommitter instead of handling randomness commitments internally. - Movement of functions related to randomness commitment and commitment eligibility from FinalityProviderInstance to DefaultRandomnessCommitter. - Update of test helpers and test managers to construct and inject the new committer in tests and integration tests. - Minor renaming for clarity: pubRandState → PubRandState, newPubRandState → NewPubRandState. - Removal of duplicated or obsolete code related to randomness commitment from fp_instance.go, with all logic now handled in the committer. - All calls to commit, check, or retrieve randomness commitments now go through the RandomnessCommitter interface. - Internal wiring and parameter lists updated throughout the codebase to accommodate the new committer dependency. Overall, this PR decouples the randomness commitment process from the core finality provider logic, laying the groundwork for easier maintenance, extension, and potential alternative commitment strategies in the future.
Wait for #512 to be merged. Enables bootstrap logic providing to the finality provider instance and app. closes #514 --- bot generated: --- This pull request refactors and modularizes the logic for determining the starting height at which the Finality Provider begins processing blocks. The main changes are: ### Key Changes 1. **Extracted Start Height Logic:** - The logic previously inside FinalityProviderInstance.DetermineStartHeight is moved into a new dedicated component, StartHeightDeterminer (in service/bootstrap.go). - This component encapsulates all the logic for calculating the correct starting height, handling both static and automatic chain scanning modes. 2. **New Interface Introduced:** - Adds a new types.HeightDeterminer interface (in types/expected_bootstraper.go), with a method DetermineStartHeight. StartHeightDeterminer implements this interface. - Introduces LastVotedHeightProvider as a function type for retrieving the last voted height. 3. **Dependency Injection:** - All relevant structs (FinalityProviderInstance, FinalityProviderApp, etc.) now take a HeightDeterminer as a dependency. - All constructors and test helpers are updated to accept and inject the new dependency. 4. **Code Cleanup and Refactoring:** - Removes duplicated logic for determining the start height from FinalityProviderInstance and moves all block height querying logic (including retries) into the new StartHeightDeterminer. - Updates tests and integration tests to use and inject the new component. - Renames fpState to FpState and updates constructors for clarity and Go idioms. 5. **New File Added:** - service/bootstrap.go: Contains the StartHeightDeterminer implementation. - types/expected_bootstraper.go: Contains the HeightDeterminer interface and related types. 6. **Minor Code Quality Improvements:** - Standardizes context usage for height determination logic (prepares for future improvements). - Adds/updates documentation and comments for clarity. ### Motivation / Benefits - Improves code modularity, readability, and testability. - Makes the logic for determining the processing start height reusable and easier to reason about. - Prepares the codebase for further enhancements or alternative bootstrapping strategies.
Plan for next PRs:
Bot generated:
Chore: Consumer Interface Refactor & Context Propagation
Key Changes
Refactored ConsumerController & Related Interfaces:
Context Propagation:
Signature & Voting Power Queries:
Batch Operations Standardized:
Implementation Updates:
Test & Benchmark Adaptation:
Makefile & Dependency Update:
go.uber.org/mock/mockgen).Changelog:
Impact: