Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 672bea9

Browse files
authored
Merge pull request #891 from iotaledger/fix/slow-witnesses
Fix witness and ratifier reading
2 parents 2d7ab67 + 3ece0d1 commit 672bea9

File tree

7 files changed

+25
-30
lines changed

7 files changed

+25
-30
lines changed

components/debugapi/debug_models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func BlockMetadataResponseFromBlock(block *blocks.Block) *BlockMetadataResponse
8181
Accepted: block.IsAccepted(),
8282
PreConfirmed: block.IsPreConfirmed(),
8383
Confirmed: block.IsConfirmed(),
84-
Witnesses: lo.Map(block.Witnesses(), func(seatIndex account.SeatIndex) string { return fmt.Sprintf("%d", seatIndex) }),
84+
Witnesses: lo.Map(block.Witnesses().ToSlice(), func(seatIndex account.SeatIndex) string { return fmt.Sprintf("%d", seatIndex) }),
8585
SpenderIDs: block.SpenderIDs().ToSlice(),
8686
PayloadSpenderIDs: block.PayloadSpenderIDs().ToSlice(),
8787
String: block.String(),

pkg/protocol/engine/blocks/block.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ func (b *Block) WitnessCount() int {
367367
return b.witnesses.Size()
368368
}
369369

370-
func (b *Block) Witnesses() []account.SeatIndex {
370+
func (b *Block) Witnesses() ds.ReadableSet[account.SeatIndex] {
371371
b.mutex.RLock()
372372
defer b.mutex.RUnlock()
373373

374-
return b.witnesses.ToSlice()
374+
return b.witnesses
375375
}
376376

377377
func (b *Block) SpenderIDs() ds.Set[iotago.TransactionID] {
@@ -424,11 +424,11 @@ func (b *Block) AddAcceptanceRatifier(seat account.SeatIndex) (added bool) {
424424
return b.acceptanceRatifiers.Add(seat)
425425
}
426426

427-
func (b *Block) AcceptanceRatifiers() []account.SeatIndex {
427+
func (b *Block) AcceptanceRatifiers() ds.ReadableSet[account.SeatIndex] {
428428
b.mutex.RLock()
429429
defer b.mutex.RUnlock()
430430

431-
return b.acceptanceRatifiers.ToSlice()
431+
return b.acceptanceRatifiers
432432
}
433433

434434
// Accepted returns a reactive variable that is true if the Block was accepted.
@@ -536,11 +536,11 @@ func (b *Block) AddConfirmationRatifier(seat account.SeatIndex) (added bool) {
536536
return b.confirmationRatifiers.Add(seat)
537537
}
538538

539-
func (b *Block) ConfirmationRatifiers() []account.SeatIndex {
539+
func (b *Block) ConfirmationRatifiers() ds.ReadableSet[account.SeatIndex] {
540540
b.mutex.RLock()
541541
defer b.mutex.RUnlock()
542542

543-
return b.confirmationRatifiers.ToSlice()
543+
return b.confirmationRatifiers
544544
}
545545

546546
func (b *Block) IsConfirmed() bool {

pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/acceptance_ratification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (g *Gadget) trackAcceptanceRatifierWeight(votingBlock *blocks.Block) {
5353
}
5454

5555
func (g *Gadget) shouldAccept(block *blocks.Block) bool {
56-
blockSeats := len(block.AcceptanceRatifiers())
56+
blockSeats := block.AcceptanceRatifiers().Size()
5757
onlineCommitteeTotalSeats := g.seatManager.OnlineCommittee().Size()
5858

5959
return votes.IsThresholdReached(blockSeats, onlineCommitteeTotalSeats, g.optsAcceptanceThreshold)

pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/confirmation_ratification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (g *Gadget) trackConfirmationRatifierWeight(votingBlock *blocks.Block) {
5959
}
6060

6161
func (g *Gadget) shouldConfirm(block *blocks.Block) bool {
62-
blockSeats := len(block.ConfirmationRatifiers())
62+
blockSeats := block.ConfirmationRatifiers().Size()
6363
totalCommitteeSeats := g.seatManager.SeatCountInSlot(block.ID().Slot())
6464

6565
return votes.IsThresholdReached(blockSeats, totalCommitteeSeats, g.optsConfirmationThreshold)

pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/gadget.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package thresholdblockgadget
22

33
import (
4-
"fmt"
5-
64
"github.com/iotaledger/hive.go/ds"
75
"github.com/iotaledger/hive.go/ds/walker"
86
"github.com/iotaledger/hive.go/ierrors"
@@ -82,10 +80,6 @@ func (g *Gadget) propagate(initialBlockIDs iotago.BlockIDs, evaluateFunc func(bl
8280
continue
8381
}
8482

85-
if !block.IsBooked() {
86-
panic(fmt.Sprintf("block %s is not booked", blockID))
87-
}
88-
8983
if !evaluateFunc(block) {
9084
continue
9185
}

pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/witness_weight.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ func (g *Gadget) TrackWitnessWeight(votingBlock *blocks.Block) {
9696

9797
func (g *Gadget) shouldPreAcceptAndPreConfirm(block *blocks.Block) (preAccept bool, preConfirm bool) {
9898
committeeTotalSeats := g.seatManager.SeatCountInSlot(block.ID().Slot())
99-
blockSeats := len(block.Witnesses())
99+
blockSeats := block.Witnesses().Size()
100100

101101
onlineCommitteeTotalSeats := g.seatManager.OnlineCommittee().Size()
102-
blockSeatsOnline := len(block.Witnesses())
103102

104103
if votes.IsThresholdReached(blockSeats, committeeTotalSeats, g.optsConfirmationThreshold) {
105104
return true, true
106-
} else if votes.IsThresholdReached(blockSeatsOnline, onlineCommitteeTotalSeats, g.optsAcceptanceThreshold) {
105+
} else if votes.IsThresholdReached(blockSeats, onlineCommitteeTotalSeats, g.optsAcceptanceThreshold) {
107106
return true, false
108107
}
109108

pkg/testsuite/testsuite_issue_blocks.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,23 @@ func (t *TestSuite) IssueBlocksAtSlots(prefix string, slots []iotago.SlotIndex,
221221
lastBlockRowIssued = lastRowInSlot
222222

223223
if waitForSlotsCommitted {
224-
if slot > t.API.ProtocolParameters().MinCommittableAge() {
225-
if useCommitmentAtMinCommittableAge {
226-
// Make sure that all nodes create blocks throughout the slot that commit to the same commitment at slot-minCommittableAge-1.
227-
commitmentSlot := slot - t.API.ProtocolParameters().MinCommittableAge()
228-
t.AssertCommitmentSlotIndexExists(commitmentSlot, t.ClientsForNodes(nodes...)...)
229-
for _, node := range nodes {
230-
commitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitmentSlot)
231-
require.NoError(t.Testing, err)
232-
233-
issuingOptions[node.Name] = []options.Option[mock.BlockHeaderParams]{
234-
mock.WithSlotCommitment(commitment.Commitment()),
235-
}
224+
if useCommitmentAtMinCommittableAge && slot > t.API.ProtocolParameters().MinCommittableAge() {
225+
// Make sure that all nodes create blocks throughout the slot that commit to the same commitment at slot-minCommittableAge-1.
226+
commitmentSlot := slot - t.API.ProtocolParameters().MinCommittableAge()
227+
t.AssertCommitmentSlotIndexExists(commitmentSlot, t.ClientsForNodes(nodes...)...)
228+
for _, node := range nodes {
229+
commitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitmentSlot)
230+
require.NoError(t.Testing, err)
231+
232+
issuingOptions[node.Name] = []options.Option[mock.BlockHeaderParams]{
233+
mock.WithSlotCommitment(commitment.Commitment()),
236234
}
237235
}
236+
} else if slot > t.API.ProtocolParameters().MaxCommittableAge()+1 {
237+
commitmentSlot := slot - t.API.ProtocolParameters().MaxCommittableAge() + 1
238+
t.AssertCommitmentSlotIndexExists(commitmentSlot, t.ClientsForNodes(nodes...)...)
238239
}
240+
239241
t.AssertBlocksExist(blocksInSlot, true, t.ClientsForNodes(nodes...)...)
240242
}
241243
}

0 commit comments

Comments
 (0)