-
Notifications
You must be signed in to change notification settings - Fork 29
chore: abstract randomness committer #515
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 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
RandomnessCommitterinterface andDefaultRandomnessCommitterimplementation. - Refactor
FinalityProviderAppandFinalityProviderInstanceto accept and useRandomnessCommitter. - Update test utilities, mocks, and integration tests to pass a
context.Contextto 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
typesconflicts with the local package name. Rename the imported package, for example tobabylonTypes, 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 itsShouldCommitandCommitmethods to verify all logic branches.
package service
| @@ -0,0 +1,268 @@ | |||
| package service | |||
Copilot
AI
Jul 14, 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] Filename rand_committ.go appears to have a typo. Consider renaming it to rand_committer.go or rand_commit.go for clarity.
|
|
||
| fp.wg.Add(2) | ||
| go fp.finalitySigSubmissionLoop() | ||
| go fp.randomnessCommitmentLoop() | ||
| // todo(lazar): will fix ctx in next PRs | ||
| go fp.randomnessCommitmentLoop(context.Background()) |
Copilot
AI
Jul 14, 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 randomness commitment loop uses context.Background() which cannot be cancelled. Consider passing a cancellable context to support graceful shutdown.
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.
read the todo above it bot 🤷♂️
SebastianElvis
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.
Overall LGTM 👍 Some final comments on the abstraction
| // TODO: implement slashed or jailed feature in rollup BSN | ||
| return false, false, nil | ||
| } | ||
|
|
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.
| } | ||
|
|
||
| // CommitPubRand commits a list of randomness from given start height | ||
| func (fp *FinalityProviderInstance) CommitPubRand(ctx context.Context, startHeight uint64) (*types.TxResponse, error) { |
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.
Do we need this function given that it's 1 line? Same q for GetLastCommittedHeight
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.
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 |
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.
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?
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.
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.
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.
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 |
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.
Same comment for L41, is it good idea to get rid of pubRandStore?
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.
Looks good, it is definitly step in good direction 👍
|
|
||
| fpState *fpState | ||
| pubRandState *pubRandState | ||
| pubRandState *PubRandState |
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.
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) |
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.
SetBtcPk and SetChainID seem like they do not belong here 🤔 maybe they can be made part of the config passed to particular implementations ?
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.
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)
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:
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.