Skip to content

Commit

Permalink
NewSpamDetectionConfig() passes up error instead of throwing error
Browse files Browse the repository at this point in the history
  • Loading branch information
gomisha committed Oct 20, 2023
1 parent a040849 commit 91607b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 3 additions & 6 deletions engine/common/synchronization/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package synchronization

import (
"context"
"fmt"
"time"

"github.com/onflow/flow-go/config"
"github.com/onflow/flow-go/module/irrecoverable"

core "github.com/onflow/flow-go/module/chainsync"
)

Expand Down Expand Up @@ -72,16 +69,16 @@ type SpamDetectionConfig struct {
rangeRequestBaseProb float32
}

func NewSpamDetectionConfig() *SpamDetectionConfig {
func NewSpamDetectionConfig() (*SpamDetectionConfig, error) {
flowConfig, err := config.DefaultConfig()
if err != nil {
irrecoverable.Throw(context.TODO(), fmt.Errorf("failed to read default config: %w", err))
return nil, fmt.Errorf("failed to read default config: %w", err)
}

return &SpamDetectionConfig{
// see config/default-config.yml for more information on the following fields
batchRequestBaseProb: flowConfig.NetworkConfig.SyncEngineBatchRequestBaseProb,
syncRequestProb: flowConfig.NetworkConfig.SyncEngineSyncRequestProb,
rangeRequestBaseProb: flowConfig.NetworkConfig.SyncEngineRangeRequestBaseProb,
}
}, nil
}
5 changes: 3 additions & 2 deletions engine/common/synchronization/engine_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func (ss *SyncSuite) SetupTest() {

idCache, err := cache.NewProtocolStateIDCache(log, ss.state, protocolEvents.NewDistributor())
require.NoError(ss.T(), err, "could not create protocol state identity cache")
spamConfig, err := NewSpamDetectionConfig()
require.NoError(ss.T(), err, "could not create spam detection config")
e, err := New(log, metrics, ss.net, ss.me, ss.state, ss.blocks, ss.comp, ss.core,
id.NewIdentityFilterIdentifierProvider(
filter.And(
Expand All @@ -167,8 +169,7 @@ func (ss *SyncSuite) SetupTest() {
),
idCache,
),
NewSpamDetectionConfig())
spamConfig)
require.NoError(ss.T(), err, "should pass engine initialization")

ss.e = e
}

0 comments on commit 91607b8

Please sign in to comment.