Skip to content

Commit

Permalink
Switch by replication policy
Browse files Browse the repository at this point in the history
Signed-off-by: Yoav Tock <tock@il.ibm.com>
Change-Id: Iaecd27c0295748f94947f5af94a7385ca455f245
  • Loading branch information
tock-ibm committed Feb 21, 2024
1 parent 41ed9b6 commit 8d9d0c5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
4 changes: 4 additions & 0 deletions orderer/common/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Cluster struct {
ReplicationPullTimeout time.Duration
ReplicationRetryTimeout time.Duration
ReplicationMaxRetries int
ReplicationPolicy string // BFT: "simple" | "consensus" (default); etcdraft: ignored, always "simple"
SendBufferSize int
CertExpirationWarningThreshold time.Duration
TLSHandshakeTimeShift time.Duration
Expand Down Expand Up @@ -188,6 +189,7 @@ var Defaults = TopLevel{
ReplicationRetryTimeout: time.Second * 5,
ReplicationPullTimeout: time.Second * 5,
CertExpirationWarningThreshold: time.Hour * 24 * 7,
ReplicationPolicy: "consensus", // BFT default; on etcdraft it is ignored
},
LocalMSPDir: "msp",
LocalMSPID: "SampleOrg",
Expand Down Expand Up @@ -332,6 +334,8 @@ func (c *TopLevel) completeInitialization(configDir string) {
c.General.Cluster.ReplicationRetryTimeout = Defaults.General.Cluster.ReplicationRetryTimeout
case c.General.Cluster.CertExpirationWarningThreshold == 0:
c.General.Cluster.CertExpirationWarningThreshold = Defaults.General.Cluster.CertExpirationWarningThreshold
case c.General.Cluster.ReplicationPolicy == "":
c.General.Cluster.ReplicationPolicy = Defaults.General.Cluster.ReplicationPolicy

case c.General.Profile.Enabled && c.General.Profile.Address == "":
logger.Infof("Profiling enabled and General.Profile.Address unset, setting to %s", Defaults.General.Profile.Address)
Expand Down
1 change: 1 addition & 0 deletions orderer/common/localconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func TestClusterDefaults(t *testing.T) {
cfg, err := cc.load()
require.NoError(t, err)
require.Equal(t, cfg.General.Cluster.ReplicationMaxRetries, Defaults.General.Cluster.ReplicationMaxRetries)
require.Equal(t, cfg.General.Cluster.ReplicationPolicy, Defaults.General.Cluster.ReplicationPolicy)
}

func TestConsensusConfig(t *testing.T) {
Expand Down
55 changes: 39 additions & 16 deletions orderer/consensus/smartbft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,45 @@ func bftSmartConsensusBuild(
// report cluster size
c.Metrics.ClusterSize.Set(float64(clusterSize))

sync := &Synchronizer{ // TODO make bft-synchro
selfID: rtc.id,
BlockToDecision: c.blockToDecision,
OnCommit: func(block *cb.Block) types.Reconfig {
c.pruneCommittedRequests(block)
return c.updateRuntimeConfig(block)
},
Support: c.support,
BlockPuller: c.BlockPuller,

ClusterSize: clusterSize, // TODO this must be dynamic as the cluster may change in size
Logger: c.Logger,
LatestConfig: func() (types.Configuration, []uint64) {
rtc := c.RuntimeConfig.Load().(RuntimeConfig)
return rtc.BFTConfig, rtc.Nodes
},
var sync api.Synchronizer
switch c.localConfigCluster.ReplicationPolicy {
case "consensus":
sync = &Synchronizer{ // TODO make bft-synchronizer
selfID: rtc.id,
BlockToDecision: c.blockToDecision,
OnCommit: func(block *cb.Block) types.Reconfig {
c.pruneCommittedRequests(block)
return c.updateRuntimeConfig(block)
},
Support: c.support,
BlockPuller: c.BlockPuller,
ClusterSize: clusterSize,
Logger: c.Logger,
LatestConfig: func() (types.Configuration, []uint64) {
rtc := c.RuntimeConfig.Load().(RuntimeConfig)
return rtc.BFTConfig, rtc.Nodes
},
}
case "simple":
sync = &Synchronizer{
selfID: rtc.id,
BlockToDecision: c.blockToDecision,
OnCommit: func(block *cb.Block) types.Reconfig {
c.pruneCommittedRequests(block)
return c.updateRuntimeConfig(block)
},
Support: c.support,
BlockPuller: c.BlockPuller,

ClusterSize: clusterSize, // TODO this must be dynamic as the cluster may change in size
Logger: c.Logger,
LatestConfig: func() (types.Configuration, []uint64) {
rtc := c.RuntimeConfig.Load().(RuntimeConfig)
return rtc.BFTConfig, rtc.Nodes
},
}
default:

}

channelDecorator := zap.String("channel", c.support.ChannelID())
Expand Down
6 changes: 6 additions & 0 deletions sampleconfig/orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ General:
# ServerPrivateKey defines the file location of the private key of the TLS certificate.
ServerPrivateKey:

# ReplicationPolicy defines how blocks are replicated between orderers.
# Permitted values:
# in BFT: "simple" | "consensus" (default);
# in etcdraft: ignored, (always "simple", regardless of value in config).
ReplicationPolicy:

# Bootstrap method: The method by which to obtain the bootstrap block
# system channel is specified. The option can be one of:
# "file" - path to a file containing the genesis block or config block of system channel
Expand Down

0 comments on commit 8d9d0c5

Please sign in to comment.