diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index 5272cec83ef0..6cdd8b1ae4fc 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -1237,7 +1237,6 @@ func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply if err != nil { return err } - defer user.Close() // Get the user's keys privKeys, err := keystore.GetKeychain(user, fromAddrs) @@ -1279,12 +1278,17 @@ func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply reply.TxID = tx.ID() reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) } @@ -1349,7 +1353,6 @@ func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply if err != nil { return err } - defer user.Close() privKeys, err := keystore.GetKeychain(user, fromAddrs) if err != nil { @@ -1390,12 +1393,17 @@ func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply reply.TxID = tx.ID() reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) } @@ -1457,7 +1465,6 @@ func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidator if err != nil { return err } - defer user.Close() keys, err := keystore.GetKeychain(user, fromAddrs) if err != nil { @@ -1497,12 +1504,17 @@ func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidator response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) } @@ -1541,7 +1553,6 @@ func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, respon if err != nil { return err } - defer user.Close() privKeys, err := keystore.GetKeychain(user, fromAddrs) if err != nil { @@ -1574,12 +1585,17 @@ func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, respon response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) } @@ -1637,7 +1653,6 @@ func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response * if err != nil { return err } - defer user.Close() privKeys, err := keystore.GetKeychain(user, fromAddrs) if err != nil { @@ -1671,12 +1686,17 @@ func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response * response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) } @@ -1725,7 +1745,6 @@ func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response * if err != nil { return err } - defer user.Close() privKeys, err := keystore.GetKeychain(user, fromAddrs) if err != nil { // Get keys @@ -1757,12 +1776,17 @@ func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response * response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) } @@ -1846,7 +1870,6 @@ func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs if err != nil { return err } - defer user.Close() keys, err := keystore.GetKeychain(user, fromAddrs) if err != nil { @@ -1882,12 +1905,17 @@ func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) + if err != nil { + return fmt.Errorf("could not format address %s: %w", changeAddr, err) + } s.vm.ctx.Lock.Unlock() + err = s.vm.Network.IssueTx(req.Context(), tx) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() return utils.Err( err, - s.vm.Network.IssueTx(req.Context(), tx), user.Close(), ) }