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

smartbft sync is called after restart test #4821

Merged
merged 4 commits into from May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions integration/nwo/network.go
Expand Up @@ -146,19 +146,20 @@ type Profile struct {

// Network holds information about a fabric network.
type Network struct {
RootDir string
StartPort uint16
Components *Components
DockerClient *docker.Client
ExternalBuilders []fabricconfig.ExternalBuilder
NetworkID string
EventuallyTimeout time.Duration
SessionCreateInterval time.Duration
MetricsProvider string
StatsdEndpoint string
ClientAuthRequired bool
TLSEnabled bool
GatewayEnabled bool
RootDir string
StartPort uint16
Components *Components
DockerClient *docker.Client
ExternalBuilders []fabricconfig.ExternalBuilder
NetworkID string
EventuallyTimeout time.Duration
SessionCreateInterval time.Duration
MetricsProvider string
StatsdEndpoint string
ClientAuthRequired bool
TLSEnabled bool
GatewayEnabled bool
OrdererReplicationPolicy string

PortsByOrdererID map[string]Ports
PortsByPeerID map[string]Ports
Expand Down
1 change: 1 addition & 0 deletions integration/nwo/template/orderer_template.go
Expand Up @@ -31,6 +31,7 @@ General:
ClientPrivateKey: {{ $w.OrdererLocalTLSDir Orderer }}/server.key
ServerCertificate: {{ $w.OrdererLocalTLSDir Orderer }}/server.crt
ServerPrivateKey: {{ $w.OrdererLocalTLSDir Orderer }}/server.key
ReplicationPolicy: {{ .OrdererReplicationPolicy }}
DialTimeout: 5s
RPCTimeout: 7s
ReplicationBufferSize: 20971520
Expand Down
106 changes: 106 additions & 0 deletions integration/smartbft/smartbft_test.go
Expand Up @@ -667,6 +667,112 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() {
ordererProcesses[3] = proc
Eventually(proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Starting view with number 0, sequence 5"))
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("BFT Sync initiated"))

By("Waiting communication to be established from the leader")
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))

assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, peer, network)

invokeQuery(network, peer, orderer, channel, 50)
time.Sleep(time.Second * 2)
invokeQuery(network, peer, orderer, channel, 40)
time.Sleep(time.Second * 2)
invokeQuery(network, peer, orderer, channel, 30)
time.Sleep(time.Second * 2)
invokeQuery(network, peer, orderer, channel, 20)
time.Sleep(time.Second * 2)
invokeQuery(network, peer, orderer, channel, 10)

By("Submitting to orderer4")
invokeQuery(network, peer, network.Orderers[3], channel, 0)
assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, peer, network)

By("Ensuring follower participates in consensus")
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Deciding on seq 14"))
})

It("smartbft assisted synchronization no rotation with simple replication policy", func() {
networkConfig := nwo.MultiNodeSmartBFT()
networkConfig.Channels = nil
channel := "testchannel1"

network = nwo.New(networkConfig, testDir, client, StartPort(), components)
network.OrdererReplicationPolicy = "simple"
network.GenerateConfigTree()
network.Bootstrap()

var ordererRunners []*ginkgomon.Runner
for _, orderer := range network.Orderers {
runner := network.OrdererRunner(orderer)
runner.Command.Env = append(runner.Command.Env, "FABRIC_LOGGING_SPEC=orderer.consensus.smartbft=debug:grpc=debug")
ordererRunners = append(ordererRunners, runner)
proc := ifrit.Invoke(runner)
ordererProcesses = append(ordererProcesses, proc)
Eventually(proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
}

peerGroupRunner, _ := peerGroupRunners(network)
peerProcesses = ifrit.Invoke(peerGroupRunner)
Eventually(peerProcesses.Ready(), network.EventuallyTimeout).Should(BeClosed())
peer := network.Peer("Org1", "peer0")

By("Join channel")
joinChannel(network, channel)

By("Waiting for followers to see the leader")
Eventually(ordererRunners[1].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))
Eventually(ordererRunners[2].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))
Eventually(ordererRunners[3].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))

orderer := network.Orderers[0]

By("Joining peers to testchannel1")
network.JoinChannel(channel, network.Orderers[0], network.PeersWithChannel(channel)...)

assertBlockReception(map[string]int{"testchannel1": 0}, network.Orderers, peer, network)

By("Restarting all nodes")
for i := 0; i < 4; i++ {
orderer := network.Orderers[i]
By(fmt.Sprintf("Killing %s", orderer.Name))
ordererProcesses[i].Signal(syscall.SIGTERM)
Eventually(ordererProcesses[i].Wait(), network.EventuallyTimeout).Should(Receive())

By(fmt.Sprintf("Launching %s", orderer.Name))
runner := network.OrdererRunner(orderer)
runner.Command.Env = append(runner.Command.Env, "FABRIC_LOGGING_SPEC=orderer.consensus.smartbft=debug:policies.ImplicitOrderer=debug")
ordererRunners[i] = runner
proc := ifrit.Invoke(runner)
ordererProcesses[i] = proc
Eventually(proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
}

By("Deploying chaincode")
deployChaincode(network, channel, testDir)

assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network)

By("Taking down a follower node")
ordererProcesses[3].Signal(syscall.SIGTERM)
Eventually(ordererProcesses[3].Wait(), network.EventuallyTimeout).Should(Receive())

invokeQuery(network, peer, orderer, channel, 90)
invokeQuery(network, peer, orderer, channel, 80)
invokeQuery(network, peer, orderer, channel, 70)
invokeQuery(network, peer, orderer, channel, 60)

By("Bringing up the follower node")
runner := network.OrdererRunner(network.Orderers[3])
runner.Command.Env = append(runner.Command.Env, "FABRIC_LOGGING_SPEC=orderer.consensus.smartbft=debug:orderer.common.cluster.puller=debug")
proc := ifrit.Invoke(runner)
ordererProcesses[3] = proc
Eventually(proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Starting view with number 0, sequence 5"))
By("Verifying the simple replication policy is used")
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Simple Sync initiated"))

By("Waiting communication to be established from the leader")
Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1"))
Expand Down
1 change: 1 addition & 0 deletions orderer/consensus/smartbft/synchronizer.go
Expand Up @@ -38,6 +38,7 @@ type Synchronizer struct {

// Sync synchronizes blocks and returns the response
func (s *Synchronizer) Sync() types.SyncResponse {
s.Logger.Debug("Simple Sync initiated")
decision, err := s.synchronize()
if err != nil {
s.Logger.Warnf("Could not synchronize with remote peers due to %s, returning state from local ledger", err)
Expand Down
1 change: 1 addition & 0 deletions orderer/consensus/smartbft/synchronizer_bft.go
Expand Up @@ -45,6 +45,7 @@ type BFTSynchronizer struct {
}

func (s *BFTSynchronizer) Sync() types.SyncResponse {
s.Logger.Debug("BFT Sync initiated")
decision, err := s.synchronize()
if err != nil {
s.Logger.Warnf("Could not synchronize with remote orderers due to %s, returning state from local ledger", err)
Expand Down