Skip to content

Commit

Permalink
Remove write lock option from the xsvm API (#2152)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Oct 11, 2023
1 parent 1bc63d4 commit 8247f74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 6 additions & 1 deletion vms/example/xsvm/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func (s *server) IssueTx(r *http.Request, args *IssueTxArgs, reply *IssueTxReply
}

ctx := r.Context()
if err := s.builder.AddTx(ctx, newTx); err != nil {
s.ctx.Lock.Lock()
err = s.builder.AddTx(ctx, newTx)
s.ctx.Lock.Unlock()
if err != nil {
return err
}

Expand All @@ -150,7 +153,9 @@ type LastAcceptedReply struct {
}

func (s *server) LastAccepted(_ *http.Request, _ *struct{}, reply *LastAcceptedReply) error {
s.ctx.Lock.RLock()
reply.BlockID = s.chain.LastAccepted()
s.ctx.Lock.RUnlock()
blkBytes, err := state.GetBlock(s.state, reply.BlockID)
if err != nil {
return err
Expand Down
9 changes: 3 additions & 6 deletions vms/example/xsvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (*VM) CreateStaticHandlers(context.Context) (map[string]*common.HTTPHandler
return nil, nil
}

func (vm *VM) CreateHandlers(_ context.Context) (map[string]*common.HTTPHandler, error) {
func (vm *VM) CreateHandlers(context.Context) (map[string]*common.HTTPHandler, error) {
server := rpc.NewServer()
server.RegisterCodec(json.NewCodec(), "application/json")
server.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
Expand All @@ -129,15 +129,12 @@ func (vm *VM) CreateHandlers(_ context.Context) (map[string]*common.HTTPHandler,
vm.chain,
vm.builder,
)
if err := server.RegisterService(api, Name); err != nil {
return nil, err
}
return map[string]*common.HTTPHandler{
"": {
LockOptions: common.WriteLock,
LockOptions: common.NoLock,
Handler: server,
},
}, nil
}, server.RegisterService(api, Name)
}

func (*VM) HealthCheck(context.Context) (interface{}, error) {
Expand Down

0 comments on commit 8247f74

Please sign in to comment.