Skip to content
Closed
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
9 changes: 3 additions & 6 deletions integration/nwo/cmd/cryptogen/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ package metadata
import (
"fmt"
"runtime"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/metadata"
)

const ProgramName = "cryptogen"

var (
CommitSHA = metadata.CommitSHA
Version = metadata.Version
)
// Variables defined by the Makefile and passed in with ldflags
var Version = "latest"
var CommitSHA = "development build"

func GetVersionInfo() string {
return fmt.Sprintf(
Expand Down
3 changes: 1 addition & 2 deletions integration/nwo/cmd/cryptogen/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"

metadata2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/cmd/cryptogen/metadata"
"github.com/stretchr/testify/assert"
)

func TestGetVersionInfo(t *testing.T) {
Expand Down
6 changes: 2 additions & 4 deletions integration/nwo/fsc/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/pkg/node"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/storage/driver"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
"github.com/onsi/gomega"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
Expand All @@ -26,10 +27,7 @@ import (
type PersistenceKey string

// Factory is used to create instances of the View interface
type Factory interface {
// NewView returns an instance of the View interface build using the passed argument.
NewView(in []byte) (view.View, error)
}
type Factory = view2.Factory

type Options struct {
Mapping map[string]interface{}
Expand Down
5 changes: 3 additions & 2 deletions platform/view/sdk/dig/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
server2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/grpc/server"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/grpc/server/protos"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/web"
"go.uber.org/dig"
)

Expand Down Expand Up @@ -123,7 +124,7 @@ func (p *SDK) Install() error {
p.Container().Provide(view.NewManager),
p.Container().Provide(
digutils.Identity[*view.Manager](),
dig.As(new(StartableViewManager), new(server2.ViewManager)),
dig.As(new(web.ViewManager)),
),

// Comm service
Expand Down Expand Up @@ -207,7 +208,7 @@ func (p *SDK) Start(ctx context.Context) error {
return p.Container().Invoke(func(in struct {
dig.In
GRPCServer *grpc.GRPCServer
ViewManager StartableViewManager
ViewManager *view.Manager
ViewService server2.Service
CommService *comm.Service
WebServer Server
Expand Down
4 changes: 2 additions & 2 deletions platform/view/sdk/dig/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics/operations"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/storage/kvs"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/tracing"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/grpc/server"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
web2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/web"
web "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/web/server"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
Expand All @@ -33,7 +33,7 @@ type Server interface {
Stop() error
}

func NewWebServer(configProvider driver.ConfigService, viewManager server.ViewManager, tracerProvider tracing.Provider) Server {
func NewWebServer(configProvider driver.ConfigService, viewManager *view.Manager, tracerProvider tracing.Provider) Server {
if !configProvider.GetBool("fsc.web.enabled") {
logger.Info("web server not enabled")
return web.NewDummyServer()
Expand Down
23 changes: 0 additions & 23 deletions platform/view/sdk/dig/vm.go

This file was deleted.

11 changes: 0 additions & 11 deletions platform/view/sdk/metadata/metadata.go

This file was deleted.

43 changes: 29 additions & 14 deletions platform/view/services/view/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type ctx struct {
}

func NewContextForInitiator(
contextID string,
context context.Context,
contextID string,
sp services.Provider,
sessionFactory SessionFactory,
resolver EndpointService,
Expand Down Expand Up @@ -163,7 +163,7 @@ func (c *ctx) Initiator() view.View {
return c.initiator
}

func (c *ctx) RunView(v view.View, opts ...view.RunViewOption) (res interface{}, err error) {
func (c *ctx) RunView(v view.View, opts ...view.RunViewOption) (res any, err error) {
return runViewOn(v, opts, c)
}

Expand Down Expand Up @@ -250,11 +250,11 @@ func (c *ctx) ResetSessions() error {
return nil
}

func (c *ctx) PutService(service interface{}) error {
func (c *ctx) PutService(service any) error {
return c.localSP.RegisterService(service)
}

func (c *ctx) GetService(v interface{}) (interface{}, error) {
func (c *ctx) GetService(v any) (any, error) {
// first search locally then globally
s, err := c.localSP.GetService(v)
if err == nil {
Expand Down Expand Up @@ -378,7 +378,7 @@ func (c *tempCtx) Context() context.Context {
return c.newCtx
}

func runViewOn(v view.View, opts []view.RunViewOption, ctx localContext) (res interface{}, err error) {
func runViewOn(v view.View, opts []view.RunViewOption, parent localContext) (res any, err error) {
options, err := view.CompileRunViewOptions(opts...)
if err != nil {
return nil, errors.Wrap(err, "failed compiling options")
Expand All @@ -388,24 +388,39 @@ func runViewOn(v view.View, opts []view.RunViewOption, ctx localContext) (res in
initiator = v
}

logger.DebugfContext(ctx.Context(), "Start view %s", GetName(v))
newCtx, span := ctx.StartSpanFrom(ctx.Context(), GetName(v), tracing.WithAttributes(
tracing.String(ViewLabel, GetIdentifier(v)),
tracing.String(InitiatorViewLabel, GetIdentifier(initiator)),
), trace.WithSpanKind(trace.SpanKindInternal))
logger.DebugfContext(parent.Context(), "Start view %s", GetName(v))

// traces
newCtx, span := parent.StartSpanFrom(
parent.Context(),
GetName(v),
tracing.WithAttributes(
tracing.String(ViewLabel, GetIdentifier(v)),
tracing.String(InitiatorViewLabel, GetIdentifier(initiator)),
),
trace.WithSpanKind(trace.SpanKindInternal),
)
defer span.End()

// timeout
if options.Timeout > 0 {
ctxWithTimeout, cancel := context.WithTimeout(newCtx, options.Timeout)
defer cancel()
newCtx = ctxWithTimeout
}

var cc localContext
if options.SameContext {
cc = wrapContext(ctx, newCtx)
cc = wrapContext(parent, newCtx)
} else {
if options.AsInitiator {
cc = &childContext{
ParentContext: wrapContext(ctx, newCtx),
ParentContext: wrapContext(parent, newCtx),
initiator: initiator,
}

// register options.Session under initiator
contextSession := ctx.Session()
contextSession := parent.Session()
if contextSession == nil {
return nil, errors.Errorf("cannot convert a non-responder context to an initiator context")
}
Expand All @@ -414,7 +429,7 @@ func runViewOn(v view.View, opts []view.RunViewOption, ctx localContext) (res in
}
} else {
cc = &childContext{
ParentContext: wrapContext(ctx, newCtx),
ParentContext: wrapContext(parent, newCtx),
session: options.Session,
initiator: initiator,
}
Expand Down
6 changes: 6 additions & 0 deletions platform/view/services/view/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ type Factory interface {
// NewView returns an instance of the View interface build using the passed argument.
NewView(in []byte) (view.View, error)
}

// LocalFactory is used to create instances of the View interface
type LocalFactory interface {
// NewViewWithArg returns an instance of the View interface build using the passed argument.
NewViewWithArg(arg any) (view.View, error)
}
4 changes: 2 additions & 2 deletions platform/view/services/view/grpc/client/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (n *LocalClient) CallView(fid string, in []byte) (interface{}, error) {
return nil, errors.Wrapf(err, "failed getting view manager [%s]", fid)
}
span.AddEvent("start_new_view")
f, err := manager.NewView(fid, in)
f, err := manager.Registry().NewView(fid, in)
span.AddEvent("end_new_view")
if err != nil {
return nil, errors.Wrapf(err, "failed instantiating view [%s]", fid)
}
span.AddEvent("start_initiate_view")
result, err := manager.InitiateView(f, ctx)
result, err := manager.InitiateView(ctx, f)
span.AddEvent("end_initiate_view")
if err != nil {
return nil, errors.Wrapf(err, "failed running view [%s]", fid)
Expand Down
25 changes: 16 additions & 9 deletions platform/view/services/view/grpc/server/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ import (

"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/tracing"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/grpc/server/protos"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/trace"
)

const fidLabel tracing.LabelName = "fid"

type Manager interface {
Context() context.Context
NewView(id string, in []byte) (view.View, error)
InitiateView(ctx context.Context, view view.View) (interface{}, error)
InitiateContext(parent context.Context, view view.View) (view.Context, error)
}

type viewHandler struct {
viewManager ViewManager
viewManager Manager
tracer trace.Tracer
}

func InstallViewHandler(viewManager ViewManager, server Service, tracerProvider tracing.Provider) {
func InstallViewHandler(viewManager Manager, server Service, tracerProvider trace.TracerProvider) {
fh := &viewHandler{
viewManager: viewManager,
tracer: tracerProvider.Tracer("view_handler", tracing.WithMetricsOpts(tracing.MetricsOpts{
Expand Down Expand Up @@ -74,7 +81,7 @@ func (s *viewHandler) callView(ctx context.Context, command *protos.Command) (in
return nil, errors.Errorf("failed instantiating view [%s], err [%s]", fid, err)
}
logger.DebugfContext(ctx, "Initiate new view")
result, err := s.viewManager.InitiateView(f, ctx)
result, err := s.viewManager.InitiateView(ctx, f)

if err != nil {
return nil, errors.Errorf("failed running view [%s], err %s", fid, err)
Expand Down Expand Up @@ -104,11 +111,11 @@ func (s *viewHandler) streamCallView(sc *protos.SignedCommand, command *protos.C
if err != nil {
return errors.Errorf("failed instantiating view [%s], err [%s]", fid, err)
}
context, err := s.viewManager.InitiateContext(f)
context, err := s.viewManager.InitiateContext(s.viewManager.Context(), f)
if err != nil {
return errors.Errorf("failed running view [%s], err %s", fid, err)
}
mutable, ok := context.(view2.MutableContext)
mutable, ok := context.(view.MutableContext)
if !ok {
return errors.Errorf("expected a mutable contexdt")
}
Expand Down Expand Up @@ -142,8 +149,8 @@ func (s *viewHandler) streamCallView(sc *protos.SignedCommand, command *protos.C
return commandServer.Send(cr)
}

func (s *viewHandler) RunView(manager ViewManager, view view2.View) (string, error) {
context, err := manager.InitiateContext(view)
func (s *viewHandler) RunView(manager Manager, view view.View) (string, error) {
context, err := manager.InitiateContext(manager.Context(), view)
if err != nil {
return "", err
}
Expand All @@ -154,7 +161,7 @@ func (s *viewHandler) RunView(manager ViewManager, view view2.View) (string, err
return context.ID(), nil
}

func (s *viewHandler) runView(view view2.View, context view2.Context) {
func (s *viewHandler) runView(view view.View, context view.Context) {
result, err := context.RunView(view)
if err != nil {
logger.Errorf("failed view execution. Err [%s]\n", err.Error())
Expand Down
Loading
Loading