Skip to content

Commit 4a179d3

Browse files
authored
BFT Block Puller: block deliverer, connection source (#4258)
- Introduce an abstraction BlockDeliverer that can CFT/BFT implementations - Expose ConnectionSource method Endpoints Change-Id: I4c2d9b8f74a4004d55e779438e41e7a80b274504 Signed-off-by: Yoav Tock <[email protected]>
1 parent 288e093 commit 4a179d3

File tree

6 files changed

+103
-31
lines changed

6 files changed

+103
-31
lines changed

core/deliverservice/deliveryclient.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@ type DeliverService interface {
4141
Stop()
4242
}
4343

44+
// BlockDeliverer communicates with orderers to obtain new blocks and send them to the committer service, for a
45+
// specific channel. It can be implemented using different protocols depending on the ordering service consensus type,
46+
// e.g CFT (etcdraft) or BFT (SmartBFT).
47+
type BlockDeliverer interface {
48+
Stop()
49+
DeliverBlocks()
50+
}
51+
4452
// deliverServiceImpl the implementation of the delivery service
4553
// maintains connection to the ordering service and maps of
4654
// blocks providers
4755
type deliverServiceImpl struct {
4856
conf *Config
49-
blockProviders map[string]*blocksprovider.Deliverer
57+
blockProviders map[string]BlockDeliverer
5058
lock sync.RWMutex
5159
stopping bool
5260
}
@@ -78,7 +86,7 @@ type Config struct {
7886
func NewDeliverService(conf *Config) DeliverService {
7987
ds := &deliverServiceImpl{
8088
conf: conf,
81-
blockProviders: make(map[string]*blocksprovider.Deliverer),
89+
blockProviders: make(map[string]BlockDeliverer),
8290
}
8391
return ds
8492
}

core/deliverservice/deliveryclient_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ eUCutqn1KYDMYh54i6p723cXbdDkmvL2UCciHyHdSWS9lmkKVdyNGIJ6
7777
}
7878

7979
bp, ok := ds.blockProviders["channel-id"]
80+
bpd := bp.(*blocksprovider.Deliverer)
8081
require.True(t, ok, "map entry must exist")
81-
require.Equal(t, "76f7a03f8dfdb0ef7c4b28b3901fe163c730e906c70e4cdf887054ad5f608bed", fmt.Sprintf("%x", bp.TLSCertHash))
82+
require.Equal(t, "76f7a03f8dfdb0ef7c4b28b3901fe163c730e906c70e4cdf887054ad5f608bed", fmt.Sprintf("%x", bpd.TLSCertHash))
8283
})
8384

8485
t.Run("Green Path without mutual TLS", func(t *testing.T) {
@@ -99,8 +100,9 @@ eUCutqn1KYDMYh54i6p723cXbdDkmvL2UCciHyHdSWS9lmkKVdyNGIJ6
99100
}
100101

101102
bp, ok := ds.blockProviders["channel-id"]
103+
bpd := bp.(*blocksprovider.Deliverer)
102104
require.True(t, ok, "map entry must exist")
103-
require.Nil(t, bp.TLSCertHash)
105+
require.Nil(t, bpd.TLSCertHash)
104106
})
105107

106108
t.Run("Exists", func(t *testing.T) {
@@ -131,11 +133,11 @@ func TestStopDeliverForChannel(t *testing.T) {
131133
t.Run("Green path", func(t *testing.T) {
132134
ds := NewDeliverService(&Config{}).(*deliverServiceImpl)
133135
doneA := make(chan struct{})
134-
ds.blockProviders = map[string]*blocksprovider.Deliverer{
135-
"a": {
136+
ds.blockProviders = map[string]BlockDeliverer{
137+
"a": &blocksprovider.Deliverer{
136138
DoneC: doneA,
137139
},
138-
"b": {
140+
"b": &blocksprovider.Deliverer{
139141
DoneC: make(chan struct{}),
140142
},
141143
}
@@ -153,11 +155,11 @@ func TestStopDeliverForChannel(t *testing.T) {
153155

154156
t.Run("Already stopping", func(t *testing.T) {
155157
ds := NewDeliverService(&Config{}).(*deliverServiceImpl)
156-
ds.blockProviders = map[string]*blocksprovider.Deliverer{
157-
"a": {
158+
ds.blockProviders = map[string]BlockDeliverer{
159+
"a": &blocksprovider.Deliverer{
158160
DoneC: make(chan struct{}),
159161
},
160-
"b": {
162+
"b": &blocksprovider.Deliverer{
161163
DoneC: make(chan struct{}),
162164
},
163165
}
@@ -169,11 +171,11 @@ func TestStopDeliverForChannel(t *testing.T) {
169171

170172
t.Run("Non-existent", func(t *testing.T) {
171173
ds := NewDeliverService(&Config{}).(*deliverServiceImpl)
172-
ds.blockProviders = map[string]*blocksprovider.Deliverer{
173-
"a": {
174+
ds.blockProviders = map[string]BlockDeliverer{
175+
"a": &blocksprovider.Deliverer{
174176
DoneC: make(chan struct{}),
175177
},
176-
"b": {
178+
"b": &blocksprovider.Deliverer{
177179
DoneC: make(chan struct{}),
178180
},
179181
}
@@ -185,18 +187,19 @@ func TestStopDeliverForChannel(t *testing.T) {
185187

186188
func TestStop(t *testing.T) {
187189
ds := NewDeliverService(&Config{}).(*deliverServiceImpl)
188-
ds.blockProviders = map[string]*blocksprovider.Deliverer{
189-
"a": {
190+
ds.blockProviders = map[string]BlockDeliverer{
191+
"a": &blocksprovider.Deliverer{
190192
DoneC: make(chan struct{}),
191193
},
192-
"b": {
194+
"b": &blocksprovider.Deliverer{
193195
DoneC: make(chan struct{}),
194196
},
195197
}
196198
require.False(t, ds.stopping)
197199
for _, bp := range ds.blockProviders {
200+
bpd := bp.(*blocksprovider.Deliverer)
198201
select {
199-
case <-bp.DoneC:
202+
case <-bpd.DoneC:
200203
require.Fail(t, "block providers should not be closed")
201204
default:
202205
}
@@ -206,8 +209,9 @@ func TestStop(t *testing.T) {
206209
require.True(t, ds.stopping)
207210
require.Len(t, ds.blockProviders, 2)
208211
for _, bp := range ds.blockProviders {
212+
bpd := bp.(*blocksprovider.Deliverer)
209213
select {
210-
case <-bp.DoneC:
214+
case <-bpd.DoneC:
211215
default:
212216
require.Fail(t, "block providers should te closed")
213217
}

internal/pkg/peer/blocksprovider/blocksprovider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type BlockVerifier interface {
7676
//go:generate counterfeiter -o fake/orderer_connection_source.go --fake-name OrdererConnectionSource . OrdererConnectionSource
7777
type OrdererConnectionSource interface {
7878
RandomEndpoint() (*orderers.Endpoint, error)
79+
Endpoints() []*orderers.Endpoint
7980
}
8081

8182
//go:generate counterfeiter -o fake/dialer.go --fake-name Dialer . Dialer

internal/pkg/peer/blocksprovider/fake/orderer_connection_source.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/pkg/peer/orderers/connection.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ func (cs *ConnectionSource) RandomEndpoint() (*Endpoint, error) {
5353
return cs.allEndpoints[rand.Intn(len(cs.allEndpoints))], nil
5454
}
5555

56+
func (cs *ConnectionSource) Endpoints() []*Endpoint {
57+
cs.mutex.RLock()
58+
defer cs.mutex.RUnlock()
59+
60+
return cs.allEndpoints
61+
}
62+
5663
func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]OrdererOrg) {
5764
cs.mutex.Lock()
5865
defer cs.mutex.Unlock()

internal/pkg/peer/orderers/connection_internal_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)