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(f3): send the last gpbft message for each new participant #12577

Merged
merged 1 commit into from
Oct 11, 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 chain/lf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,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 chain/lf3/participation_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ 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 {
return &leaser{
leases: make(map[uint64]api.F3ParticipationLease),
issuer: nodeId,
status: status,
notifyParticipation: make(chan struct{}, 1),
maxLeasableInstances: maxLeasedInstances,
}
}
Expand Down Expand Up @@ -102,6 +105,10 @@ func (l *leaser) participate(ticket api.F3ParticipationTicket) (api.F3Participat
log.Infof("started participating in F3 for miner %d", newLease.MinerID)
}
l.leases[newLease.MinerID] = newLease
select {
case l.notifyParticipation <- struct{}{}:
default:
}
return newLease, nil
}

Expand Down
Loading