From 677629ad76e7cd980cff109be8b4deff8c7c18a1 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:22:07 -0500 Subject: [PATCH] nit Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- vms/platformvm/block/builder/builder_test.go | 5 ++-- vms/platformvm/service.go | 25 +++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 0f045dba4648..da36c61cc1a1 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -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) @@ -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()) diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index 09489dd08209..5272cec83ef0 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -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 @@ -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), @@ -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 { @@ -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), @@ -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 { @@ -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), @@ -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 { @@ -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), @@ -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 { @@ -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), @@ -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 { @@ -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), @@ -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 { @@ -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), @@ -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) }