Skip to content

Clarify decidable interface simple default parameter tests #2094

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

Merged
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
2 changes: 2 additions & 0 deletions snow/choices/decidable.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ type Decidable interface {
// Accept this element.
//
// This element will be accepted by every correct node in the network.
// All subsequent Status calls return Accepted.
Accept(context.Context) error

// Reject this element.
//
// This element will not be accepted by any correct node in the network.
// All subsequent Status calls return Rejected.
Reject(context.Context) error

// Status returns this element's current status.
Expand Down
42 changes: 42 additions & 0 deletions snow/consensus/snowman/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
RandomizedConsistencyTest,
ErrorOnAddDecidedBlockTest,
ErrorOnAddDuplicateBlockIDTest,
RecordPollWithDefaultParameters,
}

errTest = errors.New("non-nil error")
Expand Down Expand Up @@ -1633,3 +1634,44 @@ func gatherCounterGauge(t *testing.T, reg *prometheus.Registry) map[string]float
}
return mss
}

// You can run this test with "go test -v -run TestTopological/RecordPollWithDefaultParameters"
func RecordPollWithDefaultParameters(t *testing.T, factory Factory) {
require := require.New(t)

sm := factory.New()

ctx := snow.DefaultConsensusContextTest()
params := snowball.DefaultParameters
require.NoError(sm.Initialize(ctx, params, GenesisID, GenesisHeight, GenesisTimestamp))

// "blk1" and "blk2" are in conflict
blk1 := &TestBlock{
TestDecidable: choices.TestDecidable{
IDV: ids.ID{1},
StatusV: choices.Processing,
},
ParentV: Genesis.IDV,
HeightV: Genesis.HeightV + 1,
}
blk2 := &TestBlock{
TestDecidable: choices.TestDecidable{
IDV: ids.ID{2},
StatusV: choices.Processing,
},
ParentV: Genesis.IDV,
HeightV: Genesis.HeightV + 1,
}
require.NoError(sm.Add(context.Background(), blk1))
require.NoError(sm.Add(context.Background(), blk2))

votes := bag.Bag[ids.ID]{}
votes.AddCount(blk1.ID(), params.Alpha)
// as "blk1" and "blk2" are in conflict, we need beta rogue rounds to finalize
for i := 0; i < params.BetaRogue; i++ {
// should not finalize with less than beta rogue rounds
require.Equal(2, sm.NumProcessing())
require.NoError(sm.RecordPoll(context.Background(), votes))
}
require.Zero(sm.NumProcessing())
}
13 changes: 13 additions & 0 deletions snow/consensus/snowman/topological.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (ts *Topological) NumProcessing() int {

func (ts *Topological) Add(ctx context.Context, blk Block) error {
blkID := blk.ID()
ts.ctx.Log.Verbo("adding block",
zap.Stringer("blkID", blkID),
)

// Make sure a block is not inserted twice. This enforces the invariant that
// blocks are always added in topological order. Essentially, a block that
Expand All @@ -169,6 +172,11 @@ func (ts *Topological) Add(ctx context.Context, blk Block) error {
parentID := blk.Parent()
parentNode, ok := ts.blocks[parentID]
if !ok {
ts.ctx.Log.Verbo("block ancestor is missing, being rejected",
zap.Stringer("blkID", blkID),
zap.Stringer("parentID", parentID),
)

// If the ancestor is missing, this means the ancestor must have already
// been pruned. Therefore, the dependent should be transitively
// rejected.
Expand All @@ -191,6 +199,11 @@ func (ts *Topological) Add(ctx context.Context, blk Block) error {
ts.tail = blkID
ts.preferredIDs.Add(blkID)
}

ts.ctx.Log.Verbo("added block",
zap.Stringer("blkID", blkID),
zap.Stringer("parentID", parentID),
)
return nil
}

Expand Down