-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break import cycle to prevent code duplication
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
- Loading branch information
1 parent
7f404af
commit 8c9a62f
Showing
4 changed files
with
76 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"github.com/SmartBFT-Go/consensus/pkg/types" | ||
"github.com/hyperledger/fabric-protos-go/orderer/smartbft" | ||
"github.com/pkg/errors" | ||
"time" | ||
) | ||
|
||
func ConfigFromMetadataOptions(selfID uint64, options *smartbft.Options) (types.Configuration, error) { | ||
var err error | ||
|
||
config := types.DefaultConfig | ||
config.SelfID = selfID | ||
|
||
if options == nil { | ||
return config, errors.New("config metadata options field is nil") | ||
} | ||
|
||
config.RequestBatchMaxCount = options.RequestBatchMaxCount | ||
config.RequestBatchMaxBytes = options.RequestBatchMaxBytes | ||
if config.RequestBatchMaxInterval, err = time.ParseDuration(options.RequestBatchMaxInterval); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option RequestBatchMaxInterval") | ||
} | ||
config.IncomingMessageBufferSize = options.IncomingMessageBufferSize | ||
config.RequestPoolSize = options.RequestPoolSize | ||
if config.RequestForwardTimeout, err = time.ParseDuration(options.RequestForwardTimeout); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option RequestForwardTimeout") | ||
} | ||
if config.RequestComplainTimeout, err = time.ParseDuration(options.RequestComplainTimeout); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option RequestComplainTimeout") | ||
} | ||
if config.RequestAutoRemoveTimeout, err = time.ParseDuration(options.RequestAutoRemoveTimeout); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option RequestAutoRemoveTimeout") | ||
} | ||
if config.ViewChangeResendInterval, err = time.ParseDuration(options.ViewChangeResendInterval); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option ViewChangeResendInterval") | ||
} | ||
if config.ViewChangeTimeout, err = time.ParseDuration(options.ViewChangeTimeout); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option ViewChangeTimeout") | ||
} | ||
if config.LeaderHeartbeatTimeout, err = time.ParseDuration(options.LeaderHeartbeatTimeout); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option LeaderHeartbeatTimeout") | ||
} | ||
config.LeaderHeartbeatCount = options.LeaderHeartbeatCount | ||
if config.CollectTimeout, err = time.ParseDuration(options.CollectTimeout); err != nil { | ||
return config, errors.Wrap(err, "bad config metadata option CollectTimeout") | ||
} | ||
config.SyncOnStart = options.SyncOnStart | ||
config.SpeedUpViewChange = options.SpeedUpViewChange | ||
|
||
config.LeaderRotation = false | ||
config.DecisionsPerLeader = 0 | ||
|
||
if err = config.Validate(); err != nil { | ||
return config, errors.Wrap(err, "config validation failed") | ||
} | ||
|
||
if options.RequestMaxBytes == 0 { | ||
config.RequestMaxBytes = config.RequestBatchMaxBytes | ||
} | ||
|
||
return config, nil | ||
} |