Skip to content

Commit

Permalink
Deploy/update NeoFS contracts automatically within Sidechain deployme…
Browse files Browse the repository at this point in the history
…nt procedure (#2444)
  • Loading branch information
roman-khimov authored Nov 13, 2023
2 parents 16e1294 + 3dad944 commit 78289be
Show file tree
Hide file tree
Showing 53 changed files with 3,346 additions and 680 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ simple Peapod.
- `neofs-lens storage inspect` CLI command (#1336)
- `neofs-lens` payload-only flag (#2543)
- `neofs-lens meta put` CLI command (#1816)
- Sidechain auto-deployment to the Inner Ring app (#2195)

### Fixed
- `neo-go` RPC connection loss handling (#1337)
Expand Down
7 changes: 3 additions & 4 deletions cmd/neofs-adm/internal/modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"text/template"

"github.com/nspcc-dev/neo-go/cli/input"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -126,9 +126,8 @@ func generateConfigExample(appDir string, credSize int) (string, error) {
}
tmpl.AlphabetDir = filepath.Join(appDir, "alphabet-wallets")

var i innerring.GlagoliticLetter
for i = 0; i < innerring.GlagoliticLetter(credSize); i++ {
tmpl.Glagolitics = append(tmpl.Glagolitics, i.String())
for i := 0; i < credSize; i++ {
tmpl.Glagolitics = append(tmpl.Glagolitics, glagolitsa.LetterByIndex(i))
}

t, err := template.New("config.yml").Parse(configTxtTemplate)
Expand Down
10 changes: 5 additions & 5 deletions cmd/neofs-adm/internal/modules/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"

"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -34,12 +34,12 @@ func TestGenerateConfigExample(t *testing.T) {
require.Equal(t, 1000, v.GetInt("network.fee.container"))
require.Equal(t, 100000000, v.GetInt("network.fee.withdraw"))

var i innerring.GlagoliticLetter
for i = 0; i < innerring.GlagoliticLetter(n); i++ {
key := "credentials." + i.String()
var i int
for i = 0; i < n; i++ {
key := "credentials." + glagolitsa.LetterByIndex(i)
require.Equal(t, "password", v.GetString(key))
}

key := "credentials." + i.String()
key := "credentials." + glagolitsa.LetterByIndex(i)
require.Equal(t, "", v.GetString(key))
}
7 changes: 4 additions & 3 deletions cmd/neofs-adm/internal/modules/morph/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/config"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -61,12 +61,13 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
passwords := make([]string, size)

for i := range wallets {
password, err := config.GetPassword(v, innerring.GlagoliticLetter(i).String())
letter := glagolitsa.LetterByIndex(i)
password, err := config.GetPassword(v, letter)
if err != nil {
return nil, fmt.Errorf("can't fetch password: %w", err)
}

p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
p := filepath.Join(walletDir, letter+".json")
f, err := os.OpenFile(p, os.O_CREATE, 0644)
if err != nil {
return nil, fmt.Errorf("can't create wallet file: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-adm/internal/modules/morph/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"golang.org/x/term"
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestGenerateAlphabet(t *testing.T) {
require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil))

for i := uint64(0); i < size; i++ {
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
p := filepath.Join(walletDir, glagolitsa.LetterByIndex(int(i))+".json")
w, err := wallet.NewWalletFromFile(p)
require.NoError(t, err, "wallet doesn't exist")
require.Equal(t, 3, len(w.Accounts), "not all accounts were created")
Expand Down
6 changes: 3 additions & 3 deletions cmd/neofs-adm/internal/modules/morph/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/config"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -198,7 +198,7 @@ func openAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, er
var size int
loop:
for i := 0; i < len(walletFiles); i++ {
name := innerring.GlagoliticLetter(i).String() + ".json"
name := glagolitsa.LetterByIndex(i) + ".json"
for j := range walletFiles {
if walletFiles[j].Name() == name {
size++
Expand All @@ -213,7 +213,7 @@ loop:

wallets := make([]*wallet.Wallet, size)
for i := 0; i < size; i++ {
letter := innerring.GlagoliticLetter(i).String()
letter := glagolitsa.LetterByIndex(i)
p := filepath.Join(walletDir, letter+".json")
w, err := wallet.NewWalletFromFile(p)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-adm/internal/modules/morph/initialize_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neofs-contract/common"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -549,7 +549,7 @@ func (c *initializeContext) getAlphabetDeployItems(i, n int) []interface{} {
items[0] = false
items[1] = c.Contracts[netmapContract].Hash
items[2] = c.Contracts[proxyContract].Hash
items[3] = innerring.GlagoliticLetter(i).String()
items[3] = glagolitsa.LetterByIndex(i)
items[4] = int64(i)
items[5] = int64(n)
return items
Expand Down
6 changes: 3 additions & 3 deletions cmd/neofs-adm/internal/modules/morph/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/glagolitsa"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -83,7 +83,7 @@ func generateTestData(t *testing.T, dir string, size int) {

var pubs []string
for i := 0; i < size; i++ {
p := filepath.Join(dir, innerring.GlagoliticLetter(i).String()+".json")
p := filepath.Join(dir, glagolitsa.LetterByIndex(i)+".json")
w, err := wallet.NewWalletFromFile(p)
require.NoError(t, err, "wallet doesn't exist")
for _, acc := range w.Accounts {
Expand Down Expand Up @@ -111,6 +111,6 @@ func generateTestData(t *testing.T, dir string, size int) {

func setTestCredentials(v *viper.Viper, size int) {
for i := 0; i < size; i++ {
v.Set("credentials."+innerring.GlagoliticLetter(i).String(), strconv.FormatUint(uint64(i), 10))
v.Set("credentials."+glagolitsa.LetterByIndex(i), strconv.FormatUint(uint64(i), 10))
}
}
42 changes: 42 additions & 0 deletions config/example/ir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,48 @@ morph:
CryptoLib: [0]
StdLib: [0]

network_settings: # NeoFS network settings managed in the Netmap contract
epoch_duration: 240 # Time interval (approximate) between two adjacent NeoFS epochs measured in Sidechain blocks.
# Must be an integer in range [1, 18446744073709551615]
max_object_size: 67108864 # [bytes] Maximum size of physically stored NeoFS objects. Note that this applies
# only to objects located on storage nodes: user objects have no restrictions and, if necessary, are sliced.
# Must be an integer in range [1, 18446744073709551615]
require_homomorphic_hashing: true # Toggles the requirement for homomorphic hashing of object payloads.
# Must be 'true' or 'false'
allow_maintenance_mode: true # Toggles permission to transition storage nodes to maintenance state.
# Must be 'true' or 'false'
eigen_trust:
alpha: 0.1 # Alpha parameter of EigenTrust algorithm used in the Reputation system.
# Must be a floating point number in range [0, 1].
iterations_number: 4 # Number of EigenTrust algorithm iterations to pass in the Reputation system.
# Must be an integer in range [1, 18446744073709551615]
price: # Price settings. NEOFS means NeoFS Balance contract tokens (usually GASe-12).
storage: 100000000 # [NEOFS] Price for 1GB of data paid every epoch by data owner to storage nodes.
# Must be an integer in range [0, 18446744073709551615]
fee:
ir_candidate: 100 # [GASe-8] Contribution from the new candidate to the Inner Ring. Must be non-negative integer
# Must be an integer in range [0, 18446744073709551615]
withdraw: 100000000 # [GASe-8] Fee paid by the user account to;
# - NeoFS Processing contract (if Notary service is enabled in the NeoFS Mainchain)
# - each Alphabet member (otherwise)
# Must be an integer in range [0, 18446744073709551615]
audit: 10000 # [NEOFS] Fee for data audit paid by storage group owner to the auditor (Inner Ring member).
# Must be an integer in range [0, 18446744073709551615]
new_container: 1000 # [NEOFS] Fee for new container paid by creator to each Alphabet member.
# Must be an integer in range [0, 18446744073709551615]
container_domain: 500 # [NEOFS] Fee for container's NNS domain paid by container creator to each Alphabet member.
# Must be a non-negative integer
custom: # Optional list of custom key-value pairs to be set in the network configuration. Forbidden keys:
# [AuditFee, BasicIncomeRate, ContainerAliasFee, ContainerFee, EigenTrustAlpha, EigenTrustIterations, EpochDuration,
# HomomorphicHashingDisabled, InnerRingCandidateFee, MaintenanceModeAllowed, MaxObjectSize, WithdrawFee]
# Note that this list can be extended in the future, so, to avoid potential collision, it is recommended
# to use the most specific keys.
- my_custom_key1=val1
- my_custom_key2=val2

nns:
system_email: [email protected]

mainnet:
dial_timeout: 5s # Timeout for RPC client connection to mainchain; ignore if mainchain is disabled
reconnections_number: 5 # number of reconnection attempts
Expand Down
2 changes: 1 addition & 1 deletion contracts/00-nns.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"NameService","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":32,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"addRecord","offset":2567,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"},{"name":"data","type":"String"}],"returntype":"Void","safe":false},{"name":"balanceOf","offset":568,"parameters":[{"name":"owner","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"decimals","offset":479,"parameters":[],"returntype":"Integer","safe":true},{"name":"deleteRecords","offset":2702,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"}],"returntype":"Void","safe":false},{"name":"getAllRecords","offset":2858,"parameters":[{"name":"name","type":"String"}],"returntype":"InteropInterface","safe":false},{"name":"getPrice","offset":972,"parameters":[],"returntype":"Integer","safe":true},{"name":"getRecords","offset":2659,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"}],"returntype":"Array","safe":true},{"name":"isAvailable","offset":1006,"parameters":[{"name":"name","type":"String"}],"returntype":"Boolean","safe":true},{"name":"ownerOf","offset":501,"parameters":[{"name":"tokenID","type":"ByteArray"}],"returntype":"Hash160","safe":true},{"name":"properties","offset":523,"parameters":[{"name":"tokenID","type":"ByteArray"}],"returntype":"Map","safe":true},{"name":"register","offset":1267,"parameters":[{"name":"name","type":"String"},{"name":"owner","type":"Hash160"},{"name":"email","type":"String"},{"name":"refresh","type":"Integer"},{"name":"retry","type":"Integer"},{"name":"expire","type":"Integer"},{"name":"ttl","type":"Integer"}],"returntype":"Boolean","safe":false},{"name":"renew","offset":2026,"parameters":[{"name":"name","type":"String"}],"returntype":"Integer","safe":false},{"name":"resolve","offset":2836,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"}],"returntype":"Array","safe":true},{"name":"roots","offset":866,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"setAdmin","offset":2237,"parameters":[{"name":"name","type":"String"},{"name":"admin","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"setPrice","offset":894,"parameters":[{"name":"price","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setRecord","offset":2371,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"},{"name":"id","type":"Integer"},{"name":"data","type":"String"}],"returntype":"Void","safe":false},{"name":"symbol","offset":473,"parameters":[],"returntype":"String","safe":true},{"name":"tokens","offset":644,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"tokensOf","offset":673,"parameters":[{"name":"owner","type":"Hash160"}],"returntype":"InteropInterface","safe":true},{"name":"totalSupply","offset":485,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":735,"parameters":[{"name":"to","type":"Hash160"},{"name":"tokenID","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"update","offset":386,"parameters":[{"name":"nef","type":"ByteArray"},{"name":"manifest","type":"String"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"updateSOA","offset":2147,"parameters":[{"name":"name","type":"String"},{"name":"email","type":"String"},{"name":"refresh","type":"Integer"},{"name":"retry","type":"Integer"},{"name":"expire","type":"Integer"},{"name":"ttl","type":"Integer"}],"returntype":"Void","safe":false},{"name":"version","offset":481,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"tokenId","type":"ByteArray"}]}]},"features":{},"groups":[],"permissions":[{"contract":"0xfffdc93764dbaddd97c48f252a53ea4643faa3fd","methods":["update"]},{"contract":"*","methods":["onNEP11Payment"]}],"supportedstandards":["NEP-11"],"trusts":[],"extra":null}
{"name":"NameService","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":32,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"addRecord","offset":3224,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"},{"name":"data","type":"String"}],"returntype":"Void","safe":false},{"name":"balanceOf","offset":976,"parameters":[{"name":"owner","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"decimals","offset":791,"parameters":[],"returntype":"Integer","safe":true},{"name":"deleteRecords","offset":3448,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"}],"returntype":"Void","safe":false},{"name":"getAllRecords","offset":3692,"parameters":[{"name":"name","type":"String"}],"returntype":"InteropInterface","safe":true},{"name":"getPrice","offset":1427,"parameters":[],"returntype":"Integer","safe":true},{"name":"getRecords","offset":3364,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"}],"returntype":"Array","safe":true},{"name":"isAvailable","offset":1461,"parameters":[{"name":"name","type":"String"}],"returntype":"Boolean","safe":true},{"name":"ownerOf","offset":813,"parameters":[{"name":"tokenID","type":"ByteArray"}],"returntype":"Hash160","safe":true},{"name":"properties","offset":883,"parameters":[{"name":"tokenID","type":"ByteArray"}],"returntype":"Map","safe":true},{"name":"register","offset":1722,"parameters":[{"name":"name","type":"String"},{"name":"owner","type":"Hash160"},{"name":"email","type":"String"},{"name":"refresh","type":"Integer"},{"name":"retry","type":"Integer"},{"name":"expire","type":"Integer"},{"name":"ttl","type":"Integer"}],"returntype":"Boolean","safe":false},{"name":"registerTLD","offset":2397,"parameters":[{"name":"name","type":"String"},{"name":"email","type":"String"},{"name":"refresh","type":"Integer"},{"name":"retry","type":"Integer"},{"name":"expire","type":"Integer"},{"name":"ttl","type":"Integer"}],"returntype":"Void","safe":false},{"name":"renew","offset":2598,"parameters":[{"name":"name","type":"String"}],"returntype":"Integer","safe":false},{"name":"resolve","offset":3630,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"}],"returntype":"Array","safe":true},{"name":"roots","offset":1321,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"setAdmin","offset":2809,"parameters":[{"name":"name","type":"String"},{"name":"admin","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"setPrice","offset":1349,"parameters":[{"name":"price","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setRecord","offset":2984,"parameters":[{"name":"name","type":"String"},{"name":"typ","type":"Integer"},{"name":"id","type":"Integer"},{"name":"data","type":"String"}],"returntype":"Void","safe":false},{"name":"symbol","offset":785,"parameters":[],"returntype":"String","safe":true},{"name":"tokens","offset":1052,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"tokensOf","offset":1081,"parameters":[{"name":"owner","type":"Hash160"}],"returntype":"InteropInterface","safe":true},{"name":"totalSupply","offset":797,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":1143,"parameters":[{"name":"to","type":"Hash160"},{"name":"tokenID","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"update","offset":698,"parameters":[{"name":"nef","type":"ByteArray"},{"name":"manifest","type":"String"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"updateSOA","offset":2719,"parameters":[{"name":"name","type":"String"},{"name":"email","type":"String"},{"name":"refresh","type":"Integer"},{"name":"retry","type":"Integer"},{"name":"expire","type":"Integer"},{"name":"ttl","type":"Integer"}],"returntype":"Void","safe":false},{"name":"version","offset":793,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"tokenId","type":"ByteArray"}]}]},"features":{},"groups":[],"permissions":[{"contract":"0xfffdc93764dbaddd97c48f252a53ea4643faa3fd","methods":["update"]},{"contract":"*","methods":["onNEP11Payment"]}],"supportedstandards":["NEP-11"],"trusts":[],"extra":null}
Binary file modified contracts/00-nns.nef
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/01-audit.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"NeoFS Audit","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"get","offset":892,"parameters":[{"name":"id","type":"ByteArray"}],"returntype":"ByteArray","safe":true},{"name":"list","offset":917,"parameters":[],"returntype":"Array","safe":true},{"name":"listByCID","offset":983,"parameters":[{"name":"epoch","type":"Integer"},{"name":"cid","type":"ByteArray"}],"returntype":"Array","safe":true},{"name":"listByEpoch","offset":951,"parameters":[{"name":"epoch","type":"Integer"}],"returntype":"Array","safe":true},{"name":"listByNode","offset":1026,"parameters":[{"name":"epoch","type":"Integer"},{"name":"cid","type":"ByteArray"},{"name":"key","type":"PublicKey"}],"returntype":"Array","safe":true},{"name":"put","offset":745,"parameters":[{"name":"rawAuditResult","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":616,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"version","offset":1104,"parameters":[],"returntype":"Integer","safe":true}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update"]}],"supportedstandards":[],"trusts":[],"extra":null}
Binary file added contracts/01-audit.nef
Binary file not shown.
Loading

0 comments on commit 78289be

Please sign in to comment.