Skip to content

Commit f99df51

Browse files
committed
nit
1 parent 2014626 commit f99df51

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

local/blockchain.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,31 @@ func (ln *localNetwork) RegisterBlockchainAliases(
142142
continue
143143
}
144144
blockchainAlias := chainSpec.BlockchainAlias
145-
chainID := chainInfos[i].blockchainID.String()
145+
blockchainID := chainInfos[i].blockchainID.String()
146146
ln.log.Info("registering blockchain alias",
147147
zap.String("alias", blockchainAlias),
148-
zap.String("chain-id", chainID))
149-
for nodeName, node := range ln.nodes {
150-
if node.paused {
151-
continue
152-
}
153-
if err := node.client.AdminAPI().AliasChain(ctx, chainID, blockchainAlias); err != nil {
154-
return fmt.Errorf("failure to register blockchain alias %v on node %v: %w", blockchainAlias, nodeName, err)
155-
}
148+
zap.String("chain-id", blockchainID))
149+
if err := ln.setBlockchainAlias(ctx, blockchainID, blockchainAlias); err != nil {
150+
return err
151+
}
152+
ln.blockchainAliases[blockchainID] = append(ln.blockchainAliases[blockchainID], blockchainAlias)
153+
}
154+
return nil
155+
}
156+
157+
func (ln *localNetwork) setBlockchainAlias(ctx context.Context, blockchainID string, blockchainAlias string) error {
158+
for nodeName, node := range ln.nodes {
159+
if node.paused {
160+
continue
161+
}
162+
if err := node.client.AdminAPI().AliasChain(ctx, blockchainID, blockchainAlias); err != nil {
163+
return fmt.Errorf(
164+
"failure to register blockchain alias %s for blockchain ID %s on node %s: %w",
165+
blockchainAlias,
166+
blockchainID,
167+
nodeName,
168+
err,
169+
)
156170
}
157171
}
158172
return nil

local/network.go

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ type localNetwork struct {
119119
redirectStderr bool
120120
// map from subnet id to elastic subnet tx id
121121
subnetID2ElasticSubnetID map[ids.ID]ids.ID
122+
// map from blockchain id to blockchain aliases
123+
blockchainAliases map[string][]string
122124
}
123125

124126
type deprecatedFlagEsp struct {
@@ -236,6 +238,7 @@ func newNetwork(
236238
redirectStdout: redirectStdout,
237239
redirectStderr: redirectStderr,
238240
subnetID2ElasticSubnetID: map[ids.ID]ids.ID{},
241+
blockchainAliases: map[string][]string{},
239242
}
240243
return net, nil
241244
}

local/snapshot.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
type NetworkState struct {
3131
// Map from subnet id to elastic subnet tx id
3232
SubnetID2ElasticSubnetID map[string]string `json:"subnetID2ElasticSubnetID"`
33+
// Map from blockchain id to blockchain aliases
34+
BlockchainAliases map[string][]string `json:"blockchainAliases"`
3335
}
3436

3537
// snapshots generated using older ANR versions may contain deprecated avago flags
@@ -203,6 +205,7 @@ func (ln *localNetwork) SaveSnapshot(ctx context.Context, snapshotName string) (
203205
}
204206
networkState := NetworkState{
205207
SubnetID2ElasticSubnetID: subnetID2ElasticSubnetID,
208+
BlockchainAliases: ln.blockchainAliases,
206209
}
207210
networkStateJSON, err := json.MarshalIndent(networkState, "", " ")
208211
if err != nil {
@@ -328,13 +331,23 @@ func (ln *localNetwork) loadSnapshot(
328331
}
329332
ln.subnetID2ElasticSubnetID[subnetID] = elasticSubnetID
330333
}
334+
ln.blockchainAliases = networkState.BlockchainAliases
331335
}
332336
if err := ln.loadConfig(ctx, networkConfig); err != nil {
333337
return err
334338
}
335339
if err := ln.healthy(ctx); err != nil {
336340
return err
337341
}
342+
// add aliases included in the snapshot state
343+
for blockchainID, blockchainAliases := range ln.blockchainAliases {
344+
for _, blockchainAlias := range blockchainAliases {
345+
if err := ln.setBlockchainAlias(ctx, blockchainID, blockchainAlias); err != nil {
346+
return err
347+
}
348+
}
349+
}
350+
// add aliases for blockchain names
338351
node := ln.getNode()
339352
blockchains, err := node.GetAPIClient().PChainAPI().GetBlockchains(ctx)
340353
if err != nil {
@@ -344,10 +357,9 @@ func (ln *localNetwork) loadSnapshot(
344357
if blockchain.Name == "C-Chain" || blockchain.Name == "X-Chain" {
345358
continue
346359
}
347-
for nodeName, node := range ln.nodes {
348-
if err := node.client.AdminAPI().AliasChain(ctx, blockchain.ID.String(), blockchain.Name); err != nil {
349-
return fmt.Errorf("failure to register blockchain alias %v on node %v: %w", blockchain.Name, nodeName, err)
350-
}
360+
if err := ln.setBlockchainAlias(ctx, blockchain.ID.String(), blockchain.Name); err != nil {
361+
// non fatal error: not required by user
362+
ln.log.Warn(err.Error())
351363
}
352364
}
353365
return nil

0 commit comments

Comments
 (0)