Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Bhat committed Sep 22, 2023
1 parent 1c8a685 commit 61b9e29
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
10 changes: 0 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ type P2PConfig struct { //nolint: maligned

// List of node IDs, to which a connection will be (re)established ignoring any existing limits
UnconditionalPeerIDs string `mapstructure:"unconditional-peer-ids"`

}

// DefaultP2PConfig returns a default configuration for the peer-to-peer layer
Expand Down Expand Up @@ -913,10 +912,6 @@ type StateSyncConfig struct {

// Timeout before considering light block verification failed
VerifyLightBlockTimeout time.Duration `mapstructure:"verify-light-block-timeout"`

// Minimum time bad witnesses must spend in blacklist before potentially being
// added back as a provider again.
BlackListTTL time.Duration `mapstructure:"black-list-ttl"`
}

func (cfg *StateSyncConfig) TrustHashBytes() []byte {
Expand All @@ -938,7 +933,6 @@ func DefaultStateSyncConfig() *StateSyncConfig {
BackfillBlocks: 0,
BackfillDuration: 0 * time.Second,
VerifyLightBlockTimeout: 60 * time.Second,
BlackListTTL: 30000 * time.Millisecond,
}
}

Expand Down Expand Up @@ -1004,10 +998,6 @@ func (cfg *StateSyncConfig) ValidateBasic() error {
return errors.New("fetchers is required")
}

if cfg.BlackListTTL < 0 {
return errors.New("black-list-ttl must not be negative")
}

return nil
}

Expand Down
5 changes: 1 addition & 4 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ recv-rate = {{ .P2P.RecvRate }}
# List of node IDs, to which a connection will be (re)established ignoring any existing limits
unconditional-peer-ids = "{{ .P2P.UnconditionalPeerIDs }}"
#######################################################
### Mempool Configuration Option ###
#######################################################
Expand Down Expand Up @@ -459,10 +460,6 @@ fetchers = "{{ .StateSync.Fetchers }}"
verify-light-block-timeout = "{{ .StateSync.VerifyLightBlockTimeout }}"
# Minimum time bad witnesses must spend in blacklist before potentially being
# added back as a provider again.
black-list-ttl = "{{ .P2P.BlackListTTL }}"
#######################################################
### Consensus Configuration Options ###
#######################################################
Expand Down
26 changes: 13 additions & 13 deletions light/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestClient(t *testing.T) {
l3 = &types.LightBlock{SignedHeader: h3, ValidatorSet: vals}
id1 = "id1"
id2 = "id2"
id3 = "id3"
)
t.Run("ValidateTrustOptions", func(t *testing.T) {
testCases := []struct {
Expand Down Expand Up @@ -697,19 +698,22 @@ func TestClient(t *testing.T) {

mockFullNode := &provider_mocks.Provider{}
mockFullNode.On("LightBlock", mock.Anything, mock.Anything).Return(l1, nil)
mockFullNode.On("ID", mock.Anything, mock.Anything).Return(id1, nil)

mockFullNode1 := &provider_mocks.Provider{}
mockFullNode1.On("LightBlock", mock.Anything, mock.Anything).Return(l1, nil)
mockFullNode1.On("ID", mock.Anything, mock.Anything).Return(id2, nil)

mockDeadNode := &provider_mocks.Provider{}
mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrNoResponse)
mockFullNode.On("ID", mock.Anything, mock.Anything).Return(id2, nil)
mockDeadNode.On("ID", mock.Anything, mock.Anything).Return(id3, nil)

logger := log.NewNopLogger()

c, err := light.NewClient(
ctx,
chainID,
trustOptions,
mockDeadNode,
[]provider.Provider{mockDeadNode, mockFullNode},
[]provider.Provider{mockDeadNode, mockFullNode, mockFullNode1},
dbs.New(dbm.NewMemDB()),
light.Logger(logger),
)
Expand All @@ -721,10 +725,9 @@ func TestClient(t *testing.T) {
// the primary should no longer be the deadNode
assert.NotEqual(t, c.Primary(), mockDeadNode)

// we should still have the dead node as a witness because it
// hasn't repeatedly been unresponsive yet
assert.Equal(t, 2, len(c.Witnesses()))
assert.Equal(t, 1, len(c.Witnesses()))
mockDeadNode.AssertExpectations(t)
mockFullNode1.AssertExpectations(t)
mockFullNode.AssertExpectations(t)
})
t.Run("ReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock", func(t *testing.T) {
Expand Down Expand Up @@ -753,9 +756,7 @@ func TestClient(t *testing.T) {
_, err = c.Update(ctx, bTime.Add(2*time.Hour))
require.NoError(t, err)

// we should still have the dead node as a witness because it
// hasn't repeatedly been unresponsive yet
assert.Equal(t, 2, len(c.Witnesses()))
assert.Equal(t, 1, len(c.Witnesses()))
mockFullNode.AssertExpectations(t)
})
t.Run("BackwardsVerification", func(t *testing.T) {
Expand Down Expand Up @@ -902,9 +903,9 @@ func TestClient(t *testing.T) {
}
mockBadNode2 := mockNodeFromHeadersAndVals(headers2, vals2)
mockBadNode2.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound)
mockBadNode2.On("ID", mock.Anything, mock.Anything).Return(id2, nil)

mockFullNode := mockNodeFromHeadersAndVals(headerSet, valSet)
mockFullNode.On("ID", mock.Anything, mock.Anything).Return(id3, nil)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -935,7 +936,7 @@ func TestClient(t *testing.T) {
// remaining witnesses don't have light block -> error
_, err = c.VerifyLightBlockAtHeight(ctx, 3, bTime.Add(2*time.Hour))
if assert.Error(t, err) {
assert.Equal(t, light.ErrFailedHeaderCrossReferencing, err)
assert.Equal(t, light.ErrNoWitnesses, err)
}
// witness does not have a light block -> left in the list
assert.EqualValues(t, 1, len(c.Witnesses()))
Expand Down Expand Up @@ -973,7 +974,6 @@ func TestClient(t *testing.T) {
1: vals,
2: vals,
})
mockFullNode.On("ID", mock.Anything, mock.Anything).Return(id1, nil)

c, err := light.NewClient(
ctx,
Expand Down
4 changes: 3 additions & 1 deletion light/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
lastBlock, _ = mockWitness.LightBlock(ctx, latestHeight)
mockWitness.On("LightBlock", mock.Anything, int64(0)).Return(lastBlock, nil).Once()
mockWitness.On("LightBlock", mock.Anything, int64(12)).Return(nil, provider.ErrHeightTooHigh)
mockWitness.On("ID", mock.Anything, mock.Anything).Return("mockWitness", nil)

mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(evidence types.Evidence) bool {
// Check evidence was sent to the witness against the full node
Expand Down Expand Up @@ -358,6 +359,7 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
// in enough time
mockLaggingWitness := mockNodeFromHeadersAndVals(witnessHeaders, witnessValidators)
mockLaggingWitness.On("LightBlock", mock.Anything, int64(12)).Return(nil, provider.ErrHeightTooHigh)
mockLaggingWitness.On("ID", mock.Anything, mock.Anything).Return("mockLaggingWitness", nil)
lastBlock, _ = mockLaggingWitness.LightBlock(ctx, latestHeight)
mockLaggingWitness.On("LightBlock", mock.Anything, int64(0)).Return(lastBlock, nil)
c, err = light.NewClient(
Expand Down Expand Up @@ -449,7 +451,7 @@ func TestClientDivergentTraces2(t *testing.T) {

_, err = c.VerifyLightBlockAtHeight(ctx, 2, bTime.Add(1*time.Hour))
assert.NoError(t, err)
assert.Equal(t, 3, len(c.Witnesses()))
assert.Equal(t, 1, len(c.Witnesses()))
mockDeadNode.AssertExpectations(t)
mockPrimaryNode.AssertExpectations(t)
}
Expand Down

0 comments on commit 61b9e29

Please sign in to comment.