From 2eb6e845a90601f88d2549286cd2e7efa31b54cd Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 11 Oct 2023 19:39:44 -0400 Subject: [PATCH] Remove write lock option from the platformvm API (#2157) --- vms/platformvm/service.go | 116 ++++++++++++++++++++++++++++++--- vms/platformvm/service_test.go | 52 ++++++++++++--- vms/platformvm/vm.go | 28 +++----- 3 files changed, 161 insertions(+), 35 deletions(-) diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index a887ee72cb17..d82b9d167780 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -106,6 +106,9 @@ func (s *Service) GetHeight(r *http.Request, _ *struct{}, response *api.GetHeigh zap.String("method", "getHeight"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + ctx := r.Context() height, err := s.vm.GetCurrentHeight(ctx) response.Height = json.Uint64(height) @@ -137,6 +140,9 @@ func (s *Service) ExportKey(_ *http.Request, args *ExportKeyArgs, reply *ExportK return fmt.Errorf("couldn't parse %s to address: %w", args.Address, err) } + 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 @@ -176,6 +182,9 @@ func (s *Service) ImportKey(_ *http.Request, args *ImportKeyArgs, reply *api.JSO return fmt.Errorf("problem formatting address: %w", err) } + 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 @@ -221,12 +230,14 @@ func (s *Service) GetBalance(_ *http.Request, args *GetBalanceRequest, response logging.UserStrings("addresses", args.Addresses), ) - // Parse to address addrs, err := avax.ParseServiceAddresses(s.addrManager, args.Addresses) if err != nil { return err } + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + utxos, err := avax.GetAllUTXOs(s.vm.state, addrs) if err != nil { return fmt.Errorf("couldn't get UTXO set of %v: %w", args.Addresses, err) @@ -341,6 +352,9 @@ func (s *Service) CreateAddress(_ *http.Request, args *api.UserPass, response *a logging.UserString("username", args.Username), ) + 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 @@ -367,6 +381,9 @@ func (s *Service) ListAddresses(_ *http.Request, args *api.UserPass, response *a logging.UserString("username", args.Username), ) + 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 @@ -446,6 +463,10 @@ func (s *Service) GetUTXOs(_ *http.Request, args *api.GetUTXOsArgs, response *ap if limit <= 0 || builder.MaxPageSize < limit { limit = builder.MaxPageSize } + + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + if sourceChain == s.vm.ctx.ChainID { utxos, endAddr, endUTXOID, err = avax.GetPaginatedUTXOs( s.vm.state, @@ -531,6 +552,9 @@ func (s *Service) GetSubnets(_ *http.Request, args *GetSubnetsArgs, response *Ge zap.String("method", "getSubnets"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + getAll := len(args.IDs) == 0 if getAll { subnets, err := s.vm.state.GetSubnets() // all subnets @@ -656,6 +680,9 @@ func (s *Service) GetStakingAssetID(_ *http.Request, args *GetStakingAssetIDArgs return nil } + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + transformSubnetIntf, err := s.vm.state.GetSubnetTransformation(args.SubnetID) if err != nil { return fmt.Errorf( @@ -757,8 +784,10 @@ func (s *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentValidato vdrToDelegators := map[ids.NodeID][]platformapi.PrimaryDelegator{} // Create set of nodeIDs - nodeIDs := set.Set[ids.NodeID]{} - nodeIDs.Add(args.NodeIDs...) + nodeIDs := set.Of(args.NodeIDs...) + + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() numNodeIDs := nodeIDs.Len() targetStakers := make([]*state.Staker, 0, numNodeIDs) @@ -972,8 +1001,10 @@ func (s *Service) GetPendingValidators(_ *http.Request, args *GetPendingValidato reply.Delegators = []interface{}{} // Create set of nodeIDs - nodeIDs := set.Set[ids.NodeID]{} - nodeIDs.Add(args.NodeIDs...) + nodeIDs := set.Of(args.NodeIDs...) + + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() numNodeIDs := nodeIDs.Len() targetStakers := make([]*state.Staker, 0, numNodeIDs) @@ -1081,6 +1112,9 @@ func (s *Service) GetCurrentSupply(r *http.Request, args *GetCurrentSupplyArgs, zap.String("method", "getCurrentSupply"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + supply, err := s.vm.state.GetCurrentSupply(args.SubnetID) if err != nil { return fmt.Errorf("fetching current supply failed: %w", err) @@ -1207,6 +1241,9 @@ func (s *Service) AddValidator(_ *http.Request, args *AddValidatorArgs, reply *a return fmt.Errorf("problem while parsing reward address: %w", err) } + 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 @@ -1317,6 +1354,9 @@ func (s *Service) AddDelegator(_ *http.Request, args *AddDelegatorArgs, reply *a return err } + 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 @@ -1423,6 +1463,9 @@ func (s *Service) AddSubnetValidator(_ *http.Request, args *AddSubnetValidatorAr return err } + 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 @@ -1505,6 +1548,9 @@ func (s *Service) CreateSubnet(_ *http.Request, args *CreateSubnetArgs, response return err } + 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 @@ -1599,6 +1645,9 @@ func (s *Service) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *ap return err } + 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 @@ -1685,6 +1734,9 @@ func (s *Service) ImportAVAX(_ *http.Request, args *ImportAVAXArgs, response *ap return err } + 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 @@ -1789,8 +1841,7 @@ func (s *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchainArgs, } // If creating AVM instance, use secp256k1fx // TODO: Document FXs and have user specify them in API call - fxIDsSet := set.Set[ids.ID]{} - fxIDsSet.Add(fxIDs...) + fxIDsSet := set.Of(fxIDs...) if vmID == constants.AVMID && !fxIDsSet.Contains(secp256k1fx.ID) { fxIDs = append(fxIDs, secp256k1fx.ID) } @@ -1805,6 +1856,9 @@ func (s *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchainArgs, return err } + 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 @@ -1878,6 +1932,9 @@ func (s *Service) GetBlockchainStatus(r *http.Request, args *GetBlockchainStatus return errMissingBlockchainID } + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + // if its aliased then vm created this chain. if aliasedID, err := s.vm.Chains.Lookup(args.BlockchainID); err == nil { if s.nodeValidates(aliasedID) { @@ -1987,6 +2044,9 @@ func (s *Service) ValidatedBy(r *http.Request, args *ValidatedByArgs, response * zap.String("method", "validatedBy"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + var err error ctx := r.Context() response.SubnetID, err = s.vm.GetSubnetID(ctx, args.BlockchainID) @@ -2010,6 +2070,9 @@ func (s *Service) Validates(_ *http.Request, args *ValidatesArgs, response *Vali zap.String("method", "validates"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + if args.SubnetID != constants.PrimaryNetworkID { subnetTx, _, err := s.vm.state.GetTx(args.SubnetID) if err != nil { @@ -2066,6 +2129,9 @@ func (s *Service) GetBlockchains(_ *http.Request, _ *struct{}, response *GetBloc zap.String("method", "getBlockchains"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + subnets, err := s.vm.state.GetSubnets() if err != nil { return fmt.Errorf("couldn't retrieve subnets: %w", err) @@ -2119,7 +2185,6 @@ func (s *Service) GetBlockchains(_ *http.Request, _ *struct{}, response *GetBloc return nil } -// IssueTx issues a tx func (s *Service) IssueTx(_ *http.Request, args *api.FormattedTx, response *api.JSONTxID) error { s.vm.ctx.Log.Debug("API called", zap.String("service", "platform"), @@ -2134,6 +2199,10 @@ func (s *Service) IssueTx(_ *http.Request, args *api.FormattedTx, response *api. if err != nil { return fmt.Errorf("couldn't parse tx: %w", err) } + + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + if err := s.vm.Builder.AddUnverifiedTx(tx); err != nil { return fmt.Errorf("couldn't issue tx: %w", err) } @@ -2148,6 +2217,9 @@ func (s *Service) GetTx(_ *http.Request, args *api.GetTxArgs, response *api.GetT zap.String("method", "getTx"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + tx, _, err := s.vm.state.GetTx(args.TxID) if err != nil { return fmt.Errorf("couldn't get tx: %w", err) @@ -2187,6 +2259,9 @@ func (s *Service) GetTxStatus(_ *http.Request, args *GetTxStatusArgs, response * zap.String("method", "getTxStatus"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + _, txStatus, err := s.vm.state.GetTx(args.TxID) if err == nil { // Found the status. Report it. response.Status = txStatus @@ -2280,6 +2355,9 @@ func (s *Service) GetStake(_ *http.Request, args *GetStakeArgs, response *GetSta return err } + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + currentStakerIterator, err := s.vm.state.GetCurrentStakerIterator() if err != nil { return err @@ -2370,6 +2448,9 @@ func (s *Service) GetMinStake(_ *http.Request, args *GetMinStakeArgs, reply *Get return nil } + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + transformSubnetIntf, err := s.vm.state.GetSubnetTransformation(args.SubnetID) if err != nil { return fmt.Errorf( @@ -2451,6 +2532,10 @@ func (s *Service) GetMaxStakeAmount(_ *http.Request, args *GetMaxStakeAmountArgs if startTime.After(endTime) { return errStartAfterEndTime } + + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + now := s.vm.state.GetTimestamp() if startTime.Before(now) { return errStartTimeInThePast @@ -2494,6 +2579,9 @@ func (s *Service) GetRewardUTXOs(_ *http.Request, args *api.GetTxArgs, reply *Ge zap.String("method", "getRewardUTXOs"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + utxos, err := s.vm.state.GetRewardUTXOs(args.TxID) if err != nil { return fmt.Errorf("couldn't get reward UTXOs: %w", err) @@ -2530,6 +2618,9 @@ func (s *Service) GetTimestamp(_ *http.Request, _ *struct{}, reply *GetTimestamp zap.String("method", "getTimestamp"), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + reply.Timestamp = s.vm.state.GetTimestamp() return nil } @@ -2615,6 +2706,9 @@ func (s *Service) GetValidatorsAt(r *http.Request, args *GetValidatorsAtArgs, re zap.Stringer("subnetID", args.SubnetID), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + ctx := r.Context() var err error reply.Validators, err = s.vm.GetValidatorSet(ctx, height, args.SubnetID) @@ -2632,6 +2726,9 @@ func (s *Service) GetBlock(_ *http.Request, args *api.GetBlockArgs, response *ap zap.Stringer("encoding", args.Encoding), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + block, err := s.vm.manager.GetStatelessBlock(args.BlockID) if err != nil { return fmt.Errorf("couldn't get block with id %s: %w", args.BlockID, err) @@ -2662,6 +2759,9 @@ func (s *Service) GetBlockByHeight(_ *http.Request, args *api.GetBlockByHeightAr zap.Stringer("encoding", args.Encoding), ) + s.vm.ctx.Lock.Lock() + defer s.vm.ctx.Lock.Unlock() + blockID, err := s.vm.state.GetBlockIDAtHeight(uint64(args.Height)) if err != nil { return fmt.Errorf("couldn't get block at height %d: %w", args.Height, err) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 1e7468cc6fba..9e37284905e5 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -134,8 +134,8 @@ func TestExportKey(t *testing.T) { service, _ := defaultService(t) defaultAddress(t, service) - service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() @@ -153,8 +153,8 @@ func TestImportKey(t *testing.T) { require.NoError(stdjson.Unmarshal([]byte(jsonString), &args)) service, _ := defaultService(t) - service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() @@ -171,6 +171,7 @@ func TestGetTxStatus(t *testing.T) { defaultAddress(t, service) service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() @@ -226,6 +227,8 @@ func TestGetTxStatus(t *testing.T) { mutableSharedMemory.SharedMemory = oldSharedMemory + service.vm.ctx.Lock.Unlock() + var ( arg = &GetTxStatusArgs{TxID: tx.ID()} resp GetTxStatusResponse @@ -234,6 +237,8 @@ func TestGetTxStatus(t *testing.T) { require.Equal(status.Unknown, resp.Status) require.Zero(resp.Reason) + service.vm.ctx.Lock.Lock() + // put the chain in existing chain list err = service.vm.Builder.AddUnverifiedTx(tx) require.ErrorIs(err, database.ErrNotFound) // Missing shared memory UTXO @@ -250,6 +255,8 @@ func TestGetTxStatus(t *testing.T) { require.NoError(blk.Accept(context.Background())) + service.vm.ctx.Lock.Unlock() + resp = GetTxStatusResponse{} // reset require.NoError(service.GetTxStatus(nil, arg, &resp)) require.Equal(status.Committed, resp.Status) @@ -322,6 +329,8 @@ func TestGetTx(t *testing.T) { tx, err := test.createTx(service) require.NoError(err) + service.vm.ctx.Lock.Unlock() + arg := &api.GetTxArgs{ TxID: tx.ID(), Encoding: encoding, @@ -330,6 +339,8 @@ func TestGetTx(t *testing.T) { err = service.GetTx(nil, arg, &response) require.ErrorIs(err, database.ErrNotFound) // We haven't issued the tx yet + service.vm.ctx.Lock.Lock() + require.NoError(service.vm.Builder.AddUnverifiedTx(tx)) blk, err := service.vm.BuildBlock(context.Background()) @@ -351,6 +362,8 @@ func TestGetTx(t *testing.T) { } } + service.vm.ctx.Lock.Unlock() + require.NoError(service.GetTx(nil, arg, &response)) switch encoding { @@ -369,6 +382,7 @@ func TestGetTx(t *testing.T) { require.Equal(expectedTxJSON, []byte(response.Tx)) } + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }) @@ -376,13 +390,12 @@ func TestGetTx(t *testing.T) { } } -// Test method GetBalance func TestGetBalance(t *testing.T) { require := require.New(t) service, _ := defaultService(t) defaultAddress(t, service) - service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() @@ -410,8 +423,8 @@ func TestGetStake(t *testing.T) { require := require.New(t) service, _ := defaultService(t) defaultAddress(t, service) - service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() @@ -479,6 +492,8 @@ func TestGetStake(t *testing.T) { oldStake := defaultWeight + service.vm.ctx.Lock.Lock() + // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 delegatorNodeID := ids.NodeID(keys[0].PublicKey().Address()) @@ -505,6 +520,8 @@ func TestGetStake(t *testing.T) { service.vm.state.AddTx(tx, status.Committed) require.NoError(service.vm.state.Commit()) + service.vm.ctx.Lock.Unlock() + // Make sure the delegator addr has the right stake (old stake + stakeAmount) addr, _ := service.addrManager.FormatLocalAddress(keys[0].PublicKey().Address()) args.Addresses = []string{addr} @@ -526,6 +543,8 @@ func TestGetStake(t *testing.T) { oldStake = uint64(response.Staked) + service.vm.ctx.Lock.Lock() + // Make sure this works for pending stakers // Add a pending staker stakeAmount = service.vm.MinValidatorStake + 54321 @@ -553,6 +572,8 @@ func TestGetStake(t *testing.T) { service.vm.state.AddTx(tx, status.Committed) require.NoError(service.vm.state.Commit()) + service.vm.ctx.Lock.Unlock() + // Make sure the delegator has the right stake (old stake + stakeAmount) require.NoError(service.GetStake(nil, &args, &response)) require.Equal(oldStake+stakeAmount, uint64(response.Staked)) @@ -571,13 +592,12 @@ func TestGetStake(t *testing.T) { require.Equal(stakeAmount+oldStake, outputs[0].Out.Amount()+outputs[1].Out.Amount()+outputs[2].Out.Amount()) } -// Test method GetCurrentValidators func TestGetCurrentValidators(t *testing.T) { require := require.New(t) service, _ := defaultService(t) defaultAddress(t, service) - service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() @@ -612,6 +632,8 @@ func TestGetCurrentValidators(t *testing.T) { delegatorStartTime := uint64(defaultValidateStartTime.Unix()) delegatorEndTime := uint64(defaultValidateStartTime.Add(defaultMinStakingDuration).Unix()) + service.vm.ctx.Lock.Lock() + delTx, err := service.vm.txBuilder.NewAddDelegatorTx( stakeAmount, delegatorStartTime, @@ -634,6 +656,8 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.state.AddTx(delTx, status.Committed) require.NoError(service.vm.state.Commit()) + service.vm.ctx.Lock.Unlock() + // Call getCurrentValidators args = GetCurrentValidatorsArgs{SubnetID: constants.PrimaryNetworkID} require.NoError(service.GetCurrentValidators(nil, &args, &response)) @@ -671,6 +695,8 @@ func TestGetCurrentValidators(t *testing.T) { } require.True(found) + service.vm.ctx.Lock.Lock() + // Reward the delegator tx, err := service.vm.txBuilder.NewRewardValidatorTx(delTx.ID()) require.NoError(err) @@ -679,6 +705,8 @@ func TestGetCurrentValidators(t *testing.T) { require.NoError(service.vm.state.SetDelegateeReward(staker.SubnetID, staker.NodeID, 100000)) require.NoError(service.vm.state.Commit()) + service.vm.ctx.Lock.Unlock() + // Call getValidators response = GetCurrentValidatorsReply{} require.NoError(service.GetCurrentValidators(nil, &args, &response)) @@ -696,19 +724,24 @@ func TestGetCurrentValidators(t *testing.T) { func TestGetTimestamp(t *testing.T) { require := require.New(t) service, _ := defaultService(t) - service.vm.ctx.Lock.Lock() defer func() { + service.vm.ctx.Lock.Lock() require.NoError(service.vm.Shutdown(context.Background())) service.vm.ctx.Lock.Unlock() }() reply := GetTimestampReply{} require.NoError(service.GetTimestamp(nil, nil, &reply)) + + service.vm.ctx.Lock.Lock() + require.Equal(service.vm.state.GetTimestamp(), reply.Timestamp) newTimestamp := reply.Timestamp.Add(time.Second) service.vm.state.SetTimestamp(newTimestamp) + service.vm.ctx.Lock.Unlock() + require.NoError(service.GetTimestamp(nil, nil, &reply)) require.Equal(newTimestamp, reply.Timestamp) } @@ -733,7 +766,6 @@ func TestGetBlock(t *testing.T) { require := require.New(t) service, _ := defaultService(t) service.vm.ctx.Lock.Lock() - defer service.vm.ctx.Lock.Unlock() service.vm.Config.CreateAssetTxFee = 100 * defaultTxFee @@ -765,6 +797,8 @@ func TestGetBlock(t *testing.T) { require.NoError(blk.Verify(context.Background())) require.NoError(blk.Accept(context.Background())) + service.vm.ctx.Lock.Unlock() + args := api.GetBlockArgs{ BlockID: blk.ID(), Encoding: test.encoding, diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index cd51c6d99eda..241e24659f72 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -422,24 +422,20 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]*common.HTTPHandler, e server.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8") server.RegisterInterceptFunc(vm.metrics.InterceptRequest) server.RegisterAfterFunc(vm.metrics.AfterRequest) - if err := server.RegisterService( - &Service{ - vm: vm, - addrManager: avax.NewAddressManager(vm.ctx), - stakerAttributesCache: &cache.LRU[ids.ID, *stakerAttributes]{ - Size: stakerAttributesCacheSize, - }, + service := &Service{ + vm: vm, + addrManager: avax.NewAddressManager(vm.ctx), + stakerAttributesCache: &cache.LRU[ids.ID, *stakerAttributes]{ + Size: stakerAttributesCacheSize, }, - "platform", - ); err != nil { - return nil, err } - + err := server.RegisterService(service, "platform") return map[string]*common.HTTPHandler{ "": { - Handler: server, + LockOptions: common.NoLock, + Handler: server, }, - }, nil + }, err } // CreateStaticHandlers returns a map where: @@ -449,16 +445,12 @@ func (*VM) CreateStaticHandlers(context.Context) (map[string]*common.HTTPHandler server := rpc.NewServer() server.RegisterCodec(json.NewCodec(), "application/json") server.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8") - if err := server.RegisterService(&api.StaticService{}, "platform"); err != nil { - return nil, err - } - return map[string]*common.HTTPHandler{ "": { LockOptions: common.NoLock, Handler: server, }, - }, nil + }, server.RegisterService(&api.StaticService{}, "platform") } func (vm *VM) Connected(_ context.Context, nodeID ids.NodeID, _ *version.Application) error {