Skip to content
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

chore: Refactor CommitPubRand #233

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gitferry
Copy link
Member

@gitferry gitferry commented Dec 18, 2024

Closes #225. The major goal of this pr is to refactor CommitPubRand but turned out included many small refactorings along the way (sorry for the mixup). Notable changes are:

  • Split retryCommitPubRandUntilBlockFinalized into ShouldCommitRandomness and CommitPubRand. The former checks whether a new commit should be made based on the last committed height and the tip height. If true, it also returns the start height of the commit. The latter makes a new commit based on the start height returned by the former.
  • Rename config.MinRandHeightGap to config.TimestampingDelayBlocks which is an estimated value of the latency between a commit is submitted and it is timestamped by the btc-timestamping protocol
  • Remove status update loop. Instead, the status update is done when querying voting power during vote submission in ProcessBlocksToVote

Reviewers, please take a careful look at fp_instance.go, especially how ShouldCommitRandomness determines the start height with consideration of btc-timestamping delay

@gitferry gitferry force-pushed the gai/add-randomness-ahead-height branch from 4ca005d to dc93487 Compare December 18, 2024 10:24
@@ -316,9 +373,17 @@ func (fp *FinalityProviderInstance) hasVotingPower(b *types.BlockInfo) (bool, er
zap.Uint64("block_height", b.Height),
)

if fp.GetStatus() == proto.FinalityProviderStatus_ACTIVE {
fp.MustSetStatus(proto.FinalityProviderStatus_INACTIVE)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: not a huge fan of this, it's a bit hidden away that this function updates state. I suggest making it return the voting power or something like (bool, uint64, err), and then the function caller can decide what to do with it.

Alternatively, add comment saying that it also updates local status

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Did some refactoring in 757156e

@@ -173,41 +171,42 @@ func (fp *FinalityProviderInstance) finalitySigSubmissionLoop() {
defer fp.wg.Done()

for {
// start submission in the first iteration
pollerBlocks := fp.getAllBlocksFromChan()
Copy link
Member

Choose a reason for hiding this comment

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

nice, I bet we do this a lot throughout the codebases, that we wait before the first iteration

Copy link
Member Author

Choose a reason for hiding this comment

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

I just realized that we can't do it for every loop for cases where we have continue upon error. If we do, then we the loop will go forever. Need to figure out other ways for it

@gitferry gitferry force-pushed the gai/add-randomness-ahead-height branch 2 times, most recently from 9c904b3 to 5ec5a77 Compare December 19, 2024 01:42
@gitferry gitferry force-pushed the gai/add-randomness-ahead-height branch from 5ec5a77 to edb1eb0 Compare December 19, 2024 03:05
@gitferry gitferry marked this pull request as ready for review December 19, 2024 03:19
Copy link
Member

@Lazar955 Lazar955 left a comment

Choose a reason for hiding this comment

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

Great work!

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.

Refactor CommitPubRand
2 participants