Skip to content

Commit

Permalink
BFT chains are up and running
Browse files Browse the repository at this point in the history
Change-Id: I59bf40ff90be2299aa1733cc672ea88f94984b4f
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Nov 22, 2022
1 parent c144b58 commit 629642a
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 89 deletions.
4 changes: 2 additions & 2 deletions integration/channelparticipation/channel_participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func GenerateJoinRequest(url, channel string, blockBytes []byte) *http.Request {
func doBody(client *http.Client, req *http.Request) []byte {
resp, err := client.Do(req)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusCreated))
bodyBytes, err := ioutil.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
fmt.Println(">>>>", string(bodyBytes))
Expect(resp.StatusCode).To(Equal(http.StatusCreated))
resp.Body.Close()

return bodyBytes
}

Expand Down
2 changes: 1 addition & 1 deletion integration/configtx/consenter_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ var _ = Describe("ConfigTx ConsenterMapping", func() {
o := &common.Orderers{}
err = proto.Unmarshal(group.GetValues()["Orderers"].GetValue(), o)
Expect(err).NotTo(HaveOccurred())
Expect(len(o.GetConsenterMapping())).To(Equal(3))
Expect(len(o.GetConsenterMapping())).To(Equal(4))
})
})
3 changes: 1 addition & 2 deletions integration/nwo/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"io/ioutil"
"net/http"

"github.com/hyperledger/fabric/integration/nwo/runner"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
Expand Down Expand Up @@ -72,5 +71,5 @@ const CCEnvDefaultImage = "hyperledger/fabric-ccenv:latest"

var RequiredImages = []string{
CCEnvDefaultImage,
runner.CouchDBDefaultImage,
//runner.CouchDBDefaultImage,
}
25 changes: 17 additions & 8 deletions integration/nwo/fabricconfig/configtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,24 @@ type Application struct {
ExtraProperties map[string]interface{} `yaml:",inline,omitempty"`
}

type ConsenterMapping struct {
ID uint64
Host string
Port int
MSPID string
Identity string
}

type ConfigTxOrderer struct {
OrdererType string `yaml:"OrdererType,omitempty"`
BatchTimeout time.Duration `yaml:"BatchTimeout,omitempty"`
BatchSize *BatchSize `yaml:"BatchSize,omitempty"`
Kafka *ConfigTxKafka `yaml:"Kafka,omitempty"`
EtcdRaft *ConfigTxEtcdRaft `yaml:"EtcdRaft,omitempty"`
Organizations []*Organization `yaml:"Organizations,omitempty"`
Policies map[string]*Policy `yaml:"Policies,omitempty"`
Capabilities map[string]bool `yaml:"Capabilities,omitempty"`
OrdererType string `yaml:"OrdererType,omitempty"`
BatchTimeout time.Duration `yaml:"BatchTimeout,omitempty"`
BatchSize *BatchSize `yaml:"BatchSize,omitempty"`
Kafka *ConfigTxKafka `yaml:"Kafka,omitempty"`
EtcdRaft *ConfigTxEtcdRaft `yaml:"EtcdRaft,omitempty"`
ConsenterMapping []ConsenterMapping `yaml:"ConsenterMapping,omitempty"`
Organizations []*Organization `yaml:"Organizations,omitempty"`
Policies map[string]*Policy `yaml:"Policies,omitempty"`
Capabilities map[string]bool `yaml:"Capabilities,omitempty"`

ExtraProperties map[string]interface{} `yaml:",inline,omitempty"`
}
Expand Down
25 changes: 17 additions & 8 deletions integration/nwo/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type Channel struct {
type Orderer struct {
Name string `yaml:"name,omitempty"`
Organization string `yaml:"organization,omitempty"`
Id int `yaml:"id,omitempty"`
}

// ID provides a unique identifier for an orderer instance.
Expand Down Expand Up @@ -691,6 +692,12 @@ func (n *Network) OrdererLocalMSPDir(o *Orderer) string {
return n.OrdererLocalCryptoDir(o, "msp")
}

func (n *Network) OrdererSignCert(o *Orderer) string {
dirName := filepath.Join(n.OrdererLocalCryptoDir(o, "msp"), "signcerts")
fileName := fmt.Sprintf("%s.%s-cert.pem", o.Name, n.Organization(o.Organization).Domain)
return filepath.Join(dirName, fileName)
}

// OrdererLocalTLSDir returns the path to the local TLS directory for the
// Orderer.
func (n *Network) OrdererLocalTLSDir(o *Orderer) string {
Expand Down Expand Up @@ -773,14 +780,16 @@ func (n *Network) Bootstrap() {

n.bootstrapIdemix()

sess, err = n.ConfigTxGen(commands.OutputBlock{
ChannelID: n.SystemChannel.Name,
Profile: n.SystemChannel.Profile,
ConfigPath: n.RootDir,
OutputBlock: n.OutputBlockPath(n.SystemChannel.Name),
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
if n.SystemChannel != nil && n.SystemChannel.Name != "" {
sess, err = n.ConfigTxGen(commands.OutputBlock{
ChannelID: n.SystemChannel.Name,
Profile: n.SystemChannel.Profile,
ConfigPath: n.RootDir,
OutputBlock: n.OutputBlockPath(n.SystemChannel.Name),
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
}

for _, c := range n.Channels {
sess, err := n.ConfigTxGen(commands.CreateChannelTx{
Expand Down
34 changes: 15 additions & 19 deletions integration/nwo/standard_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,18 @@ func MultiNodeEtcdRaft() *Config {

func MultiNodeBFT() *Config {
config := BasicConfig()

config.SystemChannel = nil
config.Consensus.Type = "BFT"
config.Orderers = []*Orderer{
{Name: "orderer1", Organization: "OrdererOrg"},
{Name: "orderer2", Organization: "OrdererOrg"},
{Name: "orderer3", Organization: "OrdererOrg"},
{Name: "orderer4", Organization: "OrdererOrg"},
}
config.Profiles = []*Profile{
{
Name: "SampleDevModeBFT",
Orderers: []string{"orderer1", "orderer2", "orderer3"},
Orderers: []string{"orderer1", "orderer2", "orderer3", "orderer4"},
},
{
Name: "TwoOrgsChannel",
Expand All @@ -317,7 +318,7 @@ func MultiNodeBFT() *Config {

func BasicSmartBFT() *Config {
config := BasicConfig()
config.Consensus.Type = "smartbft"
config.Consensus.Type = "BFT"
config.Profiles = []*Profile{{
Name: "SampleDevModeSmartBFT",
Orderers: []string{"orderer"},
Expand All @@ -326,33 +327,28 @@ func BasicSmartBFT() *Config {
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
}}
/* for _, peer := range config.Peers {
peer.BFTDeliveryClient = true
} */
config.SystemChannel.Profile = "SampleDevModeSmartBFT"
return config
}

func MultiNodeSmartBFT() *Config {
config := BasicSmartBFT()
config.Orderers = []*Orderer{
{Name: "orderer1", Organization: "OrdererOrg"},
{Name: "orderer2", Organization: "OrdererOrg"},
{Name: "orderer3", Organization: "OrdererOrg"},
{Name: "orderer4", Organization: "OrdererOrg"},
{Name: "orderer1", Organization: "OrdererOrg", Id: 1},
{Name: "orderer2", Organization: "OrdererOrg", Id: 2},
{Name: "orderer3", Organization: "OrdererOrg", Id: 3},
{Name: "orderer4", Organization: "OrdererOrg", Id: 4},
}
config.Profiles = []*Profile{{
Name: "SampleDevModeSmartBFT",
Orderers: []string{"orderer1", "orderer2", "orderer3", "orderer4"},
}, {
Name: "TwoOrgsChannel",
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
ChannelCapabilities: []string{"V3_0"},
Name: "SampleDevModeSmartBFT",
Orderers: []string{"orderer1", "orderer2", "orderer3", "orderer4"},
Organizations: []string{"Org1", "Org2"},
AppCapabilities: []string{"V2_0"},
}}

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

for _, peer := range config.Peers {
Expand Down
14 changes: 5 additions & 9 deletions integration/nwo/template/configtx_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,16 @@ Profiles:{{ range .Profiles }}
AbsoluteMaxBytes: 98 MB
PreferredMaxBytes: 512 KB
Capabilities:
{{- if eq $w.Consensus.Type "BFT" }}
V3_0: true
{{- else }}
V2_0: true
{{- end }}
{{- if eq $w.Consensus.Type "smartbft" }}
{{- if eq $w.Consensus.Type "BFT" }}
ConsenterMapping:{{ range $index, $orderer := .Orderers }}{{ with $w.Orderer . }}
- ID: {{ $index }}
- ID: {{ .Id }}
Host: 127.0.0.1
Port: {{ $w.OrdererPort . "Cluster" }}
MSPID: {{ .Organization }}
ClientTLSCert: {{ $w.OrdererLocalCryptoDir . "tls" }}/server.crt
ServerTLSCert: {{ $w.OrdererLocalCryptoDir . "tls" }}/server.crt
Identity: {{ $w.OrdererLocalCryptoDir . "tls" }}/server.crt
Identity: {{ $w.OrdererSignCert .}}
{{- end }}{{- end }}
{{- end }}
{{- if eq $w.Consensus.Type "etcdraft" }}
Expand Down Expand Up @@ -195,8 +191,6 @@ Profiles:{{ range .Profiles }}
Type: ImplicitMeta
Rule: ANY Writers
{{- end }}
{{- if .Consortium }}
Consortium: {{ .Consortium }}
Application:
Capabilities:
{{- if .AppCapabilities }}{{ range .AppCapabilities }}
Expand Down Expand Up @@ -224,6 +218,8 @@ Profiles:{{ range .Profiles }}
Endorsement:
Type: ImplicitMeta
Rule: "MAJORITY Endorsement"
{{- if .Consortium }}
Consortium: {{ .Consortium }}
{{- else }}
Consortiums:{{ range $w.Consortiums }}
{{ .Name }}:
Expand Down
111 changes: 90 additions & 21 deletions integration/smartbft/smartbft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"syscall"
"time"

"github.com/golang/protobuf/proto"

"github.com/hyperledger/fabric/integration/channelparticipation"

"github.com/tedsuo/ifrit/grouper"

docker "github.com/fsouza/go-dockerclient"
Expand Down Expand Up @@ -89,7 +93,12 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() {

Describe("smartbft network", func() {
It("smartbft multiple nodes stop start all nodes", func() {
network = nwo.New(nwo.MultiNodeSmartBFT(), testDir, client, StartPort(), components)
networkConfig := nwo.MultiNodeSmartBFT()
networkConfig.SystemChannel.Name = ""
networkConfig.Channels = nil

network = nwo.New(networkConfig, testDir, client, StartPort(), components)
network.Consortiums = nil
network.Consensus.ChannelParticipationEnabled = true
network.Consensus.BootstrapMethod = "none"
network.GenerateConfigTree()
Expand All @@ -110,24 +119,39 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() {
Eventually(peerProcesses.Ready(), network.EventuallyTimeout).Should(BeClosed())
peer := network.Peer("Org1", "peer0")

/* genesisBlock := applicationChannelGenesisBlock(network, network.Orderers, []*nwo.Peer{peer}, "participation-trophy")
expectedChannelInfoPT := channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ConsensusRelation: "consenter",
Height: 1,
}
for _, o := range network.Orderers {
By("joining " + o.Name + " to channel as a consenter")
channelparticipation.Join(network, o, "participation-trophy", genesisBlock, expectedChannelInfoPT)
channelInfo := channelparticipation.ListOne(network, o, "participation-trophy")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
}
Eventually(ordererRunners[1].Err(), 120*time.Second, time.Second).Should(gbytes.Say("Message from 1"))
Fail("stop here") */
sess, err := network.ConfigTxGen(commands.OutputBlock{
ChannelID: "testchannel1",
Profile: network.Profiles[0].Name,
ConfigPath: network.RootDir,
OutputBlock: network.OutputBlockPath("testchannel1"),
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))

genesisBlockBytes, err := os.ReadFile(network.OutputBlockPath("testchannel1"))
Expect(err).NotTo(HaveOccurred())

genesisBlock := &common.Block{}
err = proto.Unmarshal(genesisBlockBytes, genesisBlock)
Expect(err).NotTo(HaveOccurred())

expectedChannelInfoPT := channelparticipation.ChannelInfo{
Name: "testchannel1",
URL: "/participation/v1/channels/testchannel1",
Status: "active",
ConsensusRelation: "consenter",
Height: 1,
}

for _, o := range network.Orderers {
By("joining " + o.Name + " to channel as a consenter")
channelparticipation.Join(network, o, "testchannel1", genesisBlock, expectedChannelInfoPT)
channelInfo := channelparticipation.ListOne(network, o, "testchannel1")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
}

Eventually(ordererRunners[1].Err(), 120*time.Second, time.Second).Should(gbytes.Say("Message from 1"))
Fail("stop here")

assertBlockReception(map[string]int{"systemchannel": 0}, network.Orderers, peer, network)
/* By("check block validation policy on system channel")
Expand Down Expand Up @@ -160,7 +184,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() {
}

By("querying the chaincode")
sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
sess, err = network.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
ChannelID: channel,
Name: "mycc",
Ctor: `{"Args":["query","a"]}`,
Expand Down Expand Up @@ -201,6 +225,51 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() {
})
})

/*func makeGenesisBlockFromChannelCreationTx(tx []byte) *common.Block {
env := &common.Envelope{}
err := proto.Unmarshal(tx, env)
Expect(err).NotTo(HaveOccurred())
payload := &common.Payload{}
err = proto.Unmarshal(env.Payload, payload)
Expect(err).NotTo(HaveOccurred())
configUpdateEnv, err := configtx2.UnmarshalConfigUpdateEnvelope(payload.Data)
Expect(err).NotTo(HaveOccurred())
confUpdate := &common.ConfigUpdate{}
proto.Unmarshal(configUpdateEnv.ConfigUpdate, confUpdate)
confUpdate.
chHdr := protoutil.UnmarshalChannelHeaderOrPanic(payload.Header.ChannelHeader)
chHdr.Type = int32(common.HeaderType_CONFIG)
payload.Header.ChannelHeader = protoutil.MarshalOrPanic(chHdr)
env.Payload = protoutil.MarshalOrPanic(payload)
metadata := &common.BlockMetadata{
Metadata: make([][]byte, 4),
}
metadata.Metadata[common.BlockMetadataIndex_SIGNATURES] = protoutil.MarshalOrPanic(&common.OrdererBlockMetadata{
LastConfig: &common.LastConfig{Index: 0},
// This is a genesis block, peer never verify this signature because we can't bootstrap
// trust from an earlier block, hence there are no signatures here.
})
metadata.Metadata[common.BlockMetadataIndex_LAST_CONFIG] = protoutil.MarshalOrPanic(&common.Metadata{
Value: protoutil.MarshalOrPanic(&common.LastConfig{Index: 0}),
// This is a genesis block, peer never verify this signature because we can't bootstrap
// trust from an earlier block, hence there are no signatures here.
})
blockdata := &common.BlockData{Data: [][]byte{protoutil.MarshalOrPanic(env)}}
return &common.Block{
Header: &common.BlockHeader{DataHash: protoutil.BlockDataHash(blockdata)},
Data: blockdata,
Metadata: metadata,
}
}
*/
func invokeQuery(network *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, channel string, expectedBalance int) {
sess, err := network.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{
ChannelID: channel,
Expand Down Expand Up @@ -347,7 +416,7 @@ func applicationChannelGenesisBlock(n *nwo.Network, orderers []*nwo.Orderer, pee

channelConfig := configtx.Channel{
Orderer: configtx.Orderer{
OrdererType: "smartbft",
OrdererType: "etcdraft",
Organizations: ordererOrgs,
EtcdRaft: orderer.EtcdRaft{
Consenters: consenters,
Expand Down
Loading

0 comments on commit 629642a

Please sign in to comment.