From e00b454e1a31904c39735ef645e03948926e0295 Mon Sep 17 00:00:00 2001 From: May Rosenbaum Date: Wed, 30 Aug 2023 01:00:53 +0300 Subject: [PATCH] expose BlockCensorshipTimeout in config Signed-off-by: May Rosenbaum --- core/deliverservice/config.go | 26 +++++++++++++++++++++++++- core/deliverservice/config_test.go | 6 ++++++ core/deliverservice/deliveryclient.go | 6 +++--- sampleconfig/core.yaml | 7 +++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/core/deliverservice/config.go b/core/deliverservice/config.go index ea908f521f9..2f58c6d9f11 100644 --- a/core/deliverservice/config.go +++ b/core/deliverservice/config.go @@ -23,6 +23,8 @@ const ( DefaultReConnectBackoffThreshold = time.Hour * 1 DefaultReConnectTotalTimeThreshold = time.Second * 60 * 60 DefaultConnectionTimeout = time.Second * 3 + DefaultBlockCensorshipTimeout = time.Second * 30 + DefaultMinimalReconnectInterval = time.Millisecond * 100 ) // DeliverServiceConfig is the struct that defines the deliverservice configuration. @@ -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. + BlockCensorshipTimeout 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 @@ -124,6 +130,24 @@ func (c *DeliverServiceConfig) loadDeliverServiceConfig() { } c.BlockGossipEnabled = enabledConfigOptionMissing || viper.GetBool(enabledKey) + blockCensorshipTimeout := "peer.deliveryclient.blockCensorshipTimeout" + blockCensorshipTimeoutOptionMissing := !viper.IsSet(blockCensorshipTimeout) + if blockCensorshipTimeoutOptionMissing { + c.BlockCensorshipTimeout = DefaultBlockCensorshipTimeout + logger.Infof("peer.deliveryclient.blockCensorshipTimeout is not set, defaulting to 30s.") + } else { + c.BlockCensorshipTimeout = viper.GetDuration(blockCensorshipTimeout) + } + + minimalReconnectInterval := "peer.deliveryclient.minimalReconnectInterval" + MinimalReconnectIntervalOptionMissing := !viper.IsSet(minimalReconnectInterval) + if MinimalReconnectIntervalOptionMissing { + c.MinimalReconnectInterval = DefaultMinimalReconnectInterval + logger.Infof("peer.deliveryclient.minimalReconnectInterval is not set, defaulting to 100ms.") + } else { + c.MinimalReconnectInterval = viper.GetDuration(minimalReconnectInterval) + } + c.PeerTLSEnabled = viper.GetBool("peer.tls.enabled") c.ReConnectBackoffThreshold = viper.GetDuration("peer.deliveryclient.reConnectBackoffThreshold") diff --git a/core/deliverservice/config_test.go b/core/deliverservice/config_test.go index ddaa069e035..e01ddaee663 100644 --- a/core/deliverservice/config_test.go +++ b/core/deliverservice/config_test.go @@ -87,6 +87,8 @@ 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.blockCensorshipTimeout", "40s") + viper.Set("peer.deliveryclient.minimalReconnectInterval", "110ms") coreConfig := deliverservice.GlobalConfig() @@ -94,6 +96,8 @@ func TestGlobalConfig(t *testing.T) { BlockGossipEnabled: true, PeerTLSEnabled: true, ReConnectBackoffThreshold: 25 * time.Second, + BlockCensorshipTimeout: 40 * time.Second, + MinimalReconnectInterval: 110 * time.Millisecond, ReconnectTotalTimeThreshold: 20 * time.Second, ConnectionTimeout: 10 * time.Second, KeepaliveOptions: comm.KeepaliveOptions{ @@ -124,6 +128,8 @@ func TestGlobalConfigDefault(t *testing.T) { ReconnectTotalTimeThreshold: deliverservice.DefaultReConnectTotalTimeThreshold, ConnectionTimeout: deliverservice.DefaultConnectionTimeout, KeepaliveOptions: comm.DefaultKeepaliveOptions, + BlockCensorshipTimeout: deliverservice.DefaultBlockCensorshipTimeout, + MinimalReconnectInterval: deliverservice.DefaultMinimalReconnectInterval, } require.Equal(t, expectedConfig, coreConfig) diff --git a/core/deliverservice/deliveryclient.go b/core/deliverservice/deliveryclient.go index 9dabaa3f900..0de1ccf15fd 100644 --- a/core/deliverservice/deliveryclient.go +++ b/core/deliverservice/deliveryclient.go @@ -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.BlockCensorshipTimeout, + 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. }, diff --git a/sampleconfig/core.yaml b/sampleconfig/core.yaml index 7809b001daa..8f8ac78c15e 100644 --- a/sampleconfig/core.yaml +++ b/sampleconfig/core.yaml @@ -386,6 +386,13 @@ peer: # Time between retries will have exponential backoff until hitting this threshold. reConnectBackoffThreshold: 3600s + # 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. + blockCensorshipTimeout: 30s + + # The initial value of the actual retry interval, which is increased on every failed retry + minimalReconnectInterval: 100ms + # A list of orderer endpoint addresses which should be overridden # when found in channel configurations. addressOverrides: