Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion platform/fabric/core/generic/ordering/bft.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ func (o *BFTBroadcaster) getConnection(ctx context.Context, to *grpc.ConnectionC
return nil, errors.Wrapf(err, "failed to new a broadcast, rpcStatus=%+v", rpcStatus)
}

stream, err := oClient.Broadcast(ctx)
// Get the broadcast stream to receive a reply of Acknowledgement for each common.Envelope in order, indicating success or type of failure.
// Notice that this stream is shared, therefore its context must be something different from the context of the current broadcast request
stream, err := oClient.Broadcast(context.Background())
if err != nil {
client.Close()
return nil, errors.Wrapf(err, "failed creating orderer stream for %s", to.Address)
Expand Down
4 changes: 3 additions & 1 deletion platform/fabric/core/generic/ordering/cft.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ func (o *CFTBroadcaster) getConnection(ctx context.Context) (*Connection, error)
return nil, errors.Wrapf(err, "failed to new a broadcast for %s, rpcStatus=%+v", to.Address, rpcStatus)
}

stream, err := oClient.Broadcast(ctx)
// Get the broadcast stream to receive a reply of Acknowledgement for each common.Envelope in order, indicating success or type of failure.
// Notice that this stream is shared, therefore its context must be something different from the context of the current broadcast request
stream, err := oClient.Broadcast(context.Background())
if err != nil {
client.Close()
return nil, errors.Wrapf(err, "failed creating orderer stream for %s", to.Address)
Expand Down
10 changes: 3 additions & 7 deletions platform/view/services/view/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,10 @@ func (cm *Manager) InitiateView(view view.View, ctx context.Context) (interface{
}

func (cm *Manager) InitiateViewWithIdentity(view view.View, id view.Identity, ctx context.Context) (interface{}, error) {
// Get the managers context
cm.contextsMu.Lock()
cctx := cm.ctx
cm.contextsMu.Unlock()
if cctx == nil {
cctx = context.Background()
if ctx == nil {
ctx = cm.getCurrentContext()
}
ctx = trace.ContextWithSpanContext(cctx, trace.SpanContextFromContext(ctx))
ctx = trace.ContextWithSpanContext(ctx, trace.SpanContextFromContext(ctx))
viewContext, err := NewContextForInitiator(
"",
ctx,
Expand Down
25 changes: 24 additions & 1 deletion platform/view/services/view/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils"
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics/disabled"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/mock"
Expand Down Expand Up @@ -50,6 +51,18 @@ func (a DummyView) Call(context view.Context) (interface{}, error) {
return nil, nil
}

type ContextKey string

type DummyViewContextCheck struct{}

func (a DummyViewContextCheck) Call(ctx view.Context) (interface{}, error) {
v, ok := ctx.Context().Value(ContextKey("test")).(string)
if !ok {
return nil, errors.Errorf("context value %s not found", ContextKey("test"))
}
return v, nil
}

type DummyFactory struct{}

func (d *DummyFactory) NewView(in []byte) (view.View, error) {
Expand Down Expand Up @@ -93,10 +106,11 @@ func TestManagerRace(t *testing.T) {

wg := &sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(7)
wg.Add(8)
go registerFactory(t, wg, manager)
go newView(t, wg, manager)
go callView(t, wg, manager)
go callViewWithAugmentedContext(t, wg, manager)
go getContext(t, wg, manager)
go initiateView(t, wg, manager)
go start(t, wg, manager, ctx)
Expand Down Expand Up @@ -153,6 +167,15 @@ func callView(t *testing.T, wg *sync.WaitGroup, m Manager) {
assert.NoError(t, err)
}

func callViewWithAugmentedContext(t *testing.T, wg *sync.WaitGroup, m Manager) {
ctx := context.Background()
ctx = context.WithValue(ctx, ContextKey("test"), "pineapple")
v, err := m.InitiateView(&DummyViewContextCheck{}, ctx)
wg.Done()
assert.NoError(t, err)
assert.Equal(t, "pineapple", v)
}

func newView(t *testing.T, wg *sync.WaitGroup, m Manager) {
_, err := m.NewView(utils.GenerateUUID(), nil)
wg.Done()
Expand Down