Skip to content

Commit

Permalink
added to local/blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Nov 8, 2023
1 parent fb04e73 commit 06646d9
Showing 1 changed file with 85 additions and 5 deletions.
90 changes: 85 additions & 5 deletions local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (ln *localNetwork) RegisterBlockchainAliases(
return nil
}

/*
func (ln *localNetwork) AddSubnetValidators(
ctx context.Context,
subnetSpecs []network.SubnetValidatorsSpec,
Expand All @@ -164,7 +163,6 @@ func (ln *localNetwork) AddSubnetValidators(

return ln.addSubnetValidators(ctx, subnetSpecs)
}
*/

func (ln *localNetwork) RemoveSubnetValidators(
ctx context.Context,
Expand Down Expand Up @@ -354,7 +352,7 @@ func (ln *localNetwork) installCustomChains(
return nil, err
}

if err = ln.addSubnetValidators(ctx, platformCli, w, subnetIDs, subnetSpecs); err != nil {
if err = ln.issueSubnetValidatorTxs(ctx, platformCli, w, subnetIDs, subnetSpecs); err != nil {
return nil, err
}

Expand Down Expand Up @@ -421,6 +419,88 @@ func (ln *localNetwork) installCustomChains(
return chainInfos, nil
}

func (ln *localNetwork) addSubnetValidators(
ctx context.Context,
subnetValidatorsSpecs []network.SubnetValidatorsSpec,
) error {
ln.log.Info(logging.Blue.Wrap(logging.Bold.Wrap("add subnet validators")))

clientURI, err := ln.getClientURI()
if err != nil {
return err
}
platformCli := platformvm.NewClient(clientURI)

// wallet needs txs for all previously created subnets
subnetIDs := make([]ids.ID, len(subnetValidatorsSpecs))
for i, spec := range subnetValidatorsSpecs {
subnetID, err := ids.FromString(spec.SubnetID)
if err != nil {
return err
}
subnetIDs[i] = subnetID
}
w, err := newWallet(ctx, clientURI, subnetIDs)
if err != nil {
return err
}

for _, spec := range subnetValidatorsSpecs {
if len(spec.NodeNames) == 0 {
return fmt.Errorf("no validators provided for subnet %s", spec.SubnetID)
}
}

// create new nodes
for _, spec := range subnetValidatorsSpecs {
for _, nodeName := range spec.NodeNames {
_, ok := ln.nodes[nodeName]
if !ok {
ln.log.Info(logging.Green.Wrap(fmt.Sprintf("adding new participant %s", nodeName)))
if _, err := ln.addNode(node.Config{
Name: nodeName,
RedirectStdout: ln.redirectStdout,
RedirectStderr: ln.redirectStderr,
}); err != nil {
return err
}
}
}
}
if err := ln.healthy(ctx); err != nil {
return err
}

// just ensure all nodes are primary validators (so can be subnet validators)
if err := ln.addPrimaryValidators(ctx, platformCli, w); err != nil {
return err
}

// wait for nodes to be primary validators before trying to add them as subnet ones
if err = ln.waitPrimaryValidators(ctx, platformCli); err != nil {
return err
}

subnetSpecs := []network.SubnetSpec{}
for _, spec := range subnetValidatorsSpecs {
subnetSpecs = append(subnetSpecs, network.SubnetSpec{Participants: spec.NodeNames})
}

if err = ln.issueSubnetValidatorTxs(ctx, platformCli, w, subnetIDs, subnetSpecs); err != nil {
return err
}

if err := ln.restartNodes(ctx, subnetIDs, subnetSpecs, nil, nil, nil); err != nil {
return err
}

if err = ln.waitSubnetValidators(ctx, platformCli, subnetIDs, subnetSpecs); err != nil {
return err
}

return nil
}

func (ln *localNetwork) installSubnets(
ctx context.Context,
subnetSpecs []network.SubnetSpec,
Expand Down Expand Up @@ -491,7 +571,7 @@ func (ln *localNetwork) installSubnets(
return nil, err
}

if err = ln.addSubnetValidators(ctx, platformCli, w, subnetIDs, subnetSpecs); err != nil {
if err = ln.issueSubnetValidatorTxs(ctx, platformCli, w, subnetIDs, subnetSpecs); err != nil {
return nil, err
}

Expand Down Expand Up @@ -1289,7 +1369,7 @@ func createSubnets(
// add the nodes in subnet participant as validators of the given subnets, in case they are not
// the validation starts as soon as possible and its duration is as long as possible, that is,
// it ends at the time the primary network validation ends for the node
func (ln *localNetwork) addSubnetValidators(
func (ln *localNetwork) issueSubnetValidatorTxs(
ctx context.Context,
platformCli platformvm.Client,
w *wallet,
Expand Down

0 comments on commit 06646d9

Please sign in to comment.