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

fix: send the last gpbft message for each new participant #6417

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions pkg/vf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,28 @@ func (fff *F3) runSigningLoop(ctx context.Context) {

msgCh := fff.inner.MessagesToSign()

loop:
var mb *gpbft.MessageBuilder
alreadyParticipated := make(map[uint64]struct{})
for ctx.Err() == nil {
select {
case <-ctx.Done():
return
case mb, ok := <-msgCh:
if !ok {
continue loop
case <-fff.leaser.notifyParticipation:
if mb == nil {
continue
}
participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
for _, id := range participants {
if err := participateOnce(ctx, mb, id); err != nil {
log.Errorf("while participating for miner f0%d: %+v", id, err)
}
case mb = <-msgCh: // never closed
clear(alreadyParticipated)
}

participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
for _, id := range participants {
if _, ok := alreadyParticipated[id]; ok {
continue
} else if err := participateOnce(ctx, mb, id); err != nil {
log.Errorf("while participating for miner f0%d: %+v", id, err)
} else {
alreadyParticipated[id] = struct{}{}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/vf3/participation_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type leaser struct {
issuer peer.ID
status f3Status
maxLeasableInstances uint64
// Signals that a lease was created and/or updated.
notifyParticipation chan struct{}
}

func newParticipationLeaser(nodeID peer.ID, status f3Status, maxLeasedInstances uint64) *leaser {
Expand All @@ -30,6 +32,7 @@ func newParticipationLeaser(nodeID peer.ID, status f3Status, maxLeasedInstances
issuer: nodeID,
status: status,
maxLeasableInstances: maxLeasedInstances,
notifyParticipation: make(chan struct{}, 1),
}
}

Expand Down Expand Up @@ -98,6 +101,10 @@ func (l *leaser) participate(ticket types.F3ParticipationTicket) (types.F3Partic
return types.F3ParticipationLease{}, types.ErrF3ParticipationTicketStartBeforeExisting
}
l.leases[newLease.MinerID] = newLease
select {
case l.notifyParticipation <- struct{}{}:
default:
}
return newLease, nil
}

Expand Down
Loading