Skip to content

Commit

Permalink
[FAB-2576] Mock committer ledger height
Browse files Browse the repository at this point in the history
The reason mockLedgerInfo should be initialized with 1 instead of 0, is
because the state transfer expected to get the ledger with at least one
block committed. Which is the case in reality, since to create a ledger
you need to receive genesis block and genesis block committed right
away.

Without this assumption since blocks sequence uses uint64 there is an
overflow to -1 which cause anti entropy procedure to request big bulk of
blocks and extensive memory footprint.

Change-Id: Id836b20d8be474a5fef492d3082f5878e87aa738
Signed-off-by: Gennady Laventman <gennady@il.ibm.com>
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
gennadylaventman authored and C0rWin committed Mar 6, 2017
1 parent ed7ed80 commit dc7d4d4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions gossip/service/gossip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ limitations under the License.
package service

import (
"bytes"
"fmt"
"net"
"sync"
"testing"

"bytes"
"time"

"github.com/hyperledger/fabric/common/localmsp"
Expand Down Expand Up @@ -119,8 +118,7 @@ func TestLeaderElectionWithDeliverClient(t *testing.T) {
gossips[i].(*gossipServiceImpl).deliveryFactory = deliverServiceFactory
deliverServiceFactory.service.running[channelName] = false

gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
gossips[i].(*gossipServiceImpl).chains[channelName].Stop()
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
service, exist := gossips[i].(*gossipServiceImpl).leaderElection[channelName]
assert.True(t, exist, "Leader election service should be created for peer %d and channel %s", i, channelName)
services[i] = &electionService{nil, false, 0}
Expand Down Expand Up @@ -176,8 +174,7 @@ func TestWithStaticDeliverClientLeader(t *testing.T) {
for i := 0; i < n; i++ {
gossips[i].(*gossipServiceImpl).deliveryFactory = deliverServiceFactory
deliverServiceFactory.service.running[channelName] = false
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
gossips[i].(*gossipServiceImpl).chains[channelName].Stop()
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
}

for i := 0; i < n; i++ {
Expand All @@ -188,7 +185,7 @@ func TestWithStaticDeliverClientLeader(t *testing.T) {
channelName = "chanB"
for i := 0; i < n; i++ {
deliverServiceFactory.service.running[channelName] = false
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
}

for i := 0; i < n; i++ {
Expand Down Expand Up @@ -225,8 +222,7 @@ func TestWithStaticDeliverClientNotLeader(t *testing.T) {
for i := 0; i < n; i++ {
gossips[i].(*gossipServiceImpl).deliveryFactory = deliverServiceFactory
deliverServiceFactory.service.running[channelName] = false
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
gossips[i].(*gossipServiceImpl).chains[channelName].Stop()
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
}

for i := 0; i < n; i++ {
Expand Down Expand Up @@ -263,7 +259,7 @@ func TestWithStaticDeliverClientBothStaticAndLeaderElection(t *testing.T) {
for i := 0; i < n; i++ {
gossips[i].(*gossipServiceImpl).deliveryFactory = deliverServiceFactory
assert.Panics(t, func() {
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
}, "Dynamic leader lection based and static connection to ordering service can't exist simultaniosly")
}

Expand Down Expand Up @@ -626,7 +622,7 @@ func newGossipInstance(portPrefix int, id int, maxMsgCount int, boot ...int) Gos
func bootPeers(portPrefix int, ids ...int) []string {
peers := []string{}
for _, id := range ids {
peers = append(peers, fmt.Sprintf("localhost:%d", (id+portPrefix)))
peers = append(peers, fmt.Sprintf("localhost:%d", id+portPrefix))
}
return peers
}
Expand Down

0 comments on commit dc7d4d4

Please sign in to comment.