Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (t *Transitive) Gossip(ctx context.Context) error {
// nodes with a large amount of stake weight.
vdrID, ok := t.ConnectedValidators.SampleValidator()
if !ok {
t.Ctx.Log.Error("skipping block gossip",
t.Ctx.Log.Warn("skipping block gossip",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are no longer Errors as the node can recover.

zap.String("reason", "no connected validators"),
)
return nil
Expand Down Expand Up @@ -201,6 +201,11 @@ func (t *Transitive) Gossip(ctx context.Context) error {
zap.String("reason", "blocks currently processing"),
zap.Int("numProcessing", numProcessing),
)

// repoll is called here to unblock the engine if it previously errored
// when attempting to issue a query. This can happen if a subnet was
// temporarily misconfigured and there were no validators.
t.repoll(ctx)
}

// TODO: Remove periodic push gossip after v1.11.x is activated
Expand Down Expand Up @@ -932,7 +937,7 @@ func (t *Transitive) sendQuery(

vdrIDs, err := t.Validators.Sample(t.Ctx.SubnetID, t.Params.K)
if err != nil {
t.Ctx.Log.Error("dropped query for block",
t.Ctx.Log.Warn("dropped query for block",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are no longer Errors as the node can recover.

zap.String("reason", "insufficient number of validators"),
zap.Stringer("blkID", blkID),
zap.Int("size", t.Params.K),
Expand Down
105 changes: 105 additions & 0 deletions snow/engine/snowman/transitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2921,3 +2921,108 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) {

require.Equal(choices.Accepted, blk.Status())
}

func TestEngineRepollsMisconfiguredSubnet(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) I was able to grok this test, but have some suggestions for increasing maintainability:

  • separate out setup (either to helper function(s) or delineated with e.g. comments) from test
  • use comments to highlight important parts of the test that might not be immediately obvious to the uninitiated e.g.
    • create subnet that is misconfigured (missing validator?)
    • check that a tx won't be committed
    • fix misconfiguration
    • check that new tx can be commited (what about previous tx?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added comments. I'm hoping to do a large refactor of both this code and the tests... When we do that hopefully all of this will be able to be cleaned up.

require := require.New(t)

engCfg := DefaultConfig(t)
engCfg.Params = snowball.Parameters{
K: 1,
AlphaPreference: 1,
AlphaConfidence: 1,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 1,
OptimalProcessing: 1,
MaxOutstandingItems: 1,
MaxItemProcessingTime: 1,
}

vals := validators.NewManager()
engCfg.Validators = vals

sender := &common.SenderTest{T: t}
engCfg.Sender = sender

sender.Default(true)

vm := &block.TestVM{}
vm.T = t
engCfg.VM = vm

vm.Default(true)
vm.CantSetState = false
vm.CantSetPreference = false

gBlk := &snowman.TestBlock{TestDecidable: choices.TestDecidable{
IDV: ids.GenerateTestID(),
StatusV: choices.Accepted,
}}

vm.LastAcceptedF = func(context.Context) (ids.ID, error) {
return gBlk.ID(), nil
}
vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) {
require.Equal(gBlk.ID(), id)
return gBlk, nil
}

te, err := newTransitive(engCfg)
require.NoError(err)
require.NoError(te.Start(context.Background(), 0))

vm.LastAcceptedF = nil

blk := &snowman.TestBlock{
TestDecidable: choices.TestDecidable{
IDV: ids.GenerateTestID(),
StatusV: choices.Processing,
},
ParentV: gBlk.IDV,
HeightV: 1,
BytesV: []byte{1},
}

require.NoError(te.issue(
context.Background(),
te.Ctx.NodeID,
blk,
true,
te.metrics.issued.WithLabelValues(unknownSource),
))

require.Equal(choices.Processing, blk.Status())

vdr := ids.GenerateTestNodeID()
require.NoError(vals.AddStaker(engCfg.Ctx.SubnetID, vdr, nil, ids.Empty, 1))

var (
queryRequestID uint32
queried bool
)
sender.SendPullQueryF = func(_ context.Context, inVdrs set.Set[ids.NodeID], requestID uint32, blkID ids.ID, requestedHeight uint64) {
queryRequestID = requestID
require.Contains(inVdrs, vdr)
require.Equal(blk.ID(), blkID)
require.Equal(uint64(1), requestedHeight)
queried = true
}

require.NoError(te.Gossip(context.Background()))
require.True(queried)

vm.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) {
switch id {
case gBlk.ID():
return gBlk, nil
case blk.ID():
return blk, nil
}
require.FailNow(errUnknownBlock.Error())
return nil, errUnknownBlock
}

require.NoError(te.Chits(context.Background(), vdr, queryRequestID, blk.ID(), blk.ID(), blk.ID()))

require.Equal(choices.Accepted, blk.Status())
}