Skip to content

Commit

Permalink
[FAB-11894] State request to request open range
Browse files Browse the repository at this point in the history
This commit changes the way gossip creates state requests, it avoids to
send state request which considers peers ledger height as next available
block sequence number to request from remote. UT is adjasted
accordingly.

Change-Id: Ic8991c268c2411740940c7804d2b6f53dfaf2358
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Sep 6, 2018
1 parent de6c840 commit ec77fc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
10 changes: 5 additions & 5 deletions gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func (s *GossipStateProviderImpl) antiEntropy() {
continue
}

s.requestBlocksInRange(uint64(ourHeight), uint64(maxHeight))
s.requestBlocksInRange(uint64(ourHeight), uint64(maxHeight)-1)
}
}
}
Expand All @@ -619,7 +619,7 @@ func (s *GossipStateProviderImpl) maxAvailableLedgerHeight() uint64 {
}

// GetBlocksInRange capable to acquire blocks with sequence
// numbers in the range [start...end].
// numbers in the range [start...end).
func (s *GossipStateProviderImpl) requestBlocksInRange(start uint64, end uint64) {
atomic.StoreInt32(&s.stateTransferActive, 1)
defer atomic.StoreInt32(&s.stateTransferActive, 0)
Expand All @@ -634,19 +634,19 @@ func (s *GossipStateProviderImpl) requestBlocksInRange(start uint64, end uint64)

for !responseReceived {
if tryCounts > defAntiEntropyMaxRetries {
logger.Warningf("Wasn't able to get blocks in range [%d...%d], after %d retries",
logger.Warningf("Wasn't able to get blocks in range [%d...%d), after %d retries",
prev, next, tryCounts)
return
}
// Select peers to ask for blocks
peer, err := s.selectPeerToRequestFrom(next)
if err != nil {
logger.Warningf("Cannot send state request for blocks in range [%d...%d], due to %+v",
logger.Warningf("Cannot send state request for blocks in range [%d...%d), due to %+v",
prev, next, errors.WithStack(err))
return
}

logger.Debugf("State transfer, with peer %s, requesting blocks in range [%d...%d], "+
logger.Debugf("State transfer, with peer %s, requesting blocks in range [%d...%d), "+
"for chainID %s", peer.Endpoint, prev, next, s.chainID)

s.mediator.Send(gossipMsg, peer)
Expand Down
15 changes: 2 additions & 13 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {

for i := 0; i < bootstrapSetSize; i++ {
commit := newCommitter()
bootstrapSet = append(bootstrapSet, newPeerNode(newGossipConfig(portPrefix, i), commit, noopPeerIdentityAcceptor))
bootstrapSet = append(bootstrapSet, newPeerNode(newGossipConfig(portPrefix, i, 0, 1, 2, 3, 4), commit, noopPeerIdentityAcceptor))
}

defer func() {
Expand Down Expand Up @@ -1541,17 +1541,6 @@ func TestTransferOfPvtDataBetweenPeers(t *testing.T) {
peers["peer1"].coord.On("GetPvtDataAndBlockByNum", uint64(2)).Return(&pcomm.Block{
Header: &pcomm.BlockHeader{
Number: 2,
DataHash: []byte{0, 1, 1, 1},
PreviousHash: []byte{0, 0, 0, 1},
},
Data: &pcomm.BlockData{
Data: [][]byte{{1}, {2}, {3}},
},
}, gutil.PvtDataCollections{}, nil)

peers["peer1"].coord.On("GetPvtDataAndBlockByNum", uint64(3)).Return(&pcomm.Block{
Header: &pcomm.BlockHeader{
Number: 3,
DataHash: []byte{0, 0, 0, 1},
PreviousHash: []byte{0, 1, 1, 1},
},
Expand Down Expand Up @@ -1620,7 +1609,7 @@ func TestTransferOfPvtDataBetweenPeers(t *testing.T) {
})

wg := sync.WaitGroup{}
wg.Add(2)
wg.Add(1)
peers["peer2"].coord.On("StoreBlock", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
wg.Done() // Done once second peer hits commit of the block
}).Return([]string{}, nil) // No pvt data to complete and no error
Expand Down

0 comments on commit ec77fc5

Please sign in to comment.