Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 20, 2023
1 parent 6a16844 commit 677629a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) {
_, ok := env.mempool.Get(txID)
require.True(ok)

env.ctx.Lock.Lock()
defer env.ctx.Lock.Unlock()

var (
now = env.backend.Clk.Time()
nextTime = now.Add(2 * txexecutor.SyncBound)
Expand All @@ -267,8 +270,6 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) {
// Advance wall clock to [nextTime] + [txexecutor.SyncBound]
env.backend.Clk.Set(nextTime.Add(txexecutor.SyncBound))

env.ctx.Lock.Lock()
defer env.ctx.Lock.Unlock()
// [BuildBlock] should build a block advancing the time to [nextTime],
// not the current wall clock.
blkIntf, err := env.Builder.BuildBlock(context.Background())
Expand Down
25 changes: 14 additions & 11 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,6 @@ func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
return err
Expand Down Expand Up @@ -1282,6 +1280,8 @@ func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply
reply.TxID = tx.ID()
reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -1344,7 +1344,6 @@ func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
Expand Down Expand Up @@ -1392,6 +1391,8 @@ func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply
reply.TxID = tx.ID()
reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -1451,7 +1452,6 @@ func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidator
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
Expand Down Expand Up @@ -1498,6 +1498,8 @@ func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidator
response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -1534,7 +1536,6 @@ func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, respon
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
Expand Down Expand Up @@ -1574,6 +1575,8 @@ func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, respon
response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -1629,7 +1632,6 @@ func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response *
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
Expand Down Expand Up @@ -1670,6 +1672,8 @@ func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response *
response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -1716,7 +1720,6 @@ func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response *
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
Expand Down Expand Up @@ -1755,6 +1758,8 @@ func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response *
response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -1836,7 +1841,6 @@ func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

user, err := keystore.NewUserFromKeystore(s.vm.ctx.Keystore, args.Username, args.Password)
if err != nil {
Expand Down Expand Up @@ -1879,6 +1883,8 @@ func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs
response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)

s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
Expand Down Expand Up @@ -2170,9 +2176,6 @@ func (s *Service) IssueTx(req *http.Request, args *api.FormattedTx, response *ap
return fmt.Errorf("couldn't parse tx: %w", err)
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

if err := s.vm.Network.IssueTx(req.Context(), tx); err != nil {
return fmt.Errorf("couldn't issue tx: %w", err)
}
Expand Down

0 comments on commit 677629a

Please sign in to comment.