Browse Source

evidence: reactor constructor (#7533)

pull/7534/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
ae7a76a175
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 12 deletions
  1. +9
    -3
      internal/evidence/reactor.go
  2. +9
    -2
      internal/evidence/reactor_test.go
  3. +6
    -7
      node/setup.go

+ 9
- 3
internal/evidence/reactor.go View File

@ -61,11 +61,17 @@ type Reactor struct {
// service.Service interface. It accepts a p2p Channel dedicated for handling
// envelopes with EvidenceList messages.
func NewReactor(
ctx context.Context,
logger log.Logger,
evidenceCh *p2p.Channel,
chCreator p2p.ChannelCreator,
peerUpdates *p2p.PeerUpdates,
evpool *Pool,
) *Reactor {
) (*Reactor, error) {
evidenceCh, err := chCreator(ctx, GetChannelDescriptor())
if err != nil {
return nil, err
}
r := &Reactor{
logger: logger,
evpool: evpool,
@ -75,7 +81,7 @@ func NewReactor(
}
r.BaseService = *service.NewBaseService(logger, "Evidence", r)
return r
return r, err
}
// OnStart starts separate go routines for each p2p Channel and listens for


+ 9
- 2
internal/evidence/reactor_test.go View File

@ -89,10 +89,17 @@ func setup(ctx context.Context, t *testing.T, stateStores []sm.Store, chBuf uint
rts.network.Nodes[nodeID].PeerManager.Register(ctx, rts.peerUpdates[nodeID])
rts.nodes = append(rts.nodes, rts.network.Nodes[nodeID])
rts.reactors[nodeID] = evidence.NewReactor(logger,
rts.evidenceChannels[nodeID],
chCreator := func(ctx context.Context, chdesc *p2p.ChannelDescriptor) (*p2p.Channel, error) {
return rts.evidenceChannels[nodeID], nil
}
rts.reactors[nodeID], err = evidence.NewReactor(
ctx,
logger,
chCreator,
rts.peerUpdates[nodeID],
rts.pools[nodeID])
require.NoError(t, err)
require.NoError(t, rts.reactors[nodeID].Start(ctx))
require.True(t, rts.reactors[nodeID].IsRunning())


+ 6
- 7
node/setup.go View File

@ -229,17 +229,16 @@ func createEvidenceReactor(
return nil, nil, fmt.Errorf("creating evidence pool: %w", err)
}
ch, err := router.OpenChannel(ctx, evidence.GetChannelDescriptor())
if err != nil {
return nil, nil, fmt.Errorf("creating evidence channel: %w", err)
}
evidenceReactor := evidence.NewReactor(
evidenceReactor, err := evidence.NewReactor(
ctx,
logger,
ch,
router.OpenChannel,
peerManager.Subscribe(ctx),
evidencePool,
)
if err != nil {
return nil, nil, fmt.Errorf("creating evidence reactor: %w", err)
}
return evidenceReactor, evidencePool, nil
}


Loading…
Cancel
Save