Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for permissioness subnet status for creating elastic subnet, adding validators, adding delegators #667

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 68 additions & 17 deletions local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,15 +961,28 @@ func (ln *localNetwork) addPermissionlessDelegators(
}
platformCli := platformvm.NewClient(clientURI)
// wallet needs txs for all previously created subnets
preloadTXs := make([]ids.ID, len(delegatorSpecs))
subnetIDs := make([]ids.ID, len(delegatorSpecs))
for i, delegatorSpec := range delegatorSpecs {
subnetID, err := ids.FromString(delegatorSpec.SubnetID)
if err != nil {
return err
}
preloadTXs[i] = subnetID
subnetIDs[i] = subnetID
}
w, err := newWallet(ctx, clientURI, preloadTXs)
// check for all subnets to be permissionless
for _, subnetID := range subnetIDs {
b, err := subnetIsPermissionless(ctx, platformCli, subnetID)
if err != nil {
return err
}
if !b {
msg := fmt.Sprintf("subnet %s is not permissionless", subnetID)
ln.log.Info(logging.Red.Wrap(msg))
return errors.New(msg)
}
}
// wallet needs txs for all existent subnets
w, err := newWallet(ctx, clientURI, subnetIDs)
if err != nil {
return err
}
Expand Down Expand Up @@ -1049,16 +1062,28 @@ func (ln *localNetwork) addPermissionlessValidators(
return err
}
platformCli := platformvm.NewClient(clientURI)
// wallet needs txs for all previously created subnets
preloadTXs := make([]ids.ID, len(validatorSpecs))
subnetIDs := make([]ids.ID, len(validatorSpecs))
for i, validatorSpec := range validatorSpecs {
subnetID, err := ids.FromString(validatorSpec.SubnetID)
if err != nil {
return err
}
preloadTXs[i] = subnetID
subnetIDs[i] = subnetID
}
w, err := newWallet(ctx, clientURI, preloadTXs)
// check for all subnets to be permissionless
for _, subnetID := range subnetIDs {
b, err := subnetIsPermissionless(ctx, platformCli, subnetID)
if err != nil {
return err
}
if !b {
msg := fmt.Sprintf("subnet %s is not permissionless", subnetID)
ln.log.Info(logging.Red.Wrap(msg))
return errors.New(msg)
}
}
// wallet needs txs for all existent subnets
w, err := newWallet(ctx, clientURI, subnetIDs)
if err != nil {
return err
}
Expand Down Expand Up @@ -1170,20 +1195,32 @@ func (ln *localNetwork) transformToElasticSubnets(
if err != nil {
return nil, nil, err
}
// wallet needs txs for all previously created subnets
var preloadTXs []ids.ID
for _, elasticSubnetSpec := range elasticSubnetSpecs {
platformCli := platformvm.NewClient(clientURI)
subnetIDs := make([]ids.ID, len(elasticSubnetSpecs))
for i, elasticSubnetSpec := range elasticSubnetSpecs {
if elasticSubnetSpec.SubnetID == nil {
return nil, nil, errors.New("elastic subnet spec has no subnet ID")
} else {
subnetID, err := ids.FromString(*elasticSubnetSpec.SubnetID)
if err != nil {
return nil, nil, err
}
preloadTXs = append(preloadTXs, subnetID)
}
subnetID, err := ids.FromString(*elasticSubnetSpec.SubnetID)
if err != nil {
return nil, nil, err
}
subnetIDs[i] = subnetID
}
w, err := newWallet(ctx, clientURI, preloadTXs)
// check for all subnets to be not permissionless
for _, subnetID := range subnetIDs {
b, err := subnetIsPermissionless(ctx, platformCli, subnetID)
if err != nil {
return nil, nil, err
}
if b {
msg := fmt.Sprintf("subnet %s is already permissionless", subnetID)
ln.log.Info(logging.Red.Wrap(msg))
return nil, nil, errors.New(msg)
}
}
// wallet needs txs for all existent subnets
w, err := newWallet(ctx, clientURI, subnetIDs)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -1634,3 +1671,17 @@ func createDefaultCtx(ctx context.Context) (context.Context, context.CancelFunc)
}
return context.WithTimeout(ctx, defaultTimeout)
}

func subnetIsPermissionless(
ctx context.Context,
platformCli platformvm.Client,
subnetID ids.ID,
) (bool, error) {
if _, _, err := platformCli.GetCurrentSupply(ctx, subnetID); err != nil {
if strings.Contains(err.Error(), "fetching current supply failed: not found") {
return false, nil
}
return false, fmt.Errorf("failure checking if subnet %s is permissionles: %w", subnetID, err)
}
return true, nil
}