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

Conversation

@Lazar955
Copy link
Member

@Lazar955 Lazar955 commented Jul 12, 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.

Base automatically changed from lazar/consumer-interface-ref to main July 14, 2025 06:34
@Lazar955 Lazar955 marked this pull request as ready for review July 14, 2025 06:35
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 extracts the public randomness commitment logic into a new RandomnessCommitter component to improve modularity and testability, and updates all callers and tests to use the new interface with context-aware method signatures.

  • Introduce RandomnessCommitter interface and DefaultRandomnessCommitter implementation.
  • Refactor FinalityProviderApp and FinalityProviderInstance to accept and use RandomnessCommitter.
  • Update test utilities, mocks, and integration tests to pass a context.Context to all consumer controller calls.

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
types/expected_rand_committer.go Added RandomnessCommitter interface definition.
finality-provider/service/rand_committ.go New DefaultRandomnessCommitter implementation.
finality-provider/service/fp_instance.go Refactored instance to use the committer instead of inline randomness logic.
testutil/utils.go Updated mock imports and expectation signatures for context parameters.
go.mod Added direct dependency on go.uber.org/mock and cleaned up the indirect entry.
Comments suppressed due to low confidence (2)

types/expected_rand_committer.go:5

  • Import alias types conflicts with the local package name. Rename the imported package, for example to babylonTypes, to avoid shadowing the current package.
	"github.com/babylonlabs-io/babylon/v3/types"

finality-provider/service/rand_committ.go:1

  • There are no dedicated unit tests for DefaultRandomnessCommitter. Add tests covering its ShouldCommit and Commit methods to verify all logic branches.
package service

@@ -0,0 +1,268 @@
package service
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Filename rand_committ.go appears to have a typo. Consider renaming it to rand_committer.go or rand_commit.go for clarity.

Copilot uses AI. Check for mistakes.
Comment on lines 143 to +147

fp.wg.Add(2)
go fp.finalitySigSubmissionLoop()
go fp.randomnessCommitmentLoop()
// todo(lazar): will fix ctx in next PRs
go fp.randomnessCommitmentLoop(context.Background())
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The randomness commitment loop uses context.Background() which cannot be cancelled. Consider passing a cancellable context to support graceful shutdown.

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.

read the todo above it bot 🤷‍♂️

Copy link
Member

@SebastianElvis SebastianElvis left a comment

Choose a reason for hiding this comment

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

Overall LGTM 👍 Some final comments on the abstraction

// TODO: implement slashed or jailed feature in rollup BSN
return false, false, nil
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

}

// CommitPubRand commits a list of randomness from given start height
func (fp *FinalityProviderInstance) CommitPubRand(ctx context.Context, startHeight uint64) (*types.TxResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this function given that it's 1 line? Same q for GetLastCommittedHeight

Copy link
Member

@SebastianElvis SebastianElvis Jul 15, 2025

Choose a reason for hiding this comment

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

Since we are abstracting out the pub rand commit utilities, do you think this KV store should be made entirely internal for DefaultRandomnessCommitter?


fpState *fpState
pubRandState *pubRandState
pubRandState *PubRandState
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the other comment, do you think we should get rid of this pubRandState field from the FinalityProviderInstance, and instead only rely on rndCommitter for pub rand operations?

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually like the idea of RandomnessCommitter owning the storage 👍 thoug this will be probably ad Close() function to the interface to close the storage on committer level

This can be done in separate pr though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense, tho we'll have to expose more methods in the interface, but I think that's okay. Will create an issue for this and do in separate PR, don't want to drag this along

fpInsMu sync.RWMutex // Protects fpIns
fpIns *FinalityProviderInstance
eotsManager eotsmanager.EOTSManager
rndCommitter types.RandomnessCommitter
Copy link
Member

Choose a reason for hiding this comment

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

Same comment for L41, is it good idea to get rid of pubRandStore?

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.

Looks good, it is definitly step in good direction 👍


fpState *fpState
pubRandState *pubRandState
pubRandState *PubRandState
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually like the idea of RandomnessCommitter owning the storage 👍 thoug this will be probably ad Close() function to the interface to close the storage on committer level

This can be done in separate pr though.

// GetLastCommittedHeight retrieves the last height at which randomness was committed.
GetLastCommittedHeight(ctx context.Context) (uint64, error)

SetBtcPk(btcPk *types.BIP340PubKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

SetBtcPk and SetChainID seem like they do not belong here 🤔 maybe they can be made part of the config passed to particular implementations ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, definitely feels ugly. One option would be to pass them as params to GetLastCommittedHeight. The reason we can't pass them to the ctor of the struct implementing the interface is because we don't know them at that point of time (in case where FPI hasn't been registered yet)

@Lazar955 Lazar955 merged commit 734d9a2 into main Jul 15, 2025
18 checks passed
@Lazar955 Lazar955 deleted the lazar/abstract-rand-commit branch July 15, 2025 08:22
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.

Abstract randomnes committer

4 participants