这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Lazar955
Copy link
Member

@Lazar955 Lazar955 commented Jul 11, 2025

  • Refactors the Consumer interface for better granulation. PR is already quite big, so I haven't broken the consumer controller implementation into smaller ones.
  • Uses context more, but we are still a long way to go, and there will be a dedicated PR to properly propagate ctx from entry point
  • update mocks as generics don't work with old gomock

Plan for next PRs:

  • Abstract bootstrap
  • Abstract randomness commit.
  • Context propagation
  • Builder pattern

Bot generated:


Chore: Consumer Interface Refactor & Context Propagation

Key Changes

  1. Refactored ConsumerController & Related Interfaces:

    • Broke up the large ConsumerController interface into smaller, more focused interfaces:
      • RandomnessCommitter
      • BlockQuerier
      • FinalityOperator
    • Introduced new request/response types (e.g., CommitPubRandListRequest, SubmitBatchFinalitySigsRequest, QueryBlocksRequest, FinalityProviderStatusResponse).
    • Most methods now require a context.Context parameter, enabling better control over cancellation and deadlines.
  2. Context Propagation:

    • All major controller and service methods now accept context.Context, ensuring that long-running operations and retries can be cancelled or timed out appropriately.
    • Propagated context through the application, including service layer, test helpers, and integration/e2e tests.
  3. Signature & Voting Power Queries:

    • Refactored voting power and status queries to use the new request/response types and context.
    • Methods like QueryFinalityProviderHasPower, QueryLastPublicRandCommit, QueryBlocks, etc., now require context and operate with the new interfaces.
  4. Batch Operations Standardized:

    • SubmitBatchFinalitySigs, CommitPubRandList, and similar batch operations now use unified request structs and context.
    • Single signature submission methods were removed in favor of batch-oriented APIs.
  5. Implementation Updates:

    • All concrete controller implementations (Babylon, CosmWasm, OPStack L2) updated to match the new interface and context requirements.
    • Some features in CosmWasm and OPStack L2 controllers are stubbed with TODOs, reflecting pending feature development.
  6. Test & Benchmark Adaptation:

    • Updated all service, fuzz, and integration tests to work with the new context-based signatures.
    • Adjusted mocks and test managers to match the new method signatures and types.
    • Improved parallelization and reliability for tests.
  7. Makefile & Dependency Update:

    • Updated mockgen dependency to Uber’s maintained fork (go.uber.org/mock/mockgen).
    • Adjusted Makefile accordingly.
  8. Changelog:

    • Added an entry for this refactor to the CHANGELOG.md.

Impact:

  • This refactor improves modularity, testability, and observability of the codebase.
  • It enables better resource management and error handling by introducing context propagation throughout the stack.
  • The new interface structure prepares the codebase for future extensibility and makes it easier to implement/testing new consumer types or behaviors.

@Lazar955 Lazar955 changed the title feat: consumer interface refactor chore: consumer interface refactor Jul 11, 2025
@Lazar955 Lazar955 marked this pull request as ready for review July 11, 2025 13:45
Copilot AI review requested due to automatic review settings July 11, 2025 13:45
Copy link
Contributor

Copilot AI left a 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 ConsumerController into smaller interfaces and introduced new request/response structs.
  • Propagated context.Context through 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
Copy link

Copilot AI Jul 11, 2025

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.

Suggested change
// 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

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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())
Copy link

Copilot AI Jul 11, 2025

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().

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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.

Copy link
Contributor

@KonradStaniec KonradStaniec left a 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 {
Copy link
Contributor

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
Copy link
Contributor

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 ?

Copy link
Member

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

@Lazar955 Lazar955 merged commit d6efdcb into main Jul 14, 2025
18 checks passed
@Lazar955 Lazar955 deleted the lazar/consumer-interface-ref branch July 14, 2025 06:34
Lazar955 added a commit that referenced this pull request Jul 15, 2025
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.
Lazar955 added a commit that referenced this pull request Jul 15, 2025
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.
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.

4 participants