Skip to content
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

Smart sq #4

Open
wants to merge 4 commits into
base: bdls-1.4-bft
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
34 changes: 34 additions & 0 deletions common/channelconfig/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
cb "github.com/hyperledger/fabric-protos-go/common"
mspprotos "github.com/hyperledger/fabric-protos-go/msp"
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/orderer/bdls"
"github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
"github.com/hyperledger/fabric-protos-go/orderer/smartbft"
pb "github.com/hyperledger/fabric-protos-go/peer"
Expand Down Expand Up @@ -364,3 +365,36 @@ func MarshalSmartBFTMetadata(md *smartbft.ConfigMetadata) ([]byte, error) {
}
return proto.Marshal(copyMd)
}

// MarshalBdlsMetadata serializes Bdls metadata.
func MarshalBdlsMetadata(md *bdls.ConfigMetadata) ([]byte, error) {
copyMd := proto.Clone(md).(*bdls.ConfigMetadata)
for _, c := range copyMd.Consenters {
// Expect the user to set the config value for client/server certs to the
// path where they are persisted locally, then load these files to memory.
clientCert, err := ioutil.ReadFile(string(c.GetClientTlsCert()))
if err != nil {
return nil, errors.Errorf("cannot load client cert for consenter %s:%d: %s", c.GetHost(), c.GetPort(), err)
}
c.ClientTlsCert = clientCert

serverCert, err := ioutil.ReadFile(string(c.GetServerTlsCert()))
if err != nil {
return nil, errors.Errorf("cannot load server cert for consenter %s:%d: %s", c.GetHost(), c.GetPort(), err)
}
c.ServerTlsCert = serverCert

// Load OSN signing identity certificate
idBytes, err := ioutil.ReadFile(string(c.Identity))
if err != nil {
return nil, errors.Errorf("cannot load consenter identity certificate %s:%d, %s", c.GetHost(), c.GetPort(), err)
}

c.Identity, err = msp.NewSerializedIdentity(c.MspId, idBytes)

if err != nil {
return nil, errors.Errorf("cannot marshal consenter serialized identity %s:%d: %s", c.GetHost(), c.GetPort(), err)
}
}
return proto.Marshal(copyMd)
}
30 changes: 30 additions & 0 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/orderer/bdls"
"github.com/hyperledger/fabric-protos-go/orderer/smartbft"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/bccsp"
Expand Down Expand Up @@ -286,6 +287,31 @@ func (p *Peer) SmartBFTId2Identities(cid string) map[uint64][]byte {
return res
}

// BdlsId2Identities get identities from last known configuration.
func (p *Peer) BdlsId2Identities(cid string) map[uint64][]byte {
c := p.Channel(cid)
if c == nil {
return nil
}

c.lock.RLock()
defer c.lock.RUnlock()
oc, ok := c.Resources().OrdererConfig()
if !ok {
return nil
}

m := &bdls.ConfigMetadata{}
proto.Unmarshal(oc.ConsensusMetadata(), m)

res := make(map[uint64][]byte)
for _, consenter := range m.Consenters {
res[consenter.ConsenterId] = consenter.Identity
}

return res
}

type IdentityFethcer struct {
Adaptee *Peer
}
Expand All @@ -294,6 +320,10 @@ func (i *IdentityFethcer) Id2Identities(cid string) map[uint64][]byte {
return i.Adaptee.SmartBFTId2Identities(cid)
}

func (i *IdentityFethcer) Id2IdentitiesBdls(cid string) map[uint64][]byte {
return i.Adaptee.BdlsId2Identities(cid)
}

// createChannel creates a new channel object and insert it into the channels slice.
func (p *Peer) createChannel(
cid string,
Expand Down
16 changes: 16 additions & 0 deletions integration/nwo/configblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
protosorderer "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/orderer/bdls"
"github.com/hyperledger/fabric-protos-go/orderer/smartbft"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/integration/nwo/commands"
Expand Down Expand Up @@ -347,6 +348,21 @@ func UpdateSmartBFTMetadata(network *Network, peer *Peer, orderer *Orderer, chan
})
}

// UpdateBdlsMetadata executes a config update that updates the bdls metadata according to the given function f
func UpdateBdlsMetadata(network *Network, peer *Peer, orderer *Orderer, channel string, f func(md *bdls.ConfigMetadata)) {
UpdateConsensusMetadata(network, peer, orderer, channel, func(originalMetadata []byte) []byte {
metadata := &bdls.ConfigMetadata{}
err := proto.Unmarshal(originalMetadata, metadata)
Expect(err).NotTo(HaveOccurred())

f(metadata)

newMetadata, err := proto.Marshal(metadata)
Expect(err).NotTo(HaveOccurred())
return newMetadata
})
}

// UpdateOrdererEndpoints executes a config update that updates the orderer metadata according to the given endpoints
func UpdateOrdererEndpoints(network *Network, peer *Peer, orderer *Orderer, channel string, endpoints ...string) {
config := GetConfig(network, peer, orderer, channel)
Expand Down
17 changes: 17 additions & 0 deletions integration/nwo/configtx_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ Profiles:{{ range .Profiles }}
ConsenterId: {{ $w.OrdererIndex . }}
{{- end }}{{- end }}
{{- end }}
{{- if eq $w.Consensus.Type "bdls" }}
bdls:
Consenters:{{ range .Orderers }}{{ with $w.Orderer . }}
- Host: 127.0.0.1
Port: {{ $w.OrdererPort . "Cluster" }}
ClientTLSCert: {{ $w.OrdererLocalCryptoDir . "tls" }}/server.crt
ServerTLSCert: {{ $w.OrdererLocalCryptoDir . "tls" }}/server.crt
MSPID: {{ $w.OrdererMSPID . }}
Identity: {{ $w.OrdererCert . }}
ConsenterId: {{ $w.OrdererIndex . }}
{{- end }}{{- end }}
{{- end }}
Organizations:{{ range $w.OrgsForOrderers .Orderers }}
- *{{ .MSPID }}
{{- end }}
Expand All @@ -198,6 +210,11 @@ Profiles:{{ range .Profiles }}
BlockValidation:
Type: ImplicitOrderer
Rule: SMARTBFT
{{- else }}
{{- if eq $w.Consensus.Type "bdls" }}
BlockValidation:
Type: ImplicitOrderer
Rule: SMARTBFT
{{- else }}
BlockValidation:
Type: ImplicitMeta
Expand Down
53 changes: 53 additions & 0 deletions integration/nwo/standard_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,59 @@ func MinimalRaft() *Config {
return config
}


/*
BDLS function config BasicBdls & MultiNodeBdls
*/
func BasicBdls() *Config {
config := BasicSolo()
config.Consensus.Type = "bdls"
config.Profiles = []*Profile{{
Name: "SampleDevModeBdls",
Orderers: []string{"orderer"},
}, {
Name: "TwoOrgsChannel",
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
}}
for _, peer := range config.Peers {
peer.BFTDeliveryClient = true
}
config.SystemChannel.Profile = "SampleDevModeBdls"
return config
}

func MultiNodeBdls() *Config {
config := BasicBdls()
config.Orderers = []*Orderer{
{Name: "orderer1", Organization: "OrdererOrg"},
{Name: "orderer2", Organization: "OrdererOrg"},
{Name: "orderer3", Organization: "OrdererOrg"},
{Name: "orderer4", Organization: "OrdererOrg"},
}
config.Profiles = []*Profile{{
Name: "SampleDevModeBdls",
Orderers: []string{"orderer1", "orderer2", "orderer3", "orderer4"},
}, {
Name: "TwoOrgsChannel",
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
}}

config.Channels = []*Channel{
{Name: "testchannel1", Profile: "TwoOrgsChannel"},
{Name: "testchannel2", Profile: "TwoOrgsChannel"}}

for _, peer := range config.Peers {
peer.Channels = []*PeerChannel{
{Name: "testchannel1", Anchor: true},
{Name: "testchannel2", Anchor: true},
}
}
return config
}
/*********************BDLS end*********************/

func BasicSmartBFT() *Config {
config := BasicSolo()
config.Consensus.Type = "smartbft"
Expand Down
1 change: 1 addition & 0 deletions integration/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
RaftBasePort
SBEBasePort
SmartBFTBasePort
BdlsBasePort
)

// On linux, the default ephemeral port range is 32768-60999 and can be
Expand Down
7 changes: 7 additions & 0 deletions internal/configtxgen/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
ConsensusTypeEtcdRaft = "etcdraft"
// ConsensusTypeSmartBFT identifies the SmartBFT-based consensus implementation.
ConsensusTypeSmartBFT = "smartbft"
// ConsensusTypeBdls identifies the BDLS-based consensus implementation.
ConsensusTypeBdls = "bdls"

// BlockValidationPolicyKey TODO
BlockValidationPolicyKey = "BlockValidation"
Expand Down Expand Up @@ -228,6 +230,11 @@ func NewOrdererGroup(conf *genesisconfig.Orderer) (*cb.ConfigGroup, error) {
if consensusMetadata, err = channelconfig.MarshalSmartBFTMetadata(conf.SmartBFT); err != nil {
return nil, errors.Errorf("cannot marshal metadata for orderer type %s: %s", ConsensusTypeSmartBFT, err)
}
//TODO: replace the MarshalSmartBFTMetadata
case ConsensusTypeBdls:
if consensusMetadata, err = channelconfig.MarshalSmartBFTMetadata(conf.SmartBFT); err != nil {
return nil, errors.Errorf("cannot marshal metadata for orderer type %s: %s", ConsensusTypeBdls, err)
}
default:
return nil, errors.Errorf("unknown orderer type: %s", conf.OrdererType)
}
Expand Down
69 changes: 69 additions & 0 deletions internal/configtxgen/encoder/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
"github.com/hyperledger/fabric-protos-go/orderer/smartbft"
"github.com/hyperledger/fabric-protos-go/orderer/bdls"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/internal/configtxgen/encoder"
"github.com/hyperledger/fabric/internal/configtxgen/encoder/fakes"
Expand Down Expand Up @@ -516,6 +517,74 @@ var _ = Describe("Encoder", func() {
})
})

Context("when the consensus type is bdls", func() {
BeforeEach(func() {
conf.OrdererType = "bdls"
conf.Bdls = &bdls.ConfigMetadata{
Options: &bdls.Options{
RequestBatchMaxCount: uint64(100),
RequestBatchMaxBytes: uint64(1000000),
RequestBatchMaxInterval: "50ms",
IncomingMessageBufferSize: uint64(200),
RequestPoolSize: uint64(400),
RequestForwardTimeout: "2s",
RequestComplainTimeout: "10s",
RequestAutoRemoveTimeout: "1m",
ViewChangeResendInterval: "5s",
ViewChangeTimeout: "20s",
LeaderHeartbeatTimeout: "30s",
LeaderHeartbeatCount: uint64(10),
CollectTimeout: "1m",
SyncOnStart: false,
SpeedUpViewChange: false,
},
}
})

It("adds the bdls metadata", func() {
cg, err := encoder.NewOrdererGroup(conf)
Expect(err).NotTo(HaveOccurred())
Expect(len(cg.Values)).To(Equal(5))
consensusType := &ab.ConsensusType{}
err = proto.Unmarshal(cg.Values["ConsensusType"].Value, consensusType)
Expect(err).NotTo(HaveOccurred())
Expect(consensusType.Type).To(Equal("bdls"))
metadata := &bdls.ConfigMetadata{}
err = proto.Unmarshal(consensusType.Metadata, metadata)
Expect(err).NotTo(HaveOccurred())
Expect(metadata.Options.RequestBatchMaxCount).To(Equal(uint64(100)))
Expect(metadata.Options.RequestBatchMaxBytes).To(Equal(uint64(1000000)))
Expect(metadata.Options.RequestBatchMaxInterval).To(Equal("50ms"))
Expect(metadata.Options.IncomingMessageBufferSize).To(Equal(uint64(200)))
Expect(metadata.Options.RequestPoolSize).To(Equal(uint64(400)))
Expect(metadata.Options.RequestForwardTimeout).To(Equal("2s"))
Expect(metadata.Options.RequestComplainTimeout).To(Equal("10s"))
Expect(metadata.Options.RequestAutoRemoveTimeout).To(Equal("1m"))
Expect(metadata.Options.ViewChangeResendInterval).To(Equal("5s"))
Expect(metadata.Options.ViewChangeTimeout).To(Equal("20s"))
Expect(metadata.Options.LeaderHeartbeatTimeout).To(Equal("30s"))
Expect(metadata.Options.LeaderHeartbeatCount).To(Equal(uint64(10)))
Expect(metadata.Options.CollectTimeout).To(Equal("1m"))
Expect(metadata.Options.SyncOnStart).To(Equal(false))
Expect(metadata.Options.SpeedUpViewChange).To(Equal(false))
})

Context("when the bdls configuration is bad", func() {
BeforeEach(func() {
conf.Bdls = &bdls.ConfigMetadata{
Consenters: []*bdls.Consenter{
{},
},
}
})

It("wraps and returns the error", func() {
_, err := encoder.NewOrdererGroup(conf)
Expect(err).To(MatchError("cannot marshal metadata for orderer type bdls: cannot load client cert for consenter :0: open : no such file or directory"))
})
})
})

Context("when the consensus type is unknown", func() {
BeforeEach(func() {
conf.OrdererType = "bad-type"
Expand Down
28 changes: 28 additions & 0 deletions internal/configtxgen/genesisconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/SmartBFT-Go/consensus/pkg/types"
"github.com/hyperledger/fabric-protos-go/orderer/bdls"
"github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
"github.com/hyperledger/fabric-protos-go/orderer/smartbft"
"github.com/hyperledger/fabric/common/flogging"
Expand Down Expand Up @@ -61,6 +62,10 @@ const (
// the SmartBFT-based ordering service.
SampleDevModeSmartBFTProfile = "SampleDevModeSmartBFT"

// SampleDevModeBdlsProfile references the sample profile used for testing
// the Bdls-based ordering service.
SampleDevModeBdlsProfile = "SampleDevModeBdls"

// SampleAppChannelInsecureSoloProfile references the sample profile which
// does not include any MSPs and uses solo for ordering.
SampleAppChannelInsecureSoloProfile = "SampleAppChannelInsecureSolo"
Expand Down Expand Up @@ -166,6 +171,7 @@ type Orderer struct {
Kafka Kafka `yaml:"Kafka"`
EtcdRaft *etcdraft.ConfigMetadata `yaml:"EtcdRaft"`
SmartBFT *smartbft.ConfigMetadata `yaml:"SmartBFT"`
Bdls *bdls.ConfigMetadata `yaml:"Bdls"`
Organizations []*Organization `yaml:"Organizations"`
MaxChannels uint64 `yaml:"MaxChannels"`
Capabilities map[string]bool `yaml:"Capabilities"`
Expand Down Expand Up @@ -224,6 +230,25 @@ var genesisDefaults = TopLevel{
SpeedUpViewChange: types.DefaultConfig.SpeedUpViewChange,
},
},
Bdls: &bdls.ConfigMetadata{
Options: &bdls.Options{
RequestBatchMaxCount: uint64(types.DefaultConfig.RequestBatchMaxCount),
RequestBatchMaxBytes: uint64(types.DefaultConfig.RequestBatchMaxBytes),
RequestBatchMaxInterval: types.DefaultConfig.RequestBatchMaxInterval.String(),
IncomingMessageBufferSize: uint64(types.DefaultConfig.IncomingMessageBufferSize),
RequestPoolSize: uint64(types.DefaultConfig.RequestPoolSize),
RequestForwardTimeout: types.DefaultConfig.RequestForwardTimeout.String(),
RequestComplainTimeout: types.DefaultConfig.RequestComplainTimeout.String(),
RequestAutoRemoveTimeout: types.DefaultConfig.RequestAutoRemoveTimeout.String(),
ViewChangeResendInterval: types.DefaultConfig.ViewChangeResendInterval.String(),
ViewChangeTimeout: types.DefaultConfig.ViewChangeTimeout.String(),
LeaderHeartbeatTimeout: types.DefaultConfig.LeaderHeartbeatTimeout.String(),
LeaderHeartbeatCount: uint64(types.DefaultConfig.LeaderHeartbeatCount),
CollectTimeout: types.DefaultConfig.CollectTimeout.String(),
SyncOnStart: types.DefaultConfig.SyncOnStart,
SpeedUpViewChange: types.DefaultConfig.SpeedUpViewChange,
},
},
},
}

Expand Down Expand Up @@ -434,6 +459,9 @@ loop:
cf.TranslatePathInPlace(configDir, &serverCertPath)
c.ServerTlsCert = []byte(serverCertPath)
}
//TODO: add body for the bdls case
case "bdls":
// Do nothing
case SmartBFT:
if ord.SmartBFT == nil {
logger.Panicf("%s configuration missing", SmartBFT)
Expand Down
Loading