-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ConsensusTypeBFT in the orderer.go #62
base: main
Are you sure you want to change the base?
Changes from 2 commits
4e85206
e61bb40
3f92a9f
023c0b6
a7e02f7
d0ca879
b397f03
ef1a156
a044dae
a0b16ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,14 @@ import ( | |
"time" | ||
|
||
"github.com/golang/protobuf/proto" | ||
"github.com/hyperledger/fabric-config/configtx/internal/policydsl" | ||
"github.com/hyperledger/fabric-config/configtx/orderer" | ||
"github.com/hyperledger/fabric-protos-go/common" | ||
cb "github.com/hyperledger/fabric-protos-go/common" | ||
mspa "github.com/hyperledger/fabric-protos-go/msp" | ||
ob "github.com/hyperledger/fabric-protos-go/orderer" | ||
eb "github.com/hyperledger/fabric-protos-go/orderer/etcdraft" | ||
sb "github.com/hyperledger/fabric-protos-go/orderer/smartbft" | ||
) | ||
|
||
const ( | ||
|
@@ -38,6 +42,9 @@ type Orderer struct { | |
Kafka orderer.Kafka | ||
EtcdRaft orderer.EtcdRaft | ||
Organizations []Organization | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line comments on these, and update the comment on the type, above, only EtcdRaft and BFT are supported. |
||
SmartBFT *sb.Options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SmartBFT -> SmartBFTOptions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure? in Fabric 3.0 it's SmartBFT There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
ConsenterMapping []common.Consenter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There aren't any unit tests that cover these new objects, please add them. See the coverage of |
||
// MaxChannels is the maximum count of channels an orderer supports. | ||
MaxChannels uint64 | ||
// Capabilities is a map of the capabilities the orderer supports. | ||
|
@@ -821,6 +828,36 @@ func addOrdererValues(ordererGroup *cb.ConfigGroup, o Orderer) error { | |
if consensusMetadata, err = marshalEtcdRaftMetadata(o.EtcdRaft); err != nil { | ||
return fmt.Errorf("marshaling etcdraft metadata for orderer type '%s': %v", orderer.ConsensusTypeEtcdRaft, err) | ||
} | ||
case orderer.ConsensusTypeBFT: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many other places where Please scan the project for any function that uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
consenterMapping := []*cb.Consenter{} | ||
for _, consenter := range o.ConsenterMapping { | ||
consenterMapping = append(consenterMapping, &cb.Consenter{ | ||
Id: consenter.Id, | ||
Host: consenter.Host, | ||
Port: consenter.Port, | ||
MspId: consenter.MspId, | ||
Identity: consenter.Identity, | ||
ClientTlsCert: consenter.ClientTlsCert, | ||
ServerTlsCert: consenter.ServerTlsCert, | ||
}) | ||
} | ||
consentersProto, err := proto.Marshal(&cb.Orderers{ | ||
ConsenterMapping: consenterMapping, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("marshaling consenters for orderer type '%s': %v", orderer.ConsensusTypeBFT, err) | ||
} | ||
|
||
ordererGroup.Values["Orderers"] = &cb.ConfigValue{ | ||
Value: consentersProto, | ||
ModPolicy: "Admins", | ||
} | ||
// addValue(ordererGroup, channelconfig.OrderersValue(consenterProtos), channelconfig.AdminsPolicyKey) | ||
if consensusMetadata, err = MarshalBFTOptions(o.SmartBFT); err != nil { | ||
return fmt.Errorf("consenter options read failed with error %s for orderer type %s", err, orderer.ConsensusTypeBFT) | ||
} | ||
// Overwrite policy manually by computing it from the consenters | ||
encodeBFTBlockVerificationPolicy(o.ConsenterMapping, ordererGroup) | ||
default: | ||
return fmt.Errorf("unknown orderer type '%s'", o.OrdererType) | ||
} | ||
|
@@ -838,6 +875,14 @@ func addOrdererValues(ordererGroup *cb.ConfigGroup, o Orderer) error { | |
return nil | ||
} | ||
|
||
// MarshalBFTOptions serializes smartbft options. | ||
func MarshalBFTOptions(op *sb.Options) ([]byte, error) { | ||
if copyMd, ok := proto.Clone(op).(*sb.Options); ok { | ||
return proto.Marshal(copyMd) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solved |
||
return nil, errors.New("consenter options type mismatch") | ||
} | ||
|
||
// setOrdererPolicies adds *cb.ConfigPolicies to the passed Orderer *cb.ConfigGroup's Policies map. | ||
// It checks that the BlockValidation policy is defined alongside the standard policy checks. | ||
func setOrdererPolicies(cg *cb.ConfigGroup, policyMap map[string]Policy, modPolicy string) error { | ||
|
@@ -1060,3 +1105,49 @@ func blockDataHashingStructureValue() *standardConfigValue { | |
}, | ||
} | ||
} | ||
|
||
func encodeBFTBlockVerificationPolicy(consenterProtos []common.Consenter, ordererGroup *cb.ConfigGroup) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copied from Fabric right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, then how do you prefer to resolve it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any news @tock-ibm ? |
||
n := len(consenterProtos) | ||
f := (n - 1) / 3 | ||
|
||
var identities []*mspa.MSPPrincipal | ||
var pols []*cb.SignaturePolicy | ||
for i, consenter := range consenterProtos { | ||
pols = append(pols, &cb.SignaturePolicy{ | ||
Type: &cb.SignaturePolicy_SignedBy{ | ||
SignedBy: int32(i), | ||
}, | ||
}) | ||
principalBytes, err := proto.Marshal(&mspa.SerializedIdentity{Mspid: consenter.MspId, IdBytes: consenter.Identity}) | ||
if err != nil { | ||
return err | ||
} | ||
identities = append(identities, &mspa.MSPPrincipal{ | ||
PrincipalClassification: mspa.MSPPrincipal_IDENTITY, | ||
Principal: principalBytes, | ||
}) | ||
} | ||
|
||
quorumSize := computeBFTQuorum(n, f) | ||
sp := &cb.SignaturePolicyEnvelope{ | ||
Rule: policydsl.NOutOf(int32(quorumSize), pols), | ||
Identities: identities, | ||
} | ||
policyValue, err := proto.Marshal(sp) | ||
if err != nil { | ||
return err | ||
} | ||
ordererGroup.Policies[BlockValidationPolicyKey] = &cb.ConfigPolicy{ | ||
// Inherit modification policy | ||
ModPolicy: ordererGroup.Policies[BlockValidationPolicyKey].ModPolicy, | ||
Policy: &cb.Policy{ | ||
Type: int32(cb.Policy_SIGNATURE), | ||
Value: policyValue, | ||
}, | ||
} | ||
return nil | ||
} | ||
|
||
func computeBFTQuorum(totalNodes, faultyNodes int) int { | ||
return int(math.Ceil(float64(totalNodes+faultyNodes+1) / 2)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ const ( | |
// ConsensusTypeEtcdRaft identifies the Raft-based consensus implementation. | ||
ConsensusTypeEtcdRaft = "etcdraft" | ||
|
||
// ConsensusTypeBFT identifies the SmartBFT-based consensus implementation. | ||
ConsensusTypeBFT = "BFT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no unit tests which use this constant |
||
|
||
// KafkaBrokersKey is the common.ConfigValue type key name for the KafkaBrokers message. | ||
// Deprecated: the kafka consensus type is no longer supported | ||
KafkaBrokersKey = "KafkaBrokers" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is already imported with alias
cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed