Skip to content

Commit

Permalink
expose BlockCensorshipTimeout in config
Browse files Browse the repository at this point in the history
Signed-off-by: May Rosenbaum <[email protected]>
  • Loading branch information
MayRosenbaum committed Oct 16, 2023
1 parent d24cf58 commit 812c64d
Show file tree
Hide file tree
Showing 5 changed files with 871 additions and 4 deletions.
26 changes: 25 additions & 1 deletion core/deliverservice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
DefaultReConnectBackoffThreshold = time.Hour * 1
DefaultReConnectTotalTimeThreshold = time.Second * 60 * 60
DefaultConnectionTimeout = time.Second * 3
DefaultBlockCensorshipTimeoutKey = time.Second * 30
DefaultMinimalReconnectInterval = time.Millisecond * 100
)

// DeliverServiceConfig is the struct that defines the deliverservice configuration.
Expand All @@ -42,7 +44,11 @@ type DeliverServiceConfig struct {
KeepaliveOptions comm.KeepaliveOptions
// SecOpts provides the TLS info for connections
SecOpts comm.SecureOptions

// If a certain header from a header receiver is in front of the block receiver for more that this time, a
// censorship event is declared and the block source is changed.
BlockCensorshipTimeoutKey time.Duration
// The initial value of the actual retry interval, which is increased on every failed retry
MinimalReconnectInterval time.Duration
// OrdererEndpointOverrides is a map of orderer addresses which should be
// re-mapped to a different orderer endpoint.
OrdererEndpointOverrides map[string]*orderers.Endpoint
Expand Down Expand Up @@ -124,6 +130,24 @@ func (c *DeliverServiceConfig) loadDeliverServiceConfig() {
}
c.BlockGossipEnabled = enabledConfigOptionMissing || viper.GetBool(enabledKey)

blockCensorshipTimeoutKey := "peer.deliveryclient.blockCensorshipTimeoutKey"
blockCensorshipTimeoutOptionMissing := !viper.IsSet(blockCensorshipTimeoutKey)
if blockCensorshipTimeoutOptionMissing {
c.BlockCensorshipTimeoutKey = DefaultBlockCensorshipTimeoutKey
logger.Infof("peer.deliveryclient.blockCensorshipTimeoutKey is not set, defaulting to %d s.", DefaultBlockCensorshipTimeoutKey)
} else {
c.BlockCensorshipTimeoutKey = viper.GetDuration(blockCensorshipTimeoutKey)
}

minimalReconnectInterval := "peer.deliveryclient.minimalReconnectInterval"
MinimalReconnectIntervalOptionMissing := !viper.IsSet(minimalReconnectInterval)
if MinimalReconnectIntervalOptionMissing {
c.MinimalReconnectInterval = DefaultMinimalReconnectInterval
logger.Infof("peer.deliveryclient.minimalReconnectInterval is not set, defaulting to %d ms.", DefaultMinimalReconnectInterval)
} else {
c.MinimalReconnectInterval = viper.GetDuration(minimalReconnectInterval)
}

c.PeerTLSEnabled = viper.GetBool("peer.tls.enabled")

c.ReConnectBackoffThreshold = viper.GetDuration("peer.deliveryclient.reConnectBackoffThreshold")
Expand Down
36 changes: 36 additions & 0 deletions core/deliverservice/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ func TestGlobalConfig(t *testing.T) {
viper.Set("peer.deliveryclient.connTimeout", "10s")
viper.Set("peer.keepalive.deliveryClient.interval", "5s")
viper.Set("peer.keepalive.deliveryClient.timeout", "2s")
viper.Set("peer.deliveryclient.blockCensorshipTimeoutKey", "40s")
viper.Set("peer.deliveryclient.minimalReconnectInterval", "110ms")

coreConfig := deliverservice.GlobalConfig()

expectedConfig := &deliverservice.DeliverServiceConfig{
BlockGossipEnabled: true,
PeerTLSEnabled: true,
ReConnectBackoffThreshold: 25 * time.Second,
BlockCensorshipTimeoutKey: 40 * time.Second,
MinimalReconnectInterval: 110 * time.Millisecond,
ReconnectTotalTimeThreshold: 20 * time.Second,
ConnectionTimeout: 10 * time.Second,
KeepaliveOptions: comm.KeepaliveOptions{
Expand Down Expand Up @@ -124,6 +128,8 @@ func TestGlobalConfigDefault(t *testing.T) {
ReconnectTotalTimeThreshold: deliverservice.DefaultReConnectTotalTimeThreshold,
ConnectionTimeout: deliverservice.DefaultConnectionTimeout,
KeepaliveOptions: comm.DefaultKeepaliveOptions,
BlockCensorshipTimeoutKey: deliverservice.DefaultBlockCensorshipTimeoutKey,
MinimalReconnectInterval: deliverservice.DefaultMinimalReconnectInterval,
}

require.Equal(t, expectedConfig, coreConfig)
Expand Down Expand Up @@ -233,3 +239,33 @@ func TestLoadOverridesMap(t *testing.T) {
require.Nil(t, res)
})
}

func TestGlobalConfigCheckDefaultIsSet(t *testing.T) {
defer viper.Reset()
cwd, err := os.Getwd()
require.NoError(t, err, "failed to get current working directory")
viper.SetConfigFile(filepath.Join(cwd, "testdata", "core.yaml"))

err = viper.ReadInConfig()
require.NoError(t, err)

require.Equal(t, false, viper.IsSet("peer.deliveryclient.blockCensorshipTimeoutKey"))
require.Equal(t, false, viper.IsSet("peer.deliveryclient.minimalReconnectInterval"))
require.Equal(t, true, viper.IsSet("peer.deliveryclient.blockGossipEnabled"))

coreConfig := deliverservice.GlobalConfig()
require.NoError(t, err)

expectedConfig := &deliverservice.DeliverServiceConfig{
BlockGossipEnabled: true,
PeerTLSEnabled: false,
ReConnectBackoffThreshold: deliverservice.DefaultReConnectBackoffThreshold,
ReconnectTotalTimeThreshold: deliverservice.DefaultReConnectTotalTimeThreshold,
ConnectionTimeout: deliverservice.DefaultConnectionTimeout,
KeepaliveOptions: comm.DefaultKeepaliveOptions,
BlockCensorshipTimeoutKey: deliverservice.DefaultBlockCensorshipTimeoutKey,
MinimalReconnectInterval: deliverservice.DefaultMinimalReconnectInterval,
}

require.Equal(t, coreConfig, expectedConfig)
}
6 changes: 3 additions & 3 deletions core/deliverservice/deliveryclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ func (d *deliverServiceImpl) createBlockDelivererBFT(chainID string, ledgerInfo
DeliverStreamer: blocksprovider.DeliverAdapter{},
CensorshipDetectorFactory: &blocksprovider.BFTCensorshipMonitorFactory{},
Logger: flogging.MustGetLogger("peer.blocksprovider").With("channel", chainID),
InitialRetryInterval: 100 * time.Millisecond, // TODO expose in config
InitialRetryInterval: d.conf.DeliverServiceConfig.MinimalReconnectInterval,
MaxRetryInterval: d.conf.DeliverServiceConfig.ReConnectBackoffThreshold,
BlockCensorshipTimeout: 30 * time.Second, // TODO expose in config
MaxRetryDuration: 12 * time.Hour, // In v3 block gossip is no longer supported. We set it long to avoid needlessly calling the handler.
BlockCensorshipTimeout: d.conf.DeliverServiceConfig.BlockCensorshipTimeoutKey,
MaxRetryDuration: 12 * time.Hour, // In v3 block gossip is no longer supported. We set it long to avoid needlessly calling the handler.
MaxRetryDurationExceededHandler: func() (stopRetries bool) {
return false // In v3 block gossip is no longer supported, the peer never stops retrying.
},
Expand Down
Loading

0 comments on commit 812c64d

Please sign in to comment.