From ecd05ab309617d963a07438f30dd3b7cbdd6cffc Mon Sep 17 00:00:00 2001 From: Matthew B White Date: Fri, 10 Feb 2023 13:50:53 +0000 Subject: [PATCH] Default to RAFT enabled Signed-off-by: Matthew B White --- .gitignore | 4 +-- Makefile | 8 +++++ internal/app/microfabd/microfabd.go | 3 ++ internal/pkg/orderer/runtime.go | 45 +++++++++++++++++++++++++---- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bb5b679..5f95323 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,6 @@ .vscode microfabd - -_mfcfg +microfab +_*cfg diff --git a/Makefile b/Makefile index 3897df7..359a54c 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,11 @@ unit: integration: go run github.com/onsi/ginkgo/ginkgo integration + +binary: + go build -o microfabd cmd/microfabd/main.go + go build -o microfab cmd/microfab/main.go + +.PHONY: docker +docker: + docker build -t microfab -f Dockerfile2 . diff --git a/internal/app/microfabd/microfabd.go b/internal/app/microfabd/microfabd.go index 8f96c08..be8ee72 100644 --- a/internal/app/microfabd/microfabd.go +++ b/internal/app/microfabd/microfabd.go @@ -239,6 +239,9 @@ func (m *Microfab) Start() error { } }() + // wait for the orderer to wakeup + time.Sleep(8 * time.Second) + // Create and join all of the channels. if m.state == nil { for i := range m.config.Channels { diff --git a/internal/pkg/orderer/runtime.go b/internal/pkg/orderer/runtime.go index 0b459e5..da78ee5 100644 --- a/internal/pkg/orderer/runtime.go +++ b/internal/pkg/orderer/runtime.go @@ -22,6 +22,7 @@ import ( "github.com/hyperledger-labs/microfab/internal/pkg/util" "github.com/hyperledger/fabric-protos-go/common" "github.com/hyperledger/fabric-protos-go/orderer" + "github.com/hyperledger/fabric-protos-go/orderer/etcdraft" "github.com/pkg/errors" ) @@ -186,6 +187,44 @@ func (o *Orderer) hasStarted() bool { func (o *Orderer) createGenesisBlock(consortium []*organization.Organization) error { txID := txid.New(o.mspID, o.identity) header := protoutil.BuildHeader(common.HeaderType_CONFIG, "testchainid", txID) + + var consensusType *orderer.ConsensusType + + if o.tls != nil { + // can either create a SOLO or full RAFT orderering service + consensusType = &orderer.ConsensusType{ + // Metadata: nil, + // State: orderer.ConsensusType_STATE_NORMAL, + // Type: "solo", + Metadata: util.MarshalOrPanic(&etcdraft.ConfigMetadata{ + Consenters: []*etcdraft.Consenter{ + { + Host: o.apiURL.Host, + Port: uint32(o.apiPort), + // TODO: errr... what certificates?! + ClientTlsCert: o.tls.Certificate().Bytes(), + ServerTlsCert: o.tls.Certificate().Bytes(), + }, + }, + Options: &etcdraft.Options{ + TickInterval: "2500ms", + ElectionTick: 5, + HeartbeatTick: 1, + MaxInflightBlocks: 5, + SnapshotIntervalSize: 1048576, + }, + }), + State: orderer.ConsensusType_STATE_NORMAL, + Type: "etcdraft", + } + } else { + consensusType = &orderer.ConsensusType{ + Metadata: nil, + State: orderer.ConsensusType_STATE_NORMAL, + Type: "solo", + } + } + config := &common.Config{ ChannelGroup: &common.ConfigGroup{ Groups: map[string]*common.ConfigGroup{ @@ -263,11 +302,7 @@ func (o *Orderer) createGenesisBlock(consortium []*organization.Organization) er }, "ConsensusType": { ModPolicy: "Admins", - Value: util.MarshalOrPanic(&orderer.ConsensusType{ - Metadata: nil, - State: orderer.ConsensusType_STATE_NORMAL, - Type: "solo", - }), + Value: util.MarshalOrPanic(consensusType), }, }, },