Skip to content

Commit

Permalink
check for permissioness subnet status for creating elastic subnet,
Browse files Browse the repository at this point in the history
adding validators, adding delegators
  • Loading branch information
felipemadero committed Nov 8, 2023
1 parent 4a90930 commit 57b399c
Showing 1 changed file with 67 additions and 16 deletions.
83 changes: 67 additions & 16 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 existant subnets

Check failure on line 984 in local/blockchain.go

View workflow job for this annotation

GitHub Actions / Lint tests

`existant` is a misspelling of `existent` (misspell)
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 existant subnets

Check failure on line 1085 in local/blockchain.go

View workflow job for this annotation

GitHub Actions / Lint tests

`existant` is a misspelling of `existent` (misspell)
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
platformCli := platformvm.NewClient(clientURI)
var subnetIDs []ids.ID

Check failure on line 1199 in local/blockchain.go

View workflow job for this annotation

GitHub Actions / Lint tests

Consider pre-allocating `subnetIDs` (prealloc)
for _, 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 = append(subnetIDs, 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 existant subnets

Check failure on line 1222 in local/blockchain.go

View workflow job for this annotation

GitHub Actions / Lint tests

`existant` is a misspelling of `existent` (misspell)
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
}

0 comments on commit 57b399c

Please sign in to comment.