Skip to content

Commit dc7d4d4

Browse files
gennadylaventmanC0rWin
authored andcommitted
[FAB-2576] Mock committer ledger height
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 <[email protected]> Signed-off-by: Artem Barger <[email protected]>
1 parent ed7ed80 commit dc7d4d4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

gossip/service/gossip_service_test.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ limitations under the License.
1717
package service
1818

1919
import (
20+
"bytes"
2021
"fmt"
2122
"net"
2223
"sync"
2324
"testing"
24-
25-
"bytes"
2625
"time"
2726

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

122-
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
123-
gossips[i].(*gossipServiceImpl).chains[channelName].Stop()
121+
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
124122
service, exist := gossips[i].(*gossipServiceImpl).leaderElection[channelName]
125123
assert.True(t, exist, "Leader election service should be created for peer %d and channel %s", i, channelName)
126124
services[i] = &electionService{nil, false, 0}
@@ -176,8 +174,7 @@ func TestWithStaticDeliverClientLeader(t *testing.T) {
176174
for i := 0; i < n; i++ {
177175
gossips[i].(*gossipServiceImpl).deliveryFactory = deliverServiceFactory
178176
deliverServiceFactory.service.running[channelName] = false
179-
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{0}, []string{"localhost:5005"})
180-
gossips[i].(*gossipServiceImpl).chains[channelName].Stop()
177+
gossips[i].InitializeChannel(channelName, &mockLedgerInfo{1}, []string{"localhost:5005"})
181178
}
182179

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

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

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

@@ -626,7 +622,7 @@ func newGossipInstance(portPrefix int, id int, maxMsgCount int, boot ...int) Gos
626622
func bootPeers(portPrefix int, ids ...int) []string {
627623
peers := []string{}
628624
for _, id := range ids {
629-
peers = append(peers, fmt.Sprintf("localhost:%d", (id+portPrefix)))
625+
peers = append(peers, fmt.Sprintf("localhost:%d", id+portPrefix))
630626
}
631627
return peers
632628
}

0 commit comments

Comments
 (0)