Skip to content

Commit 0f95f13

Browse files
Remove write lock option from the avm wallet API (#2155)
1 parent e6dab5d commit 0f95f13

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

vms/avm/vm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]*common.HTTPHandler, e
342342

343343
return map[string]*common.HTTPHandler{
344344
"": {Handler: rpcServer},
345-
"/wallet": {Handler: walletServer},
345+
"/wallet": {LockOptions: common.NoLock, Handler: walletServer},
346346
"/events": {LockOptions: common.NoLock, Handler: vm.pubsub},
347347
}, err
348348
}

vms/avm/wallet_service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (w *WalletService) IssueTx(_ *http.Request, args *api.FormattedTx, reply *a
141141
if err != nil {
142142
return fmt.Errorf("problem decoding transaction: %w", err)
143143
}
144+
145+
w.vm.ctx.Lock.Lock()
146+
defer w.vm.ctx.Lock.Unlock()
147+
144148
txID, err := w.issue(txBytes)
145149
reply.TxID = txID
146150
return err
@@ -179,6 +183,9 @@ func (w *WalletService) SendMultiple(_ *http.Request, args *SendMultipleArgs, re
179183
return fmt.Errorf("couldn't parse 'From' addresses: %w", err)
180184
}
181185

186+
w.vm.ctx.Lock.Lock()
187+
defer w.vm.ctx.Lock.Unlock()
188+
182189
// Load user's UTXOs/keys
183190
utxos, kc, err := w.vm.LoadUser(args.Username, args.Password, fromAddrs)
184191
if err != nil {

vms/avm/wallet_service_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func TestWalletService_SendMultiple(t *testing.T) {
2525
initialKeys: keys,
2626
}},
2727
})
28+
env.vm.ctx.Lock.Unlock()
29+
2830
defer func() {
2931
require.NoError(env.vm.Shutdown(context.Background()))
3032
env.vm.ctx.Lock.Unlock()
@@ -65,6 +67,8 @@ func TestWalletService_SendMultiple(t *testing.T) {
6567
require.NoError(env.walletService.SendMultiple(nil, args, reply))
6668
require.Equal(changeAddrStr, reply.ChangeAddr)
6769

70+
env.vm.ctx.Lock.Lock()
71+
6872
buildAndAccept(require, env.vm, env.issuer, reply.TxID)
6973

7074
_, err = env.vm.state.GetTx(reply.TxID)

0 commit comments

Comments
 (0)