Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
  • Loading branch information
joshua-kim committed Jan 26, 2024
1 parent c0bc9f5 commit 8287633
Show file tree
Hide file tree
Showing 28 changed files with 766 additions and 779 deletions.
23 changes: 11 additions & 12 deletions api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/api/server"
"github.com/ava-labs/avalanchego/chains"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
Expand All @@ -40,14 +39,14 @@ var (
)

type Config struct {
Log logging.Logger
ProfileDir string
LogFactory logging.Factory
NodeConfig interface{}
ChainManager chains.Manager
HTTPServer server.PathAdderWithReadLock
VMRegistry registry.VMRegistry
VMManager vms.Manager
Log logging.Logger
ProfileDir string
LogFactory logging.Factory
NodeConfig interface{}
Aliaser ids.Aliaser
HTTPServer server.PathAdderWithReadLock
VMRegistry registry.VMRegistry
VMManager vms.Manager
}

// Admin is the API service for node admin management
Expand Down Expand Up @@ -165,15 +164,15 @@ func (a *Admin) AliasChain(_ *http.Request, args *AliasChainArgs, _ *api.EmptyRe
if len(args.Alias) > maxAliasLength {
return errAliasTooLong
}
chainID, err := a.ChainManager.Lookup(args.Chain)
chainID, err := a.Aliaser.Lookup(args.Chain)
if err != nil {
return err
}

a.lock.Lock()
defer a.lock.Unlock()

if err := a.ChainManager.Alias(chainID, args.Alias); err != nil {
if err := a.Aliaser.Alias(chainID, args.Alias); err != nil {
return err
}

Expand Down Expand Up @@ -205,7 +204,7 @@ func (a *Admin) GetChainAliases(_ *http.Request, args *GetChainAliasesArgs, repl
return err
}

reply.Aliases, err = a.ChainManager.Aliases(id)
reply.Aliases, err = a.Aliaser.Aliases(id)
return err
}

Expand Down
17 changes: 10 additions & 7 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type Info struct {
validators validators.Manager
myIP ips.DynamicIPPort
networking network.Network
chainManager chains.Manager
aliaser ids.Aliaser
chainCreator *chains.Manager
vmManager vms.Manager
benchlist benchlist.Manager
}
Expand All @@ -66,7 +67,8 @@ func NewService(
parameters Parameters,
log logging.Logger,
validators validators.Manager,
chainManager chains.Manager,
aliaser ids.Aliaser,
chainCreator *chains.Manager,
vmManager vms.Manager,
myIP ips.DynamicIPPort,
network network.Network,
Expand All @@ -81,7 +83,8 @@ func NewService(
Parameters: parameters,
log: log,
validators: validators,
chainManager: chainManager,
aliaser: aliaser,
chainCreator: chainCreator,
vmManager: vmManager,
myIP: myIP,
networking: network,
Expand Down Expand Up @@ -203,7 +206,7 @@ func (i *Info) GetBlockchainID(_ *http.Request, args *GetBlockchainIDArgs, reply
zap.String("method", "getBlockchainID"),
)

bID, err := i.chainManager.Lookup(args.Alias)
bID, err := i.aliaser.Lookup(args.Alias)
reply.BlockchainID = bID
return err
}
Expand Down Expand Up @@ -240,7 +243,7 @@ func (i *Info) Peers(_ *http.Request, args *PeersArgs, reply *PeersReply) error
benchedIDs := i.benchlist.GetBenched(peer.ID)
benchedAliases := make([]string, len(benchedIDs))
for idx, id := range benchedIDs {
alias, err := i.chainManager.PrimaryAlias(id)
alias, err := i.aliaser.PrimaryAlias(id)
if err != nil {
return fmt.Errorf("failed to get primary alias for chain ID %s: %w", id, err)
}
Expand Down Expand Up @@ -282,11 +285,11 @@ func (i *Info) IsBootstrapped(_ *http.Request, args *IsBootstrappedArgs, reply *
if args.Chain == "" {
return errNoChainProvided
}
chainID, err := i.chainManager.Lookup(args.Chain)
chainID, err := i.aliaser.Lookup(args.Chain)
if err != nil {
return fmt.Errorf("there is no chain with alias/ID '%s'", args.Chain)
}
reply.IsBootstrapped = i.chainManager.IsBootstrapped(chainID)
reply.IsBootstrapped = i.chainCreator.IsBootstrapped(chainID)
return nil
}

Expand Down
21 changes: 10 additions & 11 deletions api/ipcs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/chains"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/ipcs"
"github.com/ava-labs/avalanchego/utils/json"
"github.com/ava-labs/avalanchego/utils/logging"
)

type Service struct {
log logging.Logger
chainManager chains.Manager
lock sync.RWMutex
ipcs *ipcs.ChainIPCs
log logging.Logger
aliaser ids.Aliaser
lock sync.RWMutex
ipcs *ipcs.ChainIPCs
}

func NewService(log logging.Logger, chainManager chains.Manager, ipcs *ipcs.ChainIPCs) (http.Handler, error) {
func NewService(log logging.Logger, aliaser ids.Aliaser, ipcs *ipcs.ChainIPCs) (http.Handler, error) {
server := rpc.NewServer()
codec := json.NewCodec()
server.RegisterCodec(codec, "application/json")
server.RegisterCodec(codec, "application/json;charset=UTF-8")
return server, server.RegisterService(
&Service{
log: log,
chainManager: chainManager,
ipcs: ipcs,
log: log,
aliaser: aliaser,
ipcs: ipcs,
},
"ipcs",
)
Expand All @@ -59,7 +58,7 @@ func (s *Service) PublishBlockchain(_ *http.Request, args *PublishBlockchainArgs
logging.UserString("blockchainID", args.BlockchainID),
)

chainID, err := s.chainManager.Lookup(args.BlockchainID)
chainID, err := s.aliaser.Lookup(args.BlockchainID)
if err != nil {
s.log.Error("chain lookup failed",
logging.UserString("blockchainID", args.BlockchainID),
Expand Down Expand Up @@ -98,7 +97,7 @@ func (s *Service) UnpublishBlockchain(_ *http.Request, args *UnpublishBlockchain
logging.UserString("blockchainID", args.BlockchainID),
)

chainID, err := s.chainManager.Lookup(args.BlockchainID)
chainID, err := s.aliaser.Lookup(args.BlockchainID)
if err != nil {
s.log.Error("chain lookup failed",
logging.UserString("blockchainID", args.BlockchainID),
Expand Down
Loading

0 comments on commit 8287633

Please sign in to comment.