Skip to content

Commit

Permalink
adm: add renew-domain command
Browse files Browse the repository at this point in the history
It's a kludge until we have some proper management node-side, but domains must
be renewed for the system to work.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Jun 23, 2023
1 parent 4c812b6 commit 9a3b6b6
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog for NeoFS Node
### Added
- Embedded Neo contracts in `contracts` dir (#2391)
- `dump-names` command for adm
- `renew-domain` command for adm

### Fixed

Expand Down
73 changes: 73 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/renew_domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package morph

import (
"errors"
"strings"

"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const (
recursiveFlag = "recursive"
)

func renewDomain(cmd *cobra.Command, _ []string) error {
dom, err := cmd.Flags().GetString(nameDomainFlag)
if err != nil {
return err
}
recursive, _ := cmd.Flags().GetBool(recursiveFlag)
wCtx, err := newInitializeContext(cmd, viper.GetViper())
if err != nil {
return err
}
defer wCtx.close()
nns, err := wCtx.Client.GetContractStateByID(1)
if err != nil {
return err
}
var domains = make([]string, 0, 1)
if recursive {
var n11r = nep11.NewNonDivisibleReader(wCtx.ReadOnlyInvoker, nns.Hash)
tokIter, err := n11r.Tokens()
if err != nil {
return err
}
for toks, err := tokIter.Next(10); len(toks) != 0 && err == nil; toks, err = tokIter.Next(10) {
for i := range toks {
var name = string(toks[i])
if name != dom && !strings.HasSuffix(name, "."+dom) {
continue
}
domains = append(domains, name)
}
}
} else {
avail, err := unwrap.Bool(wCtx.ReadOnlyInvoker.Call(nns.Hash, "isAvailable"))
if err == nil && avail {
return errors.New("domain is not registered or expired")
}
domains = append(domains, dom)
}

bw := io.NewBufBinWriter()
for i := range domains {
emit.AppCall(bw.BinWriter, nns.Hash, "renew", callflag.All, domains[i])
if bw.Err != nil {
return bw.Err
}
// Default registration price is 10 GAS, adding more domains
// into the script makes test execution to fail.
if err := wCtx.sendConsensusTx(bw.Bytes()); err != nil {
return err
}
bw.Reset()
}
return wCtx.awaitTx()
}
16 changes: 16 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ var (
RunE: dumpContainers,
}

renewDomainCmd = &cobra.Command{
Use: "renew-domain",
Short: "Renew NNS domain",
PreRun: func(cmd *cobra.Command, _ []string) {
_ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag))
_ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag))
},
RunE: renewDomain,
}

restoreContainersCmd = &cobra.Command{
Use: "restore-containers",
Short: "Restore NeoFS containers from file",
Expand Down Expand Up @@ -310,6 +320,12 @@ func init() {
dumpContainersCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)")
dumpContainersCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to dump")

RootCmd.AddCommand(renewDomainCmd)
renewDomainCmd.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
renewDomainCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
renewDomainCmd.Flags().StringP(nameDomainFlag, "d", "", "Domain")
renewDomainCmd.Flags().BoolP(recursiveFlag, "u", false, "Recursive (renew all subdomain as well)")

RootCmd.AddCommand(restoreContainersCmd)
restoreContainersCmd.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
restoreContainersCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
Expand Down
2 changes: 2 additions & 0 deletions docs/cli-adm.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ credentials: # passwords for consensus node / alphabet wallets
- `force-new-epoch` increments NeoFS epoch number and executes new epoch
handlers in NeoFS nodes.

- `renew-domain` updates expiration date of the given domain for one year.

- `refill-gas` transfers sidechain GAS to the specified wallet.

- `update-contracts` updates contracts to a new version.
Expand Down

0 comments on commit 9a3b6b6

Please sign in to comment.