forked from TrueCloudLab/frostfs-node
Compare commits
1021 commits
master
...
fix-writec
Author | SHA1 | Date | |
---|---|---|---|
a550fb584b | |||
5cbf57081f | |||
35370283ba | |||
802192cfef | |||
e2cee4cf09 | |||
814c411f4a | |||
7b0e3f5010 | |||
63c34ea707 | |||
86b2515744 | |||
b8cf0a6b88 | |||
76343f19e5 | |||
e2557b2f0b | |||
9b65f1595a | |||
ce42547980 | |||
9690bd02aa | |||
36fd6c663c | |||
be15eab82a | |||
f7a8f51c66 | |||
beb9d80e34 | |||
8148c9dc19 | |||
218bd72f9a | |||
a92188e5f9 | |||
f6ff3de0ae | |||
77694a2f3b | |||
b68f7be0b6 | |||
bee3741f4e | |||
ba00fc4971 | |||
fdeb99c52f | |||
34fcab3498 | |||
7954c7f8af | |||
cda3a3d834 | |||
0bd030507e | |||
6a5769d1da | |||
3a41858a0f | |||
962e5a9c19 | |||
b36a453238 | |||
abd502215f | |||
fb74524ac7 | |||
7f692409cf | |||
|
fc31b9c947 | ||
ff488b53a1 | |||
9a622a750d | |||
d19ade23c8 | |||
60527abb65 | |||
db67c21d55 | |||
728150d1d2 | |||
e4064c4394 | |||
15d853ea22 | |||
b3f3505ada | |||
a6eb66bf9c | |||
8e2a0611f4 | |||
80b581d499 | |||
805862f4b7 | |||
426cf58b98 | |||
edbe06e07e | |||
cbfeb72466 | |||
053a195ac2 | |||
cfc5ce7853 | |||
c3fa902780 | |||
6010dfdf3d | |||
a6c9a337cd | |||
b1a1b2107d | |||
d7838790c6 | |||
20b4447df7 | |||
9ba48c582d | |||
4358d3c423 | |||
afd2ba9a66 | |||
602ee11123 | |||
c1a5b831b6 | |||
befbaf9d56 | |||
f64c48b157 | |||
9916598dfb | |||
95e15f499f | |||
2cb04379a4 | |||
a5446bc17d | |||
d0eadf7ea2 | |||
6534252c22 | |||
5be2af881a | |||
96c86c4637 | |||
4352bd0e8e | |||
483a67b170 | |||
e3573de6db | |||
c441296592 | |||
675eec91f3 | |||
c681354afd | |||
df055fead5 | |||
c916a75948 | |||
6e2cc32768 | |||
417f8fc2c2 | |||
51d1d935ef | |||
b6fc3321c5 | |||
1fe7736d92 | |||
d13e37f70b | |||
d2d850786d | |||
61a3afbf9b | |||
c00eb7ccee | |||
cc2da73b20 | |||
5ed330e436 | |||
931a5e9aaf | |||
f2f3294fc3 | |||
f526f49995 | |||
f5160b27fc | |||
e42262a863 | |||
136acdba21 | |||
6ebd61298e | |||
0e3d144695 | |||
be33070550 | |||
63d3ed1ad8 | |||
57171907e3 | |||
c1a80235db | |||
96b020626f | |||
c8baf76fae | |||
e43609c616 | |||
52ffa9f164 | |||
394f086fe2 | |||
a601391719 | |||
be8607a1f6 | |||
a2ab373a0a | |||
7166e77c2b | |||
47dcfa20f3 | |||
836818fb75 | |||
f1b2b8bffa | |||
a8e52ef7aa | |||
5d982976fd | |||
4a4c790ec1 | |||
c19396d203 | |||
5c0a736a25 | |||
79bebe4a68 | |||
4b8b4da681 | |||
d75e7e9a21 | |||
dfd62ca6b1 | |||
d5d3d8badb | |||
225fe2d4d5 | |||
530249e3bd | |||
581887148a | |||
7a9db5bcdd | |||
32c282ca10 | |||
0cb0fc1735 | |||
b118734909 | |||
764f70634d | |||
8180a0664f | |||
5b672fb392 | |||
eab981bf1a | |||
825f65f79e | |||
b1eab1de54 | |||
ac0821a1a5 | |||
419b07e8b8 | |||
32f4e72e6a | |||
7ade11922e | |||
d69d318cb0 | |||
d9cbb16bd3 | |||
be8f499b91 | |||
7d7cf05575 | |||
61da7dca24 | |||
f4877e7b42 | |||
bdd43f6211 | |||
4a64b07703 | |||
2d4c0a0f4a | |||
ef07c1a3c9 | |||
eca7ac9f0d | |||
9b2dce5763 | |||
05f8f49289 | |||
7eb46404a1 | |||
11add38e87 | |||
94ffe8bb45 | |||
5d7833c89b | |||
d2746a7d67 | |||
3b7c0362a8 | |||
681b2c5fd4 | |||
a3ef7b58b4 | |||
1cd2bfe51a | |||
d5c9dd3c83 | |||
46532fb9ce | |||
70e0c1e082 | |||
0f45e3d344 | |||
e361e017f3 | |||
39060382a1 | |||
db49ad16cc | |||
ad0697adc4 | |||
e54dc3dc7c | |||
5e8c08da3e | |||
8911656b1a | |||
8bbfb2df43 | |||
2407e5f5ff | |||
c6a739e746 | |||
f1c7905263 | |||
d4d905ecc6 | |||
b2769ca3de | |||
da4fee2d0b | |||
422226da18 | |||
a531eaf8bc | |||
c1667a11d2 | |||
484eb59893 | |||
44552a849b | |||
a478050639 | |||
d30ab5f29e | |||
f314da4af3 | |||
29550fe600 | |||
b892feeaf6 | |||
6bb27f98dd | |||
44806aa9f1 | |||
f1db468d48 | |||
b2c63e57ba | |||
445ebcc0e7 | |||
2302e5d342 | |||
a982c3df18 | |||
7f6852bbd2 | |||
26e4f7005c | |||
b21be1abdd | |||
b215817e14 | |||
306f12e6c5 | |||
5521737f0b | |||
e81a58b8da | |||
5048236441 | |||
c516c7c5f4 | |||
c99157f0b2 | |||
07390ad4e3 | |||
8d18fa159e | |||
02454df14a | |||
76ff26039c | |||
47286ebf32 | |||
5cfb758e4e | |||
29fe8c41f3 | |||
137e987a4e | |||
4d5be5ccb5 | |||
fd9128d051 | |||
364f835b7e | |||
c1ec6e33b4 | |||
f871f5cc6c | |||
b62008daca | |||
f13f5d3b0f | |||
a952a406a2 | |||
f04806ccd3 | |||
8088063195 | |||
c8a62ffedd | |||
2393d13e4d | |||
518f3baf41 | |||
5466e88444 | |||
bdfa523487 | |||
78cfb6aea8 | |||
0f75e48138 | |||
7cdae4f660 | |||
1bca8f118f | |||
9133b4389e | |||
1b22801eed | |||
3534d6d05b | |||
3ed3e2715b | |||
66848d3288 | |||
8e11ef46b8 | |||
5ec73fe8a0 | |||
3a2c319b87 | |||
70ab1ebd54 | |||
9c98fa6152 | |||
226e84d782 | |||
1e21733ea5 | |||
523fb3ca51 | |||
74c91eeef5 | |||
cae50ecb21 | |||
20d6132f31 | |||
7b1eda5107 | |||
7c8591f83b | |||
1ab567870a | |||
0b0e5dab24 | |||
c7a7229484 | |||
a26483fc30 | |||
c80b46fad3 | |||
05b508f79a | |||
8a82335b5c | |||
990f9f2d2b | |||
79088baa06 | |||
00aa6d9749 | |||
b8f79f4227 | |||
261d281154 | |||
869518be0a | |||
d4b6ebe7e7 | |||
121f5c4dd8 | |||
9f7c2d8810 | |||
cddc58ace2 | |||
0a9830564f | |||
6950312967 | |||
4f62fded01 | |||
2dbf5c612a | |||
4239f1e817 | |||
7f35f2fb1d | |||
b0d303f3ed | |||
a788c24e6d | |||
4368243bed | |||
00a0045d9a | |||
7f8ccc105b | |||
efb37b0e65 | |||
fe1acf9e9a | |||
559ad58ab1 | |||
c0b86f2d93 | |||
b0cf100427 | |||
58b6224dd8 | |||
12b7cf2533 | |||
dc4d27201b | |||
189dbb01be | |||
f2437f7ae9 | |||
f26233b47a | |||
7e0c5a55de | |||
d5c10612f4 | |||
3a997d1207 | |||
bf082348d4 | |||
994f48f8bb | |||
aca11d7474 | |||
5e229dc248 | |||
4caa934eea | |||
d07afd803c | |||
997ac7cd8d | |||
bd5bf8b1a9 | |||
f3278d76a9 | |||
627b302745 | |||
a0a35ffbec | |||
c1e4130020 | |||
b8c3c2486d | |||
c14c9a023c | |||
d9b93b12c1 | |||
3889e829e6 | |||
10570fc035 | |||
c6af4a3ec8 | |||
58239d1b2c | |||
3c76884182 | |||
f435ab1b26 | |||
aa9f8dce3d | |||
8a81af5a3b | |||
a716db99db | |||
36759f8434 | |||
39879fa868 | |||
c661ba1312 | |||
268adb79cb | |||
429f941cda | |||
382eb8a485 | |||
42696016de | |||
bdecfbc1be | |||
aa23c6a83a | |||
da8f384324 | |||
aeeb8193d2 | |||
d9de9e2bbb | |||
88d50e4c77 | |||
054e3ef3d3 | |||
a54b4472de | |||
7456c8556a | |||
c672f59ab8 | |||
b9b86d2ec8 | |||
4dff9555f1 | |||
806cc13d9f | |||
1daef2ceeb | |||
fe5aa06a75 | |||
91f3745b58 | |||
7654847f79 | |||
a724debb19 | |||
55b82e744b | |||
ae81d6660a | |||
ab2614ec2d | |||
4ea0df77d0 | |||
554ff2c06b | |||
9072772a09 | |||
c4db8e7690 | |||
f8ba60aa0c | |||
d2084ece41 | |||
40b556fc19 | |||
4db2cbc927 | |||
966ad22abf | |||
56f841b022 | |||
ba58144de1 | |||
c9e3c9956e | |||
facd3b2c4b | |||
3fcf56f2fb | |||
96e690883f | |||
322c1dc273 | |||
02b03d9c4f | |||
82cc453be9 | |||
238b8f10a0 | |||
345a1a69a2 | |||
dc3bc08c07 | |||
23be3eb627 | |||
42fb6fb372 | |||
62c2ad4b22 | |||
84ea075587 | |||
354a92ea2c | |||
d3904ec599 | |||
4d9a6c07fb | |||
a1f1d233cc | |||
f2811f8585 | |||
c4e1d8eb07 | |||
10e63537b2 | |||
809e97626b | |||
2e49d7ea7e | |||
f7042c5a6f | |||
127c676786 | |||
e604a3d749 | |||
a8de37c8a2 | |||
5a51b78946 | |||
6407bb5bd1 | |||
5335e7089e | |||
2efe9cc1be | |||
58c8722c81 | |||
baad49990c | |||
0c52186572 | |||
eec97d177e | |||
d15199c5d8 | |||
bc425b5bad | |||
88b6755c5e | |||
ae8be495c8 | |||
376f03a445 | |||
ad87493c41 | |||
21800e9fcc | |||
a5f51add25 | |||
abdb0910cc | |||
4d2af137e9 | |||
b44a8dd46c | |||
20af34ecdb | |||
dd988a5912 | |||
32a9f51586 | |||
e084c47bd6 | |||
779da6ec35 | |||
2685b1d548 | |||
55ce4dc075 | |||
c54fcb297d | |||
26a78aa366 | |||
4ad0ebb32f | |||
c3e23a1448 | |||
6bcba27757 | |||
dca31e8888 | |||
b02a1a34c1 | |||
082370583f | |||
34b5d90441 | |||
6186329aec | |||
c3c0574e3c | |||
8f994163ee | |||
023b90342c | |||
d641cba2fc | |||
33c11be0cf | |||
5b7e4a51b7 | |||
de3d1eb99c | |||
ae322e9f73 | |||
8d589314b5 | |||
7da4306e38 | |||
d3a52ec73a | |||
0e697266c3 | |||
5bbfebba2d | |||
1a0cb0f34a | |||
65c72f3e0b | |||
1e8b4b8a17 | |||
435a581b5e | |||
93c46cfdf0 | |||
1b7b54ba89 | |||
b3695411d9 | |||
ec8a631d31 | |||
9ca63ac8c3 | |||
b8052c794e | |||
35dc64bd7b | |||
05ac9e3637 | |||
7b0fdf0202 | |||
ec8b4fdc48 | |||
ad5f527bd3 | |||
ea32913430 | |||
99bb488ebd | |||
286242cad0 | |||
32c77f3a23 | |||
5ff82ff04f | |||
448b48287c | |||
c2617baf63 | |||
372160d048 | |||
fef172c5b0 | |||
5a4054eeb6 | |||
eed594431f | |||
af82c2865e | |||
b4e72a2dfd | |||
94df541426 | |||
57e7fb5ccf | |||
24dffdac6f | |||
a9d04ba86f | |||
6429975584 | |||
4680087711 | |||
f0355a453e | |||
8b78db74bc | |||
8966dd8e35 | |||
b2487e8cc5 | |||
3b66f98f27 | |||
3e8de14e7d | |||
a0c7045f29 | |||
d8e37a827f | |||
486287c2f7 | |||
397131b0ea | |||
11027945d8 | |||
8a9fc2c372 | |||
b8bcfac531 | |||
24eb988897 | |||
c83e7c875f | |||
e8091101c7 | |||
ec9b738465 | |||
800a685e84 | |||
1420b8b9ea | |||
a476d8285a | |||
70a1081988 | |||
18d8898b00 | |||
61541eaec2 | |||
7da284f3e8 | |||
80481c015c | |||
0754e6e654 | |||
676a3efa79 | |||
c42db4e761 | |||
a65e26878b | |||
fcbf90d31b | |||
7b76527759 | |||
9be5d44a46 | |||
040a623d39 | |||
140d970a95 | |||
2310a5c7ba | |||
e858479a74 | |||
a0d51090a4 | |||
033eaf77e1 | |||
4bbe9cc936 | |||
6eefe9747e | |||
f354b8a270 | |||
c6df6c84ae | |||
b520a3049e | |||
4c248d573e | |||
90e9a85acc | |||
8d16d95376 | |||
26acf5689e | |||
3223402c90 | |||
f9730f090d | |||
0c5b025788 | |||
f437ab8f15 | |||
d01c064674 | |||
d0ab552a90 | |||
33d9ebbe7f | |||
f91cfb36e6 | |||
8a4e250dae | |||
4f413fe86e | |||
cab51c8cbe | |||
73a71a71b0 | |||
f4c71cea65 | |||
64e1383df6 | |||
13b53258b4 | |||
0c866f62c5 | |||
43d263c3d5 | |||
cac4ed93d6 | |||
71a63b8e9c | |||
4bf345225c | |||
b4ce0b0412 | |||
dd3874eff1 | |||
72fedff7ad | |||
ab489265b3 | |||
71889234b7 | |||
40eae22109 | |||
a64dc9ad70 | |||
167a67f0b8 | |||
785d81a68a | |||
4d48377cec | |||
03aa210145 | |||
b5d9f4a285 | |||
e89fa110c7 | |||
af608da952 | |||
56f320dd85 | |||
16a142cd0c | |||
d8ecc69d00 | |||
d5aaec1107 | |||
059e9e88a2 | |||
f54cc0b607 | |||
8318d90ad0 | |||
3ae3c8dfdb | |||
a8526d45e9 | |||
028d4a8058 | |||
01a0c97760 | |||
50caa388b0 | |||
69df0d21c2 | |||
fe01781811 | |||
20b84f183a | |||
69b788a90b | |||
26b305f82b | |||
4449006862 | |||
847732605c | |||
c348ae35b0 | |||
1b364d8cf4 | |||
c8023a9c8d | |||
85deb12f4d | |||
07f155ac77 | |||
71bbeddb64 | |||
fb8fee0c8e | |||
344d6b2ae1 | |||
4887f489a1 | |||
90e9247b69 | |||
4f83ab0fb4 | |||
e68384d4e3 | |||
898f0686b1 | |||
957a43a124 | |||
e69a1e8482 | |||
2541d319de | |||
0c40d98f7a | |||
83d600ed77 | |||
0400153b7d | |||
41ab4d070e | |||
cd92d8a9e7 | |||
9bc1a25c07 | |||
508e2064eb | |||
5b75432ca2 | |||
263c6fdc50 | |||
189a367ef2 | |||
a770b89fd8 | |||
f8c1e0639d | |||
f1f56ef871 | |||
96c9843591 | |||
9562123c49 | |||
63473d0806 | |||
2dd3fc8b7e | |||
55c28fd5f4 | |||
dcdfb6ed41 | |||
c09144ecf1 | |||
74578052f9 | |||
7e9a1f394a | |||
f7c4c07453 | |||
4476a1dbaf | |||
dbf41391b5 | |||
3220c4df9f | |||
faca861451 | |||
f934abed8f | |||
f64322576a | |||
ebcc8afbee | |||
8dcd06c587 | |||
a3e30062df | |||
365a7ca0f4 | |||
802168c0c6 | |||
9c54a24101 | |||
271a56c2ab | |||
bc34fee6a7 | |||
f2e5dead7e | |||
5983617069 | |||
20a489bdb5 | |||
9119199f6e | |||
2613351008 | |||
a1823423cf | |||
2ce43935f9 | |||
d212d908b5 | |||
4503a61997 | |||
53a1b15693 | |||
0ab589dd52 | |||
81718afb39 | |||
656fd7f376 | |||
fb708b3a2d | |||
03ab0ca30f | |||
cf8531ccd7 | |||
4b768fd115 | |||
ff570847a4 | |||
7eb8fa6350 | |||
731bf5d0ee | |||
e3ad3c2965 | |||
35c9b6b26d | |||
|
bf79d06f03 | ||
|
9e56592be3 | ||
483fac03d6 | |||
f7c0b50d70 | |||
e4889e06ba | |||
100b1b5128 | |||
0fc494637f | |||
aabcd8d3e4 | |||
df9e099fa7 | |||
13a7a90101 | |||
6f47c75e43 | |||
0624820909 | |||
869fcbf591 | |||
ab07bad33d | |||
8da6530f41 | |||
079b28fa0f | |||
d4d921dcaf | |||
429a87e83b | |||
|
f604d6bbdc | ||
f989bc52be | |||
61776033c2 | |||
|
14c35d776e | ||
a6ee7a3087 | |||
6055b18362 | |||
02c02974b3 | |||
147ae8728a | |||
c62025c836 | |||
c8c5f14e2e | |||
fe4082799a | |||
945454f60c | |||
4578d00619 | |||
d35e4c389f | |||
969bfb603f | |||
47b0ec33c3 | |||
b480df4985 | |||
|
bcdb0f330d | ||
|
ddcc156ecc | ||
35fdf6f315 | |||
|
a5f118a987 | ||
800eb5e983 | |||
a181c9e434 | |||
90799497d3 | |||
ea10abb42a | |||
1309622b20 | |||
b2ffd7df53 | |||
35ea207df6 | |||
|
ee58b390bb | ||
d02950ad63 | |||
973af12854 | |||
cedd07bbc8 | |||
|
479c5a65e1 | ||
2f6757c828 | |||
872fe90c40 | |||
d1661ae7dc | |||
5f1af84587 | |||
a1b4ba9980 | |||
529d0bc710 | |||
eca5c210dd | |||
b939e4e5c5 | |||
235fe84ea3 | |||
d00b1c0d29 | |||
fb5dcc15d2 | |||
31b4da225a | |||
5010b35466 | |||
686f01bce5 | |||
e89fa7f69f | |||
53693071de | |||
e70f808dc3 | |||
2dbe382b5f | |||
500611f3c8 | |||
3b64dffda2 | |||
22d47376a6 | |||
45438e7b06 | |||
1440450606 | |||
591c4e7d50 | |||
265d2326a0 | |||
30e1b62b67 | |||
8fc082b688 | |||
3bac5a485d | |||
f368ccbdf0 | |||
b2bc1fccbc | |||
a9c4ba62c3 | |||
586f5986bc | |||
f1ea8fec93 | |||
7f49f07255 | |||
8879c6ea4a | |||
8b2aae73c6 | |||
f73ac6e02d | |||
ff25521204 | |||
58f1ba4b51 | |||
daa26f6e9b | |||
291f9e809a | |||
0045f1bcd4 | |||
f856ad7480 | |||
ada081dfd5 | |||
1f4061c0e2 | |||
dfe4ada838 | |||
f07e2d4812 | |||
57718bd6b4 | |||
14f83b8aa9 | |||
563780057d | |||
ef222e2487 | |||
e61aec4a7d | |||
eb7be82e87 | |||
d390f093e0 | |||
b2123bfd1a | |||
ee01275d25 | |||
9d01029733 | |||
299b24b974 | |||
700f39c3f8 | |||
|
dce5924a89 | ||
89530534a1 | |||
c04f6c5e59 | |||
04be9415d9 | |||
ddbc9e255f | |||
c70306b324 | |||
6fef2726b8 | |||
4ade5339da | |||
015d62425b | |||
|
59822f7fb4 | ||
dc2e9d70c7 | |||
|
09938a9841 | ||
|
e9461686b8 | ||
|
6b6f33ed71 | ||
|
4f5f832137 | ||
6c90bb87f1 | |||
|
3d23b08773 | ||
13c8afcb02 | |||
|
20cd080323 | ||
3d43b0f7f9 | |||
a358255c1b | |||
b447ff99aa | |||
7b981bfe97 | |||
f07d4158f5 | |||
d757d881d0 | |||
05c870f39a | |||
160147b05d | |||
|
262c9c2b93 | ||
0b42a00a60 | |||
8466894fdf | |||
|
070154d506 | ||
|
beabed788c | ||
|
b453bb754c | ||
|
8799138fcb | ||
|
960e3c219e | ||
|
560f73ab7e | ||
6121b541b5 | |||
d62c6e4ce6 | |||
200fc8b882 | |||
995db117d0 | |||
8d2f443868 | |||
41eb3129ae | |||
adcfce39cf | |||
299b6a6938 | |||
0c6aeaaf18 | |||
4496999e52 | |||
cffcc7745e | |||
0e31c12e63 | |||
|
d29b13454f | ||
d686ab49e8 | |||
|
f41ad9d419 | ||
|
be4df989e5 | ||
|
96b38f7e86 | ||
2f1beddfd3 | |||
01c0c90a86 | |||
7d39fecc6a | |||
04727ce1d6 | |||
08769f413f | |||
5d2affa5cd | |||
5778980252 | |||
b2ca730547 | |||
0920d848d0 | |||
5af9f58469 | |||
72565a91ef | |||
c4865783fc | |||
6ad5c38225 | |||
c85a0bc866 | |||
6bf11f7cca | |||
2c07f831c7 | |||
93eba19a8e | |||
2ed9fd3f94 | |||
ccf8463e69 | |||
ae86cda58c | |||
6016d78a45 | |||
02831d427b | |||
38ae71cc7d | |||
b689027d57 | |||
0b9622c418 | |||
dbc3811ff4 | |||
cb172e73a6 | |||
c236b54a65 | |||
7ebbfa3358 | |||
469e8a6e59 | |||
e2f13d03d7 | |||
e8d340287f | |||
3dbff0a478 | |||
fe87735073 | |||
d07e40d6fe | |||
775179f823 | |||
e815b19101 | |||
56282edf02 | |||
9027695371 | |||
4ec69cbbf8 | |||
f32f61df87 | |||
8908798f59 | |||
bab11492ad | |||
e21c5bea21 | |||
68a2f36636 | |||
9e2df4b7c7 | |||
ab891517de | |||
c58ab0c369 | |||
89924071cd | |||
6c7b708a98 | |||
b0786d2e5c | |||
f889893216 | |||
91ead04fa4 | |||
1bf21dbb47 | |||
206458c841 | |||
279261ace3 | |||
6f7b6a8813 | |||
d6486d172e | |||
080be5cfcd | |||
23575e1ac0 | |||
9098d0eec0 | |||
760af6b912 | |||
d85703a963 | |||
0b38419fbf | |||
5f2a1531fe | |||
4941926c9d | |||
585415fa92 | |||
9ef790f782 | |||
cd33a57f44 | |||
1f1aed87be | |||
5a66db80c5 | |||
456bc097f7 | |||
3010ca2649 | |||
0739c36a3b | |||
8273a3dfb2 | |||
594b5821ed | |||
ee7468daa7 | |||
49cc23e03c | |||
e85e5382e4 | |||
8e5a0dcf27 | |||
0948a280fa | |||
ece6c820e7 | |||
27bdddc48f | |||
cecea8053a | |||
14d894178e | |||
|
a69c6d1ec9 | ||
|
2bdf7126b8 | ||
|
aa92f977ef | ||
|
f09ee27af9 | ||
|
db5321309d | ||
|
44d5412e10 | ||
ed28ce24cd | |||
1f929fdd57 | |||
dd572825c7 | |||
56161d39b4 | |||
28dc9e2190 | |||
dcd39f8fdd | |||
c94372e6f9 | |||
3bbb516528 | |||
a7c79c773a | |||
8426d25f4b | |||
c1cbe6ff2d | |||
aeb4bbc51e | |||
30c18d46cc | |||
6be2688fb4 | |||
4d160bd4ab | |||
c8a6978563 | |||
85fb9e77c4 | |||
7be5a0fd79 | |||
ab32067152 | |||
9f0bce5c15 | |||
341fe1688f | |||
|
e843e7f090 | ||
|
ba58a77f8c | ||
|
3646723ae3 | ||
|
97e201993b | ||
221203beeb | |||
91717d4b98 | |||
382ecae96a | |||
9e54646248 | |||
bf7d80f44b | |||
5bf1ec348f | |||
93cb9e3a94 | |||
512b72591a | |||
e1b99dacad | |||
92f8810970 | |||
b0fefcb21f | |||
d62b11f5e7 | |||
ecbc211016 | |||
5f7d70c59c | |||
9534ade716 | |||
f2e880465e | |||
04b3d9d068 | |||
1d5f2dd681 | |||
c2cf708e0e | |||
c78e9cc857 | |||
|
3c7ed21f74 | ||
a5ece7889d | |||
|
f3ff9fd251 | ||
|
533e9f8b75 | ||
9ffa0d8fea | |||
d857ffeb2e | |||
|
34329d67ff | ||
9808dec591 | |||
342e571d89 | |||
f111704ceb | |||
|
da8da1c63a | ||
49234b915e | |||
1637a3edce | |||
cbc2efb1d6 | |||
484ac502ca | |||
8014fdb21a | |||
fb13902db9 | |||
3f6b962349 | |||
5368c4207a | |||
47e8c5bf23 | |||
ec2c5d45b4 | |||
7eb9e88f8f | |||
9aeea0b974 | |||
|
9a4f40626c | ||
7a31988a36 | |||
5059dcc19d | |||
6c4a1699ef | |||
|
9cd8f7cea0 | ||
44b86bac5a | |||
481a1ca6f3 | |||
97c36ed3ec | |||
cc8ff015b4 | |||
2dc86058c3 | |||
573d920821 | |||
d64fb887ff | |||
392be818e5 | |||
db3ccd2762 | |||
|
abd21f8099 | ||
|
10c419adf0 | ||
b70caa216b | |||
|
64bde68fb9 | ||
|
f006f3b342 | ||
22be532cbd | |||
724debfdcd | |||
b1c165a93b | |||
ac0a278a05 | |||
b8e93d4c08 | |||
07de839f18 | |||
2886b1581b | |||
8b9e40a848 | |||
b4582239bf | |||
4e244686cf | |||
6cd806f998 | |||
3e6fd4c611 | |||
5ae4446280 | |||
5890cd4d7d | |||
365adb4ebd | |||
bce5827f64 | |||
05471d3827 | |||
8226d49376 | |||
0893689c6a | |||
a4931ea4c7 | |||
861e9ab59a | |||
|
24a540caa8 | ||
6226c3ba86 | |||
f2250a316f | |||
9929dcf50b | |||
7486c02bbc | |||
|
f1f3c80dbf | ||
|
381e363a8b | ||
20de74a505 |
1246 changed files with 57330 additions and 44134 deletions
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.18 as builder
|
FROM golang:1.21 as builder
|
||||||
ARG BUILD=now
|
ARG BUILD=now
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
ARG REPO=repository
|
ARG REPO=repository
|
||||||
|
|
25
.docker/Dockerfile.ci
Normal file
25
.docker/Dockerfile.ci
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
FROM golang:1.21
|
||||||
|
|
||||||
|
WORKDIR /tmp
|
||||||
|
|
||||||
|
# Install apt packages
|
||||||
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
pip \
|
||||||
|
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Dash → Bash
|
||||||
|
RUN echo "dash dash/sh boolean false" | debconf-set-selections
|
||||||
|
RUN DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash
|
||||||
|
|
||||||
|
RUN useradd -u 1234 -d /home/ci -m ci
|
||||||
|
USER ci
|
||||||
|
|
||||||
|
ENV PATH="$PATH:/home/ci/.local/bin"
|
||||||
|
|
||||||
|
COPY .pre-commit-config.yaml .
|
||||||
|
|
||||||
|
RUN pip install "pre-commit==3.1.1" \
|
||||||
|
&& git init . \
|
||||||
|
&& pre-commit install-hooks \
|
||||||
|
&& rm -rf /tmp/*
|
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.18 as builder
|
FROM golang:1.21 as builder
|
||||||
ARG BUILD=now
|
ARG BUILD=now
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
ARG REPO=repository
|
ARG REPO=repository
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.18 as builder
|
FROM golang:1.21 as builder
|
||||||
ARG BUILD=now
|
ARG BUILD=now
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
ARG REPO=repository
|
ARG REPO=repository
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.18 as builder
|
FROM golang:1.21 as builder
|
||||||
ARG BUILD=now
|
ARG BUILD=now
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
ARG REPO=repository
|
ARG REPO=repository
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
FROM golang:1.18 as builder
|
|
||||||
ARG BUILD=now
|
|
||||||
ARG VERSION=dev
|
|
||||||
ARG REPO=repository
|
|
||||||
WORKDIR /src
|
|
||||||
COPY . /src
|
|
||||||
|
|
||||||
RUN make bin/frostfs-node
|
|
||||||
|
|
||||||
# Executable image
|
|
||||||
FROM alpine AS frostfs-node
|
|
||||||
RUN apk add --no-cache bash
|
|
||||||
|
|
||||||
WORKDIR /
|
|
||||||
|
|
||||||
COPY --from=builder /src/bin/frostfs-node /bin/frostfs-node
|
|
||||||
COPY --from=builder /src/config/testnet/config.yml /config.yml
|
|
||||||
|
|
||||||
CMD ["frostfs-node", "--config", "/config.yml"]
|
|
|
@ -5,4 +5,5 @@ docker-compose.yml
|
||||||
Dockerfile
|
Dockerfile
|
||||||
temp
|
temp
|
||||||
.dockerignore
|
.dockerignore
|
||||||
docker
|
docker
|
||||||
|
.cache
|
||||||
|
|
41
.forgejo/workflows/build.yml
Normal file
41
.forgejo/workflows/build.yml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build Components
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go_versions: [ '1.20', '1.21' ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
# Allows to fetch all history for all branches and tags.
|
||||||
|
# Need this for proper versioning.
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '${{ matrix.go_versions }}'
|
||||||
|
|
||||||
|
- name: Build CLI
|
||||||
|
run: make bin/frostfs-cli
|
||||||
|
- run: bin/frostfs-cli --version
|
||||||
|
|
||||||
|
- name: Build NODE
|
||||||
|
run: make bin/frostfs-node
|
||||||
|
|
||||||
|
- name: Build IR
|
||||||
|
run: make bin/frostfs-ir
|
||||||
|
|
||||||
|
- name: Build ADM
|
||||||
|
run: make bin/frostfs-adm
|
||||||
|
- run: bin/frostfs-adm --version
|
||||||
|
|
||||||
|
- name: Build LENS
|
||||||
|
run: make bin/frostfs-lens
|
||||||
|
- run: bin/frostfs-lens --version
|
21
.forgejo/workflows/dco.yml
Normal file
21
.forgejo/workflows/dco.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
name: DCO action
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dco:
|
||||||
|
name: DCO
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
|
||||||
|
- name: Run commit format checker
|
||||||
|
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3
|
||||||
|
with:
|
||||||
|
from: 'origin/${{ github.event.pull_request.base.ref }}'
|
73
.forgejo/workflows/tests.yml
Normal file
73
.forgejo/workflows/tests.yml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
name: Tests and linters
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Install linters
|
||||||
|
run: make lint-install
|
||||||
|
|
||||||
|
- name: Run linters
|
||||||
|
run: make lint
|
||||||
|
|
||||||
|
tests:
|
||||||
|
name: Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go_versions: [ '1.20', '1.21' ]
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '${{ matrix.go_versions }}'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
tests-race:
|
||||||
|
name: Tests with -race
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: go test ./... -count=1 -race
|
||||||
|
|
||||||
|
staticcheck:
|
||||||
|
name: Staticcheck
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Install staticcheck
|
||||||
|
run: make staticcheck-install
|
||||||
|
|
||||||
|
- name: Run staticcheck
|
||||||
|
run: make staticcheck-run
|
22
.forgejo/workflows/vulncheck.yml
Normal file
22
.forgejo/workflows/vulncheck.yml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
name: Vulncheck
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
vulncheck:
|
||||||
|
name: Vulncheck
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
|
||||||
|
- name: Install govulncheck
|
||||||
|
run: go install golang.org/x/vuln/cmd/govulncheck@latest
|
||||||
|
|
||||||
|
- name: Run govulncheck
|
||||||
|
run: govulncheck ./...
|
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1,2 +1,3 @@
|
||||||
/**/*.pb.go -diff -merge
|
/**/*.pb.go -diff -merge
|
||||||
/**/*.pb.go linguist-generated=true
|
/**/*.pb.go linguist-generated=true
|
||||||
|
/go.sum -diff
|
||||||
|
|
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -1 +0,0 @@
|
||||||
* @TrueCloudLab/storage-core @TrueCloudLab/committers
|
|
16
.github/ISSUE_TEMPLATE/bug_report.md
vendored
16
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
@ -2,7 +2,7 @@
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: ''
|
title: ''
|
||||||
labels: community, triage
|
labels: community, triage, bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -18,8 +18,11 @@ assignees: ''
|
||||||
If suggesting a change/improvement, explain the difference from current behavior -->
|
If suggesting a change/improvement, explain the difference from current behavior -->
|
||||||
|
|
||||||
## Possible Solution
|
## Possible Solution
|
||||||
<!-- Not obligatory, but suggest a fix/reason for the bug,
|
<!-- Not obligatory
|
||||||
or ideas how to implement the addition or change -->
|
If no reason/fix/additions for the bug can be suggested,
|
||||||
|
uncomment the following phrase:
|
||||||
|
|
||||||
|
No fix can be suggested by a QA engineer. Further solutions shall be up to developers. -->
|
||||||
|
|
||||||
## Steps to Reproduce (for bugs)
|
## Steps to Reproduce (for bugs)
|
||||||
<!-- Provide a link to a live example, or an unambiguous set of steps
|
<!-- Provide a link to a live example, or an unambiguous set of steps
|
||||||
|
@ -41,10 +44,3 @@ assignees: ''
|
||||||
* Version used:
|
* Version used:
|
||||||
* Server setup and configuration:
|
* Server setup and configuration:
|
||||||
* Operating System and version (`uname -a`):
|
* Operating System and version (`uname -a`):
|
||||||
|
|
||||||
## Don't forget to add labels!
|
|
||||||
- component label (`frostfs-adm`, `frostfs-storage`, ...)
|
|
||||||
- `goodfirstissue`, `helpwanted` if needed
|
|
||||||
- does this issue belong to an epic?
|
|
||||||
- priority (`P0`-`P4`) if already triaged
|
|
||||||
- quarter label (`202XQY`) if possible
|
|
||||||
|
|
29
.github/workflows/changelog.yml
vendored
29
.github/workflows/changelog.yml
vendored
|
@ -1,29 +0,0 @@
|
||||||
name: CHANGELOG check
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- support/**
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Check for updates
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Get changed CHANGELOG
|
|
||||||
id: changelog-diff
|
|
||||||
uses: tj-actions/changed-files@v29
|
|
||||||
with:
|
|
||||||
files: CHANGELOG.md
|
|
||||||
|
|
||||||
- name: Fail if changelog not updated
|
|
||||||
if: steps.changelog-diff.outputs.any_changed == 'false'
|
|
||||||
uses: actions/github-script@v3
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
core.setFailed('CHANGELOG.md has not been updated')
|
|
37
.github/workflows/config-update.yml
vendored
37
.github/workflows/config-update.yml
vendored
|
@ -1,37 +0,0 @@
|
||||||
name: Configuration check
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- support/**
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: config-check
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Get changed config-related files
|
|
||||||
id: config-diff
|
|
||||||
uses: tj-actions/changed-files@v29
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
config/**
|
|
||||||
cmd/neofs-node/config/**
|
|
||||||
|
|
||||||
- name: Get changed doc files
|
|
||||||
id: docs-diff
|
|
||||||
uses: tj-actions/changed-files@v29
|
|
||||||
with:
|
|
||||||
files: docs/**
|
|
||||||
|
|
||||||
- name: Fail if config files are changed but the documentation is not updated
|
|
||||||
if: steps.config-diff.outputs.any_changed == 'true' && steps.docs-diff.outputs.any_changed == 'false'
|
|
||||||
uses: actions/github-script@v3
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
core.setFailed('Documentation has not been updated')
|
|
22
.github/workflows/dco.yml
vendored
22
.github/workflows/dco.yml
vendored
|
@ -1,22 +0,0 @@
|
||||||
name: DCO check
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- support/**
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
commits_check_job:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Commits Check
|
|
||||||
steps:
|
|
||||||
- name: Get PR Commits
|
|
||||||
id: 'get-pr-commits'
|
|
||||||
uses: tim-actions/get-pr-commits@master
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- name: DCO Check
|
|
||||||
uses: tim-actions/dco@master
|
|
||||||
with:
|
|
||||||
commits: ${{ steps.get-pr-commits.outputs.commits }}
|
|
60
.github/workflows/go.yml
vendored
60
.github/workflows/go.yml
vendored
|
@ -1,60 +0,0 @@
|
||||||
name: frostfs-node tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- support/**
|
|
||||||
paths-ignore:
|
|
||||||
- '*.md'
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- support/**
|
|
||||||
paths-ignore:
|
|
||||||
- '*.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
go: [ '1.18.x', '1.19.x' ]
|
|
||||||
steps:
|
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Cache go mod
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-${{ matrix.go }}-
|
|
||||||
|
|
||||||
- name: Run go test
|
|
||||||
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
|
|
||||||
|
|
||||||
- name: Codecov
|
|
||||||
env:
|
|
||||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
run: bash <(curl -s https://codecov.io/bash)
|
|
||||||
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: 1.19
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: golangci-lint
|
|
||||||
uses: golangci/golangci-lint-action@v3
|
|
||||||
with:
|
|
||||||
version: v1.50.0
|
|
||||||
args: --timeout=5m
|
|
||||||
only-new-issues: true
|
|
11
.gitlint
Normal file
11
.gitlint
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[general]
|
||||||
|
fail-without-commits=True
|
||||||
|
regex-style-search=True
|
||||||
|
contrib=CC1
|
||||||
|
|
||||||
|
[title-match-regex]
|
||||||
|
regex=^\[\#[0-9Xx]+\]\s
|
||||||
|
|
||||||
|
[ignore-by-title]
|
||||||
|
regex=^Release(.*)
|
||||||
|
ignore=title-match-regex
|
|
@ -4,7 +4,7 @@
|
||||||
# options for analysis running
|
# options for analysis running
|
||||||
run:
|
run:
|
||||||
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||||
timeout: 5m
|
timeout: 20m
|
||||||
|
|
||||||
# include test files or not, default is true
|
# include test files or not, default is true
|
||||||
tests: false
|
tests: false
|
||||||
|
@ -24,6 +24,28 @@ linters-settings:
|
||||||
govet:
|
govet:
|
||||||
# report about shadowed variables
|
# report about shadowed variables
|
||||||
check-shadowing: false
|
check-shadowing: false
|
||||||
|
staticcheck:
|
||||||
|
checks: ["all", "-SA1019"] # TODO Enable SA1019 after deprecated warning are fixed.
|
||||||
|
funlen:
|
||||||
|
lines: 80 # default 60
|
||||||
|
statements: 60 # default 40
|
||||||
|
gocognit:
|
||||||
|
min-complexity: 40 # default 30
|
||||||
|
importas:
|
||||||
|
no-unaliased: true
|
||||||
|
no-extra-aliases: false
|
||||||
|
alias:
|
||||||
|
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object
|
||||||
|
alias: objectSDK
|
||||||
|
custom:
|
||||||
|
truecloudlab-linters:
|
||||||
|
path: bin/linters/external_linters.so
|
||||||
|
original-url: git.frostfs.info/TrueCloudLab/linters.git
|
||||||
|
settings:
|
||||||
|
noliteral:
|
||||||
|
target-methods : ["reportFlushError", "reportError"]
|
||||||
|
disable-packages: ["codes", "err", "res","exec"]
|
||||||
|
constants-package: "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
|
@ -51,6 +73,14 @@ linters:
|
||||||
- predeclared
|
- predeclared
|
||||||
- reassign
|
- reassign
|
||||||
- whitespace
|
- whitespace
|
||||||
|
- containedctx
|
||||||
|
- funlen
|
||||||
|
- gocognit
|
||||||
|
- contextcheck
|
||||||
|
- importas
|
||||||
|
- truecloudlab-linters
|
||||||
|
- perfsprint
|
||||||
|
- testifylint
|
||||||
|
- protogetter
|
||||||
disable-all: true
|
disable-all: true
|
||||||
fast: false
|
fast: false
|
||||||
|
|
||||||
|
|
63
.pre-commit-config.yaml
Normal file
63
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
ci:
|
||||||
|
autofix_prs: false
|
||||||
|
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/jorisroovers/gitlint
|
||||||
|
rev: v0.19.1
|
||||||
|
hooks:
|
||||||
|
- id: gitlint
|
||||||
|
stages: [commit-msg]
|
||||||
|
- id: gitlint-ci
|
||||||
|
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.5.0
|
||||||
|
hooks:
|
||||||
|
- id: check-added-large-files
|
||||||
|
- id: check-case-conflict
|
||||||
|
- id: check-executables-have-shebangs
|
||||||
|
- id: check-shebang-scripts-are-executable
|
||||||
|
- id: check-merge-conflict
|
||||||
|
- id: check-json
|
||||||
|
- id: check-xml
|
||||||
|
- id: check-yaml
|
||||||
|
- id: trailing-whitespace
|
||||||
|
args: [--markdown-linebreak-ext=md]
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
exclude: ".key$"
|
||||||
|
|
||||||
|
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||||
|
rev: v0.9.0.6
|
||||||
|
hooks:
|
||||||
|
- id: shellcheck
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: make-lint
|
||||||
|
name: Run Make Lint
|
||||||
|
entry: make lint
|
||||||
|
language: system
|
||||||
|
pass_filenames: false
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: go-unit-tests
|
||||||
|
name: go unit tests
|
||||||
|
entry: make test
|
||||||
|
pass_filenames: false
|
||||||
|
types: [go]
|
||||||
|
language: system
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: gofumpt
|
||||||
|
name: gofumpt
|
||||||
|
entry: make fumpt
|
||||||
|
pass_filenames: false
|
||||||
|
types: [go]
|
||||||
|
language: system
|
||||||
|
|
||||||
|
- repo: https://github.com/TekWizely/pre-commit-golang
|
||||||
|
rev: v1.0.0-rc.1
|
||||||
|
hooks:
|
||||||
|
- id: go-staticcheck-repo-mod
|
||||||
|
- id: go-mod-tidy
|
11
.woodpecker/pre-commit.yml
Normal file
11
.woodpecker/pre-commit.yml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
pipeline:
|
||||||
|
# Kludge for non-root containers under WoodPecker
|
||||||
|
fix-ownership:
|
||||||
|
image: alpine:latest
|
||||||
|
commands: chown -R 1234:1234 .
|
||||||
|
|
||||||
|
pre-commit:
|
||||||
|
image: git.frostfs.info/truecloudlab/frostfs-ci:v0.36
|
||||||
|
commands:
|
||||||
|
- export HOME="$(getent passwd $(id -u) | cut '-d:' -f6)"
|
||||||
|
- pre-commit run --hook-stage manual
|
1630
CHANGELOG.md
1630
CHANGELOG.md
File diff suppressed because it is too large
Load diff
|
@ -3,8 +3,8 @@
|
||||||
First, thank you for contributing! We love and encourage pull requests from
|
First, thank you for contributing! We love and encourage pull requests from
|
||||||
everyone. Please follow the guidelines:
|
everyone. Please follow the guidelines:
|
||||||
|
|
||||||
- Check the open [issues](https://github.com/TrueCloudLab/frostfs-node/issues) and
|
- Check the open [issues](https://git.frostfs.info/TrueCloudLab/frostfs-node/issues) and
|
||||||
[pull requests](https://github.com/TrueCloudLab/frostfs-node/pulls) for existing
|
[pull requests](https://git.frostfs.info/TrueCloudLab/frostfs-node/pulls) for existing
|
||||||
discussions.
|
discussions.
|
||||||
|
|
||||||
- Open an issue first, to discuss a new feature or enhancement.
|
- Open an issue first, to discuss a new feature or enhancement.
|
||||||
|
@ -27,19 +27,19 @@ Start by forking the `frostfs-node` repository, make changes in a branch and the
|
||||||
send a pull request. We encourage pull requests to discuss code changes. Here
|
send a pull request. We encourage pull requests to discuss code changes. Here
|
||||||
are the steps in details:
|
are the steps in details:
|
||||||
|
|
||||||
### Set up your GitHub Repository
|
### Set up your Forgejo repository
|
||||||
Fork [FrostFS node upstream](https://github.com/TrueCloudLab/frostfs-node/fork) source
|
Fork [FrostFS node upstream](https://git.frostfs.info/TrueCloudLab/frostfs-node) source
|
||||||
repository to your own personal repository. Copy the URL of your fork (you will
|
repository to your own personal repository. Copy the URL of your fork (you will
|
||||||
need it for the `git clone` command below).
|
need it for the `git clone` command below).
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ git clone https://github.com/TrueCloudLab/frostfs-node
|
$ git clone https://git.frostfs.info/TrueCloudLab/frostfs-node
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set up git remote as ``upstream``
|
### Set up git remote as ``upstream``
|
||||||
```sh
|
```sh
|
||||||
$ cd frostfs-node
|
$ cd frostfs-node
|
||||||
$ git remote add upstream https://github.com/TrueCloudLab/frostfs-node
|
$ git remote add upstream https://git.frostfs.info/TrueCloudLab/frostfs-node
|
||||||
$ git fetch upstream
|
$ git fetch upstream
|
||||||
$ git merge upstream/master
|
$ git merge upstream/master
|
||||||
...
|
...
|
||||||
|
@ -58,7 +58,7 @@ $ git checkout -b feature/123-something_awesome
|
||||||
After your code changes, make sure
|
After your code changes, make sure
|
||||||
|
|
||||||
- To add test cases for the new code.
|
- To add test cases for the new code.
|
||||||
- To run `make lint`
|
- To run `make lint` and `make staticcheck-run`
|
||||||
- To squash your commits into a single commit or a series of logically separated
|
- To squash your commits into a single commit or a series of logically separated
|
||||||
commits run `git rebase -i`. It's okay to force update your pull request.
|
commits run `git rebase -i`. It's okay to force update your pull request.
|
||||||
- To run `make test` and `make all` completes.
|
- To run `make test` and `make all` completes.
|
||||||
|
@ -89,8 +89,8 @@ $ git push origin feature/123-something_awesome
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a Pull Request
|
### Create a Pull Request
|
||||||
Pull requests can be created via GitHub. Refer to [this
|
Pull requests can be created via Forgejo. Refer to [this
|
||||||
document](https://help.github.com/articles/creating-a-pull-request/) for
|
document](https://docs.codeberg.org/collaborating/pull-requests-and-git-flow/) for
|
||||||
detailed steps on how to create a pull request. After a Pull Request gets peer
|
detailed steps on how to create a pull request. After a Pull Request gets peer
|
||||||
reviewed and approved, it will be merged.
|
reviewed and approved, it will be merged.
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ In alphabetical order:
|
||||||
- Alexey Vanin
|
- Alexey Vanin
|
||||||
- Anastasia Prasolova
|
- Anastasia Prasolova
|
||||||
- Anatoly Bogatyrev
|
- Anatoly Bogatyrev
|
||||||
- Evgeny Kulikov
|
- Evgeny Kulikov
|
||||||
- Evgeny Stratonikov
|
- Evgeny Stratonikov
|
||||||
- Leonard Liubich
|
- Leonard Liubich
|
||||||
- Sergei Liubich
|
- Sergei Liubich
|
||||||
|
|
147
Makefile
Normal file → Executable file
147
Makefile
Normal file → Executable file
|
@ -7,8 +7,17 @@ VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8
|
||||||
HUB_IMAGE ?= truecloudlab/frostfs
|
HUB_IMAGE ?= truecloudlab/frostfs
|
||||||
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
||||||
|
|
||||||
GO_VERSION ?= 1.19
|
GO_VERSION ?= 1.21
|
||||||
LINT_VERSION ?= 1.50.0
|
LINT_VERSION ?= 1.55.2
|
||||||
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.3
|
||||||
|
PROTOC_VERSION ?= 25.0
|
||||||
|
PROTOC_GEN_GO_VERSION ?= $(shell go list -f '{{.Version}}' -m google.golang.org/protobuf)
|
||||||
|
PROTOGEN_FROSTFS_VERSION ?= $(shell go list -f '{{.Version}}' -m git.frostfs.info/TrueCloudLab/frostfs-api-go/v2)
|
||||||
|
PROTOC_OS_VERSION=osx-x86_64
|
||||||
|
ifeq ($(shell uname), Linux)
|
||||||
|
PROTOC_OS_VERSION=linux-x86_64
|
||||||
|
endif
|
||||||
|
STATICCHECK_VERSION ?= 2023.1.6
|
||||||
ARCH = amd64
|
ARCH = amd64
|
||||||
|
|
||||||
BIN = bin
|
BIN = bin
|
||||||
|
@ -25,8 +34,22 @@ PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \
|
||||||
sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \
|
sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \
|
||||||
sed "s/-/~/")-${OS_RELEASE}
|
sed "s/-/~/")-${OS_RELEASE}
|
||||||
|
|
||||||
.PHONY: help all images dep clean fmts fmt imports test lint docker/lint
|
OUTPUT_LINT_DIR ?= $(abspath $(BIN))/linters
|
||||||
prepare-release debpackage
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
||||||
|
TMP_DIR := .cache
|
||||||
|
PROTOBUF_DIR ?= $(abspath $(BIN))/protobuf
|
||||||
|
PROTOC_DIR ?= $(PROTOBUF_DIR)/protoc-v$(PROTOC_VERSION)
|
||||||
|
PROTOC_GEN_GO_DIR ?= $(PROTOBUF_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION)
|
||||||
|
PROTOGEN_FROSTFS_DIR ?= $(PROTOBUF_DIR)/protogen-$(PROTOGEN_FROSTFS_VERSION)
|
||||||
|
STATICCHECK_DIR ?= $(abspath $(BIN))/staticcheck
|
||||||
|
STATICCHECK_VERSION_DIR ?= $(STATICCHECK_DIR)/$(STATICCHECK_VERSION)
|
||||||
|
|
||||||
|
FROSTFS_CONTRACTS_PATH=$(abspath ./../frostfs-contract)
|
||||||
|
LOCODE_DB_PATH=$(abspath ./.cache/locode_db)
|
||||||
|
LOCODE_DB_VERSION=v0.4.0
|
||||||
|
|
||||||
|
.PHONY: help all images dep clean fmts fumpt imports test lint docker/lint
|
||||||
|
prepare-release debpackage pre-commit unpre-commit
|
||||||
|
|
||||||
# To build a specific binary, use it's name prefix with bin/ as a target
|
# To build a specific binary, use it's name prefix with bin/ as a target
|
||||||
# For example `make bin/frostfs-node` will build only storage node binary
|
# For example `make bin/frostfs-node` will build only storage node binary
|
||||||
|
@ -65,24 +88,40 @@ dep:
|
||||||
CGO_ENABLED=0 \
|
CGO_ENABLED=0 \
|
||||||
go mod tidy -v && echo OK
|
go mod tidy -v && echo OK
|
||||||
|
|
||||||
|
# Build export-metrics
|
||||||
|
export-metrics: dep
|
||||||
|
@printf "⇒ Build export-metrics\n"
|
||||||
|
CGO_ENABLED=0 \
|
||||||
|
go build -v -trimpath -o bin/export-metrics ./scripts/export-metrics
|
||||||
|
|
||||||
# Regenerate proto files:
|
# Regenerate proto files:
|
||||||
protoc:
|
protoc:
|
||||||
@GOPRIVATE=github.com/TrueCloudLab go mod vendor
|
@if [ ! -d "$(PROTOC_DIR)" ] || [ ! -d "$(PROTOC_GEN_GO_DIR)" ] || [ ! -d "$(PROTOGEN_FROSTFS_DIR)" ]; then \
|
||||||
# Install specific version for protobuf lib
|
make protoc-install; \
|
||||||
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go install -v
|
fi
|
||||||
@GOBIN=$(abspath $(BIN)) go install -mod=mod -v github.com/TrueCloudLab/frostfs-api-go/v2/util/protogen
|
@for f in `find . -type f -name '*.proto' -not -path './bin/*'`; do \
|
||||||
# Protoc generate
|
|
||||||
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
|
|
||||||
echo "⇒ Processing $$f "; \
|
echo "⇒ Processing $$f "; \
|
||||||
protoc \
|
$(PROTOC_DIR)/bin/protoc \
|
||||||
--proto_path=.:./vendor:/usr/local/include \
|
--proto_path=.:$(PROTOC_DIR)/include:/usr/local/include \
|
||||||
--plugin=protoc-gen-go-frostfs=$(BIN)/protogen \
|
--plugin=protoc-gen-go=$(PROTOC_GEN_GO_DIR)/protoc-gen-go \
|
||||||
|
--plugin=protoc-gen-go-frostfs=$(PROTOGEN_FROSTFS_DIR)/protogen \
|
||||||
--go-frostfs_out=. --go-frostfs_opt=paths=source_relative \
|
--go-frostfs_out=. --go-frostfs_opt=paths=source_relative \
|
||||||
--go_out=. --go_opt=paths=source_relative \
|
--go_out=. --go_opt=paths=source_relative \
|
||||||
--go-grpc_opt=require_unimplemented_servers=false \
|
--go-grpc_opt=require_unimplemented_servers=false \
|
||||||
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
||||||
done
|
done
|
||||||
rm -rf vendor
|
|
||||||
|
protoc-install:
|
||||||
|
@rm -rf $(PROTOBUF_DIR)
|
||||||
|
@mkdir $(PROTOBUF_DIR)
|
||||||
|
@echo "⇒ Installing protoc... "
|
||||||
|
@wget -q -O $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip 'https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS_VERSION).zip'
|
||||||
|
@unzip -q -o $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip -d $(PROTOC_DIR)
|
||||||
|
@rm $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip
|
||||||
|
@echo "⇒ Installing protoc-gen-go..."
|
||||||
|
@GOBIN=$(PROTOC_GEN_GO_DIR) go install -v google.golang.org/protobuf/...@$(PROTOC_GEN_GO_VERSION)
|
||||||
|
@echo "⇒ Instaling protogen FrostFS plugin..."
|
||||||
|
@GOBIN=$(PROTOGEN_FROSTFS_DIR) go install -mod=mod -v git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen@$(PROTOGEN_FROSTFS_VERSION)
|
||||||
|
|
||||||
# Build FrostFS component's docker image
|
# Build FrostFS component's docker image
|
||||||
image-%:
|
image-%:
|
||||||
|
@ -95,7 +134,7 @@ image-%:
|
||||||
-t $(HUB_IMAGE)-$*:$(HUB_TAG) .
|
-t $(HUB_IMAGE)-$*:$(HUB_TAG) .
|
||||||
|
|
||||||
# Build all Docker images
|
# Build all Docker images
|
||||||
images: image-storage image-ir image-cli image-adm image-storage-testnet
|
images: image-storage image-ir image-cli image-adm
|
||||||
|
|
||||||
# Build dirty local Docker images
|
# Build dirty local Docker images
|
||||||
dirty-images: image-dirty-storage image-dirty-ir image-dirty-cli image-dirty-adm
|
dirty-images: image-dirty-storage image-dirty-ir image-dirty-cli image-dirty-adm
|
||||||
|
@ -111,26 +150,56 @@ docker/%:
|
||||||
|
|
||||||
|
|
||||||
# Run all code formatters
|
# Run all code formatters
|
||||||
fmts: fmt imports
|
fmts: fumpt imports
|
||||||
|
|
||||||
# Reformat code
|
|
||||||
fmt:
|
|
||||||
@echo "⇒ Processing gofmt check"
|
|
||||||
@gofmt -s -w cmd/ pkg/ misc/
|
|
||||||
|
|
||||||
# Reformat imports
|
# Reformat imports
|
||||||
imports:
|
imports:
|
||||||
@echo "⇒ Processing goimports check"
|
@echo "⇒ Processing goimports check"
|
||||||
@goimports -w cmd/ pkg/ misc/
|
@goimports -w cmd/ pkg/ misc/
|
||||||
|
|
||||||
|
fumpt:
|
||||||
|
@echo "⇒ Processing gofumpt check"
|
||||||
|
@gofumpt -l -w cmd/ pkg/ misc/
|
||||||
|
|
||||||
# Run Unit Test with go test
|
# Run Unit Test with go test
|
||||||
test:
|
test:
|
||||||
@echo "⇒ Running go test"
|
@echo "⇒ Running go test"
|
||||||
@go test ./...
|
@go test ./... -count=1
|
||||||
|
|
||||||
|
pre-commit-run:
|
||||||
|
@pre-commit run -a --hook-stage manual
|
||||||
|
|
||||||
|
# Install linters
|
||||||
|
lint-install:
|
||||||
|
@rm -rf $(OUTPUT_LINT_DIR)
|
||||||
|
@mkdir $(OUTPUT_LINT_DIR)
|
||||||
|
@mkdir -p $(TMP_DIR)
|
||||||
|
@rm -rf $(TMP_DIR)/linters
|
||||||
|
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
|
||||||
|
@@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
|
||||||
|
@rm -rf $(TMP_DIR)/linters
|
||||||
|
@rmdir $(TMP_DIR) 2>/dev/null || true
|
||||||
|
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
||||||
|
|
||||||
# Run linters
|
# Run linters
|
||||||
lint:
|
lint:
|
||||||
@golangci-lint --timeout=5m run
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
||||||
|
make lint-install; \
|
||||||
|
fi
|
||||||
|
$(LINT_DIR)/golangci-lint run
|
||||||
|
|
||||||
|
# Install staticcheck
|
||||||
|
staticcheck-install:
|
||||||
|
@rm -rf $(STATICCHECK_DIR)
|
||||||
|
@mkdir $(STATICCHECK_DIR)
|
||||||
|
@GOBIN=$(STATICCHECK_VERSION_DIR) go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
|
||||||
|
|
||||||
|
# Run staticcheck
|
||||||
|
staticcheck-run:
|
||||||
|
@if [ ! -d "$(STATICCHECK_VERSION_DIR)" ]; then \
|
||||||
|
make staticcheck-install; \
|
||||||
|
fi
|
||||||
|
@$(STATICCHECK_VERSION_DIR)/staticcheck ./...
|
||||||
|
|
||||||
# Run linters in Docker
|
# Run linters in Docker
|
||||||
docker/lint:
|
docker/lint:
|
||||||
|
@ -140,12 +209,20 @@ docker/lint:
|
||||||
--env HOME=/src \
|
--env HOME=/src \
|
||||||
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
||||||
|
|
||||||
|
# Activate pre-commit hooks
|
||||||
|
pre-commit:
|
||||||
|
pre-commit install -t pre-commit -t commit-msg
|
||||||
|
|
||||||
|
# Deactivate pre-commit hooks
|
||||||
|
unpre-commit:
|
||||||
|
pre-commit uninstall -t pre-commit -t commit-msg
|
||||||
|
|
||||||
# Print version
|
# Print version
|
||||||
version:
|
version:
|
||||||
@echo $(VERSION)
|
@echo $(VERSION)
|
||||||
|
|
||||||
|
# Delete built artifacts
|
||||||
clean:
|
clean:
|
||||||
rm -rf vendor
|
|
||||||
rm -rf .cache
|
rm -rf .cache
|
||||||
rm -rf $(BIN)
|
rm -rf $(BIN)
|
||||||
rm -rf $(RELEASE)
|
rm -rf $(RELEASE)
|
||||||
|
@ -161,3 +238,25 @@ debpackage:
|
||||||
|
|
||||||
debclean:
|
debclean:
|
||||||
dh clean
|
dh clean
|
||||||
|
|
||||||
|
locode-download:
|
||||||
|
@wget -q -O ./.cache/locode_db.gz 'https://git.frostfs.info/TrueCloudLab/frostfs-locode-db/releases/download/${LOCODE_DB_VERSION}/locode_db.gz'
|
||||||
|
gzip -dfk ./.cache/locode_db.gz
|
||||||
|
|
||||||
|
env-up: all
|
||||||
|
docker compose -f dev/docker-compose.yml up -d
|
||||||
|
@if [ ! -d "$(FROSTFS_CONTRACTS_PATH)" ]; then \
|
||||||
|
echo "Frostfs contracts not found"; exit 1; \
|
||||||
|
fi
|
||||||
|
${BIN}/frostfs-adm --config ./dev/adm/frostfs-adm.yml morph init --contracts ${FROSTFS_CONTRACTS_PATH}
|
||||||
|
${BIN}/frostfs-adm --config ./dev/adm/frostfs-adm.yml morph refill-gas --storage-wallet ./dev/storage/wallet.json --gas 10.0
|
||||||
|
@if [ ! -f "$(LOCODE_DB_PATH)" ]; then \
|
||||||
|
make locode-download; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
env-down:
|
||||||
|
docker compose -f dev/docker-compose.yml down
|
||||||
|
docker volume rm -f frostfs-node_neo-go
|
||||||
|
rm -f ./.cache/.frostfs-ir-state
|
||||||
|
rm -f ./.cache/.frostfs-node-state
|
||||||
|
rm -rf ./.cache/storage
|
||||||
|
|
43
README.md
43
README.md
|
@ -31,7 +31,7 @@ dApps directly from
|
||||||
code level. This way dApps are not limited to on-chain storage and can
|
code level. This way dApps are not limited to on-chain storage and can
|
||||||
manipulate large amounts of data without paying a prohibitive price.
|
manipulate large amounts of data without paying a prohibitive price.
|
||||||
|
|
||||||
FrostFS has a native [gRPC API](https://github.com/TrueCloudLab/frostfs-api) and has
|
FrostFS has a native [gRPC API](https://git.frostfs.info/TrueCloudLab/frostfs-api) and has
|
||||||
protocol gateways for popular protocols such as [AWS
|
protocol gateways for popular protocols such as [AWS
|
||||||
S3](https://github.com/TrueCloudLab/frostfs-s3-gw),
|
S3](https://github.com/TrueCloudLab/frostfs-s3-gw),
|
||||||
[HTTP](https://github.com/TrueCloudLab/frostfs-http-gw),
|
[HTTP](https://github.com/TrueCloudLab/frostfs-http-gw),
|
||||||
|
@ -49,7 +49,7 @@ The latest version of frostfs-node works with frostfs-contract
|
||||||
|
|
||||||
# Building
|
# Building
|
||||||
|
|
||||||
To make all binaries you need Go 1.18+ and `make`:
|
To make all binaries you need Go 1.20+ and `make`:
|
||||||
```
|
```
|
||||||
make all
|
make all
|
||||||
```
|
```
|
||||||
|
@ -76,6 +76,45 @@ To make docker images suitable for use in [frostfs-dev-env](https://github.com/T
|
||||||
make images
|
make images
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Debugging
|
||||||
|
|
||||||
|
## VSCode
|
||||||
|
|
||||||
|
To run and debug single node cluster with VSCode:
|
||||||
|
|
||||||
|
1. Clone and build [frostfs-contract](https://git.frostfs.info/TrueCloudLab/frostfs-contract) repository to the same directory level as `frostfs-node`. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
/
|
||||||
|
├── src
|
||||||
|
├── frostfs-node
|
||||||
|
└── frostfs-contract
|
||||||
|
```
|
||||||
|
See `frostfs-contract`'s README.md for build instructions.
|
||||||
|
|
||||||
|
2. Copy `launch.json` and `tasks.json` from `dev/.vscode-example` directory to `.vscode` directory. If you already have such files in `.vscode` directory, then merge them manually.
|
||||||
|
|
||||||
|
3. Go to **Run and Debug** (`Ctrl+Shift+D`) and start `IR+Storage node` configuration.
|
||||||
|
|
||||||
|
4. To create container and put object into it run (container and object IDs will be different):
|
||||||
|
|
||||||
|
```
|
||||||
|
./bin/frostfs-cli container create -r 127.0.0.1:8080 --wallet ./dev/wallet.json --policy "REP 1 IN X CBF 1 SELECT 1 FROM * AS X" --basic-acl public-read-write --await
|
||||||
|
Enter password > <- press ENTER, the is no password for wallet
|
||||||
|
CID: CfPhEuHQ2PRvM4gfBQDC4dWZY3NccovyfcnEdiq2ixju
|
||||||
|
|
||||||
|
./bin/frostfs-cli object put -r 127.0.0.1:8080 --wallet ./dev/wallet.json --file README.md --cid CfPhEuHQ2PRvM4gfBQDC4dWZY3NccovyfcnEdiq2ixju
|
||||||
|
Enter password >
|
||||||
|
4300 / 4300 [===========================================================================================================================================================================================================] 100.00% 0s
|
||||||
|
[README.md] Object successfully stored
|
||||||
|
OID: 78sohnudVMnPsczXqsTUcvezosan2YDNVZwDE8Kq5YwU
|
||||||
|
CID: CfPhEuHQ2PRvM4gfBQDC4dWZY3NccovyfcnEdiq2ixju
|
||||||
|
|
||||||
|
./bin/frostfs-cli object get -r 127.0.0.1:8080 --wallet ./dev/wallet.json --cid CfPhEuHQ2PRvM4gfBQDC4dWZY3NccovyfcnEdiq2ixju --oid 78sohnudVMnPsczXqsTUcvezosan2YDNVZwDE8Kq5YwU
|
||||||
|
...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
Feel free to contribute to this project after reading the [contributing
|
Feel free to contribute to this project after reading the [contributing
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
v0.35.0
|
v0.36.0
|
||||||
|
|
|
@ -3,23 +3,22 @@
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Admin tool provides an easier way to deploy and maintain private installation
|
Admin tool provides an easier way to deploy and maintain private installation
|
||||||
of FrostFS. Private installation provides a set of N3 consensus nodes, FrostFS
|
of FrostFS. Private installation provides a set of N3 consensus nodes, FrostFS
|
||||||
Alphabet, and Storage nodes. Admin tool generates consensus keys, initializes
|
Alphabet, and Storage nodes. Admin tool generates consensus keys, initializes
|
||||||
the sidechain, and provides functions to update the network and register new
|
the sidechain, and provides functions to update the network and register new
|
||||||
Storage nodes.
|
Storage nodes.
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
To build binary locally, use `make bin/frostfs-adm` command.
|
To build binary locally, use `make bin/frostfs-adm` command.
|
||||||
|
|
||||||
For clean build inside a docker container, use `make docker/bin/frostfs-adm`.
|
For clean build inside a docker container, use `make docker/bin/frostfs-adm`.
|
||||||
|
|
||||||
Build docker image with `make image-adm`.
|
Build docker image with `make image-adm`.
|
||||||
|
|
||||||
At FrostFS private install deployment, frostfs-adm requires compiled FrostFS
|
At FrostFS private install deployment, frostfs-adm requires compiled FrostFS
|
||||||
contracts. Find them in the latest release of
|
contracts. Find them in the latest release of
|
||||||
[frostfs-contract repository](https://github.com/TrueCloudLab/frostfs-contract/releases).
|
[frostfs-contract repository](https://git.frostfs.info/TrueCloudLab/frostfs-contract/releases).
|
||||||
|
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ contracts. Find them in the latest release of
|
||||||
|
|
||||||
Config section provides `init` command that creates a configuration file for
|
Config section provides `init` command that creates a configuration file for
|
||||||
private installation deployment and updates. Config file is optional, all
|
private installation deployment and updates. Config file is optional, all
|
||||||
parameters can be passed by arguments or read from standard input (wallet
|
parameters can be passed by arguments or read from standard input (wallet
|
||||||
passwords).
|
passwords).
|
||||||
|
|
||||||
Config example:
|
Config example:
|
||||||
|
@ -37,9 +36,7 @@ alphabet-wallets: /path # path to consensus node / alphabet wallets s
|
||||||
network:
|
network:
|
||||||
max_object_size: 67108864 # max size of a single FrostFS object, bytes
|
max_object_size: 67108864 # max size of a single FrostFS object, bytes
|
||||||
epoch_duration: 240 # duration of a FrostFS epoch in blocks, consider block generation frequency in the sidechain
|
epoch_duration: 240 # duration of a FrostFS epoch in blocks, consider block generation frequency in the sidechain
|
||||||
basic_income_rate: 0 # basic income rate, for private consider 0
|
|
||||||
fee:
|
fee:
|
||||||
audit: 0 # network audit fee, for private installation consider 0
|
|
||||||
candidate: 0 # inner ring candidate registration fee, for private installation consider 0
|
candidate: 0 # inner ring candidate registration fee, for private installation consider 0
|
||||||
container: 0 # container creation fee, for private installation consider 0
|
container: 0 # container creation fee, for private installation consider 0
|
||||||
container_alias: 0 # container nice-name registration fee, for private installation consider 0
|
container_alias: 0 # container nice-name registration fee, for private installation consider 0
|
||||||
|
@ -58,14 +55,14 @@ credentials: # passwords for consensus node / alphabet wallets
|
||||||
|
|
||||||
#### Network deployment
|
#### Network deployment
|
||||||
|
|
||||||
- `generate-alphabet` generates a set of wallets for consensus and
|
- `generate-alphabet` generates a set of wallets for consensus and
|
||||||
Alphabet nodes.
|
Alphabet nodes.
|
||||||
|
|
||||||
- `init` initializes the sidechain by deploying smart contracts and
|
- `init` initializes the sidechain by deploying smart contracts and
|
||||||
setting provided FrostFS network configuration.
|
setting provided FrostFS network configuration.
|
||||||
|
|
||||||
- `generate-storage-wallet` generates a wallet for the Storage node that
|
- `generate-storage-wallet` generates a wallet for the Storage node that
|
||||||
is ready for deployment. It also transfers a bit of sidechain GAS, so this
|
is ready for deployment. It also transfers a bit of sidechain GAS, so this
|
||||||
wallet can be used for FrostFS bootstrap.
|
wallet can be used for FrostFS bootstrap.
|
||||||
|
|
||||||
#### Network maintenance
|
#### Network maintenance
|
||||||
|
@ -75,7 +72,7 @@ credentials: # passwords for consensus node / alphabet wallets
|
||||||
- `force-new-epoch` increments FrostFS epoch number and executes new epoch
|
- `force-new-epoch` increments FrostFS epoch number and executes new epoch
|
||||||
handlers in FrostFS nodes.
|
handlers in FrostFS nodes.
|
||||||
|
|
||||||
- `refill-gas` transfers sidechain GAS to the specified wallet.
|
- `refill-gas` transfers sidechain GAS to the specified wallet.
|
||||||
|
|
||||||
- `update-contracts` updates contracts to a new version.
|
- `update-contracts` updates contracts to a new version.
|
||||||
|
|
||||||
|
@ -87,7 +84,7 @@ info. These commands **do not migrate actual objects**.
|
||||||
- `dump-containers` saves all containers and metadata registered in the container
|
- `dump-containers` saves all containers and metadata registered in the container
|
||||||
contract to a file.
|
contract to a file.
|
||||||
|
|
||||||
- `restore-containers` restores previously saved containers by their repeated registration in
|
- `restore-containers` restores previously saved containers by their repeated registration in
|
||||||
the container contract.
|
the container contract.
|
||||||
|
|
||||||
- `list-containers` output all containers ids.
|
- `list-containers` output all containers ids.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
This is a short guide on how to deploy a private FrostFS storage network on bare
|
This is a short guide on how to deploy a private FrostFS storage network on bare
|
||||||
metal without docker images. This guide does not cover details on how to start
|
metal without docker images. This guide does not cover details on how to start
|
||||||
consensus, Alphabet, or Storage nodes. This guide covers only `frostfs-adm`
|
consensus, Alphabet, or Storage nodes. This guide covers only `frostfs-adm`
|
||||||
related configuration details.
|
related configuration details.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
@ -12,12 +12,13 @@ To follow this guide you need:
|
||||||
- latest released version of [frostfs-adm](https://github.com/TrueCloudLab/frostfs-node/releases) utility (v0.25.1 at the moment),
|
- latest released version of [frostfs-adm](https://github.com/TrueCloudLab/frostfs-node/releases) utility (v0.25.1 at the moment),
|
||||||
- latest released version of compiled [frostfs-contract](https://github.com/TrueCloudLab/frostfs-contract/releases) (v0.11.0 at the moment).
|
- latest released version of compiled [frostfs-contract](https://github.com/TrueCloudLab/frostfs-contract/releases) (v0.11.0 at the moment).
|
||||||
|
|
||||||
## Step 1: Prepare network configuration
|
## Step 1: Prepare network configuration
|
||||||
|
|
||||||
To start a network, you need a set of consensus nodes, the same number of
|
To start a network, you need a set of consensus nodes, the same number of
|
||||||
Alphabet nodes and any number of Storage nodes. While the number of Storage
|
Alphabet nodes and any number of Storage nodes. While the number of Storage
|
||||||
nodes can be scaled almost infinitely, the number of consensus and Alphabet
|
nodes can be scaled almost infinitely, the number of consensus and Alphabet
|
||||||
nodes can't be changed so easily right now. Consider this before going any further.
|
nodes can't be changed so easily right now. Consider this before going any further.
|
||||||
|
Note also that there is an upper limit on the number of alphabet nodes (currently 22).
|
||||||
|
|
||||||
It is easier to use`frostfs-adm` with a predefined configuration. First, create
|
It is easier to use`frostfs-adm` with a predefined configuration. First, create
|
||||||
a network configuration file. In this example, there is going to be only one
|
a network configuration file. In this example, there is going to be only one
|
||||||
|
@ -27,15 +28,13 @@ consensus / Alphabet node in the network.
|
||||||
$ frostfs-adm config init --path foo.network.yml
|
$ frostfs-adm config init --path foo.network.yml
|
||||||
Initial config file saved to foo.network.yml
|
Initial config file saved to foo.network.yml
|
||||||
|
|
||||||
$ cat foo.network.yml
|
$ cat foo.network.yml
|
||||||
rpc-endpoint: https://neo.rpc.node:30333
|
rpc-endpoint: https://neo.rpc.node:30333
|
||||||
alphabet-wallets: /home/user/deploy/alphabet-wallets
|
alphabet-wallets: /home/user/deploy/alphabet-wallets
|
||||||
network:
|
network:
|
||||||
max_object_size: 67108864
|
max_object_size: 67108864
|
||||||
epoch_duration: 240
|
epoch_duration: 240
|
||||||
basic_income_rate: 0
|
|
||||||
fee:
|
fee:
|
||||||
audit: 0
|
|
||||||
candidate: 0
|
candidate: 0
|
||||||
container: 0
|
container: 0
|
||||||
withdraw: 0
|
withdraw: 0
|
||||||
|
@ -43,17 +42,17 @@ credentials:
|
||||||
az: hunter2
|
az: hunter2
|
||||||
```
|
```
|
||||||
|
|
||||||
For private installation, it is recommended to set all **fees** and **basic
|
For private installation, it is recommended to set all **fees** and **basic
|
||||||
income rate** to 0.
|
income rate** to 0.
|
||||||
|
|
||||||
As for **epoch duration**, consider consensus node block generation frequency.
|
As for **epoch duration**, consider consensus node block generation frequency.
|
||||||
With default 15 seconds per block, 240 blocks are going to be a 1-hour epoch.
|
With default 15 seconds per block, 240 blocks are going to be a 1-hour epoch.
|
||||||
|
|
||||||
For **max object size**, 67108864 (64 MiB) or 134217728 (128 MiB) should provide
|
For **max object size**, 67108864 (64 MiB) or 134217728 (128 MiB) should provide
|
||||||
good chunk distribution in most cases.
|
good chunk distribution in most cases.
|
||||||
|
|
||||||
With this config, generate wallets (private keys) of consensus nodes. The same
|
With this config, generate wallets (private keys) of consensus nodes. The same
|
||||||
wallets will be used for Alphabet nodes. Make sure, that dir for alphabet
|
wallets will be used for Alphabet nodes. Make sure, that dir for alphabet
|
||||||
wallets already exists.
|
wallets already exists.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -69,14 +68,14 @@ storage.
|
||||||
## Step 2: Launch consensus nodes
|
## Step 2: Launch consensus nodes
|
||||||
|
|
||||||
Configure blockchain nodes with the generated wallets from the previous step.
|
Configure blockchain nodes with the generated wallets from the previous step.
|
||||||
Config examples can be found in
|
Config examples can be found in
|
||||||
[neo-go repository](https://github.com/nspcc-dev/neo-go/tree/master/config).
|
[neo-go repository](https://github.com/nspcc-dev/neo-go/tree/master/config).
|
||||||
|
|
||||||
Gather public keys from **all** generated wallets. We are interested in the first
|
Gather public keys from **all** generated wallets. We are interested in the first
|
||||||
`simple signature contract` public key.
|
`simple signature contract` public key.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ neo-go wallet dump-keys -w alphabet-wallets/az.json
|
$ neo-go wallet dump-keys -w alphabet-wallets/az.json
|
||||||
NitdS4k4f1Hh5mbLJhAswBK3WC2gQgPN1o (simple signature contract):
|
NitdS4k4f1Hh5mbLJhAswBK3WC2gQgPN1o (simple signature contract):
|
||||||
02c1cc85f9c856dbe2d02017349bcb7b4e5defa78b8056a09b3240ba2a8c078869
|
02c1cc85f9c856dbe2d02017349bcb7b4e5defa78b8056a09b3240ba2a8c078869
|
||||||
|
|
||||||
|
@ -87,10 +86,10 @@ NiMKabp3ddi3xShmLAXhTfbnuWb4cSJT6E (1 out of 1 multisig contract):
|
||||||
02c1cc85f9c856dbe2d02017349bcb7b4e5defa78b8056a09b3240ba2a8c078869
|
02c1cc85f9c856dbe2d02017349bcb7b4e5defa78b8056a09b3240ba2a8c078869
|
||||||
```
|
```
|
||||||
|
|
||||||
Put the list of public keys into `ProtocolConfiguration.StandbyCommittee`
|
Put the list of public keys into `ProtocolConfiguration.StandbyCommittee`
|
||||||
section. Specify the wallet path and the password in `ApplicationConfiguration.P2PNotary`
|
section. Specify the wallet path and the password in `ApplicationConfiguration.P2PNotary`
|
||||||
and `ApplicationConfiguration.UnlockWallet` sections. If config includes
|
and `ApplicationConfiguration.UnlockWallet` sections. If config includes
|
||||||
`ProtocolConfiguration.NativeActivations` section, add notary
|
`ProtocolConfiguration.NativeActivations` section, add notary
|
||||||
contract `Notary: [0]`.
|
contract `Notary: [0]`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -121,7 +120,7 @@ and possible overload issues.
|
||||||
Use archive with compiled FrostFS contracts to initialize the sidechain.
|
Use archive with compiled FrostFS contracts to initialize the sidechain.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ tar -xzvf frostfs-contract-v0.11.0.tar.gz
|
$ tar -xzvf frostfs-contract-v0.11.0.tar.gz
|
||||||
|
|
||||||
$ ./frostfs-adm -c foo.network.yml morph init --contracts ./frostfs-contract-v0.11.0
|
$ ./frostfs-adm -c foo.network.yml morph init --contracts ./frostfs-contract-v0.11.0
|
||||||
Stage 1: transfer GAS to alphabet nodes.
|
Stage 1: transfer GAS to alphabet nodes.
|
||||||
|
@ -141,20 +140,18 @@ Waiting for transactions to persist...
|
||||||
Stage 7: set addresses in NNS.
|
Stage 7: set addresses in NNS.
|
||||||
Waiting for transactions to persist...
|
Waiting for transactions to persist...
|
||||||
NNS: Set alphabet0.frostfs -> f692dfb4d43a15b464eb51a7041160fb29c44b6a
|
NNS: Set alphabet0.frostfs -> f692dfb4d43a15b464eb51a7041160fb29c44b6a
|
||||||
NNS: Set audit.frostfs -> 7df847b993affb3852074345a7c2bd622171ee0d
|
|
||||||
NNS: Set balance.frostfs -> 103519b3067a66307080a66570c0491ee8f68879
|
NNS: Set balance.frostfs -> 103519b3067a66307080a66570c0491ee8f68879
|
||||||
NNS: Set container.frostfs -> cae60bdd689d185901e495352d0247752ce50846
|
NNS: Set container.frostfs -> cae60bdd689d185901e495352d0247752ce50846
|
||||||
NNS: Set frostfsid.frostfs -> c421fb60a3895865a8f24d197d6a80ef686041d2
|
NNS: Set frostfsid.frostfs -> c421fb60a3895865a8f24d197d6a80ef686041d2
|
||||||
NNS: Set netmap.frostfs -> 894eb854632f50fb124412ce7951ebc00763525e
|
NNS: Set netmap.frostfs -> 894eb854632f50fb124412ce7951ebc00763525e
|
||||||
NNS: Set proxy.frostfs -> ac6e6fe4b373d0ca0ca4969d1e58fa0988724e7d
|
NNS: Set proxy.frostfs -> ac6e6fe4b373d0ca0ca4969d1e58fa0988724e7d
|
||||||
NNS: Set reputation.frostfs -> 6eda57c9d93d990573646762d1fea327ce41191f
|
|
||||||
Waiting for transactions to persist...
|
Waiting for transactions to persist...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 4: Launch Alphabet nodes
|
## Step 4: Launch Alphabet nodes
|
||||||
|
|
||||||
Configure Alphabet nodes with the wallets generated in step 1. For
|
Configure Alphabet nodes with the wallets generated in step 1. For
|
||||||
`morph.validators` use a list of public keys from
|
`morph.validators` use a list of public keys from
|
||||||
`ProtocolConfiguration.StandbyCommittee`.
|
`ProtocolConfiguration.StandbyCommittee`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -178,10 +175,10 @@ Generate a new wallet for a Storage node.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ frostfs-adm -c foo.network.yml morph generate-storage-wallet --storage-wallet ./sn01.json --initial-gas 10.0
|
$ frostfs-adm -c foo.network.yml morph generate-storage-wallet --storage-wallet ./sn01.json --initial-gas 10.0
|
||||||
New password >
|
New password >
|
||||||
Waiting for transactions to persist...
|
Waiting for transactions to persist...
|
||||||
|
|
||||||
$ neo-go wallet dump-keys -w sn01.json
|
$ neo-go wallet dump-keys -w sn01.json
|
||||||
Ngr7p8Z9S22XDH6VkUG9oXobv8zZRAWwwv (simple signature contract):
|
Ngr7p8Z9S22XDH6VkUG9oXobv8zZRAWwwv (simple signature contract):
|
||||||
0355eccb72cd46f09a3e5237eaa0f4949cceb5ecfa5a225bd3bb9fd021c4d75b85
|
0355eccb72cd46f09a3e5237eaa0f4949cceb5ecfa5a225bd3bb9fd021c4d75b85
|
||||||
```
|
```
|
||||||
|
@ -205,7 +202,7 @@ Current epoch: 8, increase to 9.
|
||||||
Waiting for transactions to persist...
|
Waiting for transactions to persist...
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
After that, FrostFS Storage is ready to work. You can access it directly or
|
After that, FrostFS Storage is ready to work. You can access it directly or
|
||||||
with protocol gates.
|
with protocol gates.
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
# FrostFS subnetwork creation
|
|
||||||
|
|
||||||
This is a short guide on how to create FrostFS subnetworks. This guide
|
|
||||||
considers that the sidechain and the inner ring (alphabet nodes) have already been
|
|
||||||
deployed and the sidechain contains a deployed `subnet` contract.
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
To follow this guide, you need:
|
|
||||||
- neo-go sidechain RPC endpoint;
|
|
||||||
- latest released version of [frostfs-adm](https://github.com/TrueCloudLab/frostfs-node/releases);
|
|
||||||
- wallet with FrostFS account.
|
|
||||||
|
|
||||||
## Creation
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-adm morph subnet create \
|
|
||||||
-r <side_chain_RPC_endpoint> \
|
|
||||||
-w </path/to/owner/wallet> \
|
|
||||||
--notary
|
|
||||||
Create subnet request sent successfully. ID: 4223489767.
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** in notary-enabled environment you should have a sufficient
|
|
||||||
notary deposit (not expired, with enough GAS balance). Your subnet ID
|
|
||||||
will differ from the example.
|
|
||||||
|
|
||||||
The default account in the wallet that has been passed with `-w` flag is the owner
|
|
||||||
of the just created subnetwork.
|
|
||||||
|
|
||||||
You can check if your subnetwork was created successfully:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-adm morph subnet get \
|
|
||||||
-r <side_chain_RPC_endpoint> \
|
|
||||||
--subnet <subnet_ID>
|
|
||||||
Owner: NUc734PMJXiqa2J9jRtvskU3kCdyyuSN8Q
|
|
||||||
```
|
|
||||||
Your owner will differ from the example.
|
|
|
@ -1,137 +0,0 @@
|
||||||
# Managing Subnetworks
|
|
||||||
|
|
||||||
This is a short guide on how to manage FrostFS subnetworks. This guide
|
|
||||||
considers that the sidechain and the inner ring (alphabet nodes) have already been
|
|
||||||
deployed, and the sidechain contains a deployed `subnet` contract.
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
- neo-go sidechain RPC endpoint;
|
|
||||||
- latest released version of [frostfs-adm](https://github.com/TrueCloudLab/frostfs-node/releases);
|
|
||||||
- [created](subnetwork-creation.md) subnetwork;
|
|
||||||
- wallet with the account that owns the subnetwork;
|
|
||||||
- public key of the Storage Node;
|
|
||||||
- public keys of the node and client administrators;
|
|
||||||
- owner IDs of the FrostFS users.
|
|
||||||
|
|
||||||
## Add node administrator
|
|
||||||
|
|
||||||
Node administrators are accounts that can manage (add and delete nodes)
|
|
||||||
the whitelist of the nodes which can be included to a subnetwork. Only the subnet
|
|
||||||
owner is allowed to add and remove node administrators from the subnetwork.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-adm morph subnet admin add \
|
|
||||||
-r <side_chain_RPC_endpoint> \
|
|
||||||
-w </path/to/owner/wallet> \
|
|
||||||
--admin <HEX_admin_public_key> \
|
|
||||||
--subnet <subnet_ID>
|
|
||||||
Add admin request sent successfully.
|
|
||||||
```
|
|
||||||
|
|
||||||
## Add node
|
|
||||||
|
|
||||||
Adding a node to a subnetwork means that the node becomes able to service
|
|
||||||
containers that have been created in that subnetwork. Addition only changes
|
|
||||||
the list of the allowed nodes. Node is not required to be bootstrapped at the
|
|
||||||
moment of its inclusion.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-adm morph subnet node add \
|
|
||||||
-r <side_chain_RPC_endpoint> \
|
|
||||||
-w </path/to/node_admin/wallet> \
|
|
||||||
--node <HEX_node_public_key> \
|
|
||||||
--subnet <subnet_ID>
|
|
||||||
Add node request sent successfully.
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** the owner of the subnetwork is also allowed to add nodes.
|
|
||||||
|
|
||||||
## Add client administrator
|
|
||||||
|
|
||||||
Client administrators are accounts that can manage (add and delete
|
|
||||||
nodes) the whitelist of the clients that can create containers in the
|
|
||||||
subnetwork. Only the subnet owner is allowed to add and remove client
|
|
||||||
administrators from the subnetwork.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-adm morph subnet admin add \
|
|
||||||
-r <side_chain_RPC_endpoint> \
|
|
||||||
-w </path/to/owner/wallet> \
|
|
||||||
--admin <HEX_admin_public_key> \
|
|
||||||
--subnet <subnet_ID> \
|
|
||||||
--client \
|
|
||||||
--group <group_ID>
|
|
||||||
Add admin request sent successfully.
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** you do not need to create a group explicitly, it will be created
|
|
||||||
right after the first client admin is added. Group ID is a 4-byte
|
|
||||||
positive integer number.
|
|
||||||
|
|
||||||
## Add client
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-adm morph subnet client add \
|
|
||||||
-r <side_chain_RPC_endpoint> \
|
|
||||||
-w </path/to/client_admin/wallet> \
|
|
||||||
--client <client_ownerID> \
|
|
||||||
--subnet <subnet_ID> \
|
|
||||||
--group <group_ID>
|
|
||||||
Add client request sent successfully.
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** the owner of the subnetwork is also allowed to add clients. This is
|
|
||||||
the only one command that accepts `ownerID`, not the public key.
|
|
||||||
Administrator can manage only their group (a group where that administrator
|
|
||||||
has been added by the subnet owner).
|
|
||||||
|
|
||||||
# Bootstrapping Storage Node
|
|
||||||
|
|
||||||
After a subnetwork [is created](subnetwork-creation.md) and a node is included into it, the
|
|
||||||
node could be bootstrapped and service subnetwork containers.
|
|
||||||
|
|
||||||
For bootstrapping, you need to specify the ID of the subnetwork in the node's
|
|
||||||
configuration:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
...
|
|
||||||
node:
|
|
||||||
...
|
|
||||||
subnet:
|
|
||||||
entries: # list of IDs of subnets to enter in a text format of FrostFS API protocol (overrides corresponding attributes)
|
|
||||||
- <subnetwork_ID>
|
|
||||||
...
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** specifying subnetwork that is denied for the node is not an error:
|
|
||||||
that configuration value would be ignored. You do not need to specify zero
|
|
||||||
(with 0 ID) subnetwork: its inclusion is implicit. On the contrary, to exclude
|
|
||||||
a node from the default zero subnetwork, you need to specify it explicitly:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
...
|
|
||||||
node:
|
|
||||||
...
|
|
||||||
subnet:
|
|
||||||
exit_zero: true # toggle entrance to zero subnet (overrides corresponding attribute and occurrence in `entries`)
|
|
||||||
...
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
# Creating container in non-zero subnetwork
|
|
||||||
|
|
||||||
Creating containers without using `--subnet` flag is equivalent to
|
|
||||||
creating container in the zero subnetwork.
|
|
||||||
|
|
||||||
To create a container in a private network, your wallet must be added to
|
|
||||||
the client whitelist by the client admins or the subnet owners:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ frostfs-cli container create \
|
|
||||||
--policy 'REP 1' \
|
|
||||||
-w </path/to/wallet> \
|
|
||||||
-r s01.frostfs.devenv:8080 \
|
|
||||||
--subnet <subnet_ID>
|
|
||||||
```
|
|
|
@ -11,4 +11,29 @@ const (
|
||||||
Verbose = "verbose"
|
Verbose = "verbose"
|
||||||
VerboseShorthand = "v"
|
VerboseShorthand = "v"
|
||||||
VerboseUsage = "Verbose output"
|
VerboseUsage = "Verbose output"
|
||||||
|
|
||||||
|
EndpointFlag = "rpc-endpoint"
|
||||||
|
EndpointFlagDesc = "N3 RPC node endpoint"
|
||||||
|
EndpointFlagShort = "r"
|
||||||
|
|
||||||
|
AlphabetWalletsFlag = "alphabet-wallets"
|
||||||
|
AlphabetWalletsFlagDesc = "Path to alphabet wallets dir"
|
||||||
|
|
||||||
|
LocalDumpFlag = "local-dump"
|
||||||
|
ContractsInitFlag = "contracts"
|
||||||
|
ContractsInitFlagDesc = "Path to archive with compiled FrostFS contracts (the default is to fetch the latest release from the official repository)"
|
||||||
|
ContractsURLFlag = "contracts-url"
|
||||||
|
ContractsURLFlagDesc = "URL to archive with compiled FrostFS contracts"
|
||||||
|
EpochDurationInitFlag = "network.epoch_duration"
|
||||||
|
MaxObjectSizeInitFlag = "network.max_object_size"
|
||||||
|
RefillGasAmountFlag = "gas"
|
||||||
|
StorageWalletFlag = "storage-wallet"
|
||||||
|
ContainerFeeInitFlag = "network.fee.container"
|
||||||
|
ContainerAliasFeeInitFlag = "network.fee.container_alias"
|
||||||
|
CandidateFeeInitFlag = "network.fee.candidate"
|
||||||
|
WithdrawFeeInitFlag = "network.fee.withdraw"
|
||||||
|
MaintenanceModeAllowedInitFlag = "network.maintenance_mode_allowed"
|
||||||
|
HomomorphicHashDisabledInitFlag = "network.homomorphic_hash_disabled"
|
||||||
|
CustomZoneFlag = "domain"
|
||||||
|
AlphabetSizeFlag = "size"
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
"github.com/nspcc-dev/neo-go/cli/input"
|
"github.com/nspcc-dev/neo-go/cli/input"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -18,8 +18,6 @@ type configTemplate struct {
|
||||||
AlphabetDir string
|
AlphabetDir string
|
||||||
MaxObjectSize int
|
MaxObjectSize int
|
||||||
EpochDuration int
|
EpochDuration int
|
||||||
BasicIncomeRate int
|
|
||||||
AuditFee int
|
|
||||||
CandidateFee int
|
CandidateFee int
|
||||||
ContainerFee int
|
ContainerFee int
|
||||||
ContainerAliasFee int
|
ContainerAliasFee int
|
||||||
|
@ -33,10 +31,8 @@ alphabet-wallets: {{ .AlphabetDir}}
|
||||||
network:
|
network:
|
||||||
max_object_size: {{ .MaxObjectSize}}
|
max_object_size: {{ .MaxObjectSize}}
|
||||||
epoch_duration: {{ .EpochDuration}}
|
epoch_duration: {{ .EpochDuration}}
|
||||||
basic_income_rate: {{ .BasicIncomeRate}}
|
|
||||||
homomorphic_hash_disabled: {{ .HomomorphicHashDisabled}}
|
homomorphic_hash_disabled: {{ .HomomorphicHashDisabled}}
|
||||||
fee:
|
fee:
|
||||||
audit: {{ .AuditFee}}
|
|
||||||
candidate: {{ .CandidateFee}}
|
candidate: {{ .CandidateFee}}
|
||||||
container: {{ .ContainerFee}}
|
container: {{ .ContainerFee}}
|
||||||
container_alias: {{ .ContainerAliasFee }}
|
container_alias: {{ .ContainerAliasFee }}
|
||||||
|
@ -47,19 +43,19 @@ credentials:
|
||||||
{{.}}: password{{end}}
|
{{.}}: password{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
func initConfig(cmd *cobra.Command, args []string) error {
|
func initConfig(cmd *cobra.Command, _ []string) error {
|
||||||
configPath, err := readConfigPathFromArgs(cmd)
|
configPath, err := readConfigPathFromArgs(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pathDir := filepath.Dir(configPath)
|
pathDir := filepath.Dir(configPath)
|
||||||
err = os.MkdirAll(pathDir, 0700)
|
err = os.MkdirAll(pathDir, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("create dir %s: %w", pathDir, err)
|
return fmt.Errorf("create dir %s: %w", pathDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0600)
|
f, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open %s: %w", configPath, err)
|
return fmt.Errorf("open %s: %w", configPath, err)
|
||||||
}
|
}
|
||||||
|
@ -111,9 +107,7 @@ func generateConfigExample(appDir string, credSize int) (string, error) {
|
||||||
Endpoint: "https://neo.rpc.node:30333",
|
Endpoint: "https://neo.rpc.node:30333",
|
||||||
MaxObjectSize: 67108864, // 64 MiB
|
MaxObjectSize: 67108864, // 64 MiB
|
||||||
EpochDuration: 240, // 1 hour with 15s per block
|
EpochDuration: 240, // 1 hour with 15s per block
|
||||||
BasicIncomeRate: 1_0000_0000, // 0.0001 GAS per GiB (Fixed12)
|
|
||||||
HomomorphicHashDisabled: false, // object homomorphic hash is enabled
|
HomomorphicHashDisabled: false, // object homomorphic hash is enabled
|
||||||
AuditFee: 1_0000, // 0.00000001 GAS per audit (Fixed12)
|
|
||||||
CandidateFee: 100_0000_0000, // 100.0 GAS (Fixed8)
|
CandidateFee: 100_0000_0000, // 100.0 GAS (Fixed8)
|
||||||
ContainerFee: 1000, // 0.000000001 * 7 GAS per container (Fixed12)
|
ContainerFee: 1000, // 0.000000001 * 7 GAS per container (Fixed12)
|
||||||
ContainerAliasFee: 500, // ContainerFee / 2
|
ContainerAliasFee: 500, // ContainerFee / 2
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -28,8 +28,6 @@ func TestGenerateConfigExample(t *testing.T) {
|
||||||
require.Equal(t, filepath.Join(appDir, "alphabet-wallets"), v.GetString("alphabet-wallets"))
|
require.Equal(t, filepath.Join(appDir, "alphabet-wallets"), v.GetString("alphabet-wallets"))
|
||||||
require.Equal(t, 67108864, v.GetInt("network.max_object_size"))
|
require.Equal(t, 67108864, v.GetInt("network.max_object_size"))
|
||||||
require.Equal(t, 240, v.GetInt("network.epoch_duration"))
|
require.Equal(t, 240, v.GetInt("network.epoch_duration"))
|
||||||
require.Equal(t, 100000000, v.GetInt("network.basic_income_rate"))
|
|
||||||
require.Equal(t, 10000, v.GetInt("network.fee.audit"))
|
|
||||||
require.Equal(t, 10000000000, v.GetInt("network.fee.candidate"))
|
require.Equal(t, 10000000000, v.GetInt("network.fee.candidate"))
|
||||||
require.Equal(t, 1000, v.GetInt("network.fee.container"))
|
require.Equal(t, 1000, v.GetInt("network.fee.container"))
|
||||||
require.Equal(t, 100000000, v.GetInt("network.fee.withdraw"))
|
require.Equal(t, 100000000, v.GetInt("network.fee.withdraw"))
|
||||||
|
|
220
cmd/frostfs-adm/internal/modules/morph/ape/ape.go
Normal file
220
cmd/frostfs-adm/internal/modules/morph/ape/ape.go
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
package ape
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
parseutil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
||||||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
namespaceTarget = "namespace"
|
||||||
|
containerTarget = "container"
|
||||||
|
jsonFlag = "json"
|
||||||
|
jsonFlagDesc = "Output rule chains in JSON format"
|
||||||
|
chainIDFlag = "chain-id"
|
||||||
|
chainIDDesc = "Rule chain ID"
|
||||||
|
ruleFlag = "rule"
|
||||||
|
ruleFlagDesc = "Rule chain in text format"
|
||||||
|
ruleJSONFlag = "rule-json"
|
||||||
|
ruleJSONFlagDesc = "Chain rule in JSON format or path to the file"
|
||||||
|
targetNameFlag = "target-name"
|
||||||
|
targetNameDesc = "Resource name in APE resource name format"
|
||||||
|
targetTypeFlag = "target-type"
|
||||||
|
targetTypeDesc = "Resource type(container/namespace)"
|
||||||
|
addrAdminFlag = "addr"
|
||||||
|
addrAdminDesc = "The address of the admins wallet"
|
||||||
|
chainNameFlag = "chain-name"
|
||||||
|
chainNameFlagDesc = "Chain name(ingress|s3)"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
addRuleChainCmd = &cobra.Command{
|
||||||
|
Use: "add-rule-chain",
|
||||||
|
Short: "Add rule chain",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
Run: addRuleChain,
|
||||||
|
}
|
||||||
|
|
||||||
|
removeRuleChainCmd = &cobra.Command{
|
||||||
|
Use: "rm-rule-chain",
|
||||||
|
Short: "Remove rule chain",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
Run: removeRuleChain,
|
||||||
|
}
|
||||||
|
|
||||||
|
listRuleChainsCmd = &cobra.Command{
|
||||||
|
Use: "list-rule-chains",
|
||||||
|
Short: "List rule chains",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
Run: listRuleChains,
|
||||||
|
}
|
||||||
|
|
||||||
|
setAdminCmd = &cobra.Command{
|
||||||
|
Use: "set-admin",
|
||||||
|
Short: "Set admin",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
Run: setAdmin,
|
||||||
|
}
|
||||||
|
|
||||||
|
getAdminCmd = &cobra.Command{
|
||||||
|
Use: "get-admin",
|
||||||
|
Short: "Get admin",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
Run: getAdmin,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initAddRuleChainCmd() {
|
||||||
|
Cmd.AddCommand(addRuleChainCmd)
|
||||||
|
|
||||||
|
addRuleChainCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
addRuleChainCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
|
||||||
|
addRuleChainCmd.Flags().String(targetTypeFlag, "", targetTypeDesc)
|
||||||
|
_ = addRuleChainCmd.MarkFlagRequired(targetTypeFlag)
|
||||||
|
addRuleChainCmd.Flags().String(targetNameFlag, "", targetNameDesc)
|
||||||
|
_ = addRuleChainCmd.MarkFlagRequired(targetNameFlag)
|
||||||
|
|
||||||
|
addRuleChainCmd.Flags().String(chainIDFlag, "", chainIDDesc)
|
||||||
|
_ = addRuleChainCmd.MarkFlagRequired(chainIDFlag)
|
||||||
|
addRuleChainCmd.Flags().String(ruleFlag, "", ruleFlagDesc)
|
||||||
|
addRuleChainCmd.Flags().String(ruleJSONFlag, "", ruleJSONFlagDesc)
|
||||||
|
addRuleChainCmd.Flags().String(chainNameFlag, ingress, chainNameFlagDesc)
|
||||||
|
addRuleChainCmd.MarkFlagsMutuallyExclusive(ruleFlag, ruleJSONFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initRemoveRuleChainCmd() {
|
||||||
|
Cmd.AddCommand(removeRuleChainCmd)
|
||||||
|
|
||||||
|
removeRuleChainCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
removeRuleChainCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
|
||||||
|
removeRuleChainCmd.Flags().String(targetTypeFlag, "", targetTypeDesc)
|
||||||
|
_ = removeRuleChainCmd.MarkFlagRequired(targetTypeFlag)
|
||||||
|
removeRuleChainCmd.Flags().String(targetNameFlag, "", targetNameDesc)
|
||||||
|
_ = removeRuleChainCmd.MarkFlagRequired(targetNameFlag)
|
||||||
|
removeRuleChainCmd.Flags().String(chainIDFlag, "", chainIDDesc)
|
||||||
|
_ = removeRuleChainCmd.MarkFlagRequired(chainIDFlag)
|
||||||
|
removeRuleChainCmd.Flags().String(chainNameFlag, ingress, chainNameFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initListRuleChainsCmd() {
|
||||||
|
Cmd.AddCommand(listRuleChainsCmd)
|
||||||
|
|
||||||
|
listRuleChainsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
listRuleChainsCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
listRuleChainsCmd.Flags().StringP(targetTypeFlag, "t", "", targetTypeDesc)
|
||||||
|
_ = listRuleChainsCmd.MarkFlagRequired(targetTypeFlag)
|
||||||
|
listRuleChainsCmd.Flags().String(targetNameFlag, "", targetNameDesc)
|
||||||
|
_ = listRuleChainsCmd.MarkFlagRequired(targetNameFlag)
|
||||||
|
listRuleChainsCmd.Flags().Bool(jsonFlag, false, jsonFlagDesc)
|
||||||
|
listRuleChainsCmd.Flags().String(chainNameFlag, ingress, chainNameFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initSetAdminCmd() {
|
||||||
|
Cmd.AddCommand(setAdminCmd)
|
||||||
|
|
||||||
|
setAdminCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
setAdminCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
setAdminCmd.Flags().String(addrAdminFlag, "", addrAdminDesc)
|
||||||
|
_ = setAdminCmd.MarkFlagRequired(addrAdminFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initGetAdminCmd() {
|
||||||
|
Cmd.AddCommand(getAdminCmd)
|
||||||
|
|
||||||
|
getAdminCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
getAdminCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addRuleChain(cmd *cobra.Command, _ []string) {
|
||||||
|
chain := parseChain(cmd)
|
||||||
|
target := parseTarget(cmd)
|
||||||
|
pci, ac := newPolicyContractInterface(cmd)
|
||||||
|
h, vub, err := pci.AddMorphRuleChain(parseChainName(cmd), target, chain)
|
||||||
|
cmd.Println("Waiting for transaction to persist...")
|
||||||
|
_, err = ac.Wait(h, vub, err)
|
||||||
|
commonCmd.ExitOnErr(cmd, "add rule chain error: %w", err)
|
||||||
|
cmd.Println("Rule chain added successfully")
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeRuleChain(cmd *cobra.Command, _ []string) {
|
||||||
|
chainID := parseChainID(cmd)
|
||||||
|
target := parseTarget(cmd)
|
||||||
|
pci, ac := newPolicyContractInterface(cmd)
|
||||||
|
h, vub, err := pci.RemoveMorphRuleChain(parseChainName(cmd), target, chainID)
|
||||||
|
cmd.Println("Waiting for transaction to persist...")
|
||||||
|
_, err = ac.Wait(h, vub, err)
|
||||||
|
commonCmd.ExitOnErr(cmd, "remove rule chain error: %w", err)
|
||||||
|
cmd.Println("Rule chain removed successfully")
|
||||||
|
}
|
||||||
|
|
||||||
|
func listRuleChains(cmd *cobra.Command, _ []string) {
|
||||||
|
target := parseTarget(cmd)
|
||||||
|
pci, _ := newPolicyContractInterface(cmd)
|
||||||
|
chains, err := pci.ListMorphRuleChains(parseChainName(cmd), target)
|
||||||
|
commonCmd.ExitOnErr(cmd, "list rule chains error: %w", err)
|
||||||
|
if len(chains) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON, _ := cmd.Flags().GetBool(jsonFlag)
|
||||||
|
if toJSON {
|
||||||
|
prettyJSONFormat(cmd, chains)
|
||||||
|
} else {
|
||||||
|
for _, c := range chains {
|
||||||
|
parseutil.PrintHumanReadableAPEChain(cmd, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setAdmin(cmd *cobra.Command, _ []string) {
|
||||||
|
s, _ := cmd.Flags().GetString(addrAdminFlag)
|
||||||
|
addr, err := util.Uint160DecodeStringLE(s)
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't decode admin addr: %w", err)
|
||||||
|
pci, ac := newPolicyContractInterface(cmd)
|
||||||
|
h, vub, err := pci.SetAdmin(addr)
|
||||||
|
cmd.Println("Waiting for transaction to persist...")
|
||||||
|
_, err = ac.Wait(h, vub, err)
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't set admin: %w", err)
|
||||||
|
cmd.Println("Admin set successfully")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAdmin(cmd *cobra.Command, _ []string) {
|
||||||
|
pci, _ := newPolicyContractInterface(cmd)
|
||||||
|
addr, err := pci.GetAdmin()
|
||||||
|
commonCmd.ExitOnErr(cmd, "unable to get admin: %w", err)
|
||||||
|
cmd.Println(addr.StringLE())
|
||||||
|
}
|
||||||
|
|
||||||
|
func prettyJSONFormat(cmd *cobra.Command, chains []*apechain.Chain) {
|
||||||
|
wr := bytes.NewBufferString("")
|
||||||
|
data, err := json.Marshal(chains)
|
||||||
|
if err == nil {
|
||||||
|
err = json.Indent(wr, data, "", " ")
|
||||||
|
}
|
||||||
|
commonCmd.ExitOnErr(cmd, "print rule chain error: %w", err)
|
||||||
|
cmd.Println(wr)
|
||||||
|
}
|
126
cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go
Normal file
126
cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
package ape
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
parseutil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
||||||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
||||||
|
policyengine "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
||||||
|
morph "git.frostfs.info/TrueCloudLab/policy-engine/pkg/morph/policy"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ingress = "ingress"
|
||||||
|
s3 = "s3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var mChainName = map[string]apechain.Name{
|
||||||
|
ingress: apechain.Ingress,
|
||||||
|
s3: apechain.S3,
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseTarget(cmd *cobra.Command) policyengine.Target {
|
||||||
|
var targetType policyengine.TargetType
|
||||||
|
typ, _ := cmd.Flags().GetString(targetTypeFlag)
|
||||||
|
switch typ {
|
||||||
|
case namespaceTarget:
|
||||||
|
targetType = policyengine.Namespace
|
||||||
|
case containerTarget:
|
||||||
|
targetType = policyengine.Container
|
||||||
|
default:
|
||||||
|
commonCmd.ExitOnErr(cmd, "read target type error: %w", fmt.Errorf("unknown target type"))
|
||||||
|
}
|
||||||
|
name, _ := cmd.Flags().GetString(targetNameFlag)
|
||||||
|
|
||||||
|
return policyengine.Target{
|
||||||
|
Name: name,
|
||||||
|
Type: targetType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseChainID(cmd *cobra.Command) apechain.ID {
|
||||||
|
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
||||||
|
if chainID == "" {
|
||||||
|
commonCmd.ExitOnErr(cmd, "read chain id error: %w",
|
||||||
|
fmt.Errorf("chain id cannot be empty"))
|
||||||
|
}
|
||||||
|
return apechain.ID(chainID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseChain(cmd *cobra.Command) *apechain.Chain {
|
||||||
|
chain := new(apechain.Chain)
|
||||||
|
|
||||||
|
if ruleStmt, _ := cmd.Flags().GetString(ruleFlag); ruleStmt != "" {
|
||||||
|
parseErr := parseutil.ParseAPEChain(chain, []string{ruleStmt})
|
||||||
|
commonCmd.ExitOnErr(cmd, "ape chain parser error: %w", parseErr)
|
||||||
|
} else if ruleJSON, _ := cmd.Flags().GetString(ruleJSONFlag); ruleJSON != "" {
|
||||||
|
var rule []byte
|
||||||
|
if _, err := os.Stat(ruleJSON); err == nil {
|
||||||
|
rule, err = os.ReadFile(ruleJSON)
|
||||||
|
commonCmd.ExitOnErr(cmd, "read file error: %w", err)
|
||||||
|
} else {
|
||||||
|
rule = []byte(ruleJSON)
|
||||||
|
if !json.Valid(rule) {
|
||||||
|
commonCmd.ExitOnErr(cmd, "read raw rule error: %w",
|
||||||
|
fmt.Errorf("invalid JSON"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := chain.DecodeBytes(rule)
|
||||||
|
commonCmd.ExitOnErr(cmd, "chain decode error: %w", err)
|
||||||
|
} else {
|
||||||
|
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("rule is not passed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
chain.ID = parseChainID(cmd)
|
||||||
|
|
||||||
|
return chain
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseChainName(cmd *cobra.Command) apechain.Name {
|
||||||
|
chainName, _ := cmd.Flags().GetString(chainNameFlag)
|
||||||
|
apeChainName, ok := mChainName[strings.ToLower(chainName)]
|
||||||
|
if !ok {
|
||||||
|
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("unsupported chain name"))
|
||||||
|
}
|
||||||
|
return apeChainName
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *actor.Actor) {
|
||||||
|
v := viper.GetViper()
|
||||||
|
c, err := helper.GetN3Client(v)
|
||||||
|
commonCmd.ExitOnErr(cmd, "unable to create NEO rpc client: %w", err)
|
||||||
|
|
||||||
|
walletDir := config.ResolveHomePath(viper.GetString(commonflags.AlphabetWalletsFlag))
|
||||||
|
wallets, err := helper.GetAlphabetWallets(v, walletDir)
|
||||||
|
commonCmd.ExitOnErr(cmd, "unable to get alphabet wallets: %w", err)
|
||||||
|
|
||||||
|
committeeAcc, err := helper.GetWalletAccount(wallets[0], constants.CommitteeAccountName)
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't find committee account: %w", err)
|
||||||
|
|
||||||
|
ac, err := helper.NewActor(c, committeeAcc)
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't create actor: %w", err)
|
||||||
|
|
||||||
|
inv := &ac.Invoker
|
||||||
|
var ch util.Uint160
|
||||||
|
r := management.NewReader(inv)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't get NNS contract state: %w", err)
|
||||||
|
|
||||||
|
ch, err = helper.NNSResolveHash(inv, nnsCs.Hash, helper.DomainOf(constants.PolicyContract))
|
||||||
|
commonCmd.ExitOnErr(cmd, "unable to resolve policy contract hash: %w", err)
|
||||||
|
|
||||||
|
return morph.NewContractStorage(ac, ch), ac
|
||||||
|
}
|
16
cmd/frostfs-adm/internal/modules/morph/ape/root.go
Normal file
16
cmd/frostfs-adm/internal/modules/morph/ape/root.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package ape
|
||||||
|
|
||||||
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
|
var Cmd = &cobra.Command{
|
||||||
|
Use: "ape",
|
||||||
|
Short: "Section for APE configuration commands",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initAddRuleChainCmd()
|
||||||
|
initRemoveRuleChainCmd()
|
||||||
|
initListRuleChainsCmd()
|
||||||
|
initSetAdminCmd()
|
||||||
|
initGetAdminCmd()
|
||||||
|
}
|
|
@ -1,241 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/elliptic"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-contract/nns"
|
|
||||||
"github.com/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt"
|
|
||||||
"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/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
type accBalancePair struct {
|
|
||||||
scriptHash util.Uint160
|
|
||||||
balance *big.Int
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
dumpBalancesStorageFlag = "storage"
|
|
||||||
dumpBalancesAlphabetFlag = "alphabet"
|
|
||||||
dumpBalancesProxyFlag = "proxy"
|
|
||||||
dumpBalancesUseScriptHashFlag = "script-hash"
|
|
||||||
|
|
||||||
// notaryEnabled signifies whether contracts were deployed in a notary-enabled environment.
|
|
||||||
// The setting is here to simplify testing and building the command for testnet (notary currently disabled).
|
|
||||||
// It will be removed eventually.
|
|
||||||
notaryEnabled = true
|
|
||||||
)
|
|
||||||
|
|
||||||
func dumpBalances(cmd *cobra.Command, _ []string) error {
|
|
||||||
var (
|
|
||||||
dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag)
|
|
||||||
dumpAlphabet, _ = cmd.Flags().GetBool(dumpBalancesAlphabetFlag)
|
|
||||||
dumpProxy, _ = cmd.Flags().GetBool(dumpBalancesProxyFlag)
|
|
||||||
nnsCs *state.Contract
|
|
||||||
nmHash util.Uint160
|
|
||||||
)
|
|
||||||
|
|
||||||
c, err := getN3Client(viper.GetViper())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
|
||||||
|
|
||||||
if !notaryEnabled || dumpStorage || dumpAlphabet || dumpProxy {
|
|
||||||
nnsCs, err = c.GetContractStateByID(1)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get NNS contract info: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nmHash, err = nnsResolveHash(inv, nnsCs.Hash, netmapContract+".frostfs")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
irList, err := fetchIRNodes(c, nmHash, rolemgmt.Hash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := fetchBalances(inv, gas.Hash, irList); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
printBalances(cmd, "Inner ring nodes balances:", irList)
|
|
||||||
|
|
||||||
if dumpStorage {
|
|
||||||
arr, err := unwrap.Array(inv.Call(nmHash, "netmap"))
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("can't fetch the list of storage nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
snList := make([]accBalancePair, len(arr))
|
|
||||||
for i := range arr {
|
|
||||||
node, ok := arr[i].Value().([]stackitem.Item)
|
|
||||||
if !ok || len(node) == 0 {
|
|
||||||
return errors.New("can't parse the list of storage nodes")
|
|
||||||
}
|
|
||||||
bs, err := node[0].TryBytes()
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("can't parse the list of storage nodes")
|
|
||||||
}
|
|
||||||
var ni netmap.NodeInfo
|
|
||||||
if err := ni.Unmarshal(bs); err != nil {
|
|
||||||
return fmt.Errorf("can't parse the list of storage nodes: %w", err)
|
|
||||||
}
|
|
||||||
pub, err := keys.NewPublicKeyFromBytes(ni.PublicKey(), elliptic.P256())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't parse storage node public key: %w", err)
|
|
||||||
}
|
|
||||||
snList[i].scriptHash = pub.GetScriptHash()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := fetchBalances(inv, gas.Hash, snList); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
printBalances(cmd, "\nStorage node balances:", snList)
|
|
||||||
}
|
|
||||||
|
|
||||||
if dumpProxy {
|
|
||||||
h, err := nnsResolveHash(inv, nnsCs.Hash, proxyContract+".frostfs")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get hash of the proxy contract: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyList := []accBalancePair{{scriptHash: h}}
|
|
||||||
if err := fetchBalances(inv, gas.Hash, proxyList); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
printBalances(cmd, "\nProxy contract balance:", proxyList)
|
|
||||||
}
|
|
||||||
|
|
||||||
if dumpAlphabet {
|
|
||||||
alphaList := make([]accBalancePair, len(irList))
|
|
||||||
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
for i := range alphaList {
|
|
||||||
emit.AppCall(w.BinWriter, nnsCs.Hash, "resolve", callflag.ReadOnly,
|
|
||||||
getAlphabetNNSDomain(i),
|
|
||||||
int64(nns.TXT))
|
|
||||||
}
|
|
||||||
if w.Err != nil {
|
|
||||||
panic(w.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
alphaRes, err := c.InvokeScript(w.Bytes(), nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch info from NNS: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range alphaList {
|
|
||||||
h, err := parseNNSResolveResult(alphaRes.Stack[i])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch the alphabet contract #%d hash: %w", i, err)
|
|
||||||
}
|
|
||||||
alphaList[i].scriptHash = h
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := fetchBalances(inv, gas.Hash, alphaList); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
printBalances(cmd, "\nAlphabet contracts balances:", alphaList)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchIRNodes(c Client, nmHash, desigHash util.Uint160) ([]accBalancePair, error) {
|
|
||||||
var irList []accBalancePair
|
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
|
||||||
|
|
||||||
if notaryEnabled {
|
|
||||||
height, err := c.GetBlockCount()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't get block height: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
arr, err := getDesignatedByRole(inv, desigHash, noderoles.NeoFSAlphabet, height)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("can't fetch list of IR nodes from the netmap contract")
|
|
||||||
}
|
|
||||||
|
|
||||||
irList = make([]accBalancePair, len(arr))
|
|
||||||
for i := range arr {
|
|
||||||
irList[i].scriptHash = arr[i].GetScriptHash()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
arr, err := unwrap.ArrayOfBytes(inv.Call(nmHash, "innerRingList"))
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("can't fetch list of IR nodes from the netmap contract")
|
|
||||||
}
|
|
||||||
|
|
||||||
irList = make([]accBalancePair, len(arr))
|
|
||||||
for i := range arr {
|
|
||||||
pub, err := keys.NewPublicKeyFromBytes(arr[i], elliptic.P256())
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't parse IR node public key: %w", err)
|
|
||||||
}
|
|
||||||
irList[i].scriptHash = pub.GetScriptHash()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return irList, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func printBalances(cmd *cobra.Command, prefix string, accounts []accBalancePair) {
|
|
||||||
useScriptHash, _ := cmd.Flags().GetBool(dumpBalancesUseScriptHashFlag)
|
|
||||||
|
|
||||||
cmd.Println(prefix)
|
|
||||||
for i := range accounts {
|
|
||||||
var addr string
|
|
||||||
if useScriptHash {
|
|
||||||
addr = accounts[i].scriptHash.StringLE()
|
|
||||||
} else {
|
|
||||||
addr = address.Uint160ToString(accounts[i].scriptHash)
|
|
||||||
}
|
|
||||||
cmd.Printf("%s: %s\n", addr, fixedn.ToString(accounts[i].balance, 8))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchBalances(c *invoker.Invoker, gasHash util.Uint160, accounts []accBalancePair) error {
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
for i := range accounts {
|
|
||||||
emit.AppCall(w.BinWriter, gasHash, "balanceOf", callflag.ReadStates, accounts[i].scriptHash)
|
|
||||||
}
|
|
||||||
if w.Err != nil {
|
|
||||||
panic(w.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := c.Run(w.Bytes())
|
|
||||||
if err != nil || res.State != vmstate.Halt.String() || len(res.Stack) != len(accounts) {
|
|
||||||
return errors.New("can't fetch account balances")
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range accounts {
|
|
||||||
bal, err := res.Stack[i].TryInteger()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't parse account balance: %w", err)
|
|
||||||
}
|
|
||||||
accounts[i].balance = bal
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
246
cmd/frostfs-adm/internal/modules/morph/balance/balance.go
Normal file
246
cmd/frostfs-adm/internal/modules/morph/balance/balance.go
Normal file
|
@ -0,0 +1,246 @@
|
||||||
|
package balance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/elliptic"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt"
|
||||||
|
"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/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type accBalancePair struct {
|
||||||
|
scriptHash util.Uint160
|
||||||
|
balance *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
dumpBalancesStorageFlag = "storage"
|
||||||
|
dumpBalancesAlphabetFlag = "alphabet"
|
||||||
|
dumpBalancesProxyFlag = "proxy"
|
||||||
|
dumpBalancesUseScriptHashFlag = "script-hash"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dumpBalances(cmd *cobra.Command, _ []string) error {
|
||||||
|
var (
|
||||||
|
dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag)
|
||||||
|
dumpAlphabet, _ = cmd.Flags().GetBool(dumpBalancesAlphabetFlag)
|
||||||
|
dumpProxy, _ = cmd.Flags().GetBool(dumpBalancesProxyFlag)
|
||||||
|
nnsCs *state.Contract
|
||||||
|
nmHash util.Uint160
|
||||||
|
)
|
||||||
|
|
||||||
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
inv := invoker.New(c, nil)
|
||||||
|
|
||||||
|
if dumpStorage || dumpAlphabet || dumpProxy {
|
||||||
|
r := management.NewReader(inv)
|
||||||
|
nnsCs, err = r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nmHash, err = helper.NNSResolveHash(inv, nnsCs.Hash, helper.DomainOf(constants.NetmapContract))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
irList, err := fetchIRNodes(c, rolemgmt.Hash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fetchBalances(inv, gas.Hash, irList); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
printBalances(cmd, "Inner ring nodes balances:", irList)
|
||||||
|
|
||||||
|
if dumpStorage {
|
||||||
|
if err := printStorageNodeBalances(cmd, inv, nmHash); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if dumpProxy {
|
||||||
|
if err := printProxyContractBalance(cmd, inv, nnsCs.Hash); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if dumpAlphabet {
|
||||||
|
if err := printAlphabetContractBalances(cmd, c, inv, len(irList), nnsCs.Hash); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printStorageNodeBalances(cmd *cobra.Command, inv *invoker.Invoker, nmHash util.Uint160) error {
|
||||||
|
arr, err := unwrap.Array(inv.Call(nmHash, "netmap"))
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("can't fetch the list of storage nodes")
|
||||||
|
}
|
||||||
|
|
||||||
|
snList := make([]accBalancePair, len(arr))
|
||||||
|
for i := range arr {
|
||||||
|
node, ok := arr[i].Value().([]stackitem.Item)
|
||||||
|
if !ok || len(node) == 0 {
|
||||||
|
return errors.New("can't parse the list of storage nodes")
|
||||||
|
}
|
||||||
|
bs, err := node[0].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("can't parse the list of storage nodes")
|
||||||
|
}
|
||||||
|
var ni netmap.NodeInfo
|
||||||
|
if err := ni.Unmarshal(bs); err != nil {
|
||||||
|
return fmt.Errorf("can't parse the list of storage nodes: %w", err)
|
||||||
|
}
|
||||||
|
pub, err := keys.NewPublicKeyFromBytes(ni.PublicKey(), elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't parse storage node public key: %w", err)
|
||||||
|
}
|
||||||
|
snList[i].scriptHash = pub.GetScriptHash()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fetchBalances(inv, gas.Hash, snList); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printBalances(cmd, "\nStorage node balances:", snList)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printProxyContractBalance(cmd *cobra.Command, inv *invoker.Invoker, nnsHash util.Uint160) error {
|
||||||
|
h, err := helper.NNSResolveHash(inv, nnsHash, helper.DomainOf(constants.ProxyContract))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't get hash of the proxy contract: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyList := []accBalancePair{{scriptHash: h}}
|
||||||
|
if err := fetchBalances(inv, gas.Hash, proxyList); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printBalances(cmd, "\nProxy contract balance:", proxyList)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printAlphabetContractBalances(cmd *cobra.Command, c helper.Client, inv *invoker.Invoker, count int, nnsHash util.Uint160) error {
|
||||||
|
alphaList := make([]accBalancePair, count)
|
||||||
|
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
for i := range alphaList {
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "resolve", callflag.ReadOnly,
|
||||||
|
helper.GetAlphabetNNSDomain(i),
|
||||||
|
int64(nns.TXT))
|
||||||
|
}
|
||||||
|
if w.Err != nil {
|
||||||
|
panic(w.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
alphaRes, err := c.InvokeScript(w.Bytes(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch info from NNS: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range alphaList {
|
||||||
|
h, err := helper.ParseNNSResolveResult(alphaRes.Stack[i])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch the alphabet contract #%d hash: %w", i, err)
|
||||||
|
}
|
||||||
|
alphaList[i].scriptHash = h
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fetchBalances(inv, gas.Hash, alphaList); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printBalances(cmd, "\nAlphabet contracts balances:", alphaList)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchIRNodes(c helper.Client, desigHash util.Uint160) ([]accBalancePair, error) {
|
||||||
|
inv := invoker.New(c, nil)
|
||||||
|
|
||||||
|
height, err := c.GetBlockCount()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't get block height: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
arr, err := helper.GetDesignatedByRole(inv, desigHash, noderoles.NeoFSAlphabet, height)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("can't fetch list of IR nodes from the netmap contract")
|
||||||
|
}
|
||||||
|
|
||||||
|
irList := make([]accBalancePair, len(arr))
|
||||||
|
for i := range arr {
|
||||||
|
irList[i].scriptHash = arr[i].GetScriptHash()
|
||||||
|
}
|
||||||
|
return irList, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printBalances(cmd *cobra.Command, prefix string, accounts []accBalancePair) {
|
||||||
|
useScriptHash, _ := cmd.Flags().GetBool(dumpBalancesUseScriptHashFlag)
|
||||||
|
|
||||||
|
cmd.Println(prefix)
|
||||||
|
for i := range accounts {
|
||||||
|
var addr string
|
||||||
|
if useScriptHash {
|
||||||
|
addr = accounts[i].scriptHash.StringLE()
|
||||||
|
} else {
|
||||||
|
addr = address.Uint160ToString(accounts[i].scriptHash)
|
||||||
|
}
|
||||||
|
cmd.Printf("%s: %s\n", addr, fixedn.ToString(accounts[i].balance, 8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchBalances(c *invoker.Invoker, gasHash util.Uint160, accounts []accBalancePair) error {
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
for i := range accounts {
|
||||||
|
emit.AppCall(w.BinWriter, gasHash, "balanceOf", callflag.ReadStates, accounts[i].scriptHash)
|
||||||
|
}
|
||||||
|
if w.Err != nil {
|
||||||
|
panic(w.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := c.Run(w.Bytes())
|
||||||
|
if err != nil || res.State != vmstate.Halt.String() || len(res.Stack) != len(accounts) {
|
||||||
|
return errors.New("can't fetch account balances")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range accounts {
|
||||||
|
bal, err := res.Stack[i].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't parse account balance: %w", err)
|
||||||
|
}
|
||||||
|
accounts[i].balance = bal
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
28
cmd/frostfs-adm/internal/modules/morph/balance/root.go
Normal file
28
cmd/frostfs-adm/internal/modules/morph/balance/root.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package balance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DumpCmd = &cobra.Command{
|
||||||
|
Use: "dump-balances",
|
||||||
|
Short: "Dump GAS balances",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: dumpBalances,
|
||||||
|
}
|
||||||
|
|
||||||
|
func initDumpBalancesCmd() {
|
||||||
|
DumpCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
DumpCmd.Flags().BoolP(dumpBalancesStorageFlag, "s", false, "Dump balances of storage nodes from the current netmap")
|
||||||
|
DumpCmd.Flags().BoolP(dumpBalancesAlphabetFlag, "a", false, "Dump balances of alphabet contracts")
|
||||||
|
DumpCmd.Flags().BoolP(dumpBalancesProxyFlag, "p", false, "Dump balances of the proxy contract")
|
||||||
|
DumpCmd.Flags().Bool(dumpBalancesUseScriptHashFlag, false, "Use script-hash format for addresses")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initDumpBalancesCmd()
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package morph
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -10,12 +10,15 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"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/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -23,19 +26,20 @@ import (
|
||||||
const forceConfigSet = "force"
|
const forceConfigSet = "force"
|
||||||
|
|
||||||
func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
|
func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
|
||||||
c, err := getN3Client(viper.GetViper())
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create N3 client: %w", err)
|
return fmt.Errorf("can't create N3 client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
inv := invoker.New(c, nil)
|
||||||
|
r := management.NewReader(inv)
|
||||||
|
|
||||||
cs, err := c.GetContractStateByID(1)
|
cs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get NNS contract info: %w", err)
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".frostfs")
|
nmHash, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.NetmapContract))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -48,41 +52,24 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0)
|
tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0)
|
||||||
|
|
||||||
for _, param := range arr {
|
m, err := helper.ParseConfigFromNetmapContract(arr)
|
||||||
tuple, ok := param.Value().([]stackitem.Item)
|
if err != nil {
|
||||||
if !ok || len(tuple) != 2 {
|
return err
|
||||||
return errors.New("invalid ListConfig response from netmap contract")
|
}
|
||||||
}
|
for k, v := range m {
|
||||||
|
switch k {
|
||||||
k, err := tuple[0].TryBytes()
|
case netmap.ContainerFeeConfig, netmap.ContainerAliasFeeConfig,
|
||||||
if err != nil {
|
netmap.EpochDurationConfig, netmap.IrCandidateFeeConfig,
|
||||||
return errors.New("invalid config key from netmap contract")
|
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig:
|
||||||
}
|
|
||||||
|
|
||||||
v, err := tuple[1].TryBytes()
|
|
||||||
if err != nil {
|
|
||||||
return invalidConfigValueErr(k)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch string(k) {
|
|
||||||
case netmapAuditFeeKey, netmapBasicIncomeRateKey,
|
|
||||||
netmapContainerFeeKey, netmapContainerAliasFeeKey,
|
|
||||||
netmapEigenTrustIterationsKey,
|
|
||||||
netmapEpochKey, netmapInnerRingCandidateFeeKey,
|
|
||||||
netmapMaxObjectSizeKey, netmapWithdrawFeeKey:
|
|
||||||
nbuf := make([]byte, 8)
|
nbuf := make([]byte, 8)
|
||||||
copy(nbuf[:], v)
|
copy(nbuf[:], v)
|
||||||
n := binary.LittleEndian.Uint64(nbuf)
|
n := binary.LittleEndian.Uint64(nbuf)
|
||||||
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%d (int)\n", k, n)))
|
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%d (int)\n", k, n)))
|
||||||
case netmapEigenTrustAlphaKey:
|
case netmap.HomomorphicHashingDisabledKey, netmap.MaintenanceModeAllowedConfig:
|
||||||
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%s (str)\n", k, v)))
|
if len(v) == 0 || len(v) > 1 {
|
||||||
case netmapHomomorphicHashDisabledKey, netmapMaintenanceAllowedKey:
|
return helper.InvalidConfigValueErr(k)
|
||||||
vBool, err := tuple[1].TryBool()
|
|
||||||
if err != nil {
|
|
||||||
return invalidConfigValueErr(k)
|
|
||||||
}
|
}
|
||||||
|
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%t (bool)\n", k, v[0] == 1)))
|
||||||
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%t (bool)\n", k, vBool)))
|
|
||||||
default:
|
default:
|
||||||
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%s (hex)\n", k, hex.EncodeToString(v))))
|
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%s (hex)\n", k, hex.EncodeToString(v))))
|
||||||
}
|
}
|
||||||
|
@ -94,22 +81,23 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setConfigCmd(cmd *cobra.Command, args []string) error {
|
func SetConfigCmd(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return errors.New("empty config pairs")
|
return errors.New("empty config pairs")
|
||||||
}
|
}
|
||||||
|
|
||||||
wCtx, err := newInitializeContext(cmd, viper.GetViper())
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't initialize context: %w", err)
|
return fmt.Errorf("can't initialize context: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cs, err := wCtx.Client.GetContractStateByID(1)
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get NNS contract info: %w", err)
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs")
|
nmHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.NetmapContract))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -132,12 +120,12 @@ func setConfigCmd(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = wCtx.sendConsensusTx(bw.Bytes())
|
err = wCtx.SendConsensusTx(bw.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return wCtx.awaitTx()
|
return wCtx.AwaitTx()
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfigPair(kvStr string, force bool) (key string, val any, err error) {
|
func parseConfigPair(kvStr string, force bool) (key string, val any, err error) {
|
||||||
|
@ -150,25 +138,14 @@ func parseConfigPair(kvStr string, force bool) (key string, val any, err error)
|
||||||
valRaw := v
|
valRaw := v
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case netmapAuditFeeKey, netmapBasicIncomeRateKey,
|
case netmap.ContainerFeeConfig, netmap.ContainerAliasFeeConfig,
|
||||||
netmapContainerFeeKey, netmapContainerAliasFeeKey,
|
netmap.EpochDurationConfig, netmap.IrCandidateFeeConfig,
|
||||||
netmapEigenTrustIterationsKey,
|
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig:
|
||||||
netmapEpochKey, netmapInnerRingCandidateFeeKey,
|
|
||||||
netmapMaxObjectSizeKey, netmapWithdrawFeeKey:
|
|
||||||
val, err = strconv.ParseInt(valRaw, 10, 64)
|
val, err = strconv.ParseInt(valRaw, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("could not parse %s's value '%s' as int: %w", key, valRaw, err)
|
err = fmt.Errorf("could not parse %s's value '%s' as int: %w", key, valRaw, err)
|
||||||
}
|
}
|
||||||
case netmapEigenTrustAlphaKey:
|
case netmap.HomomorphicHashingDisabledKey, netmap.MaintenanceModeAllowedConfig:
|
||||||
// just check that it could
|
|
||||||
// be parsed correctly
|
|
||||||
_, err = strconv.ParseFloat(v, 64)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("could not parse %s's value '%s' as float: %w", key, valRaw, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
val = valRaw
|
|
||||||
case netmapHomomorphicHashDisabledKey, netmapMaintenanceAllowedKey:
|
|
||||||
val, err = strconv.ParseBool(valRaw)
|
val, err = strconv.ParseBool(valRaw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("could not parse %s's value '%s' as bool: %w", key, valRaw, err)
|
err = fmt.Errorf("could not parse %s's value '%s' as bool: %w", key, valRaw, err)
|
||||||
|
@ -186,7 +163,3 @@ func parseConfigPair(kvStr string, force bool) (key string, val any, err error)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func invalidConfigValueErr(key []byte) error {
|
|
||||||
return fmt.Errorf("invalid %s config value from netmap contract", key)
|
|
||||||
}
|
|
46
cmd/frostfs-adm/internal/modules/morph/config/root.go
Normal file
46
cmd/frostfs-adm/internal/modules/morph/config/root.go
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
SetCmd = &cobra.Command{
|
||||||
|
Use: "set-config key1=val1 [key2=val2 ...]",
|
||||||
|
DisableFlagsInUseLine: true,
|
||||||
|
Short: "Add/update global config value in the FrostFS network",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
RunE: SetConfigCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
DumpCmd = &cobra.Command{
|
||||||
|
Use: "dump-config",
|
||||||
|
Short: "Dump FrostFS network config",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: dumpNetworkConfig,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initSetConfigCmd() {
|
||||||
|
SetCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
SetCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
SetCmd.Flags().Bool(forceConfigSet, false, "Force setting not well-known configuration key")
|
||||||
|
SetCmd.Flags().String(commonflags.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func initDumpNetworkConfigCmd() {
|
||||||
|
DumpCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initSetConfigCmd()
|
||||||
|
initDumpNetworkConfigCmd()
|
||||||
|
}
|
57
cmd/frostfs-adm/internal/modules/morph/constants/const.go
Normal file
57
cmd/frostfs-adm/internal/modules/morph/constants/const.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package constants
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
ConsensusAccountName = "consensus"
|
||||||
|
ProtoConfigPath = "protocol"
|
||||||
|
|
||||||
|
// MaxAlphabetNodes is the maximum number of candidates allowed, which is currently limited by the size
|
||||||
|
// of the invocation script.
|
||||||
|
// See: https://github.com/nspcc-dev/neo-go/blob/740488f7f35e367eaa99a71c0a609c315fe2b0fc/pkg/core/transaction/witness.go#L10
|
||||||
|
MaxAlphabetNodes = 22
|
||||||
|
|
||||||
|
SingleAccountName = "single"
|
||||||
|
CommitteeAccountName = "committee"
|
||||||
|
|
||||||
|
NNSContract = "nns"
|
||||||
|
FrostfsContract = "frostfs" // not deployed in side-chain.
|
||||||
|
ProcessingContract = "processing" // not deployed in side-chain.
|
||||||
|
AlphabetContract = "alphabet"
|
||||||
|
BalanceContract = "balance"
|
||||||
|
ContainerContract = "container"
|
||||||
|
FrostfsIDContract = "frostfsid"
|
||||||
|
NetmapContract = "netmap"
|
||||||
|
PolicyContract = "policy"
|
||||||
|
ProxyContract = "proxy"
|
||||||
|
|
||||||
|
ContractWalletFilename = "contract.json"
|
||||||
|
ContractWalletPasswordKey = "contract"
|
||||||
|
|
||||||
|
FrostfsOpsEmail = "ops@frostfs.info"
|
||||||
|
|
||||||
|
DefaultExpirationTime = 10 * 365 * 24 * time.Hour / time.Second
|
||||||
|
|
||||||
|
DeployMethodName = "deploy"
|
||||||
|
UpdateMethodName = "update"
|
||||||
|
|
||||||
|
TestContractPassword = "grouppass"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ContractList = []string{
|
||||||
|
BalanceContract,
|
||||||
|
ContainerContract,
|
||||||
|
FrostfsIDContract,
|
||||||
|
NetmapContract,
|
||||||
|
PolicyContract,
|
||||||
|
ProxyContract,
|
||||||
|
}
|
||||||
|
|
||||||
|
FullContractList = append([]string{
|
||||||
|
FrostfsContract,
|
||||||
|
ProcessingContract,
|
||||||
|
NNSContract,
|
||||||
|
AlphabetContract,
|
||||||
|
}, ContractList...)
|
||||||
|
)
|
|
@ -1,4 +1,4 @@
|
||||||
package morph
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -7,10 +7,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"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/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -22,18 +25,19 @@ import (
|
||||||
|
|
||||||
var errInvalidContainerResponse = errors.New("invalid response from container contract")
|
var errInvalidContainerResponse = errors.New("invalid response from container contract")
|
||||||
|
|
||||||
func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker, c Client) (util.Uint160, error) {
|
func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker) (util.Uint160, error) {
|
||||||
s, err := cmd.Flags().GetString(containerContractFlag)
|
s, err := cmd.Flags().GetString(containerContractFlag)
|
||||||
var ch util.Uint160
|
var ch util.Uint160
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ch, err = util.Uint160DecodeStringLE(s)
|
ch, err = util.Uint160DecodeStringLE(s)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nnsCs, err := c.GetContractStateByID(1)
|
r := management.NewReader(inv)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
|
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
|
||||||
}
|
}
|
||||||
ch, err = nnsResolveHash(inv, nnsCs.Hash, containerContract+".frostfs")
|
ch, err = helper.NNSResolveHash(inv, nnsCs.Hash, helper.DomainOf(constants.ContainerContract))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint160{}, err
|
return util.Uint160{}, err
|
||||||
}
|
}
|
||||||
|
@ -41,16 +45,28 @@ func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker, c Client
|
||||||
return ch, nil
|
return ch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainersList(inv *invoker.Invoker, ch util.Uint160) ([][]byte, error) {
|
func iterateContainerList(inv *invoker.Invoker, ch util.Uint160, f func([]byte) error) error {
|
||||||
res, err := inv.Call(ch, "list", "")
|
sid, r, err := unwrap.SessionIterator(inv.Call(ch, "containersOf", ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
||||||
}
|
}
|
||||||
itm, err := unwrap.Item(res, err)
|
// Nothing bad, except live session on the server, do not report to the user.
|
||||||
if _, ok := itm.(stackitem.Null); !ok {
|
defer func() { _ = inv.TerminateSession(sid) }()
|
||||||
return unwrap.ArrayOfBytes(res, err)
|
|
||||||
|
items, err := inv.TraverseIterator(sid, &r, 0)
|
||||||
|
for err == nil && len(items) != 0 {
|
||||||
|
for j := range items {
|
||||||
|
b, err := items[j].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
||||||
|
}
|
||||||
|
if err := f(b); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
items, err = inv.TraverseIterator(sid, &r, 0)
|
||||||
}
|
}
|
||||||
return nil, nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpContainers(cmd *cobra.Command, _ []string) error {
|
func dumpContainers(cmd *cobra.Command, _ []string) error {
|
||||||
|
@ -59,97 +75,117 @@ func dumpContainers(cmd *cobra.Command, _ []string) error {
|
||||||
return fmt.Errorf("invalid filename: %w", err)
|
return fmt.Errorf("invalid filename: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := getN3Client(viper.GetViper())
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create N3 client: %w", err)
|
return fmt.Errorf("can't create N3 client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
inv := invoker.New(c, nil)
|
||||||
|
|
||||||
ch, err := getContainerContractHash(cmd, inv, c)
|
ch, err := getContainerContractHash(cmd, inv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get contaract hash: %w", err)
|
return fmt.Errorf("unable to get contaract hash: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cids, err := getContainersList(inv, ch)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
isOK, err := getCIDFilterFunc(cmd)
|
isOK, err := getCIDFilterFunc(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var containers []*Container
|
f, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0o660)
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
for _, id := range cids {
|
|
||||||
if !isOK(id) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
bw.Reset()
|
|
||||||
emit.AppCall(bw.BinWriter, ch, "get", callflag.All, id)
|
|
||||||
emit.AppCall(bw.BinWriter, ch, "eACL", callflag.All, id)
|
|
||||||
res, err := inv.Run(bw.Bytes())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get container info: %w", err)
|
|
||||||
}
|
|
||||||
if len(res.Stack) != 2 {
|
|
||||||
return fmt.Errorf("%w: expected 2 items on stack", errInvalidContainerResponse)
|
|
||||||
}
|
|
||||||
|
|
||||||
cnt := new(Container)
|
|
||||||
err = cnt.FromStackItem(res.Stack[0])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ea := new(EACL)
|
|
||||||
err = ea.FromStackItem(res.Stack[1])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
|
||||||
}
|
|
||||||
if len(ea.Value) != 0 {
|
|
||||||
cnt.EACL = ea
|
|
||||||
}
|
|
||||||
|
|
||||||
containers = append(containers, cnt)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := json.Marshal(containers)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.WriteFile(filename, out, 0o660)
|
defer f.Close()
|
||||||
|
|
||||||
|
_, err = f.Write([]byte{'['})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
written := 0
|
||||||
|
enc := json.NewEncoder(f)
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
iterErr := iterateContainerList(inv, ch, func(id []byte) error {
|
||||||
|
if !isOK(id) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cnt, err := dumpSingleContainer(bw, ch, inv, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writing directly to the file is ok, because json.Encoder does no internal buffering.
|
||||||
|
if written != 0 {
|
||||||
|
_, err = f.Write([]byte{','})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
written++
|
||||||
|
return enc.Encode(cnt)
|
||||||
|
})
|
||||||
|
if iterErr != nil {
|
||||||
|
return iterErr
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = f.Write([]byte{']'})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpSingleContainer(bw *io.BufBinWriter, ch util.Uint160, inv *invoker.Invoker, id []byte) (*Container, error) {
|
||||||
|
bw.Reset()
|
||||||
|
emit.AppCall(bw.BinWriter, ch, "get", callflag.All, id)
|
||||||
|
emit.AppCall(bw.BinWriter, ch, "eACL", callflag.All, id)
|
||||||
|
res, err := inv.Run(bw.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't get container info: %w", err)
|
||||||
|
}
|
||||||
|
if len(res.Stack) != 2 {
|
||||||
|
return nil, fmt.Errorf("%w: expected 2 items on stack", errInvalidContainerResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
cnt := new(Container)
|
||||||
|
err = cnt.FromStackItem(res.Stack[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ea := new(EACL)
|
||||||
|
err = ea.FromStackItem(res.Stack[1])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
||||||
|
}
|
||||||
|
if len(ea.Value) != 0 {
|
||||||
|
cnt.EACL = ea
|
||||||
|
}
|
||||||
|
return cnt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func listContainers(cmd *cobra.Command, _ []string) error {
|
func listContainers(cmd *cobra.Command, _ []string) error {
|
||||||
c, err := getN3Client(viper.GetViper())
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create N3 client: %w", err)
|
return fmt.Errorf("can't create N3 client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
inv := invoker.New(c, nil)
|
||||||
|
|
||||||
ch, err := getContainerContractHash(cmd, inv, c)
|
ch, err := getContainerContractHash(cmd, inv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get contaract hash: %w", err)
|
return fmt.Errorf("unable to get contaract hash: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cids, err := getContainersList(inv, ch)
|
return iterateContainerList(inv, ch, func(id []byte) error {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, id := range cids {
|
|
||||||
var idCnr cid.ID
|
var idCnr cid.ID
|
||||||
err = idCnr.Decode(id)
|
err = idCnr.Decode(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to decode container id: %w", err)
|
return fmt.Errorf("unable to decode container id: %w", err)
|
||||||
}
|
}
|
||||||
cmd.Println(idCnr)
|
cmd.Println(idCnr)
|
||||||
}
|
return nil
|
||||||
return nil
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreContainers(cmd *cobra.Command, _ []string) error {
|
func restoreContainers(cmd *cobra.Command, _ []string) error {
|
||||||
|
@ -158,31 +194,20 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
|
||||||
return fmt.Errorf("invalid filename: %w", err)
|
return fmt.Errorf("invalid filename: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wCtx, err := newInitializeContext(cmd, viper.GetViper())
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer wCtx.close()
|
defer wCtx.Close()
|
||||||
|
|
||||||
nnsCs, err := wCtx.Client.GetContractStateByID(1)
|
containers, err := parseContainers(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get NNS contract state: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch, err := nnsResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, containerContract+".frostfs")
|
ch, err := fetchContainerContractHash(wCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't fetch container contract hash: %w", err)
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
data, err := os.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't read dump file: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var containers []Container
|
|
||||||
err = json.Unmarshal(data, &containers)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't parse dump file: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isOK, err := getCIDFilterFunc(cmd)
|
isOK, err := getCIDFilterFunc(cmd)
|
||||||
|
@ -190,6 +215,15 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = restoreOrPutContainers(containers, isOK, cmd, wCtx, ch)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return wCtx.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func restoreOrPutContainers(containers []Container, isOK func([]byte) bool, cmd *cobra.Command, wCtx *helper.InitializeContext, ch util.Uint160) error {
|
||||||
bw := io.NewBufBinWriter()
|
bw := io.NewBufBinWriter()
|
||||||
for _, cnt := range containers {
|
for _, cnt := range containers {
|
||||||
hv := hash.Sha256(cnt.Value)
|
hv := hash.Sha256(cnt.Value)
|
||||||
|
@ -197,43 +231,88 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bw.Reset()
|
bw.Reset()
|
||||||
emit.AppCall(bw.BinWriter, ch, "get", callflag.All, hv.BytesBE())
|
restored, err := isContainerRestored(cmd, wCtx, ch, bw, hv)
|
||||||
res, err := wCtx.Client.InvokeScript(bw.Bytes(), nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't check if container is already restored: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
if len(res.Stack) == 0 {
|
if restored {
|
||||||
return errors.New("empty stack")
|
|
||||||
}
|
|
||||||
|
|
||||||
old := new(Container)
|
|
||||||
if err := old.FromStackItem(res.Stack[0]); err != nil {
|
|
||||||
return fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
|
||||||
}
|
|
||||||
if len(old.Value) != 0 {
|
|
||||||
var id cid.ID
|
|
||||||
id.SetSHA256(hv)
|
|
||||||
cmd.Printf("Container %s is already deployed.\n", id)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
bw.Reset()
|
bw.Reset()
|
||||||
emit.AppCall(bw.BinWriter, ch, "put", callflag.All,
|
|
||||||
cnt.Value, cnt.Signature, cnt.PublicKey, cnt.Token)
|
putContainer(bw, ch, cnt)
|
||||||
if ea := cnt.EACL; ea != nil {
|
|
||||||
emit.AppCall(bw.BinWriter, ch, "setEACL", callflag.All,
|
|
||||||
ea.Value, ea.Signature, ea.PublicKey, ea.Token)
|
|
||||||
}
|
|
||||||
if bw.Err != nil {
|
if bw.Err != nil {
|
||||||
panic(bw.Err)
|
panic(bw.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendConsensusTx(bw.Bytes()); err != nil {
|
if err := wCtx.SendConsensusTx(bw.Bytes()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return wCtx.awaitTx()
|
func putContainer(bw *io.BufBinWriter, ch util.Uint160, cnt Container) {
|
||||||
|
emit.AppCall(bw.BinWriter, ch, "put", callflag.All,
|
||||||
|
cnt.Value, cnt.Signature, cnt.PublicKey, cnt.Token)
|
||||||
|
if ea := cnt.EACL; ea != nil {
|
||||||
|
emit.AppCall(bw.BinWriter, ch, "setEACL", callflag.All,
|
||||||
|
ea.Value, ea.Signature, ea.PublicKey, ea.Token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isContainerRestored(cmd *cobra.Command, wCtx *helper.InitializeContext, containerHash util.Uint160, bw *io.BufBinWriter, hashValue util.Uint256) (bool, error) {
|
||||||
|
emit.AppCall(bw.BinWriter, containerHash, "get", callflag.All, hashValue.BytesBE())
|
||||||
|
res, err := wCtx.Client.InvokeScript(bw.Bytes(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("can't check if container is already restored: %w", err)
|
||||||
|
}
|
||||||
|
if len(res.Stack) == 0 {
|
||||||
|
return false, errors.New("empty stack")
|
||||||
|
}
|
||||||
|
|
||||||
|
old := new(Container)
|
||||||
|
if err := old.FromStackItem(res.Stack[0]); err != nil {
|
||||||
|
return false, fmt.Errorf("%w: %v", errInvalidContainerResponse, err)
|
||||||
|
}
|
||||||
|
if len(old.Value) != 0 {
|
||||||
|
var id cid.ID
|
||||||
|
id.SetSHA256(hashValue)
|
||||||
|
cmd.Printf("Container %s is already deployed.\n", id)
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseContainers(filename string) ([]Container, error) {
|
||||||
|
data, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't read dump file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var containers []Container
|
||||||
|
err = json.Unmarshal(data, &containers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't parse dump file: %w", err)
|
||||||
|
}
|
||||||
|
return containers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchContainerContractHash(wCtx *helper.InitializeContext) (util.Uint160, error) {
|
||||||
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ch, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, helper.DomainOf(constants.ContainerContract))
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, fmt.Errorf("can't fetch container contract hash: %w", err)
|
||||||
|
}
|
||||||
|
return ch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container represents container struct in contract storage.
|
// Container represents container struct in contract storage.
|
68
cmd/frostfs-adm/internal/modules/morph/container/root.go
Normal file
68
cmd/frostfs-adm/internal/modules/morph/container/root.go
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
containerDumpFlag = "dump"
|
||||||
|
containerContractFlag = "container-contract"
|
||||||
|
containerIDsFlag = "cid"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
DumpCmd = &cobra.Command{
|
||||||
|
Use: "dump-containers",
|
||||||
|
Short: "Dump FrostFS containers to file",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: dumpContainers,
|
||||||
|
}
|
||||||
|
|
||||||
|
RestoreCmd = &cobra.Command{
|
||||||
|
Use: "restore-containers",
|
||||||
|
Short: "Restore FrostFS containers from file",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: restoreContainers,
|
||||||
|
}
|
||||||
|
|
||||||
|
ListCmd = &cobra.Command{
|
||||||
|
Use: "list-containers",
|
||||||
|
Short: "List FrostFS containers",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: listContainers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initListContainersCmd() {
|
||||||
|
ListCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
ListCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func initRestoreContainersCmd() {
|
||||||
|
RestoreCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
RestoreCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
RestoreCmd.Flags().String(containerDumpFlag, "", "File to restore containers from")
|
||||||
|
RestoreCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to restore")
|
||||||
|
}
|
||||||
|
|
||||||
|
func initDumpContainersCmd() {
|
||||||
|
DumpCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
DumpCmd.Flags().String(containerDumpFlag, "", "File where to save dumped containers")
|
||||||
|
DumpCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)")
|
||||||
|
DumpCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to dump")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initDumpContainersCmd()
|
||||||
|
initRestoreContainersCmd()
|
||||||
|
initListContainersCmd()
|
||||||
|
}
|
235
cmd/frostfs-adm/internal/modules/morph/contract/deploy.go
Normal file
235
cmd/frostfs-adm/internal/modules/morph/contract/deploy.go
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
package contract
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"github.com/nspcc-dev/neo-go/cli/cmdargs"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
contractPathFlag = "contract"
|
||||||
|
updateFlag = "update"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DeployCmd = &cobra.Command{
|
||||||
|
Use: "deploy",
|
||||||
|
Short: "Deploy additional smart-contracts",
|
||||||
|
Long: `Deploy additional smart-contract which are not related to core.
|
||||||
|
All contracts are deployed by the committee, so access to the alphabet wallets is required.
|
||||||
|
Optionally, arguments can be provided to be passed to a contract's _deploy function.
|
||||||
|
The syntax is the same as for 'neo-go contract testinvokefunction' command.
|
||||||
|
Compiled contract file name must contain '_contract.nef' suffix.
|
||||||
|
Contract's manifest file name must be 'config.json'.
|
||||||
|
NNS name is taken by stripping '_contract.nef' from the NEF file (similar to frostfs contracts).`,
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: deployContractCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ff := DeployCmd.Flags()
|
||||||
|
|
||||||
|
ff.String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
_ = DeployCmd.MarkFlagFilename(commonflags.AlphabetWalletsFlag)
|
||||||
|
|
||||||
|
ff.StringP(commonflags.EndpointFlag, "r", "", commonflags.EndpointFlagDesc)
|
||||||
|
ff.String(contractPathFlag, "", "Path to the contract directory")
|
||||||
|
_ = DeployCmd.MarkFlagFilename(contractPathFlag)
|
||||||
|
|
||||||
|
ff.Bool(updateFlag, false, "Update an existing contract")
|
||||||
|
ff.String(commonflags.CustomZoneFlag, "frostfs", "Custom zone for NNS")
|
||||||
|
}
|
||||||
|
|
||||||
|
func deployContractCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
v := viper.GetViper()
|
||||||
|
c, err := helper.NewInitializeContext(cmd, v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("initialization error: %w", err)
|
||||||
|
}
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
ctrPath, _ := cmd.Flags().GetString(contractPathFlag)
|
||||||
|
ctrName, err := probeContractName(ctrPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cs, err := helper.ReadContract(ctrPath, ctrName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch NNS contract state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
callHash := management.Hash
|
||||||
|
method := constants.DeployMethodName
|
||||||
|
zone, _ := cmd.Flags().GetString(commonflags.CustomZoneFlag)
|
||||||
|
domain := ctrName + "." + zone
|
||||||
|
isUpdate, _ := cmd.Flags().GetBool(updateFlag)
|
||||||
|
if isUpdate {
|
||||||
|
cs.Hash, err = helper.NNSResolveHash(c.ReadOnlyInvoker, nnsCs.Hash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch contract hash from NNS: %w", err)
|
||||||
|
}
|
||||||
|
callHash = cs.Hash
|
||||||
|
method = constants.UpdateMethodName
|
||||||
|
} else {
|
||||||
|
cs.Hash = state.CreateContractHash(
|
||||||
|
c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
cs.NEF.Checksum,
|
||||||
|
cs.Manifest.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
writer := io.NewBufBinWriter()
|
||||||
|
if err := emitDeploymentArguments(writer.BinWriter, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
emit.Bytes(writer.BinWriter, cs.RawManifest)
|
||||||
|
emit.Bytes(writer.BinWriter, cs.RawNEF)
|
||||||
|
emit.Int(writer.BinWriter, 3)
|
||||||
|
emit.Opcodes(writer.BinWriter, opcode.PACK)
|
||||||
|
emit.AppCallNoArgs(writer.BinWriter, callHash, method, callflag.All)
|
||||||
|
emit.Opcodes(writer.BinWriter, opcode.DROP) // contract state on stack
|
||||||
|
if !isUpdate {
|
||||||
|
err := registerNNS(nnsCs, c, zone, domain, cs, writer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if writer.Err != nil {
|
||||||
|
panic(fmt.Errorf("BUG: can't create deployment script: %w", writer.Err))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.SendCommitteeTx(writer.Bytes(), false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerNNS(nnsCs *state.Contract, c *helper.InitializeContext, zone string, domain string, cs *helper.ContractState, writer *io.BufBinWriter) error {
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
emit.Instruction(bw.BinWriter, opcode.INITSSLOT, []byte{1})
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "getPrice", callflag.All)
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.STSFLD0)
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "setPrice", callflag.All, 1)
|
||||||
|
|
||||||
|
start := bw.Len()
|
||||||
|
needRecord := false
|
||||||
|
|
||||||
|
ok, err := c.NNSRootRegistered(nnsCs.Hash, zone)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !ok {
|
||||||
|
needRecord = true
|
||||||
|
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
||||||
|
zone, c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
||||||
|
domain, c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
} else {
|
||||||
|
s, ok, err := c.NNSRegisterDomainScript(nnsCs.Hash, cs.Hash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
needRecord = !ok
|
||||||
|
if len(s) != 0 {
|
||||||
|
bw.WriteBytes(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if needRecord {
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
|
||||||
|
domain, int64(nns.TXT), address.Uint160ToString(cs.Hash))
|
||||||
|
}
|
||||||
|
|
||||||
|
if bw.Err != nil {
|
||||||
|
panic(fmt.Errorf("BUG: can't create deployment script: %w", writer.Err))
|
||||||
|
} else if bw.Len() != start {
|
||||||
|
writer.WriteBytes(bw.Bytes())
|
||||||
|
emit.Opcodes(writer.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK)
|
||||||
|
emit.AppCallNoArgs(writer.BinWriter, nnsCs.Hash, "setPrice", callflag.All)
|
||||||
|
|
||||||
|
if needRecord {
|
||||||
|
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func emitDeploymentArguments(w *io.BinWriter, args []string) error {
|
||||||
|
_, ps, err := cmdargs.ParseParams(args, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ps) == 0 {
|
||||||
|
emit.Opcodes(w, opcode.NEWARRAY0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ps) != 1 {
|
||||||
|
return fmt.Errorf("at most one argument is expected for deploy, got %d", len(ps))
|
||||||
|
}
|
||||||
|
|
||||||
|
// We could emit this directly, but round-trip through JSON is more robust.
|
||||||
|
// This a CLI, so optimizing the conversion is not worth the effort.
|
||||||
|
data, err := json.Marshal(ps)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pp params.Params
|
||||||
|
if err := json.Unmarshal(data, &pp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return params.ExpandArrayIntoScript(w, pp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func probeContractName(ctrPath string) (string, error) {
|
||||||
|
ds, err := os.ReadDir(ctrPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("can't read directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var ctrName string
|
||||||
|
for i := range ds {
|
||||||
|
if strings.HasSuffix(ds[i].Name(), "_contract.nef") {
|
||||||
|
ctrName = strings.TrimSuffix(ds[i].Name(), "_contract.nef")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctrName == "" {
|
||||||
|
return "", fmt.Errorf("can't find any NEF files in %s", ctrPath)
|
||||||
|
}
|
||||||
|
return ctrName, nil
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package morph
|
package contract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -7,10 +7,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-contract/nns"
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
@ -30,26 +36,27 @@ type contractDumpInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
c, err := getN3Client(viper.GetViper())
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create N3 client: %w", err)
|
return fmt.Errorf("can't create N3 client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cs, err := c.GetContractStateByID(1)
|
r := management.NewReader(invoker.New(c, nil))
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
zone, _ := cmd.Flags().GetString(customZoneFlag)
|
zone, _ := cmd.Flags().GetString(commonflags.CustomZoneFlag)
|
||||||
if zone != "" {
|
if zone != "" {
|
||||||
return dumpCustomZoneHashes(cmd, cs.Hash, zone, c)
|
return dumpCustomZoneHashes(cmd, cs.Hash, zone, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}}
|
infos := []contractDumpInfo{{name: constants.NNSContract, hash: cs.Hash}}
|
||||||
|
|
||||||
irSize := 0
|
irSize := 0
|
||||||
for ; irSize < lastGlagoliticLetter; irSize++ {
|
for ; irSize < lastGlagoliticLetter; irSize++ {
|
||||||
ok, err := nnsIsAvailable(c, cs.Hash, getAlphabetNNSDomain(irSize))
|
ok, err := helper.NNSIsAvailable(c, cs.Hash, helper.GetAlphabetNNSDomain(irSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if ok {
|
} else if ok {
|
||||||
|
@ -63,7 +70,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
bw.Reset()
|
bw.Reset()
|
||||||
for i := 0; i < irSize; i++ {
|
for i := 0; i < irSize; i++ {
|
||||||
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
|
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
|
||||||
getAlphabetNNSDomain(i),
|
helper.GetAlphabetNNSDomain(i),
|
||||||
int64(nns.TXT))
|
int64(nns.TXT))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,17 +81,17 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
for i := 0; i < irSize; i++ {
|
for i := 0; i < irSize; i++ {
|
||||||
info := contractDumpInfo{name: fmt.Sprintf("alphabet %d", i)}
|
info := contractDumpInfo{name: fmt.Sprintf("alphabet %d", i)}
|
||||||
if h, err := parseNNSResolveResult(alphaRes.Stack[i]); err == nil {
|
if h, err := helper.ParseNNSResolveResult(alphaRes.Stack[i]); err == nil {
|
||||||
info.hash = h
|
info.hash = h
|
||||||
}
|
}
|
||||||
infos = append(infos, info)
|
infos = append(infos, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ctrName := range contractList {
|
for _, ctrName := range constants.ContractList {
|
||||||
bw.Reset()
|
bw.Reset()
|
||||||
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
|
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
|
||||||
ctrName+".frostfs", int64(nns.TXT))
|
helper.DomainOf(ctrName), int64(nns.TXT))
|
||||||
|
|
||||||
res, err := c.InvokeScript(bw.Bytes(), nil)
|
res, err := c.InvokeScript(bw.Bytes(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -93,7 +100,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
info := contractDumpInfo{name: ctrName}
|
info := contractDumpInfo{name: ctrName}
|
||||||
if len(res.Stack) != 0 {
|
if len(res.Stack) != 0 {
|
||||||
if h, err := parseNNSResolveResult(res.Stack[0]); err == nil {
|
if h, err := helper.ParseNNSResolveResult(res.Stack[0]); err == nil {
|
||||||
info.hash = h
|
info.hash = h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +113,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpCustomZoneHashes(cmd *cobra.Command, nnsHash util.Uint160, zone string, c Client) error {
|
func dumpCustomZoneHashes(cmd *cobra.Command, nnsHash util.Uint160, zone string, c helper.Client) error {
|
||||||
const nnsMaxTokens = 100
|
const nnsMaxTokens = 100
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
inv := invoker.New(c, nil)
|
||||||
|
@ -123,12 +130,12 @@ func dumpCustomZoneHashes(cmd *cobra.Command, nnsHash util.Uint160, zone string,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.HasSuffix(bs, []byte(zone)) {
|
if !bytes.HasSuffix(bs, []byte(zone)) || bytes.HasPrefix(bs, []byte(morphClient.NNSGroupKeyName)) {
|
||||||
// Related https://github.com/nspcc-dev/neofs-contract/issues/316.
|
// Related https://github.com/nspcc-dev/neofs-contract/issues/316.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h, err := nnsResolveHash(inv, nnsHash, string(bs))
|
h, err := helper.NNSResolveHash(inv, nnsHash, string(bs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrf("Could not resolve name %s: %v\n", string(bs), err)
|
cmd.PrintErrf("Could not resolve name %s: %v\n", string(bs), err)
|
||||||
return
|
return
|
||||||
|
@ -140,7 +147,12 @@ func dumpCustomZoneHashes(cmd *cobra.Command, nnsHash util.Uint160, zone string,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID, iter, err := unwrap.SessionIterator(inv.Call(nnsHash, "tokens"))
|
script, err := smartcontract.CreateCallAndPrefetchIteratorScript(nnsHash, "tokens", nnsMaxTokens)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create prefetch script: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
arr, sessionID, iter, err := unwrap.ArrayAndSessionIterator(inv.Run(script))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, unwrap.ErrNoSessionID) {
|
if errors.Is(err, unwrap.ErrNoSessionID) {
|
||||||
items, err := unwrap.Array(inv.CallAndExpandIterator(nnsHash, "tokens", nnsMaxTokens))
|
items, err := unwrap.Array(inv.CallAndExpandIterator(nnsHash, "tokens", nnsMaxTokens))
|
||||||
|
@ -157,6 +169,10 @@ func dumpCustomZoneHashes(cmd *cobra.Command, nnsHash util.Uint160, zone string,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
for i := range arr {
|
||||||
|
processItem(arr[i])
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = inv.TerminateSession(sessionID)
|
_ = inv.TerminateSession(sessionID)
|
||||||
}()
|
}()
|
||||||
|
@ -211,7 +227,7 @@ func printContractInfo(cmd *cobra.Command, infos []contractDumpInfo) {
|
||||||
cmd.Print(buf.String())
|
cmd.Print(buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillContractVersion(cmd *cobra.Command, c Client, infos []contractDumpInfo) {
|
func fillContractVersion(cmd *cobra.Command, c helper.Client, infos []contractDumpInfo) {
|
||||||
bw := io.NewBufBinWriter()
|
bw := io.NewBufBinWriter()
|
||||||
sub := io.NewBufBinWriter()
|
sub := io.NewBufBinWriter()
|
||||||
for i := range infos {
|
for i := range infos {
|
45
cmd/frostfs-adm/internal/modules/morph/contract/root.go
Normal file
45
cmd/frostfs-adm/internal/modules/morph/contract/root.go
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package contract
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
DumpHashesCmd = &cobra.Command{
|
||||||
|
Use: "dump-hashes",
|
||||||
|
Short: "Dump deployed contract hashes",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: dumpContractHashes,
|
||||||
|
}
|
||||||
|
UpdateCmd = &cobra.Command{
|
||||||
|
Use: "update-contracts",
|
||||||
|
Short: "Update FrostFS contracts",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: updateContracts,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initDumpContractHashesCmd() {
|
||||||
|
DumpHashesCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
DumpHashesCmd.Flags().String(commonflags.CustomZoneFlag, "", "Custom zone to search.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func initUpdateContractsCmd() {
|
||||||
|
UpdateCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
UpdateCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
UpdateCmd.Flags().String(commonflags.ContractsInitFlag, "", commonflags.ContractsInitFlagDesc)
|
||||||
|
UpdateCmd.Flags().String(commonflags.ContractsURLFlag, "", commonflags.ContractsURLFlagDesc)
|
||||||
|
UpdateCmd.MarkFlagsMutuallyExclusive(commonflags.ContractsInitFlag, commonflags.ContractsURLFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initDumpContractHashesCmd()
|
||||||
|
initUpdateContractsCmd()
|
||||||
|
}
|
197
cmd/frostfs-adm/internal/modules/morph/contract/update.go
Normal file
197
cmd/frostfs-adm/internal/modules/morph/contract/update.go
Normal file
|
@ -0,0 +1,197 @@
|
||||||
|
package contract
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
io2 "github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
neoUtil "github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var errMissingNNSRecord = errors.New("missing NNS record")
|
||||||
|
|
||||||
|
func updateContracts(cmd *cobra.Command, _ []string) error {
|
||||||
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("initialization error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := helper.DeployNNS(wCtx, constants.UpdateMethodName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return updateContractsInternal(wCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateContractsInternal(c *helper.InitializeContext) error {
|
||||||
|
alphaCs := c.GetContract(constants.AlphabetContract)
|
||||||
|
|
||||||
|
nnsCs, err := c.NNSContractState()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
nnsHash := nnsCs.Hash
|
||||||
|
|
||||||
|
w := io2.NewBufBinWriter()
|
||||||
|
|
||||||
|
// Update script size for a single-node committee is close to the maximum allowed size of 65535.
|
||||||
|
// Because of this we want to reuse alphabet contract NEF and manifest for different updates.
|
||||||
|
// The generated script is as following.
|
||||||
|
// 1. Initialize static slot for alphabet NEF.
|
||||||
|
// 2. Store NEF into the static slot.
|
||||||
|
// 3. Push parameters for each alphabet contract on stack.
|
||||||
|
// 4. Add contract group to the manifest.
|
||||||
|
// 5. For each alphabet contract, invoke `update` using parameters on stack and
|
||||||
|
// NEF from step 2 and manifest from step 4.
|
||||||
|
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
||||||
|
emit.Bytes(w.BinWriter, alphaCs.RawNEF)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
||||||
|
|
||||||
|
keysParam, err := deployAlphabetAccounts(c, nnsHash, w, alphaCs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Reset()
|
||||||
|
|
||||||
|
if err = deployOrUpdateContracts(c, w, nnsHash, keysParam); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
groupKey := c.ContractWallet.Accounts[0].PrivateKey().PublicKey()
|
||||||
|
_, _, err = c.EmitUpdateNNSGroupScript(w, nnsHash, groupKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Command.Printf("NNS: Set %s -> %s\n", morphClient.NNSGroupKeyName, hex.EncodeToString(groupKey.Bytes()))
|
||||||
|
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
||||||
|
emit.Int(w.BinWriter, 1)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.PACK)
|
||||||
|
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)
|
||||||
|
|
||||||
|
if err := c.SendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func deployAlphabetAccounts(c *helper.InitializeContext, nnsHash neoUtil.Uint160, w *io2.BufBinWriter, alphaCs *helper.ContractState) ([]any, error) {
|
||||||
|
var keysParam []any
|
||||||
|
|
||||||
|
baseGroups := alphaCs.Manifest.Groups
|
||||||
|
|
||||||
|
// alphabet contracts should be deployed by individual nodes to get different hashes.
|
||||||
|
for i, acc := range c.Accounts {
|
||||||
|
ctrHash, err := helper.NNSResolveHash(c.ReadOnlyInvoker, nnsHash, helper.GetAlphabetNNSDomain(i))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't resolve hash for contract update: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
|
||||||
|
params := c.GetAlphabetDeployItems(i, len(c.Wallets))
|
||||||
|
emit.Array(w.BinWriter, params...)
|
||||||
|
|
||||||
|
alphaCs.Manifest.Groups = baseGroups
|
||||||
|
err = helper.AddManifestGroup(c.ContractWallet, ctrHash, alphaCs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't sign manifest group: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
emit.Bytes(w.BinWriter, alphaCs.RawManifest)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
||||||
|
emit.Int(w.BinWriter, 3)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.PACK)
|
||||||
|
emit.AppCallNoArgs(w.BinWriter, ctrHash, constants.UpdateMethodName, callflag.All)
|
||||||
|
}
|
||||||
|
if err := c.SendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
|
if !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.Command.Println("Alphabet contracts are already updated.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return keysParam, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deployOrUpdateContracts(c *helper.InitializeContext, w *io2.BufBinWriter, nnsHash neoUtil.Uint160, keysParam []any) error {
|
||||||
|
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "getPrice", callflag.All)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "setPrice", callflag.All, 1)
|
||||||
|
|
||||||
|
for _, ctrName := range constants.ContractList {
|
||||||
|
cs := c.GetContract(ctrName)
|
||||||
|
|
||||||
|
method := constants.UpdateMethodName
|
||||||
|
ctrHash, err := helper.NNSResolveHash(c.ReadOnlyInvoker, nnsHash, helper.DomainOf(ctrName))
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, errMissingNNSRecord) {
|
||||||
|
// if contract not found we deploy it instead of update
|
||||||
|
method = constants.DeployMethodName
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("can't resolve hash for contract update: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = helper.AddManifestGroup(c.ContractWallet, ctrHash, cs)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't sign manifest group: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
invokeHash := management.Hash
|
||||||
|
if method == constants.UpdateMethodName {
|
||||||
|
invokeHash = ctrHash
|
||||||
|
}
|
||||||
|
|
||||||
|
args, err := helper.GetContractDeployData(c, ctrName, keysParam, constants.UpdateMethodName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s: getting update params: %v", ctrName, err)
|
||||||
|
}
|
||||||
|
params := helper.GetContractDeployParameters(cs, args)
|
||||||
|
res, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
|
||||||
|
if err != nil {
|
||||||
|
if method != constants.UpdateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
||||||
|
return fmt.Errorf("deploy contract: %w", err)
|
||||||
|
}
|
||||||
|
c.Command.Printf("%s contract is already updated.\n", ctrName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteBytes(res.Script)
|
||||||
|
|
||||||
|
if method == constants.DeployMethodName {
|
||||||
|
// same actions are done in InitializeContext.setNNS, can be unified
|
||||||
|
domain := ctrName + ".frostfs"
|
||||||
|
script, ok, err := c.NNSRegisterDomainScript(nnsHash, cs.Hash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
w.WriteBytes(script)
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||||
|
domain, int64(nns.TXT), cs.Hash.StringLE())
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||||
|
domain, int64(nns.TXT), address.Uint160ToString(cs.Hash))
|
||||||
|
}
|
||||||
|
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,224 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-contract/nns"
|
|
||||||
"github.com/nspcc-dev/neo-go/cli/cmdargs"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
contractPathFlag = "contract"
|
|
||||||
updateFlag = "update"
|
|
||||||
customZoneFlag = "domain"
|
|
||||||
)
|
|
||||||
|
|
||||||
var deployCmd = &cobra.Command{
|
|
||||||
Use: "deploy",
|
|
||||||
Short: "Deploy additional smart-contracts",
|
|
||||||
Long: `Deploy additional smart-contract which are not related to core.
|
|
||||||
All contracts are deployed by the committee, so access to the alphabet wallets is required.
|
|
||||||
Optionally, arguments can be provided to be passed to a contract's _deploy function.
|
|
||||||
The syntax is the same as for 'neo-go contract testinvokefunction' command.
|
|
||||||
Compiled contract file name must contain '_contract.nef' suffix.
|
|
||||||
Contract's manifest file name must be 'config.json'.
|
|
||||||
NNS name is taken by stripping '_contract.nef' from the NEF file (similar to frostfs contracts).`,
|
|
||||||
PreRun: func(cmd *cobra.Command, _ []string) {
|
|
||||||
_ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag))
|
|
||||||
_ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag))
|
|
||||||
},
|
|
||||||
RunE: deployContractCmd,
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
ff := deployCmd.Flags()
|
|
||||||
|
|
||||||
ff.String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
|
||||||
_ = deployCmd.MarkFlagFilename(alphabetWalletsFlag)
|
|
||||||
|
|
||||||
ff.StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
|
||||||
ff.String(contractPathFlag, "", "Path to the contract directory")
|
|
||||||
_ = deployCmd.MarkFlagFilename(contractPathFlag)
|
|
||||||
|
|
||||||
ff.Bool(updateFlag, false, "Update an existing contract")
|
|
||||||
ff.String(customZoneFlag, "frostfs", "Custom zone for NNS")
|
|
||||||
}
|
|
||||||
|
|
||||||
func deployContractCmd(cmd *cobra.Command, args []string) error {
|
|
||||||
v := viper.GetViper()
|
|
||||||
c, err := newInitializeContext(cmd, v)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("initialization error: %w", err)
|
|
||||||
}
|
|
||||||
defer c.close()
|
|
||||||
|
|
||||||
ctrPath, _ := cmd.Flags().GetString(contractPathFlag)
|
|
||||||
ctrName, err := probeContractName(ctrPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cs, err := readContract(ctrPath, ctrName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nnsCs, err := c.Client.GetContractStateByID(1)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch NNS contract state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
callHash := management.Hash
|
|
||||||
method := deployMethodName
|
|
||||||
zone, _ := cmd.Flags().GetString(customZoneFlag)
|
|
||||||
domain := ctrName + "." + zone
|
|
||||||
isUpdate, _ := cmd.Flags().GetBool(updateFlag)
|
|
||||||
if isUpdate {
|
|
||||||
cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsCs.Hash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch contract hash from NNS: %w", err)
|
|
||||||
}
|
|
||||||
callHash = cs.Hash
|
|
||||||
method = updateMethodName
|
|
||||||
} else {
|
|
||||||
cs.Hash = state.CreateContractHash(
|
|
||||||
c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
cs.NEF.Checksum,
|
|
||||||
cs.Manifest.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
if err := emitDeploymentArguments(w.BinWriter, args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
emit.Bytes(w.BinWriter, cs.RawManifest)
|
|
||||||
emit.Bytes(w.BinWriter, cs.RawNEF)
|
|
||||||
emit.Int(w.BinWriter, 3)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.PACK)
|
|
||||||
emit.AppCallNoArgs(w.BinWriter, callHash, method, callflag.All)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.DROP) // contract state on stack
|
|
||||||
if !isUpdate {
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
emit.Instruction(bw.BinWriter, opcode.INITSSLOT, []byte{1})
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "getPrice", callflag.All)
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.STSFLD0)
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "setPrice", callflag.All, 1)
|
|
||||||
|
|
||||||
start := bw.Len()
|
|
||||||
needRecord := false
|
|
||||||
|
|
||||||
ok, err := c.nnsRootRegistered(nnsCs.Hash, zone)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else if !ok {
|
|
||||||
needRecord = true
|
|
||||||
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
|
||||||
zone, c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
|
||||||
domain, c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
} else {
|
|
||||||
s, ok, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
needRecord = !ok
|
|
||||||
if len(s) != 0 {
|
|
||||||
bw.WriteBytes(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if needRecord {
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
|
|
||||||
domain, int64(nns.TXT), address.Uint160ToString(cs.Hash))
|
|
||||||
}
|
|
||||||
|
|
||||||
if bw.Err != nil {
|
|
||||||
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))
|
|
||||||
} else if bw.Len() != start {
|
|
||||||
w.WriteBytes(bw.Bytes())
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK)
|
|
||||||
emit.AppCallNoArgs(w.BinWriter, nnsCs.Hash, "setPrice", callflag.All)
|
|
||||||
|
|
||||||
if needRecord {
|
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.Err != nil {
|
|
||||||
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitDeploymentArguments(w *io.BinWriter, args []string) error {
|
|
||||||
_, ps, err := cmdargs.ParseParams(args, true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ps) == 0 {
|
|
||||||
emit.Opcodes(w, opcode.NEWARRAY0)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ps) != 1 {
|
|
||||||
return fmt.Errorf("at most one argument is expected for deploy, got %d", len(ps))
|
|
||||||
}
|
|
||||||
|
|
||||||
// We could emit this directly, but round-trip through JSON is more robust.
|
|
||||||
// This a CLI, so optimizing the conversion is not worth the effort.
|
|
||||||
data, err := json.Marshal(ps)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var pp params.Params
|
|
||||||
if err := json.Unmarshal(data, &pp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return params.ExpandArrayIntoScript(w, pp)
|
|
||||||
}
|
|
||||||
|
|
||||||
func probeContractName(ctrPath string) (string, error) {
|
|
||||||
ds, err := os.ReadDir(ctrPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("can't read directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ctrName string
|
|
||||||
for i := range ds {
|
|
||||||
if strings.HasSuffix(ds[i].Name(), "_contract.nef") {
|
|
||||||
ctrName = strings.TrimSuffix(ds[i].Name(), "_contract.nef")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctrName == "" {
|
|
||||||
return "", fmt.Errorf("can't find any NEF files in %s", ctrPath)
|
|
||||||
}
|
|
||||||
return ctrName, nil
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/google/go-github/v39/github"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func downloadContractsFromGithub(cmd *cobra.Command) (io.ReadCloser, error) {
|
|
||||||
gcl := github.NewClient(nil)
|
|
||||||
release, _, err := gcl.Repositories.GetLatestRelease(context.Background(), "nspcc-dev", "frostfs-contract")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't fetch release info: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Printf("Found %s (%s), downloading...\n", release.GetTagName(), release.GetName())
|
|
||||||
|
|
||||||
var url string
|
|
||||||
for _, a := range release.Assets {
|
|
||||||
if strings.HasPrefix(a.GetName(), "frostfs-contract") {
|
|
||||||
url = a.GetBrowserDownloadURL()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if url == "" {
|
|
||||||
return nil, errors.New("can't find contracts archive in release assets")
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't fetch contracts archive: %w", err)
|
|
||||||
}
|
|
||||||
return resp.Body, nil
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"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/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func forceNewEpochCmd(cmd *cobra.Command, args []string) error {
|
|
||||||
wCtx, err := newInitializeContext(cmd, viper.GetViper())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't to initialize context: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cs, err := wCtx.Client.GetContractStateByID(1)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get NNS contract info: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
if err := emitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := wCtx.sendConsensusTx(bw.Bytes()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return wCtx.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func emitNewEpochCall(bw *io.BufBinWriter, wCtx *initializeContext, nmHash util.Uint160) error {
|
|
||||||
curr, err := unwrap.Int64(wCtx.ReadOnlyInvoker.Call(nmHash, "epoch"))
|
|
||||||
if err != nil {
|
|
||||||
return errors.New("can't fetch current epoch from the netmap contract")
|
|
||||||
}
|
|
||||||
|
|
||||||
newEpoch := curr + 1
|
|
||||||
wCtx.Command.Printf("Current epoch: %d, increase to %d.\n", curr, newEpoch)
|
|
||||||
|
|
||||||
// In NeoFS this is done via Notary contract. Here, however, we can form the
|
|
||||||
// transaction locally.
|
|
||||||
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
|
|
||||||
return bw.Err
|
|
||||||
}
|
|
474
cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go
Normal file
474
cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go
Normal file
|
@ -0,0 +1,474 @@
|
||||||
|
package frostfsid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
frostfsidclient "git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
namespaceFlag = "namespace"
|
||||||
|
subjectNameFlag = "subject-name"
|
||||||
|
subjectKeyFlag = "subject-key"
|
||||||
|
subjectAddressFlag = "subject-address"
|
||||||
|
includeNamesFlag = "include-names"
|
||||||
|
groupNameFlag = "group-name"
|
||||||
|
groupIDFlag = "group-id"
|
||||||
|
|
||||||
|
rootNamespacePlaceholder = "<root>"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Cmd = &cobra.Command{
|
||||||
|
Use: "frostfsid",
|
||||||
|
Short: "Section for frostfsid interactions commands",
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidCreateNamespaceCmd = &cobra.Command{
|
||||||
|
Use: "create-namespace",
|
||||||
|
Short: "Create new namespace in frostfsid contract",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidCreateNamespace,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidListNamespacesCmd = &cobra.Command{
|
||||||
|
Use: "list-namespaces",
|
||||||
|
Short: "List all namespaces in frostfsid",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidListNamespaces,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidCreateSubjectCmd = &cobra.Command{
|
||||||
|
Use: "create-subject",
|
||||||
|
Short: "Create subject in frostfsid contract",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidCreateSubject,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidDeleteSubjectCmd = &cobra.Command{
|
||||||
|
Use: "delete-subject",
|
||||||
|
Short: "Delete subject from frostfsid contract",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidDeleteSubject,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidListSubjectsCmd = &cobra.Command{
|
||||||
|
Use: "list-subjects",
|
||||||
|
Short: "List subjects in namespace",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidListSubjects,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidCreateGroupCmd = &cobra.Command{
|
||||||
|
Use: "create-group",
|
||||||
|
Short: "Create group in frostfsid contract",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidCreateGroup,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidDeleteGroupCmd = &cobra.Command{
|
||||||
|
Use: "delete-group",
|
||||||
|
Short: "Delete group from frostfsid contract",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidDeleteGroup,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidListGroupsCmd = &cobra.Command{
|
||||||
|
Use: "list-groups",
|
||||||
|
Short: "List groups in namespace",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidListGroups,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidAddSubjectToGroupCmd = &cobra.Command{
|
||||||
|
Use: "add-subject-to-group",
|
||||||
|
Short: "Add subject to group",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidAddSubjectToGroup,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidRemoveSubjectFromGroupCmd = &cobra.Command{
|
||||||
|
Use: "remove-subject-from-group",
|
||||||
|
Short: "Remove subject from group",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidRemoveSubjectFromGroup,
|
||||||
|
}
|
||||||
|
|
||||||
|
frostfsidListGroupSubjectsCmd = &cobra.Command{
|
||||||
|
Use: "list-group-subjects",
|
||||||
|
Short: "List subjects in group",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
Run: frostfsidListGroupSubjects,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initFrostfsIDCreateNamespaceCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidCreateNamespaceCmd)
|
||||||
|
frostfsidCreateNamespaceCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidCreateNamespaceCmd.Flags().String(namespaceFlag, "", "Namespace name to create")
|
||||||
|
frostfsidCreateNamespaceCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDListNamespacesCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidListNamespacesCmd)
|
||||||
|
frostfsidListNamespacesCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidListNamespacesCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDCreateSubjectCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidCreateSubjectCmd)
|
||||||
|
frostfsidCreateSubjectCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidCreateSubjectCmd.Flags().String(namespaceFlag, "", "Namespace where create subject")
|
||||||
|
frostfsidCreateSubjectCmd.Flags().String(subjectNameFlag, "", "Subject name, must be unique in namespace")
|
||||||
|
frostfsidCreateSubjectCmd.Flags().String(subjectKeyFlag, "", "Subject hex-encoded public key")
|
||||||
|
frostfsidCreateSubjectCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDDeleteSubjectCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidDeleteSubjectCmd)
|
||||||
|
frostfsidDeleteSubjectCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidDeleteSubjectCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
||||||
|
frostfsidDeleteSubjectCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDListSubjectsCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidListSubjectsCmd)
|
||||||
|
frostfsidListSubjectsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidListSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace to list subjects")
|
||||||
|
frostfsidListSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
||||||
|
frostfsidListSubjectsCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDCreateGroupCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidCreateGroupCmd)
|
||||||
|
frostfsidCreateGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidCreateGroupCmd.Flags().String(namespaceFlag, "", "Namespace where create group")
|
||||||
|
frostfsidCreateGroupCmd.Flags().String(groupNameFlag, "", "Group name, must be unique in namespace")
|
||||||
|
frostfsidCreateGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDDeleteGroupCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidDeleteGroupCmd)
|
||||||
|
frostfsidDeleteGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidDeleteGroupCmd.Flags().String(namespaceFlag, "", "Namespace to delete group")
|
||||||
|
frostfsidDeleteGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
||||||
|
frostfsidDeleteGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDListGroupsCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidListGroupsCmd)
|
||||||
|
frostfsidListGroupsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidListGroupsCmd.Flags().String(namespaceFlag, "", "Namespace to list groups")
|
||||||
|
frostfsidListGroupsCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDAddSubjectToGroupCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidAddSubjectToGroupCmd)
|
||||||
|
frostfsidAddSubjectToGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidAddSubjectToGroupCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
||||||
|
frostfsidAddSubjectToGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
||||||
|
frostfsidAddSubjectToGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDRemoveSubjectFromGroupCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidRemoveSubjectFromGroupCmd)
|
||||||
|
frostfsidRemoveSubjectFromGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidRemoveSubjectFromGroupCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
||||||
|
frostfsidRemoveSubjectFromGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
||||||
|
frostfsidRemoveSubjectFromGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIDListGroupSubjectsCmd() {
|
||||||
|
Cmd.AddCommand(frostfsidListGroupSubjectsCmd)
|
||||||
|
frostfsidListGroupSubjectsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
frostfsidListGroupSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace name")
|
||||||
|
frostfsidListGroupSubjectsCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
||||||
|
frostfsidListGroupSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
||||||
|
frostfsidListGroupSubjectsCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.CreateNamespaceCall(ns))
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "create namespace error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidListNamespaces(cmd *cobra.Command, _ []string) {
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract invoker: %w", err)
|
||||||
|
|
||||||
|
namespaces, err := ffsid.roCli.ListNamespaces()
|
||||||
|
commonCmd.ExitOnErr(cmd, "list namespaces: %w", err)
|
||||||
|
|
||||||
|
sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].Name < namespaces[j].Name })
|
||||||
|
|
||||||
|
for _, namespace := range namespaces {
|
||||||
|
if namespace.Name == "" {
|
||||||
|
namespace.Name = rootNamespacePlaceholder
|
||||||
|
}
|
||||||
|
cmd.Printf("%s\n", namespace.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidCreateSubject(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
subjName := getFrostfsIDSubjectName(cmd)
|
||||||
|
subjKey := getFrostfsIDSubjectKey(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.CreateSubjectCall(ns, subjKey))
|
||||||
|
if subjName != "" {
|
||||||
|
ffsid.addCall(ffsid.roCli.SetSubjectNameCall(subjKey.GetScriptHash(), subjName))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "create subject: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidDeleteSubject(cmd *cobra.Command, _ []string) {
|
||||||
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.DeleteSubjectCall(subjectAddress))
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "delete subject error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidListSubjects(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract invoker: %w", err)
|
||||||
|
|
||||||
|
subAddresses, err := ffsid.roCli.ListNamespaceSubjects(ns)
|
||||||
|
commonCmd.ExitOnErr(cmd, "list subjects: %w", err)
|
||||||
|
|
||||||
|
sort.Slice(subAddresses, func(i, j int) bool { return subAddresses[i].Less(subAddresses[j]) })
|
||||||
|
|
||||||
|
for _, addr := range subAddresses {
|
||||||
|
if !includeNames {
|
||||||
|
cmd.Println(address.Uint160ToString(addr))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
subj, err := ffsid.roCli.GetSubject(addr)
|
||||||
|
commonCmd.ExitOnErr(cmd, "get subject: %w", err)
|
||||||
|
|
||||||
|
cmd.Printf("%s (%s)\n", address.Uint160ToString(addr), subj.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidCreateGroup(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
groupName := getFrostfsIDGroupName(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.CreateGroupCall(ns, groupName))
|
||||||
|
|
||||||
|
groupID, err := ffsid.roCli.ParseGroupID(ffsid.sendWaitRes())
|
||||||
|
commonCmd.ExitOnErr(cmd, "create group: %w", err)
|
||||||
|
|
||||||
|
cmd.Printf("group '%s' created with id: %d\n", groupName, groupID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidDeleteGroup(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
groupID := getFrostfsIDGroupID(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.DeleteGroupCall(ns, groupID))
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "delete group error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidListGroups(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract invoker: %w", err)
|
||||||
|
|
||||||
|
groups, err := ffsid.roCli.ListGroups(ns)
|
||||||
|
commonCmd.ExitOnErr(cmd, "list groups: %w", err)
|
||||||
|
|
||||||
|
sort.Slice(groups, func(i, j int) bool { return groups[i].Name < groups[j].Name })
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
cmd.Printf("%s (%d)\n", group.Name, group.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidAddSubjectToGroup(cmd *cobra.Command, _ []string) {
|
||||||
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
||||||
|
groupID := getFrostfsIDGroupID(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.AddSubjectToGroupCall(subjectAddress, groupID))
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "add subject to group error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidRemoveSubjectFromGroup(cmd *cobra.Command, _ []string) {
|
||||||
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
||||||
|
groupID := getFrostfsIDGroupID(cmd)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
ffsid.addCall(ffsid.roCli.RemoveSubjectFromGroupCall(subjectAddress, groupID))
|
||||||
|
|
||||||
|
err = ffsid.sendWait()
|
||||||
|
commonCmd.ExitOnErr(cmd, "remove subject from group error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
||||||
|
ns := getFrostfsIDNamespace(cmd)
|
||||||
|
groupID := getFrostfsIDGroupID(cmd)
|
||||||
|
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
||||||
|
|
||||||
|
ffsid, err := newFrostfsIDClient(cmd)
|
||||||
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
||||||
|
|
||||||
|
subjects, err := ffsid.roCli.ListGroupSubjects(ns, groupID)
|
||||||
|
commonCmd.ExitOnErr(cmd, "list group subjects: %w", err)
|
||||||
|
|
||||||
|
sort.Slice(subjects, func(i, j int) bool { return subjects[i].Less(subjects[j]) })
|
||||||
|
|
||||||
|
for _, subjAddr := range subjects {
|
||||||
|
if !includeNames {
|
||||||
|
cmd.Println(address.Uint160ToString(subjAddr))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
subj, err := ffsid.roCli.GetSubject(subjAddr)
|
||||||
|
commonCmd.ExitOnErr(cmd, "get subject: %w", err)
|
||||||
|
|
||||||
|
cmd.Printf("%s (%s)\n", address.Uint160ToString(subjAddr), subj.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type frostfsidClient struct {
|
||||||
|
bw *io.BufBinWriter
|
||||||
|
contractHash util.Uint160
|
||||||
|
roCli *frostfsidclient.Client // client can be used only for waiting tx, parsing and forming method params
|
||||||
|
wCtx *helper.InitializeContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFrostfsIDClient(cmd *cobra.Command) (*frostfsidClient, error) {
|
||||||
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't to initialize context: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't get NNS contract info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ffsidHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't get proxy contract hash: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &frostfsidClient{
|
||||||
|
bw: io.NewBufBinWriter(),
|
||||||
|
contractHash: ffsidHash,
|
||||||
|
roCli: frostfsidclient.NewSimple(wCtx.CommitteeAct, ffsidHash),
|
||||||
|
wCtx: wCtx,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *frostfsidClient) addCall(method string, args []any) {
|
||||||
|
emit.AppCall(f.bw.BinWriter, f.contractHash, method, callflag.All, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *frostfsidClient) sendWait() error {
|
||||||
|
if err := f.wCtx.SendConsensusTx(f.bw.Bytes()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.bw.Reset()
|
||||||
|
|
||||||
|
return f.wCtx.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *frostfsidClient) sendWaitRes() (*state.AppExecResult, error) {
|
||||||
|
if err := f.wCtx.SendConsensusTx(f.bw.Bytes()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
f.bw.Reset()
|
||||||
|
|
||||||
|
if len(f.wCtx.SentTxs) == 0 {
|
||||||
|
return nil, errors.New("no transactions to wait")
|
||||||
|
}
|
||||||
|
|
||||||
|
f.wCtx.Command.Println("Waiting for transactions to persist...")
|
||||||
|
return f.roCli.Wait(f.wCtx.SentTxs[0].Hash, f.wCtx.SentTxs[0].Vub, nil)
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package frostfsid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/ape"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getFrostfsIDSubjectKey(cmd *cobra.Command) *keys.PublicKey {
|
||||||
|
subjKeyHex, _ := cmd.Flags().GetString(subjectKeyFlag)
|
||||||
|
subjKey, err := keys.NewPublicKeyFromString(subjKeyHex)
|
||||||
|
commonCmd.ExitOnErr(cmd, "invalid subject key: %w", err)
|
||||||
|
return subjKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFrostfsIDSubjectAddress(cmd *cobra.Command) util.Uint160 {
|
||||||
|
subjAddress, _ := cmd.Flags().GetString(subjectAddressFlag)
|
||||||
|
subjAddr, err := address.StringToUint160(subjAddress)
|
||||||
|
commonCmd.ExitOnErr(cmd, "invalid subject address: %w", err)
|
||||||
|
return subjAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFrostfsIDSubjectName(cmd *cobra.Command) string {
|
||||||
|
subjectName, _ := cmd.Flags().GetString(subjectNameFlag)
|
||||||
|
|
||||||
|
if subjectName == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ape.SubjectNameRegexp.MatchString(subjectName) {
|
||||||
|
commonCmd.ExitOnErr(cmd, "invalid subject name: %w",
|
||||||
|
fmt.Errorf("name must match regexp: %s", ape.SubjectNameRegexp.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
return subjectName
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFrostfsIDGroupName(cmd *cobra.Command) string {
|
||||||
|
groupName, _ := cmd.Flags().GetString(groupNameFlag)
|
||||||
|
|
||||||
|
if !ape.GroupNameRegexp.MatchString(groupName) {
|
||||||
|
commonCmd.ExitOnErr(cmd, "invalid group name: %w",
|
||||||
|
fmt.Errorf("name must match regexp: %s", ape.GroupNameRegexp.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupName
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFrostfsIDGroupID(cmd *cobra.Command) int64 {
|
||||||
|
groupID, _ := cmd.Flags().GetInt64(groupIDFlag)
|
||||||
|
if groupID <= 0 {
|
||||||
|
commonCmd.ExitOnErr(cmd, "invalid group id: %w",
|
||||||
|
errors.New("group id must be positive integer"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupID
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFrostfsIDNamespace(cmd *cobra.Command) string {
|
||||||
|
ns, _ := cmd.Flags().GetString(namespaceFlag)
|
||||||
|
if ns == rootNamespacePlaceholder {
|
||||||
|
ns = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ape.NamespaceNameRegexp.MatchString(ns) {
|
||||||
|
commonCmd.ExitOnErr(cmd, "invalid namespace: %w",
|
||||||
|
fmt.Errorf("name must match regexp: %s", ape.NamespaceNameRegexp.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ns
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
package frostfsid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/ape"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFrostfsIDConfig(t *testing.T) {
|
||||||
|
pks := make([]*keys.PrivateKey, 4)
|
||||||
|
for i := range pks {
|
||||||
|
pk, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
pks[i] = pk
|
||||||
|
}
|
||||||
|
|
||||||
|
fmts := []string{
|
||||||
|
pks[0].GetScriptHash().StringLE(),
|
||||||
|
address.Uint160ToString(pks[1].GetScriptHash()),
|
||||||
|
hex.EncodeToString(pks[2].PublicKey().UncompressedBytes()),
|
||||||
|
hex.EncodeToString(pks[3].PublicKey().Bytes()),
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range fmts {
|
||||||
|
v := viper.New()
|
||||||
|
v.Set("frostfsid.admin", fmts[i])
|
||||||
|
|
||||||
|
actual, found, err := helper.GetFrostfsIDAdmin(v)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, found)
|
||||||
|
require.Equal(t, pks[i].GetScriptHash(), actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("bad key", func(t *testing.T) {
|
||||||
|
v := viper.New()
|
||||||
|
v.Set("frostfsid.admin", "abc")
|
||||||
|
|
||||||
|
_, found, err := helper.GetFrostfsIDAdmin(v)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.True(t, found)
|
||||||
|
})
|
||||||
|
t.Run("missing key", func(t *testing.T) {
|
||||||
|
v := viper.New()
|
||||||
|
|
||||||
|
_, found, err := helper.GetFrostfsIDAdmin(v)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, found)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNamespaceRegexp(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
namespace string
|
||||||
|
matched bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "root empty ns",
|
||||||
|
namespace: "",
|
||||||
|
matched: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "simple valid ns",
|
||||||
|
namespace: "my-namespace-123",
|
||||||
|
matched: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "root placeholder",
|
||||||
|
namespace: "<root>",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "too long",
|
||||||
|
namespace: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "start with hyphen",
|
||||||
|
namespace: "-ns",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "end with hyphen",
|
||||||
|
namespace: "ns-",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with spaces",
|
||||||
|
namespace: "ns ns",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tc.matched, ape.NamespaceNameRegexp.MatchString(tc.namespace))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSubjectNameRegexp(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
subject string
|
||||||
|
matched bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
subject: "",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid",
|
||||||
|
subject: "invalid{name}",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "too long",
|
||||||
|
subject: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid",
|
||||||
|
subject: "valid_name.012345@6789",
|
||||||
|
matched: true,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tc.matched, ape.SubjectNameRegexp.MatchString(tc.subject))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSubjectGroupRegexp(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
subject string
|
||||||
|
matched bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
subject: "",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid",
|
||||||
|
subject: "invalid{name}",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "too long",
|
||||||
|
subject: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
||||||
|
matched: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "long",
|
||||||
|
subject: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
||||||
|
matched: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid",
|
||||||
|
subject: "valid_name.012345@6789",
|
||||||
|
matched: true,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tc.matched, ape.GroupNameRegexp.MatchString(tc.subject))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
15
cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go
Normal file
15
cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package frostfsid
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initFrostfsIDCreateNamespaceCmd()
|
||||||
|
initFrostfsIDListNamespacesCmd()
|
||||||
|
initFrostfsIDCreateSubjectCmd()
|
||||||
|
initFrostfsIDDeleteSubjectCmd()
|
||||||
|
initFrostfsIDListSubjectsCmd()
|
||||||
|
initFrostfsIDCreateGroupCmd()
|
||||||
|
initFrostfsIDDeleteGroupCmd()
|
||||||
|
initFrostfsIDListGroupsCmd()
|
||||||
|
initFrostfsIDAddSubjectToGroupCmd()
|
||||||
|
initFrostfsIDRemoveSubjectFromGroupCmd()
|
||||||
|
initFrostfsIDListGroupSubjectsCmd()
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package morph
|
package generate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -6,11 +6,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
|
@ -21,32 +23,30 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
func AlphabetCreds(cmd *cobra.Command, _ []string) error {
|
||||||
singleAccountName = "single"
|
|
||||||
committeeAccountName = "committee"
|
|
||||||
consensusAccountName = "consensus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func generateAlphabetCreds(cmd *cobra.Command, args []string) error {
|
|
||||||
// alphabet size is not part of the config
|
// alphabet size is not part of the config
|
||||||
size, err := cmd.Flags().GetUint(alphabetSizeFlag)
|
size, err := cmd.Flags().GetUint(commonflags.AlphabetSizeFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
return errors.New("size must be > 0")
|
return errors.New("size must be > 0")
|
||||||
}
|
}
|
||||||
|
if size > constants.MaxAlphabetNodes {
|
||||||
|
return helper.ErrTooManyAlphabetNodes
|
||||||
|
}
|
||||||
|
|
||||||
v := viper.GetViper()
|
v := viper.GetViper()
|
||||||
walletDir := config.ResolveHomePath(viper.GetString(alphabetWalletsFlag))
|
walletDir := config.ResolveHomePath(viper.GetString(commonflags.AlphabetWalletsFlag))
|
||||||
pwds, err := initializeWallets(v, walletDir, int(size))
|
pwds, err := initializeWallets(v, walletDir, int(size))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = initializeContractWallet(v, walletDir)
|
_, err = helper.InitializeContractWallet(v, walletDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
|
||||||
}
|
}
|
||||||
|
|
||||||
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||||
f, err := os.OpenFile(p, os.O_CREATE, 0644)
|
f, err := os.OpenFile(p, os.O_CREATE, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't create wallet file: %w", err)
|
return nil, fmt.Errorf("can't create wallet file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't create wallet: %w", err)
|
return nil, fmt.Errorf("can't create wallet: %w", err)
|
||||||
}
|
}
|
||||||
if err := w.CreateAccount(singleAccountName, password); err != nil {
|
if err := w.CreateAccount(constants.SingleAccountName, password); err != nil {
|
||||||
return nil, fmt.Errorf("can't create account: %w", err)
|
return nil, fmt.Errorf("can't create account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,28 +92,31 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
|
||||||
pubs[i] = w.Accounts[0].PrivateKey().PublicKey()
|
pubs[i] = w.Accounts[0].PrivateKey().PublicKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errG errgroup.Group
|
||||||
|
|
||||||
// Create committee account with N/2+1 multi-signature.
|
// Create committee account with N/2+1 multi-signature.
|
||||||
majCount := smartcontract.GetMajorityHonestNodeCount(size)
|
majCount := smartcontract.GetMajorityHonestNodeCount(size)
|
||||||
for i, w := range wallets {
|
|
||||||
if err := addMultisigAccount(w, majCount, committeeAccountName, passwords[i], pubs); err != nil {
|
|
||||||
return nil, fmt.Errorf("can't create committee account: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create consensus account with 2*N/3+1 multi-signature.
|
// Create consensus account with 2*N/3+1 multi-signature.
|
||||||
bftCount := smartcontract.GetDefaultHonestNodeCount(size)
|
bftCount := smartcontract.GetDefaultHonestNodeCount(size)
|
||||||
for i, w := range wallets {
|
for i := range wallets {
|
||||||
if err := addMultisigAccount(w, bftCount, consensusAccountName, passwords[i], pubs); err != nil {
|
i := i
|
||||||
return nil, fmt.Errorf("can't create consensus account: %w", err)
|
ps := pubs.Copy()
|
||||||
}
|
errG.Go(func() error {
|
||||||
|
if err := addMultisigAccount(wallets[i], majCount, constants.CommitteeAccountName, passwords[i], ps); err != nil {
|
||||||
|
return fmt.Errorf("can't create committee account: %w", err)
|
||||||
|
}
|
||||||
|
if err := addMultisigAccount(wallets[i], bftCount, constants.ConsensusAccountName, passwords[i], ps); err != nil {
|
||||||
|
return fmt.Errorf("can't create consentus account: %w", err)
|
||||||
|
}
|
||||||
|
if err := wallets[i].SavePretty(); err != nil {
|
||||||
|
return fmt.Errorf("can't save wallet: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if err := errG.Wait(); err != nil {
|
||||||
for _, w := range wallets {
|
return nil, err
|
||||||
if err := w.SavePretty(); err != nil {
|
|
||||||
return nil, fmt.Errorf("can't save wallet: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return passwords, nil
|
return passwords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +140,7 @@ func generateStorageCreds(cmd *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error) {
|
func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error) {
|
||||||
// storage wallet path is not part of the config
|
// storage wallet path is not part of the config
|
||||||
storageWalletPath, _ := cmd.Flags().GetString(storageWalletFlag)
|
storageWalletPath, _ := cmd.Flags().GetString(commonflags.StorageWalletFlag)
|
||||||
// wallet address is not part of the config
|
// wallet address is not part of the config
|
||||||
walletAddress, _ := cmd.Flags().GetString(walletAddressFlag)
|
walletAddress, _ := cmd.Flags().GetString(walletAddressFlag)
|
||||||
|
|
||||||
|
@ -150,7 +153,7 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if storageWalletPath == "" {
|
if storageWalletPath == "" {
|
||||||
return fmt.Errorf("missing wallet path (use '--%s <out.json>')", storageWalletFlag)
|
return fmt.Errorf("missing wallet path (use '--%s <out.json>')", commonflags.StorageWalletFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
var w *wallet.Wallet
|
var w *wallet.Wallet
|
||||||
|
@ -175,7 +178,7 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error
|
||||||
}
|
}
|
||||||
|
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = singleAccountName
|
label = constants.SingleAccountName
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := w.CreateAccount(label, password); err != nil {
|
if err := w.CreateAccount(label, password); err != nil {
|
||||||
|
@ -188,12 +191,12 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error
|
||||||
|
|
||||||
gasStr := viper.GetString(gasFlag)
|
gasStr := viper.GetString(gasFlag)
|
||||||
|
|
||||||
gasAmount, err := parseGASAmount(gasStr)
|
gasAmount, err := helper.ParseGASAmount(gasStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
wCtx, err := newInitializeContext(cmd, viper.GetViper())
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -206,20 +209,9 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error
|
||||||
return fmt.Errorf("BUG: invalid transfer arguments: %w", bw.Err)
|
return fmt.Errorf("BUG: invalid transfer arguments: %w", bw.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
if err := wCtx.SendCommitteeTx(bw.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return wCtx.awaitTx()
|
return wCtx.AwaitTx()
|
||||||
}
|
|
||||||
|
|
||||||
func parseGASAmount(s string) (fixedn.Fixed8, error) {
|
|
||||||
gasAmount, err := fixedn.Fixed8FromString(s)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("invalid GAS amount %s: %w", s, err)
|
|
||||||
}
|
|
||||||
if gasAmount <= 0 {
|
|
||||||
return 0, fmt.Errorf("GAS amount must be positive (got %d)", gasAmount)
|
|
||||||
}
|
|
||||||
return gasAmount, nil
|
|
||||||
}
|
}
|
121
cmd/frostfs-adm/internal/modules/morph/generate/generate_test.go
Normal file
121
cmd/frostfs-adm/internal/modules/morph/generate/generate_test.go
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
package generate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
|
"github.com/nspcc-dev/neo-go/cli/input"
|
||||||
|
"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/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"golang.org/x/term"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGenerateAlphabet(t *testing.T) {
|
||||||
|
const size = 4
|
||||||
|
|
||||||
|
walletDir := t.TempDir()
|
||||||
|
buf := setupTestTerminal(t)
|
||||||
|
|
||||||
|
cmd := GenerateAlphabetCmd
|
||||||
|
v := viper.GetViper()
|
||||||
|
|
||||||
|
t.Run("zero size", func(t *testing.T) {
|
||||||
|
buf.Reset()
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
||||||
|
require.NoError(t, cmd.Flags().Set(commonflags.AlphabetSizeFlag, "0"))
|
||||||
|
buf.WriteString("pass\r")
|
||||||
|
require.Error(t, AlphabetCreds(cmd, nil))
|
||||||
|
})
|
||||||
|
t.Run("no password provided", func(t *testing.T) {
|
||||||
|
buf.Reset()
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
||||||
|
require.NoError(t, cmd.Flags().Set(commonflags.AlphabetSizeFlag, "1"))
|
||||||
|
require.Error(t, AlphabetCreds(cmd, nil))
|
||||||
|
})
|
||||||
|
t.Run("missing directory", func(t *testing.T) {
|
||||||
|
buf.Reset()
|
||||||
|
dir := filepath.Join(os.TempDir(), "notexist."+strconv.FormatUint(rand.Uint64(), 10))
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, dir)
|
||||||
|
require.NoError(t, cmd.Flags().Set(commonflags.AlphabetSizeFlag, "1"))
|
||||||
|
buf.WriteString("pass\r")
|
||||||
|
require.Error(t, AlphabetCreds(cmd, nil))
|
||||||
|
})
|
||||||
|
t.Run("no password for contract group wallet", func(t *testing.T) {
|
||||||
|
buf.Reset()
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
||||||
|
require.NoError(t, cmd.Flags().Set(commonflags.AlphabetSizeFlag, strconv.FormatUint(size, 10)))
|
||||||
|
for i := uint64(0); i < size; i++ {
|
||||||
|
buf.WriteString(strconv.FormatUint(i, 10) + "\r")
|
||||||
|
}
|
||||||
|
require.Error(t, AlphabetCreds(cmd, nil))
|
||||||
|
})
|
||||||
|
|
||||||
|
buf.Reset()
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
||||||
|
require.NoError(t, GenerateAlphabetCmd.Flags().Set(commonflags.AlphabetSizeFlag, strconv.FormatUint(size, 10)))
|
||||||
|
for i := uint64(0); i < size; i++ {
|
||||||
|
buf.WriteString(strconv.FormatUint(i, 10) + "\r")
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.WriteString(constants.TestContractPassword + "\r")
|
||||||
|
require.NoError(t, AlphabetCreds(GenerateAlphabetCmd, nil))
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i := uint64(0); i < size; i++ {
|
||||||
|
i := i
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".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")
|
||||||
|
|
||||||
|
for _, a := range w.Accounts {
|
||||||
|
err := a.Decrypt(strconv.FormatUint(i, 10), keys.NEP2ScryptParams())
|
||||||
|
require.NoError(t, err, "can't decrypt account")
|
||||||
|
switch a.Label {
|
||||||
|
case constants.ConsensusAccountName:
|
||||||
|
require.Equal(t, smartcontract.GetDefaultHonestNodeCount(size), len(a.Contract.Parameters))
|
||||||
|
case constants.CommitteeAccountName:
|
||||||
|
require.Equal(t, smartcontract.GetMajorityHonestNodeCount(size), len(a.Contract.Parameters))
|
||||||
|
default:
|
||||||
|
require.Equal(t, constants.SingleAccountName, a.Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
t.Run("check contract group wallet", func(t *testing.T) {
|
||||||
|
p := filepath.Join(walletDir, constants.ContractWalletFilename)
|
||||||
|
w, err := wallet.NewWalletFromFile(p)
|
||||||
|
require.NoError(t, err, "contract wallet doesn't exist")
|
||||||
|
require.Equal(t, 1, len(w.Accounts), "contract wallet must have 1 accout")
|
||||||
|
require.NoError(t, w.Accounts[0].Decrypt(constants.TestContractPassword, keys.NEP2ScryptParams()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupTestTerminal(t *testing.T) *bytes.Buffer {
|
||||||
|
in := bytes.NewBuffer(nil)
|
||||||
|
input.Terminal = term.NewTerminal(input.ReadWriter{
|
||||||
|
Reader: in,
|
||||||
|
Writer: io.Discard,
|
||||||
|
}, "")
|
||||||
|
|
||||||
|
t.Cleanup(func() { input.Terminal = nil })
|
||||||
|
|
||||||
|
return in
|
||||||
|
}
|
76
cmd/frostfs-adm/internal/modules/morph/generate/root.go
Normal file
76
cmd/frostfs-adm/internal/modules/morph/generate/root.go
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
package generate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
storageWalletLabelFlag = "label"
|
||||||
|
storageGasCLIFlag = "initial-gas"
|
||||||
|
storageGasConfigFlag = "storage.initial_gas"
|
||||||
|
walletAddressFlag = "wallet-address"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
GenerateStorageCmd = &cobra.Command{
|
||||||
|
Use: "generate-storage-wallet",
|
||||||
|
Short: "Generate storage node wallet for the morph network",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(storageGasConfigFlag, cmd.Flags().Lookup(storageGasCLIFlag))
|
||||||
|
},
|
||||||
|
RunE: generateStorageCreds,
|
||||||
|
}
|
||||||
|
RefillGasCmd = &cobra.Command{
|
||||||
|
Use: "refill-gas",
|
||||||
|
Short: "Refill GAS of storage node's wallet in the morph network",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.RefillGasAmountFlag, cmd.Flags().Lookup(commonflags.RefillGasAmountFlag))
|
||||||
|
},
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return refillGas(cmd, commonflags.RefillGasAmountFlag, false)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
GenerateAlphabetCmd = &cobra.Command{
|
||||||
|
Use: "generate-alphabet",
|
||||||
|
Short: "Generate alphabet wallets for consensus nodes of the morph network",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
// PreRun fixes https://github.com/spf13/viper/issues/233
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
RunE: AlphabetCreds,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initRefillGasCmd() {
|
||||||
|
RefillGasCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
RefillGasCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
RefillGasCmd.Flags().String(commonflags.StorageWalletFlag, "", "Path to storage node wallet")
|
||||||
|
RefillGasCmd.Flags().String(walletAddressFlag, "", "Address of wallet")
|
||||||
|
RefillGasCmd.Flags().String(commonflags.RefillGasAmountFlag, "", "Additional amount of GAS to transfer")
|
||||||
|
RefillGasCmd.MarkFlagsMutuallyExclusive(walletAddressFlag, commonflags.StorageWalletFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initGenerateStorageCmd() {
|
||||||
|
GenerateStorageCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
GenerateStorageCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
GenerateStorageCmd.Flags().String(commonflags.StorageWalletFlag, "", "Path to new storage node wallet")
|
||||||
|
GenerateStorageCmd.Flags().String(storageGasCLIFlag, "", "Initial amount of GAS to transfer")
|
||||||
|
GenerateStorageCmd.Flags().StringP(storageWalletLabelFlag, "l", "", "Wallet label")
|
||||||
|
}
|
||||||
|
|
||||||
|
func initGenerateAlphabetCmd() {
|
||||||
|
GenerateAlphabetCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
GenerateAlphabetCmd.Flags().Uint(commonflags.AlphabetSizeFlag, 7, "Amount of alphabet wallets to generate")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initRefillGasCmd()
|
||||||
|
initGenerateStorageCmd()
|
||||||
|
initGenerateAlphabetCmd()
|
||||||
|
}
|
|
@ -1,112 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"math/rand"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
|
||||||
"github.com/nspcc-dev/neo-go/cli/input"
|
|
||||||
"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/spf13/viper"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"golang.org/x/term"
|
|
||||||
)
|
|
||||||
|
|
||||||
const testContractPassword = "grouppass"
|
|
||||||
|
|
||||||
func TestGenerateAlphabet(t *testing.T) {
|
|
||||||
const size = 4
|
|
||||||
|
|
||||||
walletDir := t.TempDir()
|
|
||||||
buf := setupTestTerminal(t)
|
|
||||||
|
|
||||||
cmd := generateAlphabetCmd
|
|
||||||
v := viper.GetViper()
|
|
||||||
|
|
||||||
t.Run("zero size", func(t *testing.T) {
|
|
||||||
buf.Reset()
|
|
||||||
v.Set(alphabetWalletsFlag, walletDir)
|
|
||||||
require.NoError(t, cmd.Flags().Set(alphabetSizeFlag, "0"))
|
|
||||||
buf.WriteString("pass\r")
|
|
||||||
require.Error(t, generateAlphabetCreds(cmd, nil))
|
|
||||||
})
|
|
||||||
t.Run("no password provided", func(t *testing.T) {
|
|
||||||
buf.Reset()
|
|
||||||
v.Set(alphabetWalletsFlag, walletDir)
|
|
||||||
require.NoError(t, cmd.Flags().Set(alphabetSizeFlag, "1"))
|
|
||||||
require.Error(t, generateAlphabetCreds(cmd, nil))
|
|
||||||
})
|
|
||||||
t.Run("missing directory", func(t *testing.T) {
|
|
||||||
buf.Reset()
|
|
||||||
dir := filepath.Join(os.TempDir(), "notexist."+strconv.FormatUint(rand.Uint64(), 10))
|
|
||||||
v.Set(alphabetWalletsFlag, dir)
|
|
||||||
require.NoError(t, cmd.Flags().Set(alphabetSizeFlag, "1"))
|
|
||||||
buf.WriteString("pass\r")
|
|
||||||
require.Error(t, generateAlphabetCreds(cmd, nil))
|
|
||||||
})
|
|
||||||
t.Run("no password for contract group wallet", func(t *testing.T) {
|
|
||||||
buf.Reset()
|
|
||||||
v.Set(alphabetWalletsFlag, walletDir)
|
|
||||||
require.NoError(t, cmd.Flags().Set(alphabetSizeFlag, strconv.FormatUint(size, 10)))
|
|
||||||
for i := uint64(0); i < size; i++ {
|
|
||||||
buf.WriteString(strconv.FormatUint(i, 10) + "\r")
|
|
||||||
}
|
|
||||||
require.Error(t, generateAlphabetCreds(cmd, nil))
|
|
||||||
})
|
|
||||||
|
|
||||||
buf.Reset()
|
|
||||||
v.Set(alphabetWalletsFlag, walletDir)
|
|
||||||
require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, strconv.FormatUint(size, 10)))
|
|
||||||
for i := uint64(0); i < size; i++ {
|
|
||||||
buf.WriteString(strconv.FormatUint(i, 10) + "\r")
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.WriteString(testContractPassword + "\r")
|
|
||||||
require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil))
|
|
||||||
|
|
||||||
for i := uint64(0); i < size; i++ {
|
|
||||||
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".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")
|
|
||||||
for _, a := range w.Accounts {
|
|
||||||
err := a.Decrypt(strconv.FormatUint(i, 10), keys.NEP2ScryptParams())
|
|
||||||
require.NoError(t, err, "can't decrypt account")
|
|
||||||
switch a.Label {
|
|
||||||
case consensusAccountName:
|
|
||||||
require.Equal(t, smartcontract.GetDefaultHonestNodeCount(size), len(a.Contract.Parameters))
|
|
||||||
case committeeAccountName:
|
|
||||||
require.Equal(t, smartcontract.GetMajorityHonestNodeCount(size), len(a.Contract.Parameters))
|
|
||||||
default:
|
|
||||||
require.Equal(t, singleAccountName, a.Label)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("check contract group wallet", func(t *testing.T) {
|
|
||||||
p := filepath.Join(walletDir, contractWalletFilename)
|
|
||||||
w, err := wallet.NewWalletFromFile(p)
|
|
||||||
require.NoError(t, err, "contract wallet doesn't exist")
|
|
||||||
require.Equal(t, 1, len(w.Accounts), "contract wallet must have 1 accout")
|
|
||||||
require.NoError(t, w.Accounts[0].Decrypt(testContractPassword, keys.NEP2ScryptParams()))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupTestTerminal(t *testing.T) *bytes.Buffer {
|
|
||||||
in := bytes.NewBuffer(nil)
|
|
||||||
input.Terminal = term.NewTerminal(input.ReadWriter{
|
|
||||||
Reader: in,
|
|
||||||
Writer: io.Discard,
|
|
||||||
}, "")
|
|
||||||
|
|
||||||
t.Cleanup(func() { input.Terminal = nil })
|
|
||||||
|
|
||||||
return in
|
|
||||||
}
|
|
|
@ -1,106 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
contractWalletFilename = "contract.json"
|
|
||||||
contractWalletPasswordKey = "contract"
|
|
||||||
)
|
|
||||||
|
|
||||||
func initializeContractWallet(v *viper.Viper, walletDir string) (*wallet.Wallet, error) {
|
|
||||||
password, err := config.GetPassword(v, contractWalletPasswordKey)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
w, err := wallet.NewWallet(filepath.Join(walletDir, contractWalletFilename))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
acc, err := wallet.NewAccount()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = acc.Encrypt(password, keys.NEP2ScryptParams())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
w.AddAccount(acc)
|
|
||||||
if err := w.SavePretty(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return w, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func openContractWallet(v *viper.Viper, cmd *cobra.Command, walletDir string) (*wallet.Wallet, error) {
|
|
||||||
p := filepath.Join(walletDir, contractWalletFilename)
|
|
||||||
w, err := wallet.NewWalletFromFile(p)
|
|
||||||
if err != nil {
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
return nil, fmt.Errorf("can't open wallet: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Printf("Contract group wallet is missing, initialize at %s\n", p)
|
|
||||||
return initializeContractWallet(v, walletDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
password, err := config.GetPassword(v, contractWalletPasswordKey)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range w.Accounts {
|
|
||||||
if err := w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil {
|
|
||||||
return nil, fmt.Errorf("can't unlock wallet: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return w, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) addManifestGroup(h util.Uint160, cs *contractState) error {
|
|
||||||
priv := c.ContractWallet.Accounts[0].PrivateKey()
|
|
||||||
pub := priv.PublicKey()
|
|
||||||
|
|
||||||
sig := priv.Sign(h.BytesBE())
|
|
||||||
found := false
|
|
||||||
|
|
||||||
for i := range cs.Manifest.Groups {
|
|
||||||
if cs.Manifest.Groups[i].PublicKey.Equal(pub) {
|
|
||||||
cs.Manifest.Groups[i].Signature = sig
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
cs.Manifest.Groups = append(cs.Manifest.Groups, manifest.Group{
|
|
||||||
PublicKey: pub,
|
|
||||||
Signature: sig,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := json.Marshal(cs.Manifest)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cs.RawManifest = data
|
|
||||||
return nil
|
|
||||||
}
|
|
170
cmd/frostfs-adm/internal/modules/morph/helper/contract.go
Normal file
170
cmd/frostfs-adm/internal/modules/morph/helper/contract.go
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getFrostfsIDAdminFromContract(roInvoker *invoker.Invoker) (util.Uint160, bool, error) {
|
||||||
|
r := management.NewReader(roInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, false, fmt.Errorf("get nns contract: %w", err)
|
||||||
|
}
|
||||||
|
fidHash, err := NNSResolveHash(roInvoker, cs.Hash, DomainOf(constants.FrostfsIDContract))
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err)
|
||||||
|
}
|
||||||
|
item, err := unwrap.Item(roInvoker.Call(fidHash, "getAdmin"))
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, false, fmt.Errorf("getAdmin: %w", err)
|
||||||
|
}
|
||||||
|
if _, ok := item.(stackitem.Null); ok {
|
||||||
|
return util.Uint160{}, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bs, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, true, fmt.Errorf("getAdmin: decode result: %w", err)
|
||||||
|
}
|
||||||
|
h, err := util.Uint160DecodeBytesBE(bs)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, true, fmt.Errorf("getAdmin: decode result: %w", err)
|
||||||
|
}
|
||||||
|
return h, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetContractDeployData(c *InitializeContext, ctrName string, keysParam []any, method string) ([]any, error) {
|
||||||
|
items := make([]any, 0, 6)
|
||||||
|
|
||||||
|
switch ctrName {
|
||||||
|
case constants.FrostfsContract:
|
||||||
|
items = append(items,
|
||||||
|
c.Contracts[constants.ProcessingContract].Hash,
|
||||||
|
keysParam,
|
||||||
|
smartcontract.Parameter{})
|
||||||
|
case constants.ProcessingContract:
|
||||||
|
items = append(items, c.Contracts[constants.FrostfsContract].Hash)
|
||||||
|
return items[1:], nil // no notary info
|
||||||
|
case constants.BalanceContract:
|
||||||
|
items = append(items,
|
||||||
|
c.Contracts[constants.NetmapContract].Hash,
|
||||||
|
c.Contracts[constants.ContainerContract].Hash)
|
||||||
|
case constants.ContainerContract:
|
||||||
|
// In case if NNS is updated multiple times, we can't calculate
|
||||||
|
// it's actual hash based on local data, thus query chain.
|
||||||
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("get nns contract: %w", err)
|
||||||
|
}
|
||||||
|
items = append(items,
|
||||||
|
c.Contracts[constants.NetmapContract].Hash,
|
||||||
|
c.Contracts[constants.BalanceContract].Hash,
|
||||||
|
c.Contracts[constants.FrostfsIDContract].Hash,
|
||||||
|
nnsCs.Hash,
|
||||||
|
"container")
|
||||||
|
case constants.FrostfsIDContract:
|
||||||
|
var (
|
||||||
|
h util.Uint160
|
||||||
|
found bool
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if method == constants.UpdateMethodName {
|
||||||
|
h, found, err = getFrostfsIDAdminFromContract(c.ReadOnlyInvoker)
|
||||||
|
}
|
||||||
|
if method != constants.UpdateMethodName || err == nil && !found {
|
||||||
|
h, found, err = GetFrostfsIDAdmin(viper.GetViper())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if found {
|
||||||
|
items = append(items, h)
|
||||||
|
} else {
|
||||||
|
items = append(items, c.Contracts[constants.ProxyContract].Hash)
|
||||||
|
}
|
||||||
|
case constants.NetmapContract:
|
||||||
|
md := GetDefaultNetmapContractConfigMap()
|
||||||
|
if method == constants.UpdateMethodName {
|
||||||
|
if err := MergeNetmapConfig(c.ReadOnlyInvoker, md); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var configParam []any
|
||||||
|
for k, v := range md {
|
||||||
|
configParam = append(configParam, k, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
items = append(items,
|
||||||
|
c.Contracts[constants.BalanceContract].Hash,
|
||||||
|
c.Contracts[constants.ContainerContract].Hash,
|
||||||
|
keysParam,
|
||||||
|
configParam)
|
||||||
|
case constants.ProxyContract:
|
||||||
|
items = nil
|
||||||
|
case constants.PolicyContract:
|
||||||
|
items = append(items, c.Contracts[constants.ProxyContract].Hash)
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("invalid contract name: %s", ctrName))
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetContractDeployParameters(cs *ContractState, deployData []any) []any {
|
||||||
|
return []any{cs.RawNEF, cs.RawManifest, deployData}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeployNNS(c *InitializeContext, method string) error {
|
||||||
|
cs := c.GetContract(constants.NNSContract)
|
||||||
|
h := cs.Hash
|
||||||
|
|
||||||
|
nnsCs, err := c.NNSContractState()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if nnsCs != nil {
|
||||||
|
if nnsCs.NEF.Checksum == cs.NEF.Checksum {
|
||||||
|
if method == constants.DeployMethodName {
|
||||||
|
c.Command.Println("NNS contract is already deployed.")
|
||||||
|
} else {
|
||||||
|
c.Command.Println("NNS contract is already updated.")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
h = nnsCs.Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
err = AddManifestGroup(c.ContractWallet, h, cs)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't sign manifest group: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := GetContractDeployParameters(cs, nil)
|
||||||
|
|
||||||
|
invokeHash := management.Hash
|
||||||
|
if method == constants.UpdateMethodName {
|
||||||
|
invokeHash = nnsCs.Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
tx, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create deploy tx for %s: %w", constants.NNSContract, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.MultiSignAndSend(tx, constants.CommitteeAccountName); err != nil {
|
||||||
|
return fmt.Errorf("can't send deploy transaction: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
81
cmd/frostfs-adm/internal/modules/morph/helper/download.go
Normal file
81
cmd/frostfs-adm/internal/modules/morph/helper/download.go
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func downloadContracts(cmd *cobra.Command, url string) (io.ReadCloser, error) {
|
||||||
|
cmd.Printf("Downloading contracts archive from '%s'\n", url)
|
||||||
|
|
||||||
|
// HTTP client with connect timeout
|
||||||
|
client := http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
DialContext: (&net.Dialer{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}).DialContext,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(cmd.Context(), 60*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't create request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't fetch contracts archive: %w", err)
|
||||||
|
}
|
||||||
|
return resp.Body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadContractsFromRepository(cmd *cobra.Command) (io.ReadCloser, error) {
|
||||||
|
client, err := gitea.NewClient("https://git.frostfs.info")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't initialize repository client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
releases, _, err := client.ListReleases("TrueCloudLab", "frostfs-contract", gitea.ListReleasesOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't fetch release information: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var latestRelease *gitea.Release
|
||||||
|
for _, r := range releases {
|
||||||
|
if !r.IsDraft && !r.IsPrerelease {
|
||||||
|
latestRelease = r
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if latestRelease == nil {
|
||||||
|
return nil, fmt.Errorf("attempt to fetch contracts archive from the offitial repository failed: no releases found")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Found release %s (%s)\n", latestRelease.TagName, latestRelease.Title)
|
||||||
|
|
||||||
|
var url string
|
||||||
|
for _, a := range latestRelease.Attachments {
|
||||||
|
if strings.HasPrefix(a.Name, "frostfs-contract") {
|
||||||
|
url = a.DownloadURL
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if url == "" {
|
||||||
|
return nil, errors.New("can't find contracts archive in the latest release")
|
||||||
|
}
|
||||||
|
|
||||||
|
return downloadContracts(cmd, url)
|
||||||
|
}
|
35
cmd/frostfs-adm/internal/modules/morph/helper/frostfsid.go
Normal file
35
cmd/frostfs-adm/internal/modules/morph/helper/frostfsid.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const frostfsIDAdminConfigKey = "frostfsid.admin"
|
||||||
|
|
||||||
|
func GetFrostfsIDAdmin(v *viper.Viper) (util.Uint160, bool, error) {
|
||||||
|
admin := v.GetString(frostfsIDAdminConfigKey)
|
||||||
|
if admin == "" {
|
||||||
|
return util.Uint160{}, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h, err := address.StringToUint160(admin)
|
||||||
|
if err == nil {
|
||||||
|
return h, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h, err = util.Uint160DecodeStringLE(admin)
|
||||||
|
if err == nil {
|
||||||
|
return h, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pk, err := keys.NewPublicKeyFromString(admin)
|
||||||
|
if err == nil {
|
||||||
|
return pk.GetScriptHash(), true, nil
|
||||||
|
}
|
||||||
|
return util.Uint160{}, true, fmt.Errorf("frostfsid: admin is invalid: '%s'", admin)
|
||||||
|
}
|
39
cmd/frostfs-adm/internal/modules/morph/helper/group.go
Normal file
39
cmd/frostfs-adm/internal/modules/morph/helper/group.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AddManifestGroup(cw *wallet.Wallet, h util.Uint160, cs *ContractState) error {
|
||||||
|
priv := cw.Accounts[0].PrivateKey()
|
||||||
|
pub := priv.PublicKey()
|
||||||
|
|
||||||
|
sig := priv.Sign(h.BytesBE())
|
||||||
|
found := false
|
||||||
|
|
||||||
|
for i := range cs.Manifest.Groups {
|
||||||
|
if cs.Manifest.Groups[i].PublicKey.Equal(pub) {
|
||||||
|
cs.Manifest.Groups[i].Signature = sig
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
cs.Manifest.Groups = append(cs.Manifest.Groups, manifest.Group{
|
||||||
|
PublicKey: pub,
|
||||||
|
Signature: sig,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(cs.Manifest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cs.RawManifest = data
|
||||||
|
return nil
|
||||||
|
}
|
211
cmd/frostfs-adm/internal/modules/morph/helper/initialize.go
Normal file
211
cmd/frostfs-adm/internal/modules/morph/helper/initialize.go
Normal file
|
@ -0,0 +1,211 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
nns2 "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrTooManyAlphabetNodes = fmt.Errorf("too many alphabet nodes (maximum allowed is %d)", constants.MaxAlphabetNodes)
|
||||||
|
|
||||||
|
func AwaitTx(cmd *cobra.Command, c Client, txs []HashVUBPair) error {
|
||||||
|
cmd.Println("Waiting for transactions to persist...")
|
||||||
|
|
||||||
|
at := trigger.Application
|
||||||
|
|
||||||
|
var retErr error
|
||||||
|
|
||||||
|
loop:
|
||||||
|
for i := range txs {
|
||||||
|
var it int
|
||||||
|
var pollInterval time.Duration
|
||||||
|
var pollIntervalChanged bool
|
||||||
|
for {
|
||||||
|
// We must fetch current height before application log, to avoid race condition.
|
||||||
|
currBlock, err := c.GetBlockCount()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch current block height: %w", err)
|
||||||
|
}
|
||||||
|
res, err := c.GetApplicationLog(txs[i].Hash, &at)
|
||||||
|
if err == nil {
|
||||||
|
if retErr == nil && len(res.Executions) > 0 && res.Executions[0].VMState != vmstate.Halt {
|
||||||
|
retErr = fmt.Errorf("tx %d persisted in %s state: %s",
|
||||||
|
i, res.Executions[0].VMState, res.Executions[0].FaultException)
|
||||||
|
}
|
||||||
|
continue loop
|
||||||
|
}
|
||||||
|
if txs[i].Vub < currBlock {
|
||||||
|
return fmt.Errorf("tx was not persisted: Vub=%d, height=%d", txs[i].Vub, currBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
pollInterval, pollIntervalChanged = NextPollInterval(it, pollInterval)
|
||||||
|
if pollIntervalChanged && viper.GetBool(commonflags.Verbose) {
|
||||||
|
cmd.Printf("Pool interval to check transaction persistence changed: %s\n", pollInterval.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
timer := time.NewTimer(pollInterval)
|
||||||
|
select {
|
||||||
|
case <-cmd.Context().Done():
|
||||||
|
return cmd.Context().Err()
|
||||||
|
case <-timer.C:
|
||||||
|
}
|
||||||
|
|
||||||
|
it++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func NextPollInterval(it int, previous time.Duration) (time.Duration, bool) {
|
||||||
|
const minPollInterval = 1 * time.Second
|
||||||
|
const maxPollInterval = 16 * time.Second
|
||||||
|
const changeAfter = 5
|
||||||
|
if it == 0 {
|
||||||
|
return minPollInterval, true
|
||||||
|
}
|
||||||
|
if it%changeAfter != 0 {
|
||||||
|
return previous, false
|
||||||
|
}
|
||||||
|
nextInterval := previous * 2
|
||||||
|
if nextInterval > maxPollInterval {
|
||||||
|
return maxPollInterval, previous != maxPollInterval
|
||||||
|
}
|
||||||
|
return nextInterval, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) {
|
||||||
|
for i := range w.Accounts {
|
||||||
|
if w.Accounts[i].Label == typ {
|
||||||
|
return w.Accounts[i], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("account for '%s' not found", typ)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NNSResolve(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (stackitem.Item, error) {
|
||||||
|
return unwrap.Item(inv.Call(nnsHash, "resolve", domain, int64(nns.TXT)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseNNSResolveResult parses the result of resolving NNS record.
|
||||||
|
// It works with multiple formats (corresponding to multiple NNS versions).
|
||||||
|
// If array of hashes is provided, it returns only the first one.
|
||||||
|
func ParseNNSResolveResult(res stackitem.Item) (util.Uint160, error) {
|
||||||
|
arr, ok := res.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
arr = []stackitem.Item{res}
|
||||||
|
}
|
||||||
|
if _, ok := res.Value().(stackitem.Null); ok || len(arr) == 0 {
|
||||||
|
return util.Uint160{}, errors.New("NNS record is missing")
|
||||||
|
}
|
||||||
|
for i := range arr {
|
||||||
|
bs, err := arr[i].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// We support several formats for hash encoding, this logic should be maintained in sync
|
||||||
|
// with NNSResolve from pkg/morph/client/nns.go
|
||||||
|
h, err := util.Uint160DecodeStringLE(string(bs))
|
||||||
|
if err == nil {
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h, err = address.StringToUint160(string(bs))
|
||||||
|
if err == nil {
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.Uint160{}, errors.New("no valid hashes are found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// NNSResolveHash Returns errMissingNNSRecord if invocation fault exception contains "token not found".
|
||||||
|
func NNSResolveHash(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (util.Uint160, error) {
|
||||||
|
item, err := NNSResolve(inv, nnsHash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return ParseNNSResolveResult(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DomainOf(contract string) string {
|
||||||
|
return contract + ".frostfs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func NNSResolveKey(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (*keys.PublicKey, error) {
|
||||||
|
res, err := NNSResolve(inv, nnsHash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _, ok := res.Value().(stackitem.Null); ok {
|
||||||
|
return nil, errors.New("NNS record is missing")
|
||||||
|
}
|
||||||
|
arr, ok := res.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("API of the NNS contract method `resolve` has changed")
|
||||||
|
}
|
||||||
|
for i := range arr {
|
||||||
|
var bs []byte
|
||||||
|
bs, err = arr[i].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys.NewPublicKeyFromString(string(bs))
|
||||||
|
}
|
||||||
|
return nil, errors.New("no valid keys are found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NNSIsAvailable(c Client, nnsHash util.Uint160, name string) (bool, error) {
|
||||||
|
switch c.(type) {
|
||||||
|
case *rpcclient.Client:
|
||||||
|
inv := invoker.New(c, nil)
|
||||||
|
reader := nns2.NewReader(inv, nnsHash)
|
||||||
|
return reader.IsAvailable(name)
|
||||||
|
default:
|
||||||
|
b, err := unwrap.Bool(InvokeFunction(c, nnsHash, "isAvailable", []any{name}, nil))
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("`isAvailable`: invalid response: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckNotaryEnabled(c Client) error {
|
||||||
|
ns, err := c.GetNativeContracts()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't get native contract hashes: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
notaryEnabled := false
|
||||||
|
nativeHashes := make(map[string]util.Uint160, len(ns))
|
||||||
|
for i := range ns {
|
||||||
|
if ns[i].Manifest.Name == nativenames.Notary {
|
||||||
|
notaryEnabled = true
|
||||||
|
}
|
||||||
|
nativeHashes[ns[i].Manifest.Name] = ns[i].Hash
|
||||||
|
}
|
||||||
|
if !notaryEnabled {
|
||||||
|
return errors.New("notary contract must be enabled")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
545
cmd/frostfs-adm/internal/modules/morph/helper/initialize_ctx.go
Normal file
545
cmd/frostfs-adm/internal/modules/morph/helper/initialize_ctx.go
Normal file
|
@ -0,0 +1,545 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
io2 "io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/context"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ContractState struct {
|
||||||
|
NEF *nef.File
|
||||||
|
RawNEF []byte
|
||||||
|
Manifest *manifest.Manifest
|
||||||
|
RawManifest []byte
|
||||||
|
Hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
type Cache struct {
|
||||||
|
NNSCs *state.Contract
|
||||||
|
GroupKey *keys.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
type InitializeContext struct {
|
||||||
|
ClientContext
|
||||||
|
Cache
|
||||||
|
// CommitteeAcc is used for retrieving the committee address and the verification script.
|
||||||
|
CommitteeAcc *wallet.Account
|
||||||
|
// ConsensusAcc is used for retrieving the committee address and the verification script.
|
||||||
|
ConsensusAcc *wallet.Account
|
||||||
|
Wallets []*wallet.Wallet
|
||||||
|
// ContractWallet is a wallet for providing the contract group signature.
|
||||||
|
ContractWallet *wallet.Wallet
|
||||||
|
// Accounts contains simple signature accounts in the same order as in Wallets.
|
||||||
|
Accounts []*wallet.Account
|
||||||
|
Contracts map[string]*ContractState
|
||||||
|
Command *cobra.Command
|
||||||
|
ContractPath string
|
||||||
|
ContractURL string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *ContractState) Parse() error {
|
||||||
|
nf, err := nef.FileFromBytes(cs.RawNEF)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't parse NEF file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
m := new(manifest.Manifest)
|
||||||
|
if err := json.Unmarshal(cs.RawManifest, m); err != nil {
|
||||||
|
return fmt.Errorf("can't parse manifest file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cs.NEF = &nf
|
||||||
|
cs.Manifest = m
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInitializeContext(cmd *cobra.Command, v *viper.Viper) (*InitializeContext, error) {
|
||||||
|
walletDir := config.ResolveHomePath(viper.GetString(commonflags.AlphabetWalletsFlag))
|
||||||
|
wallets, err := GetAlphabetWallets(v, walletDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
needContracts := cmd.Name() == "update-contracts" || cmd.Name() == "init"
|
||||||
|
|
||||||
|
var w *wallet.Wallet
|
||||||
|
w, err = getWallet(cmd, v, needContracts, walletDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err := createClient(cmd, v, wallets)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
committeeAcc, err := GetWalletAccount(wallets[0], constants.CommitteeAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't find committee account: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
consensusAcc, err := GetWalletAccount(wallets[0], constants.ConsensusAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't find consensus account: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateInit(cmd); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrPath, err := getContractsPath(cmd, needContracts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ctrURL string
|
||||||
|
if needContracts {
|
||||||
|
ctrURL, _ = cmd.Flags().GetString(commonflags.ContractsURLFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := CheckNotaryEnabled(c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
accounts, err := createWalletAccounts(wallets)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cliCtx, err := DefaultClientContext(c, committeeAcc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("client context: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
initCtx := &InitializeContext{
|
||||||
|
ClientContext: *cliCtx,
|
||||||
|
ConsensusAcc: consensusAcc,
|
||||||
|
CommitteeAcc: committeeAcc,
|
||||||
|
ContractWallet: w,
|
||||||
|
Wallets: wallets,
|
||||||
|
Accounts: accounts,
|
||||||
|
Command: cmd,
|
||||||
|
Contracts: make(map[string]*ContractState),
|
||||||
|
ContractPath: ctrPath,
|
||||||
|
ContractURL: ctrURL,
|
||||||
|
}
|
||||||
|
|
||||||
|
if needContracts {
|
||||||
|
err := readContracts(initCtx, constants.FullContractList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return initCtx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateInit(cmd *cobra.Command) error {
|
||||||
|
if cmd.Name() != "init" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if viper.GetInt64(commonflags.EpochDurationInitFlag) <= 0 {
|
||||||
|
return fmt.Errorf("epoch duration must be positive")
|
||||||
|
}
|
||||||
|
|
||||||
|
if viper.GetInt64(commonflags.MaxObjectSizeInitFlag) <= 0 {
|
||||||
|
return fmt.Errorf("max object size must be positive")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet) (Client, error) {
|
||||||
|
var c Client
|
||||||
|
var err error
|
||||||
|
if ldf := cmd.Flags().Lookup(commonflags.LocalDumpFlag); ldf != nil && ldf.Changed {
|
||||||
|
if cmd.Flags().Changed(commonflags.EndpointFlag) {
|
||||||
|
return nil, fmt.Errorf("`%s` and `%s` flags are mutually exclusive", commonflags.EndpointFlag, commonflags.LocalDumpFlag)
|
||||||
|
}
|
||||||
|
c, err = NewLocalClient(cmd, v, wallets, ldf.Value.String())
|
||||||
|
} else {
|
||||||
|
c, err = GetN3Client(v)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't create N3 client: %w", err)
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getContractsPath(cmd *cobra.Command, needContracts bool) (string, error) {
|
||||||
|
if !needContracts {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrPath, err := cmd.Flags().GetString(commonflags.ContractsInitFlag)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("invalid contracts path: %w", err)
|
||||||
|
}
|
||||||
|
return ctrPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createWalletAccounts(wallets []*wallet.Wallet) ([]*wallet.Account, error) {
|
||||||
|
accounts := make([]*wallet.Account, len(wallets))
|
||||||
|
for i, w := range wallets {
|
||||||
|
acc, err := GetWalletAccount(w, constants.SingleAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("wallet %s is invalid (no single account): %w", w.Path(), err)
|
||||||
|
}
|
||||||
|
accounts[i] = acc
|
||||||
|
}
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readContracts(c *InitializeContext, names []string) error {
|
||||||
|
var (
|
||||||
|
fi os.FileInfo
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if c.ContractPath != "" {
|
||||||
|
fi, err = os.Stat(c.ContractPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid contracts path: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.ContractPath != "" && fi.IsDir() {
|
||||||
|
for _, ctrName := range names {
|
||||||
|
cs, err := ReadContract(filepath.Join(c.ContractPath, ctrName), ctrName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Contracts[ctrName] = cs
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var r io2.ReadCloser
|
||||||
|
if c.ContractPath != "" {
|
||||||
|
r, err = os.Open(c.ContractPath)
|
||||||
|
} else if c.ContractURL != "" {
|
||||||
|
r, err = downloadContracts(c.Command, c.ContractURL)
|
||||||
|
} else {
|
||||||
|
r, err = downloadContractsFromRepository(c.Command)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't open contracts archive: %w", err)
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
|
m, err := readContractsFromArchive(r, names)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, name := range names {
|
||||||
|
if err := m[name].Parse(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Contracts[name] = m[name]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ctrName := range names {
|
||||||
|
if ctrName != constants.AlphabetContract {
|
||||||
|
cs := c.Contracts[ctrName]
|
||||||
|
cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
cs.NEF.Checksum, cs.Manifest.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) Close() {
|
||||||
|
if local, ok := c.Client.(*LocalClient); ok {
|
||||||
|
err := local.Dump()
|
||||||
|
if err != nil {
|
||||||
|
c.Command.PrintErrf("Can't write dump: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) AwaitTx() error {
|
||||||
|
return c.ClientContext.AwaitTx(c.Command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) NNSContractState() (*state.Contract, error) {
|
||||||
|
if c.NNSCs != nil {
|
||||||
|
return c.NNSCs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.NNSCs = cs
|
||||||
|
return cs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) GetSigner(tryGroup bool, acc *wallet.Account) transaction.Signer {
|
||||||
|
if tryGroup && c.GroupKey != nil {
|
||||||
|
return transaction.Signer{
|
||||||
|
Account: acc.Contract.ScriptHash(),
|
||||||
|
Scopes: transaction.CustomGroups,
|
||||||
|
AllowedGroups: keys.PublicKeys{c.GroupKey},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signer := transaction.Signer{
|
||||||
|
Account: acc.Contract.ScriptHash(),
|
||||||
|
Scopes: transaction.Global, // Scope is important, as we have nested call to container contract.
|
||||||
|
}
|
||||||
|
|
||||||
|
if !tryGroup {
|
||||||
|
return signer
|
||||||
|
}
|
||||||
|
|
||||||
|
nnsCs, err := c.NNSContractState()
|
||||||
|
if err != nil {
|
||||||
|
return signer
|
||||||
|
}
|
||||||
|
|
||||||
|
groupKey, err := NNSResolveKey(c.ReadOnlyInvoker, nnsCs.Hash, client.NNSGroupKeyName)
|
||||||
|
if err == nil {
|
||||||
|
c.GroupKey = groupKey
|
||||||
|
|
||||||
|
signer.Scopes = transaction.CustomGroups
|
||||||
|
signer.AllowedGroups = keys.PublicKeys{groupKey}
|
||||||
|
}
|
||||||
|
return signer
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendCommitteeTx creates transaction from script, signs it by committee nodes and sends it to RPC.
|
||||||
|
// If tryGroup is false, global scope is used for the signer (useful when
|
||||||
|
// working with native contracts).
|
||||||
|
func (c *InitializeContext) SendCommitteeTx(script []byte, tryGroup bool) error {
|
||||||
|
return c.sendMultiTx(script, tryGroup, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendConsensusTx creates transaction from script, signs it by alphabet nodes and sends it to RPC.
|
||||||
|
// Not that because this is used only after the contracts were initialized and deployed,
|
||||||
|
// we always try to have a group scope.
|
||||||
|
func (c *InitializeContext) SendConsensusTx(script []byte) error {
|
||||||
|
return c.sendMultiTx(script, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) sendMultiTx(script []byte, tryGroup bool, withConsensus bool) error {
|
||||||
|
var act *actor.Actor
|
||||||
|
var err error
|
||||||
|
|
||||||
|
withConsensus = withConsensus && !c.ConsensusAcc.Contract.ScriptHash().Equals(c.CommitteeAcc.ScriptHash())
|
||||||
|
if tryGroup {
|
||||||
|
// Even for consensus signatures we need the committee to pay.
|
||||||
|
signers := make([]actor.SignerAccount, 1, 2)
|
||||||
|
signers[0] = actor.SignerAccount{
|
||||||
|
Signer: c.GetSigner(tryGroup, c.CommitteeAcc),
|
||||||
|
Account: c.CommitteeAcc,
|
||||||
|
}
|
||||||
|
if withConsensus {
|
||||||
|
signers = append(signers, actor.SignerAccount{
|
||||||
|
Signer: c.GetSigner(tryGroup, c.ConsensusAcc),
|
||||||
|
Account: c.ConsensusAcc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
act, err = actor.New(c.Client, signers)
|
||||||
|
} else {
|
||||||
|
if withConsensus {
|
||||||
|
panic("BUG: should never happen")
|
||||||
|
}
|
||||||
|
act, err = c.CommitteeAct, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create actor: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tx, err := act.MakeUnsignedRun(script, []transaction.Attribute{{Type: transaction.HighPriority}})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not perform test invocation: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.MultiSign(tx, constants.CommitteeAccountName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if withConsensus {
|
||||||
|
if err := c.MultiSign(tx, constants.ConsensusAccountName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendTx(tx, c.Command, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) MultiSignAndSend(tx *transaction.Transaction, accType string) error {
|
||||||
|
if err := c.MultiSign(tx, accType); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendTx(tx, c.Command, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) MultiSign(tx *transaction.Transaction, accType string) error {
|
||||||
|
version, err := c.Client.GetVersion()
|
||||||
|
if err != nil {
|
||||||
|
// error appears only if client
|
||||||
|
// has not been initialized
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
network := version.Protocol.Network
|
||||||
|
|
||||||
|
// Use parameter context to avoid dealing with signature order.
|
||||||
|
pc := context.NewParameterContext("", network, tx)
|
||||||
|
h := c.CommitteeAcc.Contract.ScriptHash()
|
||||||
|
if accType == constants.ConsensusAccountName {
|
||||||
|
h = c.ConsensusAcc.Contract.ScriptHash()
|
||||||
|
}
|
||||||
|
for _, w := range c.Wallets {
|
||||||
|
acc, err := GetWalletAccount(w, accType)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't find %s wallet account: %w", accType, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
priv := acc.PrivateKey()
|
||||||
|
sign := priv.SignHashable(uint32(network), tx)
|
||||||
|
if err := pc.AddSignature(h, acc.Contract, priv.PublicKey(), sign); err != nil {
|
||||||
|
return fmt.Errorf("can't add signature: %w", err)
|
||||||
|
}
|
||||||
|
if len(pc.Items[h].Signatures) == len(acc.Contract.Parameters) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := pc.GetWitness(h)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("incomplete signature: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range tx.Signers {
|
||||||
|
if tx.Signers[i].Account == h {
|
||||||
|
if i < len(tx.Scripts) {
|
||||||
|
tx.Scripts[i] = *w
|
||||||
|
} else if i == len(tx.Scripts) {
|
||||||
|
tx.Scripts = append(tx.Scripts, *w)
|
||||||
|
} else {
|
||||||
|
panic("BUG: invalid signing order")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("%s account was not found among transaction signers", accType)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmitUpdateNNSGroupScript emits script for updating group key stored in NNS.
|
||||||
|
// First return value is true iff the key is already there and nothing should be done.
|
||||||
|
// Second return value is true iff a domain registration code was emitted.
|
||||||
|
func (c *InitializeContext) EmitUpdateNNSGroupScript(bw *io.BufBinWriter, nnsHash util.Uint160, pub *keys.PublicKey) (bool, bool, error) {
|
||||||
|
isAvail, err := NNSIsAvailable(c.Client, nnsHash, client.NNSGroupKeyName)
|
||||||
|
if err != nil {
|
||||||
|
return false, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isAvail {
|
||||||
|
currentPub, err := NNSResolveKey(c.ReadOnlyInvoker, nnsHash, client.NNSGroupKeyName)
|
||||||
|
if err != nil {
|
||||||
|
return false, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if pub.Equal(currentPub) {
|
||||||
|
return true, false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isAvail {
|
||||||
|
emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All,
|
||||||
|
client.NNSGroupKeyName, c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
}
|
||||||
|
|
||||||
|
emit.AppCall(bw.BinWriter, nnsHash, "deleteRecords", callflag.All, "group.frostfs", int64(nns.TXT))
|
||||||
|
emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||||
|
"group.frostfs", int64(nns.TXT), hex.EncodeToString(pub.Bytes()))
|
||||||
|
|
||||||
|
return false, isAvail, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) NNSRegisterDomainScript(nnsHash, expectedHash util.Uint160, domain string) ([]byte, bool, error) {
|
||||||
|
ok, err := NNSIsAvailable(c.Client, nnsHash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All,
|
||||||
|
domain, c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
|
||||||
|
if bw.Err != nil {
|
||||||
|
panic(bw.Err)
|
||||||
|
}
|
||||||
|
return bw.Bytes(), false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := NNSResolveHash(c.ReadOnlyInvoker, nnsHash, domain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
return nil, s == expectedHash, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) NNSRootRegistered(nnsHash util.Uint160, zone string) (bool, error) {
|
||||||
|
res, err := c.CommitteeAct.Call(nnsHash, "isAvailable", "name."+zone)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.State == vmstate.Halt.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) IsUpdated(ctrHash util.Uint160, cs *ContractState) bool {
|
||||||
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
realCs, err := r.GetContract(ctrHash)
|
||||||
|
return err == nil && realCs != nil && realCs.NEF.Checksum == cs.NEF.Checksum
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) GetContract(ctrName string) *ContractState {
|
||||||
|
return c.Contracts[ctrName]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *InitializeContext) GetAlphabetDeployItems(i, n int) []any {
|
||||||
|
items := make([]any, 5)
|
||||||
|
items[0] = c.Contracts[constants.NetmapContract].Hash
|
||||||
|
items[1] = c.Contracts[constants.ProxyContract].Hash
|
||||||
|
items[2] = innerring.GlagoliticLetter(i).String()
|
||||||
|
items[3] = int64(i)
|
||||||
|
items[4] = int64(n)
|
||||||
|
return items
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNextPollInterval(t *testing.T) {
|
||||||
|
var pollInterval time.Duration
|
||||||
|
var iteration int
|
||||||
|
|
||||||
|
pollInterval, hasChanged := NextPollInterval(iteration, pollInterval)
|
||||||
|
require.True(t, hasChanged)
|
||||||
|
require.Equal(t, time.Second, pollInterval)
|
||||||
|
|
||||||
|
iteration = 4
|
||||||
|
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
|
||||||
|
require.False(t, hasChanged)
|
||||||
|
require.Equal(t, time.Second, pollInterval)
|
||||||
|
|
||||||
|
iteration = 5
|
||||||
|
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
|
||||||
|
require.True(t, hasChanged)
|
||||||
|
require.Equal(t, 2*time.Second, pollInterval)
|
||||||
|
|
||||||
|
iteration = 10
|
||||||
|
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
|
||||||
|
require.True(t, hasChanged)
|
||||||
|
require.Equal(t, 4*time.Second, pollInterval)
|
||||||
|
|
||||||
|
iteration = 20
|
||||||
|
pollInterval = 32 * time.Second
|
||||||
|
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
|
||||||
|
require.True(t, hasChanged) // from 32s to 16s
|
||||||
|
require.Equal(t, 16*time.Second, pollInterval)
|
||||||
|
|
||||||
|
pollInterval = 16 * time.Second
|
||||||
|
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
|
||||||
|
require.False(t, hasChanged)
|
||||||
|
require.Equal(t, 16*time.Second, pollInterval)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package morph
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
|
@ -8,42 +8,38 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/chaindump"
|
"github.com/nspcc-dev/neo-go/pkg/core/chaindump"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type localClient struct {
|
type LocalClient struct {
|
||||||
bc *core.Blockchain
|
bc *core.Blockchain
|
||||||
transactions []*transaction.Transaction
|
transactions []*transaction.Transaction
|
||||||
dumpPath string
|
dumpPath string
|
||||||
|
@ -51,8 +47,8 @@ type localClient struct {
|
||||||
maxGasInvoke int64
|
maxGasInvoke int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet) (*localClient, error) {
|
func NewLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet, dumpPath string) (*LocalClient, error) {
|
||||||
cfg, err := config.LoadFile(v.GetString(protoConfigPath))
|
cfg, err := config.LoadFile(v.GetString(constants.ProtoConfigPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -62,10 +58,10 @@ func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m := smartcontract.GetDefaultHonestNodeCount(cfg.ProtocolConfiguration.ValidatorsCount)
|
m := smartcontract.GetDefaultHonestNodeCount(int(cfg.ProtocolConfiguration.ValidatorsCount))
|
||||||
accounts := make([]*wallet.Account, len(wallets))
|
accounts := make([]*wallet.Account, len(wallets))
|
||||||
for i := range accounts {
|
for i := range accounts {
|
||||||
accounts[i], err = getWalletAccount(wallets[i], consensusAccountName)
|
accounts[i], err = GetWalletAccount(wallets[i], constants.ConsensusAccountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -87,9 +83,8 @@ func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet
|
||||||
|
|
||||||
go bc.Run()
|
go bc.Run()
|
||||||
|
|
||||||
dumpPath := v.GetString(localDumpFlag)
|
|
||||||
if cmd.Name() != "init" {
|
if cmd.Name() != "init" {
|
||||||
f, err := os.OpenFile(dumpPath, os.O_RDONLY, 0600)
|
f, err := os.OpenFile(dumpPath, os.O_RDONLY, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't open local dump: %w", err)
|
return nil, fmt.Errorf("can't open local dump: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -108,7 +103,7 @@ func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &localClient{
|
return &LocalClient{
|
||||||
bc: bc,
|
bc: bc,
|
||||||
dumpPath: dumpPath,
|
dumpPath: dumpPath,
|
||||||
accounts: accounts[:m],
|
accounts: accounts[:m],
|
||||||
|
@ -116,34 +111,15 @@ func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) GetBlockCount() (uint32, error) {
|
func (l *LocalClient) GetBlockCount() (uint32, error) {
|
||||||
return l.bc.BlockHeight(), nil
|
return l.bc.BlockHeight(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) GetContractStateByID(id int32) (*state.Contract, error) {
|
func (l *LocalClient) GetNativeContracts() ([]state.NativeContract, error) {
|
||||||
h, err := l.bc.GetContractScriptHash(id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return l.GetContractStateByHash(h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) GetContractStateByHash(h util.Uint160) (*state.Contract, error) {
|
|
||||||
if cs := l.bc.GetContractState(h); cs != nil {
|
|
||||||
return cs, nil
|
|
||||||
}
|
|
||||||
return nil, storage.ErrKeyNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) GetNativeContracts() ([]state.NativeContract, error) {
|
|
||||||
return l.bc.GetNatives(), nil
|
return l.bc.GetNatives(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) GetNetwork() (netmode.Magic, error) {
|
func (l *LocalClient) GetApplicationLog(h util.Uint256, t *trigger.Type) (*result.ApplicationLog, error) {
|
||||||
return l.bc.GetConfig().Magic, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) GetApplicationLog(h util.Uint256, t *trigger.Type) (*result.ApplicationLog, error) {
|
|
||||||
aer, err := l.bc.GetAppExecResults(h, *t)
|
aer, err := l.bc.GetAppExecResults(h, *t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -153,41 +129,13 @@ func (l *localClient) GetApplicationLog(h util.Uint256, t *trigger.Type) (*resul
|
||||||
return &a, nil
|
return &a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee int64, netFee int64, cosigners []rpcclient.SignerAccount) (*transaction.Transaction, error) {
|
func (l *LocalClient) GetCommittee() (keys.PublicKeys, error) {
|
||||||
signers, accounts, err := getSigners(acc, cosigners)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to construct tx signers: %w", err)
|
|
||||||
}
|
|
||||||
if sysFee < 0 {
|
|
||||||
res, err := l.InvokeScript(script, signers)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't add system fee to transaction: %w", err)
|
|
||||||
}
|
|
||||||
if res.State != "HALT" {
|
|
||||||
return nil, fmt.Errorf("can't add system fee to transaction: bad vm state: %s due to an error: %s", res.State, res.FaultException)
|
|
||||||
}
|
|
||||||
sysFee = res.GasConsumed
|
|
||||||
}
|
|
||||||
|
|
||||||
tx := transaction.New(script, sysFee)
|
|
||||||
tx.Signers = signers
|
|
||||||
tx.ValidUntilBlock = l.bc.BlockHeight() + 2
|
|
||||||
|
|
||||||
err = l.AddNetworkFee(tx, netFee, accounts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to add network fee: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return tx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) GetCommittee() (keys.PublicKeys, error) {
|
|
||||||
// not used by `morph init` command
|
// not used by `morph init` command
|
||||||
panic("unexpected call")
|
panic("unexpected call")
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvokeFunction is implemented via `InvokeScript`.
|
// InvokeFunction is implemented via `InvokeScript`.
|
||||||
func (l *localClient) InvokeFunction(h util.Uint160, method string, sPrm []smartcontract.Parameter, ss []transaction.Signer) (*result.Invoke, error) {
|
func (l *LocalClient) InvokeFunction(h util.Uint160, method string, sPrm []smartcontract.Parameter, ss []transaction.Signer) (*result.Invoke, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
pp := make([]any, len(sPrm))
|
pp := make([]any, len(sPrm))
|
||||||
|
@ -198,36 +146,21 @@ func (l *localClient) InvokeFunction(h util.Uint160, method string, sPrm []smart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return invokeFunction(l, h, method, pp, ss)
|
return InvokeFunction(l, h, method, pp, ss)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) CalculateNotaryFee(_ uint8) (int64, error) {
|
func (l *LocalClient) TerminateSession(_ uuid.UUID) (bool, error) {
|
||||||
// not used by `morph init` command
|
// not used by `morph init` command
|
||||||
panic("unexpected call")
|
panic("unexpected call")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) SignAndPushP2PNotaryRequest(_ *transaction.Transaction, _ []byte, _ int64, _ int64, _ uint32, _ *wallet.Account) (*payload.P2PNotaryRequest, error) {
|
func (l *LocalClient) TraverseIterator(_, _ uuid.UUID, _ int) ([]stackitem.Item, error) {
|
||||||
// not used by `morph init` command
|
|
||||||
panic("unexpected call")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) SignAndPushInvocationTx(_ []byte, _ *wallet.Account, _ int64, _ fixedn.Fixed8, _ []rpcclient.SignerAccount) (util.Uint256, error) {
|
|
||||||
// not used by `morph init` command
|
|
||||||
panic("unexpected call")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) TerminateSession(_ uuid.UUID) (bool, error) {
|
|
||||||
// not used by `morph init` command
|
|
||||||
panic("unexpected call")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) TraverseIterator(_, _ uuid.UUID, _ int) ([]stackitem.Item, error) {
|
|
||||||
// not used by `morph init` command
|
// not used by `morph init` command
|
||||||
panic("unexpected call")
|
panic("unexpected call")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVersion return default version.
|
// GetVersion return default version.
|
||||||
func (l *localClient) GetVersion() (*result.Version, error) {
|
func (l *LocalClient) GetVersion() (*result.Version, error) {
|
||||||
c := l.bc.GetConfig()
|
c := l.bc.GetConfig()
|
||||||
return &result.Version{
|
return &result.Version{
|
||||||
Protocol: result.Protocol{
|
Protocol: result.Protocol{
|
||||||
|
@ -248,120 +181,86 @@ func (l *localClient) GetVersion() (*result.Version, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
func (l *LocalClient) InvokeContractVerify(util.Uint160, []smartcontract.Parameter, []transaction.Signer, ...transaction.Witness) (*result.Invoke, error) {
|
||||||
// not used by `morph init` command
|
// not used by `morph init` command
|
||||||
panic("unexpected call")
|
panic("unexpected call")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalculateNetworkFee calculates network fee for the given transaction.
|
// CalculateNetworkFee calculates network fee for the given transaction.
|
||||||
// Copied from neo-go with minor corrections (no need to support non-notary mode):
|
// Copied from neo-go with minor corrections (no need to support non-notary mode):
|
||||||
// https://github.com/nspcc-dev/neo-go/blob/v0.99.2/pkg/services/rpcsrv/server.go#L744
|
// https://github.com/nspcc-dev/neo-go/blob/v0.103.0/pkg/services/rpcsrv/server.go#L911
|
||||||
func (l *localClient) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
|
func (l *LocalClient) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
|
||||||
hashablePart, err := tx.EncodeHashableFields()
|
// Avoid setting hash for this tx: server code doesn't touch client transaction.
|
||||||
if err != nil {
|
data := tx.Bytes()
|
||||||
return 0, fmt.Errorf("failed to compute tx size: %w", err)
|
tx, err := transaction.NewTransactionFromBytes(data)
|
||||||
}
|
|
||||||
|
|
||||||
size := len(hashablePart) + io.GetVarSize(len(tx.Signers))
|
|
||||||
ef := l.bc.GetBaseExecFee()
|
|
||||||
|
|
||||||
var netFee int64
|
|
||||||
for i, signer := range tx.Signers {
|
|
||||||
var verificationScript []byte
|
|
||||||
for _, w := range tx.Scripts {
|
|
||||||
if w.VerificationScript != nil && hash.Hash160(w.VerificationScript).Equals(signer.Account) {
|
|
||||||
verificationScript = w.VerificationScript
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if verificationScript == nil {
|
|
||||||
gasConsumed, err := l.bc.VerifyWitness(signer.Account, tx, &tx.Scripts[i], l.maxGasInvoke)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("invalid signature: %w", err)
|
|
||||||
}
|
|
||||||
netFee += gasConsumed
|
|
||||||
size += io.GetVarSize([]byte{}) + io.GetVarSize(tx.Scripts[i].InvocationScript)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fee, sizeDelta := fee.Calculate(ef, verificationScript)
|
|
||||||
netFee += fee
|
|
||||||
size += sizeDelta
|
|
||||||
}
|
|
||||||
|
|
||||||
fee := l.bc.FeePerByte()
|
|
||||||
netFee += int64(size) * fee
|
|
||||||
|
|
||||||
return netFee, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddNetworkFee adds network fee for each witness script and optional extra
|
|
||||||
// network fee to transaction. `accs` is an array signer's accounts.
|
|
||||||
// Copied from neo-go with minor corrections (no need to support contract signers):
|
|
||||||
// https://github.com/nspcc-dev/neo-go/blob/6ff11baa1b9e4c71ef0d1de43b92a8c541ca732c/pkg/rpc/client/rpc.go#L960
|
|
||||||
func (l *localClient) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) error {
|
|
||||||
if len(tx.Signers) != len(accs) {
|
|
||||||
return errors.New("number of signers must match number of scripts")
|
|
||||||
}
|
|
||||||
|
|
||||||
size := io.GetVarSize(tx)
|
|
||||||
ef := l.bc.GetBaseExecFee()
|
|
||||||
for i := range tx.Signers {
|
|
||||||
netFee, sizeDelta := fee.Calculate(ef, accs[i].Contract.Script)
|
|
||||||
tx.NetworkFee += netFee
|
|
||||||
size += sizeDelta
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.NetworkFee += int64(size)*l.bc.FeePerByte() + extraFee
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getSigners returns an array of transaction signers and corresponding accounts from
|
|
||||||
// given sender and cosigners. If cosigners list already contains sender, the sender
|
|
||||||
// will be placed at the start of the list.
|
|
||||||
// Copied from neo-go with minor corrections:
|
|
||||||
// https://github.com/nspcc-dev/neo-go/blob/6ff11baa1b9e4c71ef0d1de43b92a8c541ca732c/pkg/rpc/client/rpc.go#L735
|
|
||||||
func getSigners(sender *wallet.Account, cosigners []rpcclient.SignerAccount) ([]transaction.Signer, []*wallet.Account, error) {
|
|
||||||
var (
|
|
||||||
signers []transaction.Signer
|
|
||||||
accounts []*wallet.Account
|
|
||||||
)
|
|
||||||
|
|
||||||
from := sender.Contract.ScriptHash()
|
|
||||||
s := transaction.Signer{
|
|
||||||
Account: from,
|
|
||||||
Scopes: transaction.None,
|
|
||||||
}
|
|
||||||
for _, c := range cosigners {
|
|
||||||
if c.Signer.Account == from {
|
|
||||||
s = c.Signer
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
signers = append(signers, c.Signer)
|
|
||||||
accounts = append(accounts, c.Account)
|
|
||||||
}
|
|
||||||
signers = append([]transaction.Signer{s}, signers...)
|
|
||||||
accounts = append([]*wallet.Account{sender}, accounts...)
|
|
||||||
return signers, accounts, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) NEP17BalanceOf(h util.Uint160, acc util.Uint160) (int64, error) {
|
|
||||||
res, err := invokeFunction(l, h, "balanceOf", []any{acc}, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if res.State != vmstate.Halt.String() || len(res.Stack) == 0 {
|
|
||||||
return 0, fmt.Errorf("`balance`: invalid response (empty: %t): %s",
|
hashablePart, err := tx.EncodeHashableFields()
|
||||||
len(res.Stack) == 0, res.FaultException)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
bi, err := res.Stack[0].TryInteger()
|
size := len(hashablePart) + io.GetVarSize(len(tx.Signers))
|
||||||
if err != nil || !bi.IsInt64() {
|
var (
|
||||||
return 0, fmt.Errorf("`balance`: invalid response")
|
netFee int64
|
||||||
|
// Verification GAS cost can't exceed this policy.
|
||||||
|
gasLimit = l.bc.GetMaxVerificationGAS()
|
||||||
|
)
|
||||||
|
for i, signer := range tx.Signers {
|
||||||
|
w := tx.Scripts[i]
|
||||||
|
if len(w.InvocationScript) == 0 { // No invocation provided, try to infer one.
|
||||||
|
var paramz []manifest.Parameter
|
||||||
|
if len(w.VerificationScript) == 0 { // Contract-based verification
|
||||||
|
cs := l.bc.GetContractState(signer.Account)
|
||||||
|
if cs == nil {
|
||||||
|
return 0, fmt.Errorf("signer %d has no verification script and no deployed contract", i)
|
||||||
|
}
|
||||||
|
md := cs.Manifest.ABI.GetMethod(manifest.MethodVerify, -1)
|
||||||
|
if md == nil || md.ReturnType != smartcontract.BoolType {
|
||||||
|
return 0, fmt.Errorf("signer %d has no verify method in deployed contract", i)
|
||||||
|
}
|
||||||
|
paramz = md.Parameters // Might as well have none params and it's OK.
|
||||||
|
} else { // Regular signature verification.
|
||||||
|
if vm.IsSignatureContract(w.VerificationScript) {
|
||||||
|
paramz = []manifest.Parameter{{Type: smartcontract.SignatureType}}
|
||||||
|
} else if nSigs, _, ok := vm.ParseMultiSigContract(w.VerificationScript); ok {
|
||||||
|
paramz = make([]manifest.Parameter, nSigs)
|
||||||
|
for j := 0; j < nSigs; j++ {
|
||||||
|
paramz[j] = manifest.Parameter{Type: smartcontract.SignatureType}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inv := io.NewBufBinWriter()
|
||||||
|
for _, p := range paramz {
|
||||||
|
p.Type.EncodeDefaultValue(inv.BinWriter)
|
||||||
|
}
|
||||||
|
if inv.Err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to create dummy invocation script (signer %d): %s", i, inv.Err.Error())
|
||||||
|
}
|
||||||
|
w.InvocationScript = inv.Bytes()
|
||||||
|
}
|
||||||
|
gasConsumed, err := l.bc.VerifyWitness(signer.Account, tx, &w, gasLimit)
|
||||||
|
if err != nil && !errors.Is(err, core.ErrInvalidSignature) {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
gasLimit -= gasConsumed
|
||||||
|
netFee += gasConsumed
|
||||||
|
size += io.GetVarSize(w.VerificationScript) + io.GetVarSize(w.InvocationScript)
|
||||||
}
|
}
|
||||||
return bi.Int64(), nil
|
if l.bc.P2PSigExtensionsEnabled() {
|
||||||
|
attrs := tx.GetAttributes(transaction.NotaryAssistedT)
|
||||||
|
if len(attrs) != 0 {
|
||||||
|
na := attrs[0].Value.(*transaction.NotaryAssisted)
|
||||||
|
netFee += (int64(na.NKeys) + 1) * l.bc.GetNotaryServiceFeePerKey()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fee := l.bc.FeePerByte()
|
||||||
|
netFee += int64(size) * fee
|
||||||
|
return netFee, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
func (l *LocalClient) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
lastBlock, err := l.bc.GetBlock(l.bc.CurrentBlockHash())
|
lastBlock, err := l.bc.GetBlock(l.bc.CurrentBlockHash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -397,7 +296,7 @@ func (l *localClient) InvokeScript(script []byte, signers []transaction.Signer)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) SendRawTransaction(tx *transaction.Transaction) (util.Uint256, error) {
|
func (l *LocalClient) SendRawTransaction(tx *transaction.Transaction) (util.Uint256, error) {
|
||||||
// We need to test that transaction was formed correctly to catch as many errors as we can.
|
// We need to test that transaction was formed correctly to catch as many errors as we can.
|
||||||
bs := tx.Bytes()
|
bs := tx.Bytes()
|
||||||
_, err := transaction.NewTransactionFromBytes(bs)
|
_, err := transaction.NewTransactionFromBytes(bs)
|
||||||
|
@ -409,7 +308,7 @@ func (l *localClient) SendRawTransaction(tx *transaction.Transaction) (util.Uint
|
||||||
return tx.Hash(), nil
|
return tx.Hash(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) putTransactions() error {
|
func (l *LocalClient) putTransactions() error {
|
||||||
// 1. Prepare new block.
|
// 1. Prepare new block.
|
||||||
lastBlock, err := l.bc.GetBlock(l.bc.CurrentBlockHash())
|
lastBlock, err := l.bc.GetBlock(l.bc.CurrentBlockHash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -451,7 +350,7 @@ func (l *localClient) putTransactions() error {
|
||||||
return l.bc.AddBlock(b)
|
return l.bc.AddBlock(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func invokeFunction(c Client, h util.Uint160, method string, parameters []any, signers []transaction.Signer) (*result.Invoke, error) {
|
func InvokeFunction(c Client, h util.Uint160, method string, parameters []any, signers []transaction.Signer) (*result.Invoke, error) {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.Array(w.BinWriter, parameters...)
|
emit.Array(w.BinWriter, parameters...)
|
||||||
emit.AppCallNoArgs(w.BinWriter, h, method, callflag.All)
|
emit.AppCallNoArgs(w.BinWriter, h, method, callflag.All)
|
||||||
|
@ -463,7 +362,7 @@ func invokeFunction(c Client, h util.Uint160, method string, parameters []any, s
|
||||||
|
|
||||||
var errGetDesignatedByRoleResponse = errors.New("`getDesignatedByRole`: invalid response")
|
var errGetDesignatedByRoleResponse = errors.New("`getDesignatedByRole`: invalid response")
|
||||||
|
|
||||||
func getDesignatedByRole(inv *invoker.Invoker, h util.Uint160, role noderoles.Role, u uint32) (keys.PublicKeys, error) {
|
func GetDesignatedByRole(inv *invoker.Invoker, h util.Uint160, role noderoles.Role, u uint32) (keys.PublicKeys, error) {
|
||||||
arr, err := unwrap.Array(inv.Call(h, "getDesignatedByRole", int64(role), int64(u)))
|
arr, err := unwrap.Array(inv.Call(h, "getDesignatedByRole", int64(role), int64(u)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errGetDesignatedByRoleResponse
|
return nil, errGetDesignatedByRoleResponse
|
||||||
|
@ -484,7 +383,7 @@ func getDesignatedByRole(inv *invoker.Invoker, h util.Uint160, role noderoles.Ro
|
||||||
return pubs, nil
|
return pubs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) dump() (err error) {
|
func (l *LocalClient) Dump() (err error) {
|
||||||
defer l.bc.Close()
|
defer l.bc.Close()
|
||||||
|
|
||||||
f, err := os.Create(l.dumpPath)
|
f, err := os.Create(l.dumpPath)
|
|
@ -1,4 +1,4 @@
|
||||||
package morph
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -6,13 +6,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
@ -29,36 +27,27 @@ type Client interface {
|
||||||
invoker.RPCInvoke
|
invoker.RPCInvoke
|
||||||
|
|
||||||
GetBlockCount() (uint32, error)
|
GetBlockCount() (uint32, error)
|
||||||
GetContractStateByID(int32) (*state.Contract, error)
|
|
||||||
GetContractStateByHash(util.Uint160) (*state.Contract, error)
|
|
||||||
GetNativeContracts() ([]state.NativeContract, error)
|
GetNativeContracts() ([]state.NativeContract, error)
|
||||||
GetNetwork() (netmode.Magic, error)
|
|
||||||
GetApplicationLog(util.Uint256, *trigger.Type) (*result.ApplicationLog, error)
|
GetApplicationLog(util.Uint256, *trigger.Type) (*result.ApplicationLog, error)
|
||||||
GetVersion() (*result.Version, error)
|
GetVersion() (*result.Version, error)
|
||||||
CreateTxFromScript([]byte, *wallet.Account, int64, int64, []rpcclient.SignerAccount) (*transaction.Transaction, error)
|
|
||||||
NEP17BalanceOf(util.Uint160, util.Uint160) (int64, error)
|
|
||||||
SendRawTransaction(*transaction.Transaction) (util.Uint256, error)
|
SendRawTransaction(*transaction.Transaction) (util.Uint256, error)
|
||||||
GetCommittee() (keys.PublicKeys, error)
|
GetCommittee() (keys.PublicKeys, error)
|
||||||
CalculateNotaryFee(uint8) (int64, error)
|
|
||||||
CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
|
CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
|
||||||
AddNetworkFee(*transaction.Transaction, int64, ...*wallet.Account) error
|
|
||||||
SignAndPushInvocationTx([]byte, *wallet.Account, int64, fixedn.Fixed8, []rpcclient.SignerAccount) (util.Uint256, error)
|
|
||||||
SignAndPushP2PNotaryRequest(*transaction.Transaction, []byte, int64, int64, uint32, *wallet.Account) (*payload.P2PNotaryRequest, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type hashVUBPair struct {
|
type HashVUBPair struct {
|
||||||
hash util.Uint256
|
Hash util.Uint256
|
||||||
vub uint32
|
Vub uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientContext struct {
|
type ClientContext struct {
|
||||||
Client Client // a raw neo-go client OR a local chain implementation
|
Client Client // a raw neo-go client OR a local chain implementation
|
||||||
CommitteeAct *actor.Actor // committee actor with the Global witness scope
|
CommitteeAct *actor.Actor // committee actor with the Global witness scope
|
||||||
ReadOnlyInvoker *invoker.Invoker // R/O contract invoker, does not contain any signer
|
ReadOnlyInvoker *invoker.Invoker // R/O contract invoker, does not contain any signer
|
||||||
SentTxs []hashVUBPair
|
SentTxs []HashVUBPair
|
||||||
}
|
}
|
||||||
|
|
||||||
func getN3Client(v *viper.Viper) (Client, error) {
|
func GetN3Client(v *viper.Viper) (Client, error) {
|
||||||
// number of opened connections
|
// number of opened connections
|
||||||
// by neo-go client per one host
|
// by neo-go client per one host
|
||||||
const (
|
const (
|
||||||
|
@ -67,7 +56,7 @@ func getN3Client(v *viper.Viper) (Client, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
endpoint := v.GetString(endpointFlag)
|
endpoint := v.GetString(commonflags.EndpointFlag)
|
||||||
if endpoint == "" {
|
if endpoint == "" {
|
||||||
return nil, errors.New("missing endpoint")
|
return nil, errors.New("missing endpoint")
|
||||||
}
|
}
|
||||||
|
@ -84,26 +73,20 @@ func getN3Client(v *viper.Viper) (Client, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultClientContext(c Client, committeeAcc *wallet.Account) (*clientContext, error) {
|
func DefaultClientContext(c Client, committeeAcc *wallet.Account) (*ClientContext, error) {
|
||||||
commAct, err := actor.New(c, []actor.SignerAccount{{
|
commAct, err := NewActor(c, committeeAcc)
|
||||||
Signer: transaction.Signer{
|
|
||||||
Account: committeeAcc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.Global,
|
|
||||||
},
|
|
||||||
Account: committeeAcc,
|
|
||||||
}})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &clientContext{
|
return &ClientContext{
|
||||||
Client: c,
|
Client: c,
|
||||||
CommitteeAct: commAct,
|
CommitteeAct: commAct,
|
||||||
ReadOnlyInvoker: invoker.New(c, nil),
|
ReadOnlyInvoker: invoker.New(c, nil),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientContext) sendTx(tx *transaction.Transaction, cmd *cobra.Command, await bool) error {
|
func (c *ClientContext) SendTx(tx *transaction.Transaction, cmd *cobra.Command, await bool) error {
|
||||||
h, err := c.Client.SendRawTransaction(tx)
|
h, err := c.Client.SendRawTransaction(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -113,10 +96,27 @@ func (c *clientContext) sendTx(tx *transaction.Transaction, cmd *cobra.Command,
|
||||||
return fmt.Errorf("sent and actual tx hashes mismatch:\n\tsent: %v\n\tactual: %v", tx.Hash().StringLE(), h.StringLE())
|
return fmt.Errorf("sent and actual tx hashes mismatch:\n\tsent: %v\n\tactual: %v", tx.Hash().StringLE(), h.StringLE())
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SentTxs = append(c.SentTxs, hashVUBPair{hash: h, vub: tx.ValidUntilBlock})
|
c.SentTxs = append(c.SentTxs, HashVUBPair{Hash: h, Vub: tx.ValidUntilBlock})
|
||||||
|
|
||||||
if await {
|
if await {
|
||||||
return c.awaitTx(cmd)
|
return c.AwaitTx(cmd)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClientContext) AwaitTx(cmd *cobra.Command) error {
|
||||||
|
if len(c.SentTxs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if local, ok := c.Client.(*LocalClient); ok {
|
||||||
|
if err := local.putTransactions(); err != nil {
|
||||||
|
return fmt.Errorf("can't persist transactions: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := AwaitTx(cmd, c.Client, c.SentTxs)
|
||||||
|
c.SentTxs = c.SentTxs[:0]
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
121
cmd/frostfs-adm/internal/modules/morph/helper/netmap.go
Normal file
121
cmd/frostfs-adm/internal/modules/morph/helper/netmap.go
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"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/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var NetmapConfigKeys = []string{
|
||||||
|
netmap.EpochDurationConfig,
|
||||||
|
netmap.MaxObjectSizeConfig,
|
||||||
|
netmap.ContainerFeeConfig,
|
||||||
|
netmap.ContainerAliasFeeConfig,
|
||||||
|
netmap.IrCandidateFeeConfig,
|
||||||
|
netmap.WithdrawFeeConfig,
|
||||||
|
netmap.HomomorphicHashingDisabledKey,
|
||||||
|
netmap.MaintenanceModeAllowedConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDefaultNetmapContractConfigMap() map[string]any {
|
||||||
|
m := make(map[string]any)
|
||||||
|
m[netmap.EpochDurationConfig] = viper.GetInt64(commonflags.EpochDurationInitFlag)
|
||||||
|
m[netmap.MaxObjectSizeConfig] = viper.GetInt64(commonflags.MaxObjectSizeInitFlag)
|
||||||
|
m[netmap.ContainerFeeConfig] = viper.GetInt64(commonflags.ContainerFeeInitFlag)
|
||||||
|
m[netmap.ContainerAliasFeeConfig] = viper.GetInt64(commonflags.ContainerAliasFeeInitFlag)
|
||||||
|
m[netmap.IrCandidateFeeConfig] = viper.GetInt64(commonflags.CandidateFeeInitFlag)
|
||||||
|
m[netmap.WithdrawFeeConfig] = viper.GetInt64(commonflags.WithdrawFeeInitFlag)
|
||||||
|
m[netmap.HomomorphicHashingDisabledKey] = viper.GetBool(commonflags.HomomorphicHashDisabledInitFlag)
|
||||||
|
m[netmap.MaintenanceModeAllowedConfig] = viper.GetBool(commonflags.MaintenanceModeAllowedInitFlag)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseConfigFromNetmapContract(arr []stackitem.Item) (map[string][]byte, error) {
|
||||||
|
m := make(map[string][]byte, len(arr))
|
||||||
|
for _, param := range arr {
|
||||||
|
tuple, ok := param.Value().([]stackitem.Item)
|
||||||
|
if !ok || len(tuple) != 2 {
|
||||||
|
return nil, errors.New("invalid ListConfig response from netmap contract")
|
||||||
|
}
|
||||||
|
|
||||||
|
k, err := tuple[0].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("invalid config key from netmap contract")
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := tuple[1].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, InvalidConfigValueErr(string(k))
|
||||||
|
}
|
||||||
|
m[string(k)] = v
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func InvalidConfigValueErr(key string) error {
|
||||||
|
return fmt.Errorf("invalid %s config value from netmap contract", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func EmitNewEpochCall(bw *io.BufBinWriter, wCtx *InitializeContext, nmHash util.Uint160) error {
|
||||||
|
curr, err := unwrap.Int64(wCtx.ReadOnlyInvoker.Call(nmHash, "epoch"))
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("can't fetch current epoch from the netmap contract")
|
||||||
|
}
|
||||||
|
|
||||||
|
newEpoch := curr + 1
|
||||||
|
wCtx.Command.Printf("Current epoch: %d, increase to %d.\n", curr, newEpoch)
|
||||||
|
|
||||||
|
// In NeoFS this is done via Notary contract. Here, however, we can form the
|
||||||
|
// transaction locally.
|
||||||
|
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
|
||||||
|
return bw.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetConfigFromNetmapContract(roInvoker *invoker.Invoker) ([]stackitem.Item, error) {
|
||||||
|
r := management.NewReader(roInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("get nns contract: %w", err)
|
||||||
|
}
|
||||||
|
nmHash, err := NNSResolveHash(roInvoker, cs.Hash, DomainOf(constants.NetmapContract))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||||
|
}
|
||||||
|
arr, err := unwrap.Array(roInvoker.Call(nmHash, "listConfig"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't fetch list of network config keys from the netmap contract")
|
||||||
|
}
|
||||||
|
return arr, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func MergeNetmapConfig(roInvoker *invoker.Invoker, md map[string]any) error {
|
||||||
|
arr, err := GetNetConfigFromNetmapContract(roInvoker)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m, err := ParseConfigFromNetmapContract(arr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for k, v := range m {
|
||||||
|
for _, key := range NetmapConfigKeys {
|
||||||
|
if k == key {
|
||||||
|
md[k] = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
177
cmd/frostfs-adm/internal/modules/morph/helper/util.go
Normal file
177
cmd/frostfs-adm/internal/modules/morph/helper/util.go
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"compress/gzip"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, error) {
|
||||||
|
wallets, err := openAlphabetWallets(v, walletDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(wallets) > constants.MaxAlphabetNodes {
|
||||||
|
return nil, ErrTooManyAlphabetNodes
|
||||||
|
}
|
||||||
|
return wallets, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, error) {
|
||||||
|
walletFiles, err := os.ReadDir(walletDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't read alphabet wallets dir: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var size int
|
||||||
|
loop:
|
||||||
|
for i := 0; i < len(walletFiles); i++ {
|
||||||
|
name := innerring.GlagoliticLetter(i).String() + ".json"
|
||||||
|
for j := range walletFiles {
|
||||||
|
if walletFiles[j].Name() == name {
|
||||||
|
size++
|
||||||
|
continue loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if size == 0 {
|
||||||
|
return nil, errors.New("alphabet wallets dir is empty (run `generate-alphabet` command first)")
|
||||||
|
}
|
||||||
|
|
||||||
|
wallets := make([]*wallet.Wallet, size)
|
||||||
|
for i := 0; i < size; i++ {
|
||||||
|
letter := innerring.GlagoliticLetter(i).String()
|
||||||
|
p := filepath.Join(walletDir, letter+".json")
|
||||||
|
w, err := wallet.NewWalletFromFile(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't open wallet: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
password, err := config.GetPassword(v, letter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't fetch password: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range w.Accounts {
|
||||||
|
if err := w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil {
|
||||||
|
return nil, fmt.Errorf("can't unlock wallet: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wallets[i] = w
|
||||||
|
}
|
||||||
|
|
||||||
|
return wallets, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewActor(c actor.RPCActor, committeeAcc *wallet.Account) (*actor.Actor, error) {
|
||||||
|
return actor.New(c, []actor.SignerAccount{{
|
||||||
|
Signer: transaction.Signer{
|
||||||
|
Account: committeeAcc.Contract.ScriptHash(),
|
||||||
|
Scopes: transaction.Global,
|
||||||
|
},
|
||||||
|
Account: committeeAcc,
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadContract(ctrPath, ctrName string) (*ContractState, error) {
|
||||||
|
rawNef, err := os.ReadFile(filepath.Join(ctrPath, ctrName+"_contract.nef"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
|
||||||
|
}
|
||||||
|
rawManif, err := os.ReadFile(filepath.Join(ctrPath, "config.json"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't read manifest file for %s contract: %w", ctrName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cs := &ContractState{
|
||||||
|
RawNEF: rawNef,
|
||||||
|
RawManifest: rawManif,
|
||||||
|
}
|
||||||
|
|
||||||
|
return cs, cs.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
func readContractsFromArchive(file io.Reader, names []string) (map[string]*ContractState, error) {
|
||||||
|
m := make(map[string]*ContractState, len(names))
|
||||||
|
for i := range names {
|
||||||
|
m[names[i]] = new(ContractState)
|
||||||
|
}
|
||||||
|
|
||||||
|
gr, err := gzip.NewReader(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("contracts file must be tar.gz archive: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := tar.NewReader(gr)
|
||||||
|
for h, err := r.Next(); ; h, err = r.Next() {
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, _ := filepath.Split(h.Name)
|
||||||
|
ctrName := filepath.Base(dir)
|
||||||
|
|
||||||
|
cs, ok := m[ctrName]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case strings.HasSuffix(h.Name, filepath.Join(ctrName, ctrName+"_contract.nef")):
|
||||||
|
cs.RawNEF, err = io.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
|
||||||
|
}
|
||||||
|
case strings.HasSuffix(h.Name, "config.json"):
|
||||||
|
cs.RawManifest, err = io.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't read manifest file for %s contract: %w", ctrName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m[ctrName] = cs
|
||||||
|
}
|
||||||
|
|
||||||
|
for ctrName, cs := range m {
|
||||||
|
if cs.RawNEF == nil {
|
||||||
|
return nil, fmt.Errorf("NEF for %s contract wasn't found", ctrName)
|
||||||
|
}
|
||||||
|
if cs.RawManifest == nil {
|
||||||
|
return nil, fmt.Errorf("manifest for %s contract wasn't found", ctrName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAlphabetNNSDomain(i int) string {
|
||||||
|
return constants.AlphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseGASAmount(s string) (fixedn.Fixed8, error) {
|
||||||
|
gasAmount, err := fixedn.Fixed8FromString(s)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("invalid GAS amount %s: %w", s, err)
|
||||||
|
}
|
||||||
|
if gasAmount <= 0 {
|
||||||
|
return 0, fmt.Errorf("GAS amount must be positive (got %d)", gasAmount)
|
||||||
|
}
|
||||||
|
return gasAmount, nil
|
||||||
|
}
|
76
cmd/frostfs-adm/internal/modules/morph/helper/wallet.go
Normal file
76
cmd/frostfs-adm/internal/modules/morph/helper/wallet.go
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitializeContractWallet(v *viper.Viper, walletDir string) (*wallet.Wallet, error) {
|
||||||
|
password, err := config.GetPassword(v, constants.ContractWalletPasswordKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := wallet.NewWallet(filepath.Join(walletDir, constants.ContractWalletFilename))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
acc, err := wallet.NewAccount()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = acc.Encrypt(password, keys.NEP2ScryptParams())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
w.AddAccount(acc)
|
||||||
|
if err := w.SavePretty(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return w, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openContractWallet(v *viper.Viper, cmd *cobra.Command, walletDir string) (*wallet.Wallet, error) {
|
||||||
|
p := filepath.Join(walletDir, constants.ContractWalletFilename)
|
||||||
|
w, err := wallet.NewWalletFromFile(p)
|
||||||
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
return nil, fmt.Errorf("can't open wallet: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Contract group wallet is missing, initialize at %s\n", p)
|
||||||
|
return InitializeContractWallet(v, walletDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
password, err := config.GetPassword(v, constants.ContractWalletPasswordKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range w.Accounts {
|
||||||
|
if err := w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil {
|
||||||
|
return nil, fmt.Errorf("can't unlock wallet: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return w, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getWallet(cmd *cobra.Command, v *viper.Viper, needContracts bool, walletDir string) (*wallet.Wallet, error) {
|
||||||
|
if !needContracts {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return openContractWallet(v, cmd, walletDir)
|
||||||
|
}
|
|
@ -1,465 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
|
||||||
morphClient "github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
type cache struct {
|
|
||||||
nnsCs *state.Contract
|
|
||||||
groupKey *keys.PublicKey
|
|
||||||
}
|
|
||||||
|
|
||||||
type initializeContext struct {
|
|
||||||
clientContext
|
|
||||||
cache
|
|
||||||
// CommitteeAcc is used for retrieving the committee address and the verification script.
|
|
||||||
CommitteeAcc *wallet.Account
|
|
||||||
// ConsensusAcc is used for retrieving the committee address and the verification script.
|
|
||||||
ConsensusAcc *wallet.Account
|
|
||||||
Wallets []*wallet.Wallet
|
|
||||||
// ContractWallet is a wallet for providing the contract group signature.
|
|
||||||
ContractWallet *wallet.Wallet
|
|
||||||
// Accounts contains simple signature accounts in the same order as in Wallets.
|
|
||||||
Accounts []*wallet.Account
|
|
||||||
Contracts map[string]*contractState
|
|
||||||
Command *cobra.Command
|
|
||||||
ContractPath string
|
|
||||||
}
|
|
||||||
|
|
||||||
func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
|
||||||
initCtx, err := newInitializeContext(cmd, viper.GetViper())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("initialization error: %w", err)
|
|
||||||
}
|
|
||||||
defer initCtx.close()
|
|
||||||
|
|
||||||
// 1. Transfer funds to committee accounts.
|
|
||||||
cmd.Println("Stage 1: transfer GAS to alphabet nodes.")
|
|
||||||
if err := initCtx.transferFunds(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Println("Stage 2: set notary and alphabet nodes in designate contract.")
|
|
||||||
if err := initCtx.setNotaryAndAlphabetNodes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Deploy NNS contract.
|
|
||||||
cmd.Println("Stage 3: deploy NNS contract.")
|
|
||||||
if err := initCtx.deployNNS(deployMethodName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Deploy NeoFS contracts.
|
|
||||||
cmd.Println("Stage 4: deploy NeoFS contracts.")
|
|
||||||
if err := initCtx.deployContracts(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Println("Stage 4.1: Transfer GAS to proxy contract.")
|
|
||||||
if err := initCtx.transferGASToProxy(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Println("Stage 5: register candidates.")
|
|
||||||
if err := initCtx.registerCandidates(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Println("Stage 6: transfer NEO to alphabet contracts.")
|
|
||||||
if err := initCtx.transferNEOToAlphabetContracts(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Println("Stage 7: set addresses in NNS.")
|
|
||||||
if err := initCtx.setNNS(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) close() {
|
|
||||||
if local, ok := c.Client.(*localClient); ok {
|
|
||||||
err := local.dump()
|
|
||||||
if err != nil {
|
|
||||||
c.Command.PrintErrf("Can't write dump: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContext, error) {
|
|
||||||
walletDir := config.ResolveHomePath(viper.GetString(alphabetWalletsFlag))
|
|
||||||
wallets, err := openAlphabetWallets(v, walletDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
needContracts := cmd.Name() == "update-contracts" || cmd.Name() == "init"
|
|
||||||
|
|
||||||
var w *wallet.Wallet
|
|
||||||
if needContracts {
|
|
||||||
w, err = openContractWallet(v, cmd, walletDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var c Client
|
|
||||||
if v.GetString(localDumpFlag) != "" {
|
|
||||||
if v.GetString(endpointFlag) != "" {
|
|
||||||
return nil, fmt.Errorf("`%s` and `%s` flags are mutually exclusive", endpointFlag, localDumpFlag)
|
|
||||||
}
|
|
||||||
c, err = newLocalClient(cmd, v, wallets)
|
|
||||||
} else {
|
|
||||||
c, err = getN3Client(v)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't create N3 client: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
committeeAcc, err := getWalletAccount(wallets[0], committeeAccountName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't find committee account: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
consensusAcc, err := getWalletAccount(wallets[0], consensusAccountName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't find consensus account: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ctrPath string
|
|
||||||
if cmd.Name() == "init" {
|
|
||||||
if viper.GetInt64(epochDurationInitFlag) <= 0 {
|
|
||||||
return nil, fmt.Errorf("epoch duration must be positive")
|
|
||||||
}
|
|
||||||
|
|
||||||
if viper.GetInt64(maxObjectSizeInitFlag) <= 0 {
|
|
||||||
return nil, fmt.Errorf("max object size must be positive")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if needContracts {
|
|
||||||
ctrPath, err = cmd.Flags().GetString(contractsInitFlag)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid contracts path: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := checkNotaryEnabled(c); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
accounts := make([]*wallet.Account, len(wallets))
|
|
||||||
for i, w := range wallets {
|
|
||||||
acc, err := getWalletAccount(w, singleAccountName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("wallet %s is invalid (no single account): %w", w.Path(), err)
|
|
||||||
}
|
|
||||||
accounts[i] = acc
|
|
||||||
}
|
|
||||||
|
|
||||||
cliCtx, err := defaultClientContext(c, committeeAcc)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("client context: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
initCtx := &initializeContext{
|
|
||||||
clientContext: *cliCtx,
|
|
||||||
ConsensusAcc: consensusAcc,
|
|
||||||
CommitteeAcc: committeeAcc,
|
|
||||||
ContractWallet: w,
|
|
||||||
Wallets: wallets,
|
|
||||||
Accounts: accounts,
|
|
||||||
Command: cmd,
|
|
||||||
Contracts: make(map[string]*contractState),
|
|
||||||
ContractPath: ctrPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
if needContracts {
|
|
||||||
err := initCtx.readContracts(fullContractList)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return initCtx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func openAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, error) {
|
|
||||||
walletFiles, err := os.ReadDir(walletDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't read alphabet wallets dir: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var size int
|
|
||||||
loop:
|
|
||||||
for i := 0; i < len(walletFiles); i++ {
|
|
||||||
name := innerring.GlagoliticLetter(i).String() + ".json"
|
|
||||||
for j := range walletFiles {
|
|
||||||
if walletFiles[j].Name() == name {
|
|
||||||
size++
|
|
||||||
continue loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if size == 0 {
|
|
||||||
return nil, errors.New("alphabet wallets dir is empty (run `generate-alphabet` command first)")
|
|
||||||
}
|
|
||||||
|
|
||||||
wallets := make([]*wallet.Wallet, size)
|
|
||||||
for i := 0; i < size; i++ {
|
|
||||||
letter := innerring.GlagoliticLetter(i).String()
|
|
||||||
p := filepath.Join(walletDir, letter+".json")
|
|
||||||
w, err := wallet.NewWalletFromFile(p)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't open wallet: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
password, err := config.GetPassword(v, letter)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't fetch password: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range w.Accounts {
|
|
||||||
if err := w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil {
|
|
||||||
return nil, fmt.Errorf("can't unlock wallet: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wallets[i] = w
|
|
||||||
}
|
|
||||||
|
|
||||||
return wallets, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) awaitTx() error {
|
|
||||||
return c.clientContext.awaitTx(c.Command)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) nnsContractState() (*state.Contract, error) {
|
|
||||||
if c.nnsCs != nil {
|
|
||||||
return c.nnsCs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cs, err := c.Client.GetContractStateByID(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.nnsCs = cs
|
|
||||||
return cs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) getSigner(tryGroup bool, acc *wallet.Account) transaction.Signer {
|
|
||||||
if tryGroup && c.groupKey != nil {
|
|
||||||
return transaction.Signer{
|
|
||||||
Account: acc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CustomGroups,
|
|
||||||
AllowedGroups: keys.PublicKeys{c.groupKey},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signer := transaction.Signer{
|
|
||||||
Account: acc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.Global, // Scope is important, as we have nested call to container contract.
|
|
||||||
}
|
|
||||||
|
|
||||||
if !tryGroup {
|
|
||||||
return signer
|
|
||||||
}
|
|
||||||
|
|
||||||
nnsCs, err := c.nnsContractState()
|
|
||||||
if err != nil {
|
|
||||||
return signer
|
|
||||||
}
|
|
||||||
|
|
||||||
groupKey, err := nnsResolveKey(c.ReadOnlyInvoker, nnsCs.Hash, morphClient.NNSGroupKeyName)
|
|
||||||
if err == nil {
|
|
||||||
c.groupKey = groupKey
|
|
||||||
|
|
||||||
signer.Scopes = transaction.CustomGroups
|
|
||||||
signer.AllowedGroups = keys.PublicKeys{groupKey}
|
|
||||||
}
|
|
||||||
return signer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *clientContext) awaitTx(cmd *cobra.Command) error {
|
|
||||||
if len(c.SentTxs) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if local, ok := c.Client.(*localClient); ok {
|
|
||||||
if err := local.putTransactions(); err != nil {
|
|
||||||
return fmt.Errorf("can't persist transactions: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err := awaitTx(cmd, c.Client, c.SentTxs)
|
|
||||||
c.SentTxs = c.SentTxs[:0]
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func awaitTx(cmd *cobra.Command, c Client, txs []hashVUBPair) error {
|
|
||||||
cmd.Println("Waiting for transactions to persist...")
|
|
||||||
|
|
||||||
const pollInterval = time.Second
|
|
||||||
|
|
||||||
tick := time.NewTicker(pollInterval)
|
|
||||||
defer tick.Stop()
|
|
||||||
|
|
||||||
at := trigger.Application
|
|
||||||
|
|
||||||
var retErr error
|
|
||||||
|
|
||||||
currBlock, err := c.GetBlockCount()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch current block height: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
loop:
|
|
||||||
for i := range txs {
|
|
||||||
res, err := c.GetApplicationLog(txs[i].hash, &at)
|
|
||||||
if err == nil {
|
|
||||||
if retErr == nil && len(res.Executions) > 0 && res.Executions[0].VMState != vmstate.Halt {
|
|
||||||
retErr = fmt.Errorf("tx %d persisted in %s state: %s",
|
|
||||||
i, res.Executions[0].VMState, res.Executions[0].FaultException)
|
|
||||||
}
|
|
||||||
continue loop
|
|
||||||
}
|
|
||||||
if txs[i].vub < currBlock {
|
|
||||||
return fmt.Errorf("tx was not persisted: vub=%d, height=%d", txs[i].vub, currBlock)
|
|
||||||
}
|
|
||||||
for range tick.C {
|
|
||||||
// We must fetch current height before application log, to avoid race condition.
|
|
||||||
currBlock, err = c.GetBlockCount()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch current block height: %w", err)
|
|
||||||
}
|
|
||||||
res, err := c.GetApplicationLog(txs[i].hash, &at)
|
|
||||||
if err == nil {
|
|
||||||
if retErr == nil && len(res.Executions) > 0 && res.Executions[0].VMState != vmstate.Halt {
|
|
||||||
retErr = fmt.Errorf("tx %d persisted in %s state: %s",
|
|
||||||
i, res.Executions[0].VMState, res.Executions[0].FaultException)
|
|
||||||
}
|
|
||||||
continue loop
|
|
||||||
}
|
|
||||||
if txs[i].vub < currBlock {
|
|
||||||
return fmt.Errorf("tx was not persisted: vub=%d, height=%d", txs[i].vub, currBlock)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendCommitteeTx creates transaction from script, signs it by committee nodes and sends it to RPC.
|
|
||||||
// If tryGroup is false, global scope is used for the signer (useful when
|
|
||||||
// working with native contracts).
|
|
||||||
func (c *initializeContext) sendCommitteeTx(script []byte, tryGroup bool) error {
|
|
||||||
return c.sendMultiTx(script, tryGroup, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendConsensusTx creates transaction from script, signs it by alphabet nodes and sends it to RPC.
|
|
||||||
// Not that because this is used only after the contracts were initialized and deployed,
|
|
||||||
// we always try to have a group scope.
|
|
||||||
func (c *initializeContext) sendConsensusTx(script []byte) error {
|
|
||||||
return c.sendMultiTx(script, true, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) sendMultiTx(script []byte, tryGroup bool, withConsensus bool) error {
|
|
||||||
var act *actor.Actor
|
|
||||||
var err error
|
|
||||||
|
|
||||||
withConsensus = withConsensus && !c.ConsensusAcc.Contract.ScriptHash().Equals(c.CommitteeAcc.ScriptHash())
|
|
||||||
if tryGroup {
|
|
||||||
// Even for consensus signatures we need the committee to pay.
|
|
||||||
signers := make([]actor.SignerAccount, 1, 2)
|
|
||||||
signers[0] = actor.SignerAccount{
|
|
||||||
Signer: c.getSigner(tryGroup, c.CommitteeAcc),
|
|
||||||
Account: c.CommitteeAcc,
|
|
||||||
}
|
|
||||||
if withConsensus {
|
|
||||||
signers = append(signers, actor.SignerAccount{
|
|
||||||
Signer: c.getSigner(tryGroup, c.ConsensusAcc),
|
|
||||||
Account: c.ConsensusAcc,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
act, err = actor.New(c.Client, signers)
|
|
||||||
} else {
|
|
||||||
if withConsensus {
|
|
||||||
panic("BUG: should never happen")
|
|
||||||
}
|
|
||||||
act, err = c.CommitteeAct, nil
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not create actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := act.MakeUnsignedRun(script, []transaction.Attribute{{Type: transaction.HighPriority}})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not perform test invocation: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.multiSign(tx, committeeAccountName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if withConsensus {
|
|
||||||
if err := c.multiSign(tx, consensusAccountName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.sendTx(tx, c.Command, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) {
|
|
||||||
for i := range w.Accounts {
|
|
||||||
if w.Accounts[i].Label == typ {
|
|
||||||
return w.Accounts[i], nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("account for '%s' not found", typ)
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkNotaryEnabled(c Client) error {
|
|
||||||
ns, err := c.GetNativeContracts()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't get native contract hashes: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
notaryEnabled := false
|
|
||||||
nativeHashes := make(map[string]util.Uint160, len(ns))
|
|
||||||
for i := range ns {
|
|
||||||
if ns[i].Manifest.Name == nativenames.Notary {
|
|
||||||
notaryEnabled = len(ns[i].UpdateHistory) > 0
|
|
||||||
}
|
|
||||||
nativeHashes[ns[i].Manifest.Name] = ns[i].Hash
|
|
||||||
}
|
|
||||||
if !notaryEnabled {
|
|
||||||
return errors.New("notary contract must be enabled")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initializeSideChainCmd(cmd *cobra.Command, _ []string) error {
|
||||||
|
initCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("initialization error: %w", err)
|
||||||
|
}
|
||||||
|
defer initCtx.Close()
|
||||||
|
|
||||||
|
// 1. Transfer funds to committee accounts.
|
||||||
|
cmd.Println("Stage 1: transfer GAS to alphabet nodes.")
|
||||||
|
if err := transferFunds(initCtx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Println("Stage 2: set notary and alphabet nodes in designate contract.")
|
||||||
|
if err := setNotaryAndAlphabetNodes(initCtx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Deploy NNS contract.
|
||||||
|
cmd.Println("Stage 3: deploy NNS contract.")
|
||||||
|
if err := helper.DeployNNS(initCtx, constants.DeployMethodName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Deploy NeoFS contracts.
|
||||||
|
cmd.Println("Stage 4: deploy NeoFS contracts.")
|
||||||
|
if err := deployContracts(initCtx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Println("Stage 4.1: Transfer GAS to proxy contract.")
|
||||||
|
if err := transferGASToProxy(initCtx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Println("Stage 5: register candidates.")
|
||||||
|
if err := registerCandidates(initCtx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Println("Stage 6: transfer NEO to alphabet contracts.")
|
||||||
|
if err := transferNEOToAlphabetContracts(initCtx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Println("Stage 7: set addresses in NNS.")
|
||||||
|
return setNNS(initCtx)
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
)
|
||||||
|
|
||||||
|
func deployContracts(c *helper.InitializeContext) error {
|
||||||
|
alphaCs := c.GetContract(constants.AlphabetContract)
|
||||||
|
|
||||||
|
var keysParam []any
|
||||||
|
|
||||||
|
baseGroups := alphaCs.Manifest.Groups
|
||||||
|
|
||||||
|
// alphabet contracts should be deployed by individual nodes to get different hashes.
|
||||||
|
for i, acc := range c.Accounts {
|
||||||
|
ctrHash := state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
||||||
|
if c.IsUpdated(ctrHash, alphaCs) {
|
||||||
|
c.Command.Printf("Alphabet contract #%d is already deployed.\n", i)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
alphaCs.Manifest.Groups = baseGroups
|
||||||
|
err := helper.AddManifestGroup(c.ContractWallet, ctrHash, alphaCs)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't sign manifest group: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
params := helper.GetContractDeployParameters(alphaCs, c.GetAlphabetDeployItems(i, len(c.Wallets)))
|
||||||
|
|
||||||
|
act, err := actor.NewSimple(c.Client, acc)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create actor: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
txHash, vub, err := act.SendCall(management.Hash, constants.DeployMethodName, params...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.SentTxs = append(c.SentTxs, helper.HashVUBPair{Hash: txHash, Vub: vub})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ctrName := range constants.ContractList {
|
||||||
|
cs := c.GetContract(ctrName)
|
||||||
|
|
||||||
|
ctrHash := cs.Hash
|
||||||
|
if c.IsUpdated(ctrHash, cs) {
|
||||||
|
c.Command.Printf("%s contract is already deployed.\n", ctrName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err := helper.AddManifestGroup(c.ContractWallet, ctrHash, cs)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't sign manifest group: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
args, err := helper.GetContractDeployData(c, ctrName, keysParam, constants.DeployMethodName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s: getting deploy params: %v", ctrName, err)
|
||||||
|
}
|
||||||
|
params := helper.GetContractDeployParameters(cs, args)
|
||||||
|
res, err := c.CommitteeAct.MakeCall(management.Hash, constants.DeployMethodName, params...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't deploy %s contract: %w", ctrName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.SendCommitteeTx(res.Script, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setNNS(c *helper.InitializeContext) error {
|
||||||
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := c.NNSRootRegistered(nnsCs.Hash, "frostfs")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !ok {
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
||||||
|
"frostfs", c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
if err := c.SendCommitteeTx(bw.Bytes(), true); err != nil {
|
||||||
|
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
||||||
|
}
|
||||||
|
if err := c.AwaitTx(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
alphaCs := c.GetContract(constants.AlphabetContract)
|
||||||
|
for i, acc := range c.Accounts {
|
||||||
|
alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
||||||
|
|
||||||
|
domain := helper.GetAlphabetNNSDomain(i)
|
||||||
|
if err := nnsRegisterDomain(c, nnsCs.Hash, alphaCs.Hash, domain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Command.Printf("NNS: Set %s -> %s\n", domain, alphaCs.Hash.StringLE())
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ctrName := range constants.ContractList {
|
||||||
|
cs := c.GetContract(ctrName)
|
||||||
|
|
||||||
|
domain := ctrName + ".frostfs"
|
||||||
|
if err := nnsRegisterDomain(c, nnsCs.Hash, cs.Hash, domain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
||||||
|
}
|
||||||
|
|
||||||
|
groupKey := c.ContractWallet.Accounts[0].PrivateKey().PublicKey()
|
||||||
|
err = updateNNSGroup(c, nnsCs.Hash, groupKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Command.Printf("NNS: Set %s -> %s\n", morphClient.NNSGroupKeyName, hex.EncodeToString(groupKey.Bytes()))
|
||||||
|
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNNSGroup(c *helper.InitializeContext, nnsHash util.Uint160, pub *keys.PublicKey) error {
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
keyAlreadyAdded, domainRegCodeEmitted, err := c.EmitUpdateNNSGroupScript(bw, nnsHash, pub)
|
||||||
|
if keyAlreadyAdded || err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
script := bw.Bytes()
|
||||||
|
if domainRegCodeEmitted {
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
||||||
|
wrapRegisterScriptWithPrice(w, nnsHash, script)
|
||||||
|
script = w.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendCommitteeTx(script, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS.
|
||||||
|
// It is intended to be used for a single transaction, and not as a part of other scripts.
|
||||||
|
// It is assumed that script already contains static slot initialization code, the first one
|
||||||
|
// (with index 0) is used to store the price.
|
||||||
|
func wrapRegisterScriptWithPrice(w *io.BufBinWriter, nnsHash util.Uint160, s []byte) {
|
||||||
|
if len(s) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "getPrice", callflag.All)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "setPrice", callflag.All, 1)
|
||||||
|
|
||||||
|
w.WriteBytes(s)
|
||||||
|
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK)
|
||||||
|
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)
|
||||||
|
|
||||||
|
if w.Err != nil {
|
||||||
|
panic(fmt.Errorf("BUG: can't wrap register script: %w", w.Err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func nnsRegisterDomain(c *helper.InitializeContext, nnsHash, expectedHash util.Uint160, domain string) error {
|
||||||
|
script, ok, err := c.NNSRegisterDomainScript(nnsHash, expectedHash, domain)
|
||||||
|
if ok || err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
||||||
|
wrapRegisterScriptWithPrice(w, nnsHash, script)
|
||||||
|
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||||
|
domain, int64(nns.TXT), expectedHash.StringLE())
|
||||||
|
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||||
|
domain, int64(nns.TXT), address.Uint160ToString(expectedHash))
|
||||||
|
return c.SendCommitteeTx(w.Bytes(), true)
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/neo"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
||||||
|
"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/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// initialAlphabetNEOAmount represents the total amount of GAS distributed between alphabet nodes.
|
||||||
|
const (
|
||||||
|
initialAlphabetNEOAmount = native.NEOTotalSupply
|
||||||
|
registerBatchSize = transaction.MaxAttributes - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
func registerCandidateRange(c *helper.InitializeContext, start, end int) error {
|
||||||
|
regPrice, err := getCandidateRegisterPrice(c)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't fetch registration price: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
emit.AppCall(w.BinWriter, neo.Hash, "setRegisterPrice", callflag.States, 1)
|
||||||
|
for _, acc := range c.Accounts[start:end] {
|
||||||
|
emit.AppCall(w.BinWriter, neo.Hash, "registerCandidate", callflag.States, acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
||||||
|
}
|
||||||
|
emit.AppCall(w.BinWriter, neo.Hash, "setRegisterPrice", callflag.States, regPrice)
|
||||||
|
if w.Err != nil {
|
||||||
|
panic(fmt.Sprintf("BUG: %v", w.Err))
|
||||||
|
}
|
||||||
|
|
||||||
|
signers := []actor.SignerAccount{{
|
||||||
|
Signer: c.GetSigner(false, c.CommitteeAcc),
|
||||||
|
Account: c.CommitteeAcc,
|
||||||
|
}}
|
||||||
|
for _, acc := range c.Accounts[start:end] {
|
||||||
|
signers = append(signers, actor.SignerAccount{
|
||||||
|
Signer: transaction.Signer{
|
||||||
|
Account: acc.Contract.ScriptHash(),
|
||||||
|
Scopes: transaction.CustomContracts,
|
||||||
|
AllowedContracts: []util.Uint160{neo.Hash},
|
||||||
|
},
|
||||||
|
Account: acc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
act, err := actor.New(c.Client, signers)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't create actor: %w", err)
|
||||||
|
}
|
||||||
|
tx, err := act.MakeRun(w.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't create tx: %w", err)
|
||||||
|
}
|
||||||
|
if err := c.MultiSign(tx, constants.CommitteeAccountName); err != nil {
|
||||||
|
return fmt.Errorf("can't sign a transaction: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
network := c.CommitteeAct.GetNetwork()
|
||||||
|
for _, acc := range c.Accounts[start:end] {
|
||||||
|
if err := acc.SignTx(network, tx); err != nil {
|
||||||
|
return fmt.Errorf("can't sign a transaction: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendTx(tx, c.Command, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerCandidates(c *helper.InitializeContext) error {
|
||||||
|
cc, err := unwrap.Array(c.ReadOnlyInvoker.Call(neo.Hash, "getCandidates"))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("`getCandidates`: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
need := len(c.Accounts)
|
||||||
|
have := len(cc)
|
||||||
|
|
||||||
|
if need == have {
|
||||||
|
c.Command.Println("Candidates are already registered.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register candidates in batches in order to overcome the signers amount limit.
|
||||||
|
// See: https://github.com/nspcc-dev/neo-go/blob/master/pkg/core/transaction/transaction.go#L27
|
||||||
|
for i := 0; i < need; i += registerBatchSize {
|
||||||
|
start, end := i, i+registerBatchSize
|
||||||
|
if end > need {
|
||||||
|
end = need
|
||||||
|
}
|
||||||
|
// This check is sound because transactions are accepted/rejected atomically.
|
||||||
|
if have >= end {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := registerCandidateRange(c, start, end); err != nil {
|
||||||
|
return fmt.Errorf("registering candidates %d..%d: %q", start, end-1, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func transferNEOToAlphabetContracts(c *helper.InitializeContext) error {
|
||||||
|
neoHash := neo.Hash
|
||||||
|
|
||||||
|
ok, err := transferNEOFinished(c, neoHash)
|
||||||
|
if ok || err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cs := c.GetContract(constants.AlphabetContract)
|
||||||
|
amount := initialAlphabetNEOAmount / len(c.Wallets)
|
||||||
|
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
for _, acc := range c.Accounts {
|
||||||
|
h := state.CreateContractHash(acc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
||||||
|
emit.AppCall(bw.BinWriter, neoHash, "transfer", callflag.All,
|
||||||
|
c.CommitteeAcc.Contract.ScriptHash(), h, int64(amount), nil)
|
||||||
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.SendCommitteeTx(bw.Bytes(), false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func transferNEOFinished(c *helper.InitializeContext, neoHash util.Uint160) (bool, error) {
|
||||||
|
r := nep17.NewReader(c.ReadOnlyInvoker, neoHash)
|
||||||
|
bal, err := r.BalanceOf(c.CommitteeAcc.Contract.ScriptHash())
|
||||||
|
return bal.Cmp(big.NewInt(native.NEOTotalSupply)) == -1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var errGetPriceInvalid = errors.New("`getRegisterPrice`: invalid response")
|
||||||
|
|
||||||
|
func getCandidateRegisterPrice(c *helper.InitializeContext) (int64, error) {
|
||||||
|
switch c.Client.(type) {
|
||||||
|
case *rpcclient.Client:
|
||||||
|
inv := invoker.New(c.Client, nil)
|
||||||
|
reader := neo.NewReader(inv)
|
||||||
|
return reader.GetRegisterPrice()
|
||||||
|
default:
|
||||||
|
neoHash := neo.Hash
|
||||||
|
res, err := helper.InvokeFunction(c.Client, neoHash, "getRegisterPrice", nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if len(res.Stack) == 0 {
|
||||||
|
return 0, errGetPriceInvalid
|
||||||
|
}
|
||||||
|
bi, err := res.Stack[0].TryInteger()
|
||||||
|
if err != nil || !bi.IsInt64() {
|
||||||
|
return 0, errGetPriceInvalid
|
||||||
|
}
|
||||||
|
return bi.Int64(), nil
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package morph
|
package initialize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt"
|
||||||
|
@ -8,8 +9,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
func setNotaryAndAlphabetNodes(c *helper.InitializeContext) error {
|
||||||
if ok, err := c.setRolesFinished(); ok || err != nil {
|
if ok, err := setRolesFinished(c); ok || err != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Command.Println("Stage 2: already performed.")
|
c.Command.Println("Stage 2: already performed.")
|
||||||
}
|
}
|
||||||
|
@ -27,19 +28,19 @@ func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
||||||
emit.AppCall(w.BinWriter, rolemgmt.Hash, "designateAsRole",
|
emit.AppCall(w.BinWriter, rolemgmt.Hash, "designateAsRole",
|
||||||
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
if err := c.SendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.awaitTx()
|
return c.AwaitTx()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) setRolesFinished() (bool, error) {
|
func setRolesFinished(c *helper.InitializeContext) (bool, error) {
|
||||||
height, err := c.Client.GetBlockCount()
|
height, err := c.Client.GetBlockCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pubs, err := getDesignatedByRole(c.ReadOnlyInvoker, rolemgmt.Hash, noderoles.NeoFSAlphabet, height)
|
pubs, err := helper.GetDesignatedByRole(c.ReadOnlyInvoker, rolemgmt.Hash, noderoles.NeoFSAlphabet, height)
|
||||||
return len(pubs) == len(c.Wallets), err
|
return len(pubs) == len(c.Wallets), err
|
||||||
}
|
}
|
|
@ -0,0 +1,155 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
cmdConfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/generate"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/netmap"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/node"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
|
"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/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
contractsPath = "../../../../../../contract/frostfs-contract-v0.18.0.tar.gz"
|
||||||
|
protoFileName = "proto.yml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitialize(t *testing.T) {
|
||||||
|
// This test needs frostfs-contract tarball, so it is skipped by default.
|
||||||
|
// It is here for performing local testing after the changes.
|
||||||
|
t.Skip()
|
||||||
|
|
||||||
|
t.Run("1 nodes", func(t *testing.T) {
|
||||||
|
testInitialize(t, 1)
|
||||||
|
})
|
||||||
|
t.Run("4 nodes", func(t *testing.T) {
|
||||||
|
testInitialize(t, 4)
|
||||||
|
})
|
||||||
|
t.Run("7 nodes", func(t *testing.T) {
|
||||||
|
testInitialize(t, 7)
|
||||||
|
})
|
||||||
|
t.Run("16 nodes", func(t *testing.T) {
|
||||||
|
testInitialize(t, 16)
|
||||||
|
})
|
||||||
|
t.Run("max nodes", func(t *testing.T) {
|
||||||
|
testInitialize(t, constants.MaxAlphabetNodes)
|
||||||
|
})
|
||||||
|
t.Run("too many nodes", func(t *testing.T) {
|
||||||
|
require.ErrorIs(t, generateTestData(t, t.TempDir(), constants.MaxAlphabetNodes+1), helper.ErrTooManyAlphabetNodes)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInitialize(t *testing.T, committeeSize int) {
|
||||||
|
testdataDir := t.TempDir()
|
||||||
|
v := viper.GetViper()
|
||||||
|
|
||||||
|
require.NoError(t, generateTestData(t, testdataDir, committeeSize))
|
||||||
|
v.Set(constants.ProtoConfigPath, filepath.Join(testdataDir, protoFileName))
|
||||||
|
|
||||||
|
// Set to the path or remove the next statement to download from the network.
|
||||||
|
require.NoError(t, Cmd.Flags().Set(commonflags.ContractsInitFlag, contractsPath))
|
||||||
|
|
||||||
|
dumpPath := filepath.Join(testdataDir, "out")
|
||||||
|
require.NoError(t, Cmd.Flags().Set(commonflags.LocalDumpFlag, dumpPath))
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, testdataDir)
|
||||||
|
v.Set(commonflags.EpochDurationInitFlag, 1)
|
||||||
|
v.Set(commonflags.MaxObjectSizeInitFlag, 1024)
|
||||||
|
|
||||||
|
setTestCredentials(v, committeeSize)
|
||||||
|
require.NoError(t, initializeSideChainCmd(Cmd, nil))
|
||||||
|
|
||||||
|
t.Run("force-new-epoch", func(t *testing.T) {
|
||||||
|
require.NoError(t, netmap.ForceNewEpoch.Flags().Set(commonflags.LocalDumpFlag, dumpPath))
|
||||||
|
require.NoError(t, netmap.ForceNewEpochCmd(netmap.ForceNewEpoch, nil))
|
||||||
|
})
|
||||||
|
t.Run("set-config", func(t *testing.T) {
|
||||||
|
require.NoError(t, cmdConfig.SetCmd.Flags().Set(commonflags.LocalDumpFlag, dumpPath))
|
||||||
|
require.NoError(t, cmdConfig.SetConfigCmd(cmdConfig.SetCmd, []string{"MaintenanceModeAllowed=true"}))
|
||||||
|
})
|
||||||
|
t.Run("set-policy", func(t *testing.T) {
|
||||||
|
require.NoError(t, policy.Set.Flags().Set(commonflags.LocalDumpFlag, dumpPath))
|
||||||
|
require.NoError(t, policy.SetPolicyCmd(policy.Set, []string{"ExecFeeFactor=1"}))
|
||||||
|
})
|
||||||
|
t.Run("remove-node", func(t *testing.T) {
|
||||||
|
pk, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pub := hex.EncodeToString(pk.PublicKey().Bytes())
|
||||||
|
require.NoError(t, node.RemoveCmd.Flags().Set(commonflags.LocalDumpFlag, dumpPath))
|
||||||
|
require.NoError(t, node.RemoveNodesCmd(node.RemoveCmd, []string{pub}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateTestData(t *testing.T, dir string, size int) error {
|
||||||
|
v := viper.GetViper()
|
||||||
|
v.Set(commonflags.AlphabetWalletsFlag, dir)
|
||||||
|
|
||||||
|
sizeStr := strconv.FormatUint(uint64(size), 10)
|
||||||
|
if err := generate.GenerateAlphabetCmd.Flags().Set(commonflags.AlphabetSizeFlag, sizeStr); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
setTestCredentials(v, size)
|
||||||
|
if err := generate.AlphabetCreds(generate.GenerateAlphabetCmd, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pubs []string
|
||||||
|
for i := 0; i < size; i++ {
|
||||||
|
p := filepath.Join(dir, innerring.GlagoliticLetter(i).String()+".json")
|
||||||
|
w, err := wallet.NewWalletFromFile(p)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("wallet doesn't exist: %w", err)
|
||||||
|
}
|
||||||
|
for _, acc := range w.Accounts {
|
||||||
|
if acc.Label == constants.SingleAccountName {
|
||||||
|
pub, ok := vm.ParseSignatureContract(acc.Contract.Script)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("could not parse signature script for %s", acc.Address)
|
||||||
|
}
|
||||||
|
pubs = append(pubs, hex.EncodeToString(pub))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := config.Config{}
|
||||||
|
cfg.ProtocolConfiguration.Magic = 12345
|
||||||
|
cfg.ProtocolConfiguration.ValidatorsCount = uint32(size)
|
||||||
|
cfg.ProtocolConfiguration.TimePerBlock = time.Second
|
||||||
|
cfg.ProtocolConfiguration.StandbyCommittee = pubs // sorted by glagolic letters
|
||||||
|
cfg.ProtocolConfiguration.P2PSigExtensions = true
|
||||||
|
cfg.ProtocolConfiguration.VerifyTransactions = true
|
||||||
|
data, err := yaml.Marshal(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
protoPath := filepath.Join(dir, protoFileName)
|
||||||
|
return os.WriteFile(protoPath, data, os.ModePerm)
|
||||||
|
}
|
||||||
|
|
||||||
|
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.contract", constants.TestContractPassword)
|
||||||
|
}
|
|
@ -0,0 +1,144 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/neo"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
gasInitialTotalSupply = 30000000 * native.GASFactor
|
||||||
|
// initialAlphabetGASAmount represents the amount of GAS given to each alphabet node.
|
||||||
|
initialAlphabetGASAmount = 10_000 * native.GASFactor
|
||||||
|
// initialProxyGASAmount represents the amount of GAS given to a proxy contract.
|
||||||
|
initialProxyGASAmount = 50_000 * native.GASFactor
|
||||||
|
)
|
||||||
|
|
||||||
|
func transferFunds(c *helper.InitializeContext) error {
|
||||||
|
ok, err := transferFundsFinished(c)
|
||||||
|
if ok || err != nil {
|
||||||
|
if err == nil {
|
||||||
|
c.Command.Println("Stage 1: already performed.")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var transfers []transferTarget
|
||||||
|
for _, acc := range c.Accounts {
|
||||||
|
to := acc.Contract.ScriptHash()
|
||||||
|
transfers = append(transfers,
|
||||||
|
transferTarget{
|
||||||
|
Token: gas.Hash,
|
||||||
|
Address: to,
|
||||||
|
Amount: initialAlphabetGASAmount,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// It is convenient to have all funds at the committee account.
|
||||||
|
transfers = append(transfers,
|
||||||
|
transferTarget{
|
||||||
|
Token: gas.Hash,
|
||||||
|
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
Amount: (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2,
|
||||||
|
},
|
||||||
|
transferTarget{
|
||||||
|
Token: neo.Hash,
|
||||||
|
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
|
Amount: native.NEOTotalSupply,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
tx, err := createNEP17MultiTransferTx(c.Client, c.ConsensusAcc, transfers)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't create transfer transaction: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.MultiSignAndSend(tx, constants.ConsensusAccountName); err != nil {
|
||||||
|
return fmt.Errorf("can't send transfer transaction: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func transferFundsFinished(c *helper.InitializeContext) (bool, error) {
|
||||||
|
acc := c.Accounts[0]
|
||||||
|
|
||||||
|
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
||||||
|
res, err := r.BalanceOf(acc.Contract.ScriptHash())
|
||||||
|
return res.Cmp(big.NewInt(initialAlphabetGASAmount/2)) == 1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func transferGASToProxy(c *helper.InitializeContext) error {
|
||||||
|
proxyCs := c.GetContract(constants.ProxyContract)
|
||||||
|
|
||||||
|
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
||||||
|
bal, err := r.BalanceOf(proxyCs.Hash)
|
||||||
|
if err != nil || bal.Sign() > 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tx, err := createNEP17MultiTransferTx(c.Client, c.CommitteeAcc, []transferTarget{{
|
||||||
|
Token: gas.Hash,
|
||||||
|
Address: proxyCs.Hash,
|
||||||
|
Amount: initialProxyGASAmount,
|
||||||
|
}})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.MultiSignAndSend(tx, constants.CommitteeAccountName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
type transferTarget struct {
|
||||||
|
Token util.Uint160
|
||||||
|
Address util.Uint160
|
||||||
|
Amount int64
|
||||||
|
Data any
|
||||||
|
}
|
||||||
|
|
||||||
|
func createNEP17MultiTransferTx(c helper.Client, acc *wallet.Account, recipients []transferTarget) (*transaction.Transaction, error) {
|
||||||
|
from := acc.Contract.ScriptHash()
|
||||||
|
|
||||||
|
w := io.NewBufBinWriter()
|
||||||
|
for i := range recipients {
|
||||||
|
emit.AppCall(w.BinWriter, recipients[i].Token, "transfer", callflag.All,
|
||||||
|
from, recipients[i].Address, recipients[i].Amount, recipients[i].Data)
|
||||||
|
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
||||||
|
}
|
||||||
|
if w.Err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create transfer script: %w", w.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
signers := []actor.SignerAccount{{
|
||||||
|
Signer: transaction.Signer{
|
||||||
|
Account: acc.Contract.ScriptHash(),
|
||||||
|
Scopes: transaction.CalledByEntry,
|
||||||
|
},
|
||||||
|
Account: acc,
|
||||||
|
}}
|
||||||
|
|
||||||
|
act, err := actor.New(c, signers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't create actor: %w", err)
|
||||||
|
}
|
||||||
|
return act.MakeRun(w.Bytes())
|
||||||
|
}
|
56
cmd/frostfs-adm/internal/modules/morph/initialize/root.go
Normal file
56
cmd/frostfs-adm/internal/modules/morph/initialize/root.go
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxObjectSizeCLIFlag = "max-object-size"
|
||||||
|
epochDurationCLIFlag = "epoch-duration"
|
||||||
|
containerFeeCLIFlag = "container-fee"
|
||||||
|
containerAliasFeeCLIFlag = "container-alias-fee"
|
||||||
|
candidateFeeCLIFlag = "candidate-fee"
|
||||||
|
homomorphicHashDisabledCLIFlag = "homomorphic-disabled"
|
||||||
|
withdrawFeeCLIFlag = "withdraw-fee"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Cmd = &cobra.Command{
|
||||||
|
Use: "init",
|
||||||
|
Short: "Initialize side chain network with smart-contracts and network settings",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EpochDurationInitFlag, cmd.Flags().Lookup(epochDurationCLIFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.MaxObjectSizeInitFlag, cmd.Flags().Lookup(maxObjectSizeCLIFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.HomomorphicHashDisabledInitFlag, cmd.Flags().Lookup(homomorphicHashDisabledCLIFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.CandidateFeeInitFlag, cmd.Flags().Lookup(candidateFeeCLIFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.ContainerFeeInitFlag, cmd.Flags().Lookup(containerFeeCLIFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.ContainerAliasFeeInitFlag, cmd.Flags().Lookup(containerAliasFeeCLIFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.WithdrawFeeInitFlag, cmd.Flags().Lookup(withdrawFeeCLIFlag))
|
||||||
|
_ = viper.BindPFlag(constants.ProtoConfigPath, cmd.Flags().Lookup(constants.ProtoConfigPath))
|
||||||
|
},
|
||||||
|
RunE: initializeSideChainCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
func initInitCmd() {
|
||||||
|
Cmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
Cmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
Cmd.Flags().String(commonflags.ContractsInitFlag, "", commonflags.ContractsInitFlagDesc)
|
||||||
|
Cmd.Flags().String(commonflags.ContractsURLFlag, "", commonflags.ContractsURLFlagDesc)
|
||||||
|
Cmd.Flags().Uint(epochDurationCLIFlag, 240, "Amount of side chain blocks in one FrostFS epoch")
|
||||||
|
Cmd.Flags().Uint(maxObjectSizeCLIFlag, 67108864, "Max single object size in bytes")
|
||||||
|
Cmd.Flags().Bool(homomorphicHashDisabledCLIFlag, false, "Disable object homomorphic hashing")
|
||||||
|
// Defaults are taken from neo-preodolenie.
|
||||||
|
Cmd.Flags().Uint64(containerFeeCLIFlag, 1000, "Container registration fee")
|
||||||
|
Cmd.Flags().Uint64(containerAliasFeeCLIFlag, 500, "Container alias fee")
|
||||||
|
Cmd.Flags().String(constants.ProtoConfigPath, "", "Path to the consensus node configuration")
|
||||||
|
Cmd.Flags().String(commonflags.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||||
|
Cmd.MarkFlagsMutuallyExclusive(commonflags.ContractsInitFlag, commonflags.ContractsURLFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initInitCmd()
|
||||||
|
}
|
|
@ -1,592 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"archive/tar"
|
|
||||||
"compress/gzip"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-contract/common"
|
|
||||||
"github.com/TrueCloudLab/frostfs-contract/nns"
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
|
||||||
morphClient "github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
||||||
io2 "github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
nnsContract = "nns"
|
|
||||||
frostfsContract = "frostfs" // not deployed in side-chain.
|
|
||||||
processingContract = "processing" // not deployed in side-chain.
|
|
||||||
alphabetContract = "alphabet"
|
|
||||||
auditContract = "audit"
|
|
||||||
balanceContract = "balance"
|
|
||||||
containerContract = "container"
|
|
||||||
frostfsIDContract = "frostfsid"
|
|
||||||
netmapContract = "netmap"
|
|
||||||
proxyContract = "proxy"
|
|
||||||
reputationContract = "reputation"
|
|
||||||
subnetContract = "subnet"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
netmapEpochKey = "EpochDuration"
|
|
||||||
netmapMaxObjectSizeKey = "MaxObjectSize"
|
|
||||||
netmapAuditFeeKey = "AuditFee"
|
|
||||||
netmapContainerFeeKey = "ContainerFee"
|
|
||||||
netmapContainerAliasFeeKey = "ContainerAliasFee"
|
|
||||||
netmapEigenTrustIterationsKey = "EigenTrustIterations"
|
|
||||||
netmapEigenTrustAlphaKey = "EigenTrustAlpha"
|
|
||||||
netmapBasicIncomeRateKey = "BasicIncomeRate"
|
|
||||||
netmapInnerRingCandidateFeeKey = "InnerRingCandidateFee"
|
|
||||||
netmapWithdrawFeeKey = "WithdrawFee"
|
|
||||||
netmapHomomorphicHashDisabledKey = "HomomorphicHashingDisabled"
|
|
||||||
netmapMaintenanceAllowedKey = "MaintenanceModeAllowed"
|
|
||||||
|
|
||||||
defaultEigenTrustIterations = 4
|
|
||||||
defaultEigenTrustAlpha = "0.1"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
contractList = []string{
|
|
||||||
auditContract,
|
|
||||||
balanceContract,
|
|
||||||
containerContract,
|
|
||||||
frostfsIDContract,
|
|
||||||
netmapContract,
|
|
||||||
proxyContract,
|
|
||||||
reputationContract,
|
|
||||||
subnetContract,
|
|
||||||
}
|
|
||||||
|
|
||||||
fullContractList = append([]string{
|
|
||||||
frostfsContract,
|
|
||||||
processingContract,
|
|
||||||
nnsContract,
|
|
||||||
alphabetContract,
|
|
||||||
}, contractList...)
|
|
||||||
)
|
|
||||||
|
|
||||||
type contractState struct {
|
|
||||||
NEF *nef.File
|
|
||||||
RawNEF []byte
|
|
||||||
Manifest *manifest.Manifest
|
|
||||||
RawManifest []byte
|
|
||||||
Hash util.Uint160
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
updateMethodName = "update"
|
|
||||||
deployMethodName = "deploy"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *initializeContext) deployNNS(method string) error {
|
|
||||||
cs := c.getContract(nnsContract)
|
|
||||||
h := cs.Hash
|
|
||||||
|
|
||||||
nnsCs, err := c.nnsContractState()
|
|
||||||
if err == nil {
|
|
||||||
if nnsCs.NEF.Checksum == cs.NEF.Checksum {
|
|
||||||
if method == deployMethodName {
|
|
||||||
c.Command.Println("NNS contract is already deployed.")
|
|
||||||
} else {
|
|
||||||
c.Command.Println("NNS contract is already updated.")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
h = nnsCs.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.addManifestGroup(h, cs)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
params := getContractDeployParameters(cs, nil)
|
|
||||||
signer := transaction.Signer{
|
|
||||||
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
}
|
|
||||||
|
|
||||||
invokeHash := management.Hash
|
|
||||||
if method == updateMethodName {
|
|
||||||
invokeHash = nnsCs.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := invokeFunction(c.Client, invokeHash, method, params, []transaction.Signer{signer})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't deploy NNS contract: %w", err)
|
|
||||||
}
|
|
||||||
if res.State != vmstate.Halt.String() {
|
|
||||||
return fmt.Errorf("can't deploy NNS contract: %s", res.FaultException)
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := c.Client.CreateTxFromScript(res.Script, c.CommitteeAcc, res.GasConsumed, 0, []rpcclient.SignerAccount{{
|
|
||||||
Signer: signer,
|
|
||||||
Account: c.CommitteeAcc,
|
|
||||||
}})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create deploy tx for %s: %w", nnsContract, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.multiSignAndSend(tx, committeeAccountName); err != nil {
|
|
||||||
return fmt.Errorf("can't send deploy transaction: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) updateContracts() error {
|
|
||||||
alphaCs := c.getContract(alphabetContract)
|
|
||||||
|
|
||||||
nnsCs, err := c.nnsContractState()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nnsHash := nnsCs.Hash
|
|
||||||
|
|
||||||
w := io2.NewBufBinWriter()
|
|
||||||
|
|
||||||
var keysParam []any
|
|
||||||
|
|
||||||
// Update script size for a single-node committee is close to the maximum allowed size of 65535.
|
|
||||||
// Because of this we want to reuse alphabet contract NEF and manifest for different updates.
|
|
||||||
// The generated script is as following.
|
|
||||||
// 1. Initialize static slot for alphabet NEF.
|
|
||||||
// 2. Store NEF into the static slot.
|
|
||||||
// 3. Push parameters for each alphabet contract on stack.
|
|
||||||
// 4. Add contract group to the manifest.
|
|
||||||
// 5. For each alphabet contract, invoke `update` using parameters on stack and
|
|
||||||
// NEF from step 2 and manifest from step 4.
|
|
||||||
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
|
||||||
emit.Bytes(w.BinWriter, alphaCs.RawNEF)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
|
||||||
|
|
||||||
baseGroups := alphaCs.Manifest.Groups
|
|
||||||
|
|
||||||
// alphabet contracts should be deployed by individual nodes to get different hashes.
|
|
||||||
for i, acc := range c.Accounts {
|
|
||||||
ctrHash, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, getAlphabetNNSDomain(i))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't resolve hash for contract update: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
|
||||||
|
|
||||||
params := c.getAlphabetDeployItems(i, len(c.Wallets))
|
|
||||||
emit.Array(w.BinWriter, params...)
|
|
||||||
|
|
||||||
alphaCs.Manifest.Groups = baseGroups
|
|
||||||
err = c.addManifestGroup(ctrHash, alphaCs)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
emit.Bytes(w.BinWriter, alphaCs.RawManifest)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
|
||||||
emit.Int(w.BinWriter, 3)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.PACK)
|
|
||||||
emit.AppCallNoArgs(w.BinWriter, ctrHash, updateMethodName, callflag.All)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
|
||||||
if !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Command.Println("Alphabet contracts are already updated.")
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Reset()
|
|
||||||
|
|
||||||
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "getPrice", callflag.All)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "setPrice", callflag.All, 1)
|
|
||||||
|
|
||||||
for _, ctrName := range contractList {
|
|
||||||
cs := c.getContract(ctrName)
|
|
||||||
|
|
||||||
method := updateMethodName
|
|
||||||
ctrHash, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, ctrName+".frostfs")
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, errMissingNNSRecord) {
|
|
||||||
// if contract not found we deploy it instead of update
|
|
||||||
method = deployMethodName
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("can't resolve hash for contract update: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.addManifestGroup(ctrHash, cs)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
invokeHash := management.Hash
|
|
||||||
if method == updateMethodName {
|
|
||||||
invokeHash = ctrHash
|
|
||||||
}
|
|
||||||
|
|
||||||
params := getContractDeployParameters(cs, c.getContractDeployData(ctrName, keysParam))
|
|
||||||
res, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
|
|
||||||
if err != nil {
|
|
||||||
if method != updateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
|
||||||
return fmt.Errorf("deploy contract: %w", err)
|
|
||||||
}
|
|
||||||
c.Command.Printf("%s contract is already updated.\n", ctrName)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
w.WriteBytes(res.Script)
|
|
||||||
|
|
||||||
if method == deployMethodName {
|
|
||||||
// same actions are done in initializeContext.setNNS, can be unified
|
|
||||||
domain := ctrName + ".frostfs"
|
|
||||||
script, ok, err := c.nnsRegisterDomainScript(nnsHash, cs.Hash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
w.WriteBytes(script)
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
|
||||||
domain, int64(nns.TXT), cs.Hash.StringLE())
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
|
||||||
domain, int64(nns.TXT), address.Uint160ToString(cs.Hash))
|
|
||||||
}
|
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groupKey := c.ContractWallet.Accounts[0].PrivateKey().PublicKey()
|
|
||||||
_, _, err = c.emitUpdateNNSGroupScript(w, nnsHash, groupKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", morphClient.NNSGroupKeyName, hex.EncodeToString(groupKey.Bytes()))
|
|
||||||
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
|
||||||
emit.Int(w.BinWriter, 1)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.PACK)
|
|
||||||
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)
|
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) deployContracts() error {
|
|
||||||
alphaCs := c.getContract(alphabetContract)
|
|
||||||
|
|
||||||
var keysParam []any
|
|
||||||
|
|
||||||
baseGroups := alphaCs.Manifest.Groups
|
|
||||||
|
|
||||||
// alphabet contracts should be deployed by individual nodes to get different hashes.
|
|
||||||
for i, acc := range c.Accounts {
|
|
||||||
ctrHash := state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
|
||||||
if c.isUpdated(ctrHash, alphaCs) {
|
|
||||||
c.Command.Printf("Alphabet contract #%d is already deployed.\n", i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
alphaCs.Manifest.Groups = baseGroups
|
|
||||||
err := c.addManifestGroup(ctrHash, alphaCs)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
|
||||||
params := getContractDeployParameters(alphaCs, c.getAlphabetDeployItems(i, len(c.Wallets)))
|
|
||||||
|
|
||||||
act, err := actor.NewSimple(c.Client, acc)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not create actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
txHash, vub, err := act.SendCall(management.Hash, deployMethodName, params...)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.SentTxs = append(c.SentTxs, hashVUBPair{hash: txHash, vub: vub})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ctrName := range contractList {
|
|
||||||
cs := c.getContract(ctrName)
|
|
||||||
|
|
||||||
ctrHash := cs.Hash
|
|
||||||
if c.isUpdated(ctrHash, cs) {
|
|
||||||
c.Command.Printf("%s contract is already deployed.\n", ctrName)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err := c.addManifestGroup(ctrHash, cs)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
params := getContractDeployParameters(cs, c.getContractDeployData(ctrName, keysParam))
|
|
||||||
res, err := c.CommitteeAct.MakeCall(management.Hash, deployMethodName, params...)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't deploy %s contract: %w", ctrName, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(res.Script, false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) isUpdated(ctrHash util.Uint160, cs *contractState) bool {
|
|
||||||
realCs, err := c.Client.GetContractStateByHash(ctrHash)
|
|
||||||
return err == nil && realCs.NEF.Checksum == cs.NEF.Checksum
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) getContract(ctrName string) *contractState {
|
|
||||||
return c.Contracts[ctrName]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) readContracts(names []string) error {
|
|
||||||
var (
|
|
||||||
fi os.FileInfo
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if c.ContractPath != "" {
|
|
||||||
fi, err = os.Stat(c.ContractPath)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid contracts path: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.ContractPath != "" && fi.IsDir() {
|
|
||||||
for _, ctrName := range names {
|
|
||||||
cs, err := readContract(filepath.Join(c.ContractPath, ctrName), ctrName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Contracts[ctrName] = cs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var r io.ReadCloser
|
|
||||||
if c.ContractPath == "" {
|
|
||||||
c.Command.Println("Contracts flag is missing, latest release will be fetched from Github.")
|
|
||||||
r, err = downloadContractsFromGithub(c.Command)
|
|
||||||
} else {
|
|
||||||
r, err = os.Open(c.ContractPath)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't open contracts archive: %w", err)
|
|
||||||
}
|
|
||||||
defer r.Close()
|
|
||||||
|
|
||||||
m, err := readContractsFromArchive(r, names)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, name := range names {
|
|
||||||
if err := m[name].parse(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Contracts[name] = m[name]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ctrName := range names {
|
|
||||||
if ctrName != alphabetContract {
|
|
||||||
cs := c.Contracts[ctrName]
|
|
||||||
cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
cs.NEF.Checksum, cs.Manifest.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readContract(ctrPath, ctrName string) (*contractState, error) {
|
|
||||||
rawNef, err := os.ReadFile(filepath.Join(ctrPath, ctrName+"_contract.nef"))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
|
|
||||||
}
|
|
||||||
rawManif, err := os.ReadFile(filepath.Join(ctrPath, "config.json"))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't read manifest file for %s contract: %w", ctrName, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cs := &contractState{
|
|
||||||
RawNEF: rawNef,
|
|
||||||
RawManifest: rawManif,
|
|
||||||
}
|
|
||||||
|
|
||||||
return cs, cs.parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs *contractState) parse() error {
|
|
||||||
nf, err := nef.FileFromBytes(cs.RawNEF)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't parse NEF file: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
m := new(manifest.Manifest)
|
|
||||||
if err := json.Unmarshal(cs.RawManifest, m); err != nil {
|
|
||||||
return fmt.Errorf("can't parse manifest file: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cs.NEF = &nf
|
|
||||||
cs.Manifest = m
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readContractsFromArchive(file io.Reader, names []string) (map[string]*contractState, error) {
|
|
||||||
m := make(map[string]*contractState, len(names))
|
|
||||||
for i := range names {
|
|
||||||
m[names[i]] = new(contractState)
|
|
||||||
}
|
|
||||||
|
|
||||||
gr, err := gzip.NewReader(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("contracts file must be tar.gz archive: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
r := tar.NewReader(gr)
|
|
||||||
for h, err := r.Next(); ; h, err = r.Next() {
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
dir, _ := filepath.Split(h.Name)
|
|
||||||
ctrName := filepath.Base(dir)
|
|
||||||
|
|
||||||
cs, ok := m[ctrName]
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case strings.HasSuffix(h.Name, filepath.Join(ctrName, ctrName+"_contract.nef")):
|
|
||||||
cs.RawNEF, err = io.ReadAll(r)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
|
|
||||||
}
|
|
||||||
case strings.HasSuffix(h.Name, "config.json"):
|
|
||||||
cs.RawManifest, err = io.ReadAll(r)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("can't read manifest file for %s contract: %w", ctrName, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m[ctrName] = cs
|
|
||||||
}
|
|
||||||
|
|
||||||
for ctrName, cs := range m {
|
|
||||||
if cs.RawNEF == nil {
|
|
||||||
return nil, fmt.Errorf("NEF for %s contract wasn't found", ctrName)
|
|
||||||
}
|
|
||||||
if cs.RawManifest == nil {
|
|
||||||
return nil, fmt.Errorf("manifest for %s contract wasn't found", ctrName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getContractDeployParameters(cs *contractState, deployData []any) []any {
|
|
||||||
return []any{cs.RawNEF, cs.RawManifest, deployData}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) getContractDeployData(ctrName string, keysParam []any) []any {
|
|
||||||
items := make([]any, 1, 6)
|
|
||||||
items[0] = false // notaryDisabled is false
|
|
||||||
|
|
||||||
switch ctrName {
|
|
||||||
case frostfsContract:
|
|
||||||
items = append(items,
|
|
||||||
c.Contracts[processingContract].Hash,
|
|
||||||
keysParam,
|
|
||||||
smartcontract.Parameter{})
|
|
||||||
case processingContract:
|
|
||||||
items = append(items, c.Contracts[frostfsContract].Hash)
|
|
||||||
return items[1:] // no notary info
|
|
||||||
case auditContract:
|
|
||||||
items = append(items, c.Contracts[netmapContract].Hash)
|
|
||||||
case balanceContract:
|
|
||||||
items = append(items,
|
|
||||||
c.Contracts[netmapContract].Hash,
|
|
||||||
c.Contracts[containerContract].Hash)
|
|
||||||
case containerContract:
|
|
||||||
// In case if NNS is updated multiple times, we can't calculate
|
|
||||||
// it's actual hash based on local data, thus query chain.
|
|
||||||
nnsCs, err := c.Client.GetContractStateByID(1)
|
|
||||||
if err != nil {
|
|
||||||
panic("NNS is not yet deployed")
|
|
||||||
}
|
|
||||||
items = append(items,
|
|
||||||
c.Contracts[netmapContract].Hash,
|
|
||||||
c.Contracts[balanceContract].Hash,
|
|
||||||
c.Contracts[frostfsIDContract].Hash,
|
|
||||||
nnsCs.Hash,
|
|
||||||
"container")
|
|
||||||
case frostfsIDContract:
|
|
||||||
items = append(items,
|
|
||||||
c.Contracts[netmapContract].Hash,
|
|
||||||
c.Contracts[containerContract].Hash)
|
|
||||||
case netmapContract:
|
|
||||||
configParam := []any{
|
|
||||||
netmapEpochKey, viper.GetInt64(epochDurationInitFlag),
|
|
||||||
netmapMaxObjectSizeKey, viper.GetInt64(maxObjectSizeInitFlag),
|
|
||||||
netmapAuditFeeKey, viper.GetInt64(auditFeeInitFlag),
|
|
||||||
netmapContainerFeeKey, viper.GetInt64(containerFeeInitFlag),
|
|
||||||
netmapContainerAliasFeeKey, viper.GetInt64(containerAliasFeeInitFlag),
|
|
||||||
netmapEigenTrustIterationsKey, int64(defaultEigenTrustIterations),
|
|
||||||
netmapEigenTrustAlphaKey, defaultEigenTrustAlpha,
|
|
||||||
netmapBasicIncomeRateKey, viper.GetInt64(incomeRateInitFlag),
|
|
||||||
netmapInnerRingCandidateFeeKey, viper.GetInt64(candidateFeeInitFlag),
|
|
||||||
netmapWithdrawFeeKey, viper.GetInt64(withdrawFeeInitFlag),
|
|
||||||
netmapHomomorphicHashDisabledKey, viper.GetBool(homomorphicHashDisabledInitFlag),
|
|
||||||
netmapMaintenanceAllowedKey, viper.GetBool(maintenanceModeAllowedInitFlag),
|
|
||||||
}
|
|
||||||
items = append(items,
|
|
||||||
c.Contracts[balanceContract].Hash,
|
|
||||||
c.Contracts[containerContract].Hash,
|
|
||||||
keysParam,
|
|
||||||
configParam)
|
|
||||||
case proxyContract:
|
|
||||||
items = nil
|
|
||||||
case reputationContract:
|
|
||||||
case subnetContract:
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("invalid contract name: %s", ctrName))
|
|
||||||
}
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) getAlphabetDeployItems(i, n int) []any {
|
|
||||||
items := make([]any, 6)
|
|
||||||
items[0] = false
|
|
||||||
items[1] = c.Contracts[netmapContract].Hash
|
|
||||||
items[2] = c.Contracts[proxyContract].Hash
|
|
||||||
items[3] = innerring.GlagoliticLetter(i).String()
|
|
||||||
items[4] = int64(i)
|
|
||||||
items[5] = int64(n)
|
|
||||||
return items
|
|
||||||
}
|
|
|
@ -1,291 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/hex"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-contract/nns"
|
|
||||||
morphClient "github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
|
||||||
"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/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
|
||||||
)
|
|
||||||
|
|
||||||
const defaultExpirationTime = 10 * 365 * 24 * time.Hour / time.Second
|
|
||||||
|
|
||||||
func (c *initializeContext) setNNS() error {
|
|
||||||
nnsCs, err := c.Client.GetContractStateByID(1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ok, err := c.nnsRootRegistered(nnsCs.Hash, "frostfs")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else if !ok {
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
|
||||||
"frostfs", c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
if err := c.sendCommitteeTx(bw.Bytes(), true); err != nil {
|
|
||||||
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
|
||||||
}
|
|
||||||
if err := c.awaitTx(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
alphaCs := c.getContract(alphabetContract)
|
|
||||||
for i, acc := range c.Accounts {
|
|
||||||
alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
|
||||||
|
|
||||||
domain := getAlphabetNNSDomain(i)
|
|
||||||
if err := c.nnsRegisterDomain(nnsCs.Hash, alphaCs.Hash, domain); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", domain, alphaCs.Hash.StringLE())
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ctrName := range contractList {
|
|
||||||
cs := c.getContract(ctrName)
|
|
||||||
|
|
||||||
domain := ctrName + ".frostfs"
|
|
||||||
if err := c.nnsRegisterDomain(nnsCs.Hash, cs.Hash, domain); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
|
||||||
}
|
|
||||||
|
|
||||||
groupKey := c.ContractWallet.Accounts[0].PrivateKey().PublicKey()
|
|
||||||
err = c.updateNNSGroup(nnsCs.Hash, groupKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", morphClient.NNSGroupKeyName, hex.EncodeToString(groupKey.Bytes()))
|
|
||||||
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) updateNNSGroup(nnsHash util.Uint160, pub *keys.PublicKey) error {
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
needUpdate, needRegister, err := c.emitUpdateNNSGroupScript(bw, nnsHash, pub)
|
|
||||||
if !needUpdate || err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
script := bw.Bytes()
|
|
||||||
if needRegister {
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
|
||||||
wrapRegisterScriptWithPrice(w, nnsHash, script)
|
|
||||||
script = w.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.sendCommitteeTx(script, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// emitUpdateNNSGroupScript emits script for updating group key stored in NNS.
|
|
||||||
// First return value is true iff the key is already there and nothing should be done.
|
|
||||||
// Second return value is true iff a domain registration code was emitted.
|
|
||||||
func (c *initializeContext) emitUpdateNNSGroupScript(bw *io.BufBinWriter, nnsHash util.Uint160, pub *keys.PublicKey) (bool, bool, error) {
|
|
||||||
isAvail, err := nnsIsAvailable(c.Client, nnsHash, morphClient.NNSGroupKeyName)
|
|
||||||
if err != nil {
|
|
||||||
return false, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isAvail {
|
|
||||||
currentPub, err := nnsResolveKey(c.ReadOnlyInvoker, nnsHash, morphClient.NNSGroupKeyName)
|
|
||||||
if err != nil {
|
|
||||||
return false, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if pub.Equal(currentPub) {
|
|
||||||
return true, false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if isAvail {
|
|
||||||
emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All,
|
|
||||||
morphClient.NNSGroupKeyName, c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
}
|
|
||||||
|
|
||||||
emit.AppCall(bw.BinWriter, nnsHash, "deleteRecords", callflag.All, "group.frostfs", int64(nns.TXT))
|
|
||||||
emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All,
|
|
||||||
"group.frostfs", int64(nns.TXT), hex.EncodeToString(pub.Bytes()))
|
|
||||||
|
|
||||||
return false, isAvail, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getAlphabetNNSDomain(i int) string {
|
|
||||||
return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs"
|
|
||||||
}
|
|
||||||
|
|
||||||
// wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS.
|
|
||||||
// It is intended to be used for a single transaction, and not as a part of other scripts.
|
|
||||||
// It is assumed that script already contains static slot initialization code, the first one
|
|
||||||
// (with index 0) is used to store the price.
|
|
||||||
func wrapRegisterScriptWithPrice(w *io.BufBinWriter, nnsHash util.Uint160, s []byte) {
|
|
||||||
if len(s) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "getPrice", callflag.All)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "setPrice", callflag.All, 1)
|
|
||||||
|
|
||||||
w.WriteBytes(s)
|
|
||||||
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK)
|
|
||||||
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)
|
|
||||||
|
|
||||||
if w.Err != nil {
|
|
||||||
panic(fmt.Errorf("BUG: can't wrap register script: %w", w.Err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) nnsRegisterDomainScript(nnsHash, expectedHash util.Uint160, domain string) ([]byte, bool, error) {
|
|
||||||
ok, err := nnsIsAvailable(c.Client, nnsHash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok {
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All,
|
|
||||||
domain, c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
|
|
||||||
if bw.Err != nil {
|
|
||||||
panic(bw.Err)
|
|
||||||
}
|
|
||||||
return bw.Bytes(), false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
s, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
return nil, s == expectedHash, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160, domain string) error {
|
|
||||||
script, ok, err := c.nnsRegisterDomainScript(nnsHash, expectedHash, domain)
|
|
||||||
if ok || err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1})
|
|
||||||
wrapRegisterScriptWithPrice(w, nnsHash, script)
|
|
||||||
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
|
||||||
domain, int64(nns.TXT), expectedHash.StringLE())
|
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
|
||||||
domain, int64(nns.TXT), address.Uint160ToString(expectedHash))
|
|
||||||
return c.sendCommitteeTx(w.Bytes(), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160, zone string) (bool, error) {
|
|
||||||
res, err := c.CommitteeAct.Call(nnsHash, "isAvailable", "name."+zone)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.State == vmstate.Halt.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var errMissingNNSRecord = errors.New("missing NNS record")
|
|
||||||
|
|
||||||
// Returns errMissingNNSRecord if invocation fault exception contains "token not found".
|
|
||||||
func nnsResolveHash(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (util.Uint160, error) {
|
|
||||||
item, err := nnsResolve(inv, nnsHash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return util.Uint160{}, err
|
|
||||||
}
|
|
||||||
return parseNNSResolveResult(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
func nnsResolve(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (stackitem.Item, error) {
|
|
||||||
return unwrap.Item(inv.Call(nnsHash, "resolve", domain, int64(nns.TXT)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func nnsResolveKey(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (*keys.PublicKey, error) {
|
|
||||||
item, err := nnsResolve(inv, nnsHash, domain)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
v, ok := item.Value().(stackitem.Null)
|
|
||||||
if ok {
|
|
||||||
return nil, errors.New("NNS record is missing")
|
|
||||||
}
|
|
||||||
bs, err := v.TryBytes()
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("malformed response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return keys.NewPublicKeyFromString(string(bs))
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseNNSResolveResult parses the result of resolving NNS record.
|
|
||||||
// It works with multiple formats (corresponding to multiple NNS versions).
|
|
||||||
// If array of hashes is provided, it returns only the first one.
|
|
||||||
func parseNNSResolveResult(res stackitem.Item) (util.Uint160, error) {
|
|
||||||
arr, ok := res.Value().([]stackitem.Item)
|
|
||||||
if !ok {
|
|
||||||
arr = []stackitem.Item{res}
|
|
||||||
}
|
|
||||||
if _, ok := res.Value().(stackitem.Null); ok || len(arr) == 0 {
|
|
||||||
return util.Uint160{}, errors.New("NNS record is missing")
|
|
||||||
}
|
|
||||||
for i := range arr {
|
|
||||||
bs, err := arr[i].TryBytes()
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// We support several formats for hash encoding, this logic should be maintained in sync
|
|
||||||
// with nnsResolve from pkg/morph/client/nns.go
|
|
||||||
h, err := util.Uint160DecodeStringLE(string(bs))
|
|
||||||
if err == nil {
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
h, err = address.StringToUint160(string(bs))
|
|
||||||
if err == nil {
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.Uint160{}, errors.New("no valid hashes are found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func nnsIsAvailable(c Client, nnsHash util.Uint160, name string) (bool, error) {
|
|
||||||
switch ct := c.(type) {
|
|
||||||
case *rpcclient.Client:
|
|
||||||
return ct.NNSIsAvailable(nnsHash, name)
|
|
||||||
default:
|
|
||||||
b, err := unwrap.Bool(invokeFunction(c, nnsHash, "isAvailable", []any{name}, nil))
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("`isAvailable`: invalid response: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,137 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/neo"
|
|
||||||
"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/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
||||||
)
|
|
||||||
|
|
||||||
// initialAlphabetNEOAmount represents the total amount of GAS distributed between alphabet nodes.
|
|
||||||
const initialAlphabetNEOAmount = native.NEOTotalSupply
|
|
||||||
|
|
||||||
func (c *initializeContext) registerCandidates() error {
|
|
||||||
neoHash := neo.Hash
|
|
||||||
|
|
||||||
cc, err := unwrap.Array(c.ReadOnlyInvoker.Call(neoHash, "getCandidates"))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("`getCandidates`: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cc) > 0 {
|
|
||||||
c.Command.Println("Candidates are already registered.")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
regPrice, err := c.getCandidateRegisterPrice()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch registration price: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
emit.AppCall(w.BinWriter, neoHash, "setRegisterPrice", callflag.States, 1)
|
|
||||||
for _, acc := range c.Accounts {
|
|
||||||
emit.AppCall(w.BinWriter, neoHash, "registerCandidate", callflag.States, acc.PrivateKey().PublicKey().Bytes())
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
|
||||||
}
|
|
||||||
emit.AppCall(w.BinWriter, neoHash, "setRegisterPrice", callflag.States, regPrice)
|
|
||||||
if w.Err != nil {
|
|
||||||
panic(fmt.Sprintf("BUG: %v", w.Err))
|
|
||||||
}
|
|
||||||
|
|
||||||
signers := []rpcclient.SignerAccount{{
|
|
||||||
Signer: c.getSigner(false, c.CommitteeAcc),
|
|
||||||
Account: c.CommitteeAcc,
|
|
||||||
}}
|
|
||||||
for i := range c.Accounts {
|
|
||||||
signers = append(signers, rpcclient.SignerAccount{
|
|
||||||
Signer: transaction.Signer{
|
|
||||||
Account: c.Accounts[i].Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CustomContracts,
|
|
||||||
AllowedContracts: []util.Uint160{neoHash},
|
|
||||||
},
|
|
||||||
Account: c.Accounts[i],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := c.Client.CreateTxFromScript(w.Bytes(), c.CommitteeAcc, -1, 0, signers)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't create tx: %w", err)
|
|
||||||
}
|
|
||||||
if err := c.multiSign(tx, committeeAccountName); err != nil {
|
|
||||||
return fmt.Errorf("can't sign a transaction: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
network := c.CommitteeAct.GetNetwork()
|
|
||||||
for i := range c.Accounts {
|
|
||||||
if err := c.Accounts[i].SignTx(network, tx); err != nil {
|
|
||||||
return fmt.Errorf("can't sign a transaction: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.sendTx(tx, c.Command, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) transferNEOToAlphabetContracts() error {
|
|
||||||
neoHash := neo.Hash
|
|
||||||
|
|
||||||
ok, err := c.transferNEOFinished(neoHash)
|
|
||||||
if ok || err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cs := c.getContract(alphabetContract)
|
|
||||||
amount := initialAlphabetNEOAmount / len(c.Wallets)
|
|
||||||
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
for _, acc := range c.Accounts {
|
|
||||||
h := state.CreateContractHash(acc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
|
||||||
emit.AppCall(bw.BinWriter, neoHash, "transfer", callflag.All,
|
|
||||||
c.CommitteeAcc.Contract.ScriptHash(), h, int64(amount), nil)
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) transferNEOFinished(neoHash util.Uint160) (bool, error) {
|
|
||||||
bal, err := c.Client.NEP17BalanceOf(neoHash, c.CommitteeAcc.Contract.ScriptHash())
|
|
||||||
return bal < native.NEOTotalSupply, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var errGetPriceInvalid = errors.New("`getRegisterPrice`: invalid response")
|
|
||||||
|
|
||||||
func (c *initializeContext) getCandidateRegisterPrice() (int64, error) {
|
|
||||||
switch ct := c.Client.(type) {
|
|
||||||
case *rpcclient.Client:
|
|
||||||
return ct.GetCandidateRegisterPrice()
|
|
||||||
default:
|
|
||||||
neoHash := neo.Hash
|
|
||||||
res, err := invokeFunction(c.Client, neoHash, "getRegisterPrice", nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if len(res.Stack) == 0 {
|
|
||||||
return 0, errGetPriceInvalid
|
|
||||||
}
|
|
||||||
bi, err := res.Stack[0].TryInteger()
|
|
||||||
if err != nil || !bi.IsInt64() {
|
|
||||||
return 0, errGetPriceInvalid
|
|
||||||
}
|
|
||||||
return bi.Int64(), nil
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,121 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/hex"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/innerring"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
|
||||||
"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/spf13/viper"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
contractsPath = "../../../../../../frostfs-contract/frostfs-contract-v0.16.0.tar.gz"
|
|
||||||
protoFileName = "proto.yml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestInitialize(t *testing.T) {
|
|
||||||
// This test needs frostfs-contract tarball, so it is skipped by default.
|
|
||||||
// It is here for performing local testing after the changes.
|
|
||||||
t.Skip()
|
|
||||||
|
|
||||||
t.Run("1 nodes", func(t *testing.T) {
|
|
||||||
testInitialize(t, 1)
|
|
||||||
})
|
|
||||||
t.Run("4 nodes", func(t *testing.T) {
|
|
||||||
testInitialize(t, 4)
|
|
||||||
})
|
|
||||||
t.Run("7 nodes", func(t *testing.T) {
|
|
||||||
testInitialize(t, 7)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testInitialize(t *testing.T, committeeSize int) {
|
|
||||||
testdataDir := t.TempDir()
|
|
||||||
v := viper.GetViper()
|
|
||||||
|
|
||||||
generateTestData(t, testdataDir, committeeSize)
|
|
||||||
v.Set(protoConfigPath, filepath.Join(testdataDir, protoFileName))
|
|
||||||
|
|
||||||
// Set to the path or remove the next statement to download from the network.
|
|
||||||
require.NoError(t, initCmd.Flags().Set(contractsInitFlag, contractsPath))
|
|
||||||
v.Set(localDumpFlag, filepath.Join(testdataDir, "out"))
|
|
||||||
v.Set(alphabetWalletsFlag, testdataDir)
|
|
||||||
v.Set(epochDurationInitFlag, 1)
|
|
||||||
v.Set(maxObjectSizeInitFlag, 1024)
|
|
||||||
|
|
||||||
setTestCredentials(v, committeeSize)
|
|
||||||
require.NoError(t, initializeSideChainCmd(initCmd, nil))
|
|
||||||
|
|
||||||
t.Run("force-new-epoch", func(t *testing.T) {
|
|
||||||
require.NoError(t, forceNewEpochCmd(forceNewEpoch, nil))
|
|
||||||
})
|
|
||||||
t.Run("set-config", func(t *testing.T) {
|
|
||||||
require.NoError(t, setConfigCmd(setConfig, []string{"MaintenanceModeAllowed=true"}))
|
|
||||||
})
|
|
||||||
t.Run("set-policy", func(t *testing.T) {
|
|
||||||
require.NoError(t, setPolicyCmd(setPolicy, []string{"ExecFeeFactor=1"}))
|
|
||||||
})
|
|
||||||
t.Run("remove-node", func(t *testing.T) {
|
|
||||||
pk, err := keys.NewPrivateKey()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
pub := hex.EncodeToString(pk.PublicKey().Bytes())
|
|
||||||
require.NoError(t, removeNodesCmd(removeNodes, []string{pub}))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateTestData(t *testing.T, dir string, size int) {
|
|
||||||
v := viper.GetViper()
|
|
||||||
v.Set(alphabetWalletsFlag, dir)
|
|
||||||
|
|
||||||
sizeStr := strconv.FormatUint(uint64(size), 10)
|
|
||||||
require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, sizeStr))
|
|
||||||
|
|
||||||
setTestCredentials(v, size)
|
|
||||||
require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil))
|
|
||||||
|
|
||||||
var pubs []string
|
|
||||||
for i := 0; i < size; i++ {
|
|
||||||
p := filepath.Join(dir, innerring.GlagoliticLetter(i).String()+".json")
|
|
||||||
w, err := wallet.NewWalletFromFile(p)
|
|
||||||
require.NoError(t, err, "wallet doesn't exist")
|
|
||||||
for _, acc := range w.Accounts {
|
|
||||||
if acc.Label == singleAccountName {
|
|
||||||
pub, ok := vm.ParseSignatureContract(acc.Contract.Script)
|
|
||||||
require.True(t, ok)
|
|
||||||
pubs = append(pubs, hex.EncodeToString(pub))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg := config.Config{}
|
|
||||||
cfg.ProtocolConfiguration.Magic = 12345
|
|
||||||
cfg.ProtocolConfiguration.ValidatorsCount = size
|
|
||||||
cfg.ProtocolConfiguration.SecondsPerBlock = 1
|
|
||||||
cfg.ProtocolConfiguration.StandbyCommittee = pubs // sorted by glagolic letters
|
|
||||||
cfg.ProtocolConfiguration.P2PSigExtensions = true
|
|
||||||
cfg.ProtocolConfiguration.VerifyTransactions = true
|
|
||||||
cfg.ProtocolConfiguration.VerifyBlocks = true
|
|
||||||
data, err := yaml.Marshal(cfg)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
protoPath := filepath.Join(dir, protoFileName)
|
|
||||||
require.NoError(t, os.WriteFile(protoPath, data, os.ModePerm))
|
|
||||||
}
|
|
||||||
|
|
||||||
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.contract", testContractPassword)
|
|
||||||
}
|
|
|
@ -1,190 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/neo"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
|
||||||
scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
gasInitialTotalSupply = 30000000 * native.GASFactor
|
|
||||||
// initialAlphabetGASAmount represents the amount of GAS given to each alphabet node.
|
|
||||||
initialAlphabetGASAmount = 10_000 * native.GASFactor
|
|
||||||
// initialProxyGASAmount represents the amount of GAS given to a proxy contract.
|
|
||||||
initialProxyGASAmount = 50_000 * native.GASFactor
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *initializeContext) transferFunds() error {
|
|
||||||
ok, err := c.transferFundsFinished()
|
|
||||||
if ok || err != nil {
|
|
||||||
if err == nil {
|
|
||||||
c.Command.Println("Stage 1: already performed.")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var transfers []rpcclient.TransferTarget
|
|
||||||
for _, acc := range c.Accounts {
|
|
||||||
to := acc.Contract.ScriptHash()
|
|
||||||
transfers = append(transfers,
|
|
||||||
rpcclient.TransferTarget{
|
|
||||||
Token: gas.Hash,
|
|
||||||
Address: to,
|
|
||||||
Amount: initialAlphabetGASAmount,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is convenient to have all funds at the committee account.
|
|
||||||
transfers = append(transfers,
|
|
||||||
rpcclient.TransferTarget{
|
|
||||||
Token: gas.Hash,
|
|
||||||
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
Amount: (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2,
|
|
||||||
},
|
|
||||||
rpcclient.TransferTarget{
|
|
||||||
Token: neo.Hash,
|
|
||||||
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
Amount: native.NEOTotalSupply,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
tx, err := createNEP17MultiTransferTx(c.Client, c.ConsensusAcc, 0, transfers, []rpcclient.SignerAccount{{
|
|
||||||
Signer: transaction.Signer{
|
|
||||||
Account: c.ConsensusAcc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
},
|
|
||||||
Account: c.ConsensusAcc,
|
|
||||||
}})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't create transfer transaction: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.multiSignAndSend(tx, consensusAccountName); err != nil {
|
|
||||||
return fmt.Errorf("can't send transfer transaction: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) transferFundsFinished() (bool, error) {
|
|
||||||
acc := c.Accounts[0]
|
|
||||||
|
|
||||||
res, err := c.Client.NEP17BalanceOf(gas.Hash, acc.Contract.ScriptHash())
|
|
||||||
return res > initialAlphabetGASAmount/2, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accType string) error {
|
|
||||||
if err := c.multiSign(tx, accType); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.sendTx(tx, c.Command, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) multiSign(tx *transaction.Transaction, accType string) error {
|
|
||||||
network, err := c.Client.GetNetwork()
|
|
||||||
if err != nil {
|
|
||||||
// error appears only if client
|
|
||||||
// has not been initialized
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use parameter context to avoid dealing with signature order.
|
|
||||||
pc := scContext.NewParameterContext("", network, tx)
|
|
||||||
h := c.CommitteeAcc.Contract.ScriptHash()
|
|
||||||
if accType == consensusAccountName {
|
|
||||||
h = c.ConsensusAcc.Contract.ScriptHash()
|
|
||||||
}
|
|
||||||
for _, w := range c.Wallets {
|
|
||||||
acc, err := getWalletAccount(w, accType)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't find %s wallet account: %w", accType, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
priv := acc.PrivateKey()
|
|
||||||
sign := priv.SignHashable(uint32(network), tx)
|
|
||||||
if err := pc.AddSignature(h, acc.Contract, priv.PublicKey(), sign); err != nil {
|
|
||||||
return fmt.Errorf("can't add signature: %w", err)
|
|
||||||
}
|
|
||||||
if len(pc.Items[h].Signatures) == len(acc.Contract.Parameters) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w, err := pc.GetWitness(h)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("incomplete signature: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range tx.Signers {
|
|
||||||
if tx.Signers[i].Account == h {
|
|
||||||
if i < len(tx.Scripts) {
|
|
||||||
tx.Scripts[i] = *w
|
|
||||||
} else if i == len(tx.Scripts) {
|
|
||||||
tx.Scripts = append(tx.Scripts, *w)
|
|
||||||
} else {
|
|
||||||
panic("BUG: invalid signing order")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("%s account was not found among transaction signers", accType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *initializeContext) transferGASToProxy() error {
|
|
||||||
proxyCs := c.getContract(proxyContract)
|
|
||||||
|
|
||||||
bal, err := c.Client.NEP17BalanceOf(gas.Hash, proxyCs.Hash)
|
|
||||||
if err != nil || bal > 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := createNEP17MultiTransferTx(c.Client, c.CommitteeAcc, 0, []rpcclient.TransferTarget{{
|
|
||||||
Token: gas.Hash,
|
|
||||||
Address: proxyCs.Hash,
|
|
||||||
Amount: initialProxyGASAmount,
|
|
||||||
}}, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.multiSignAndSend(tx, committeeAccountName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.awaitTx()
|
|
||||||
}
|
|
||||||
|
|
||||||
func createNEP17MultiTransferTx(c Client, acc *wallet.Account, netFee int64,
|
|
||||||
recipients []rpcclient.TransferTarget, cosigners []rpcclient.SignerAccount) (*transaction.Transaction, error) {
|
|
||||||
from := acc.Contract.ScriptHash()
|
|
||||||
|
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
for i := range recipients {
|
|
||||||
emit.AppCall(w.BinWriter, recipients[i].Token, "transfer", callflag.All,
|
|
||||||
from, recipients[i].Address, recipients[i].Amount, recipients[i].Data)
|
|
||||||
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
|
||||||
}
|
|
||||||
if w.Err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to create transfer script: %w", w.Err)
|
|
||||||
}
|
|
||||||
return c.CreateTxFromScript(w.Bytes(), acc, -1, netFee, append([]rpcclient.SignerAccount{{
|
|
||||||
Signer: transaction.Signer{
|
|
||||||
Account: from,
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
},
|
|
||||||
Account: acc,
|
|
||||||
}}, cosigners...))
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
package internal
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StringifySubnetClientGroupID returns string representation of SubnetClientGroupID using MarshalText.
|
|
||||||
// Returns a string with a message on error.
|
|
||||||
func StringifySubnetClientGroupID(id *SubnetClientGroupID) string {
|
|
||||||
text, err := id.MarshalText()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Sprintf("<invalid> %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalText encodes SubnetClientGroupID into text format according to FrostFS API V2 protocol:
|
|
||||||
// value in base-10 integer string format.
|
|
||||||
//
|
|
||||||
// It implements encoding.TextMarshaler.
|
|
||||||
func (x *SubnetClientGroupID) MarshalText() ([]byte, error) {
|
|
||||||
num := x.GetValue() // NPE safe, returns zero on nil
|
|
||||||
|
|
||||||
return []byte(strconv.FormatUint(uint64(num), 10)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalText decodes the SubnetID from the text according to FrostFS API V2 protocol:
|
|
||||||
// should be base-10 integer string format with bitsize = 32.
|
|
||||||
//
|
|
||||||
// Returns strconv.ErrRange if integer overflows uint32.
|
|
||||||
//
|
|
||||||
// Must not be called on nil.
|
|
||||||
//
|
|
||||||
// Implements encoding.TextUnmarshaler.
|
|
||||||
func (x *SubnetClientGroupID) UnmarshalText(txt []byte) error {
|
|
||||||
num, err := strconv.ParseUint(string(txt), 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid numeric value: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
x.SetNumber(uint32(num))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal encodes the SubnetClientGroupID into a binary format of FrostFS API V2 protocol
|
|
||||||
// (Protocol Buffers with direct field order).
|
|
||||||
func (x *SubnetClientGroupID) Marshal() ([]byte, error) {
|
|
||||||
return proto.Marshal(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal decodes the SubnetClientGroupID from FrostFS API V2 binary format (see Marshal). Must not be called on nil.
|
|
||||||
func (x *SubnetClientGroupID) Unmarshal(data []byte) error {
|
|
||||||
return proto.Unmarshal(data, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNumber sets SubnetClientGroupID value in uint32 format. Must not be called on nil.
|
|
||||||
// By default, number is 0.
|
|
||||||
func (x *SubnetClientGroupID) SetNumber(num uint32) {
|
|
||||||
x.Value = num
|
|
||||||
}
|
|
Binary file not shown.
|
@ -1,15 +0,0 @@
|
||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package neo.fs.v2.refs;
|
|
||||||
|
|
||||||
option go_package = "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/internal";
|
|
||||||
|
|
||||||
// Client group identifier in the FrostFS subnet.
|
|
||||||
//
|
|
||||||
// String representation of a value is base-10 integer.
|
|
||||||
//
|
|
||||||
// JSON representation is an object containing single `value` number field.
|
|
||||||
message SubnetClientGroupID {
|
|
||||||
// 4-byte integer identifier of the subnet client group.
|
|
||||||
fixed32 value = 1 [json_name = "value"];
|
|
||||||
}
|
|
45
cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go
Normal file
45
cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ForceNewEpochCmd(cmd *cobra.Command, _ []string) error {
|
||||||
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't to initialize context: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nmHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.NetmapContract))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
if err := helper.EmitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = wCtx.SendConsensusTx(bw.Bytes()); err == nil {
|
||||||
|
err = wCtx.AwaitTx()
|
||||||
|
}
|
||||||
|
if err != nil && strings.Contains(err.Error(), "invalid epoch") {
|
||||||
|
cmd.Println("Epoch has already ticked.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
|
@ -1,24 +1,28 @@
|
||||||
package morph
|
package netmap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) {
|
func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) {
|
||||||
c, err := getN3Client(viper.GetViper())
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err)
|
commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err)
|
||||||
|
|
||||||
inv := invoker.New(c, nil)
|
inv := invoker.New(c, nil)
|
||||||
|
r := management.NewReader(inv)
|
||||||
|
|
||||||
cs, err := c.GetContractStateByID(1)
|
cs, err := r.GetContractByID(1)
|
||||||
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
|
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
|
||||||
|
|
||||||
nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".frostfs")
|
nmHash, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.NetmapContract))
|
||||||
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
||||||
|
|
||||||
res, err := inv.Call(nmHash, "netmapCandidates")
|
res, err := inv.Call(nmHash, "netmapCandidates")
|
43
cmd/frostfs-adm/internal/modules/morph/netmap/root.go
Normal file
43
cmd/frostfs-adm/internal/modules/morph/netmap/root.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
CandidatesCmd = &cobra.Command{
|
||||||
|
Use: "netmap-candidates",
|
||||||
|
Short: "List netmap candidates nodes",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
},
|
||||||
|
Run: listNetmapCandidatesNodes,
|
||||||
|
}
|
||||||
|
ForceNewEpoch = &cobra.Command{
|
||||||
|
Use: "force-new-epoch",
|
||||||
|
Short: "Create new FrostFS epoch event in the side chain",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: ForceNewEpochCmd,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func initNetmapCandidatesCmd() {
|
||||||
|
CandidatesCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initForceNewEpochCmd() {
|
||||||
|
ForceNewEpoch.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
ForceNewEpoch.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
ForceNewEpoch.Flags().String(commonflags.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initNetmapCandidatesCmd()
|
||||||
|
initForceNewEpochCmd()
|
||||||
|
}
|
|
@ -1,19 +1,22 @@
|
||||||
package morph
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
netmapcontract "github.com/TrueCloudLab/frostfs-contract/netmap"
|
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
func RemoveNodesCmd(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return errors.New("at least one node key must be provided")
|
return errors.New("at least one node key must be provided")
|
||||||
}
|
}
|
||||||
|
@ -27,18 +30,19 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wCtx, err := newInitializeContext(cmd, viper.GetViper())
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't initialize context: %w", err)
|
return fmt.Errorf("can't initialize context: %w", err)
|
||||||
}
|
}
|
||||||
defer wCtx.close()
|
defer wCtx.Close()
|
||||||
|
|
||||||
cs, err := wCtx.Client.GetContractStateByID(1)
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get NNS contract info: %w", err)
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs")
|
nmHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.NetmapContract))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
return fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -49,13 +53,13 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
||||||
int64(netmapcontract.NodeStateOffline), nodeKeys[i].Bytes())
|
int64(netmapcontract.NodeStateOffline), nodeKeys[i].Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := emitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
if err := helper.EmitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendConsensusTx(bw.Bytes()); err != nil {
|
if err := wCtx.SendConsensusTx(bw.Bytes()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return wCtx.awaitTx()
|
return wCtx.AwaitTx()
|
||||||
}
|
}
|
28
cmd/frostfs-adm/internal/modules/morph/node/root.go
Normal file
28
cmd/frostfs-adm/internal/modules/morph/node/root.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package node
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var RemoveCmd = &cobra.Command{
|
||||||
|
Use: "remove-nodes key1 [key2 [...]]",
|
||||||
|
Short: "Remove storage nodes from the netmap",
|
||||||
|
Long: `Move nodes to the Offline state in the candidates list and tick an epoch to update the netmap`,
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: RemoveNodesCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
func initRemoveNodesCmd() {
|
||||||
|
RemoveCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
||||||
|
RemoveCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
RemoveCmd.Flags().String(commonflags.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initRemoveNodesCmd()
|
||||||
|
}
|
|
@ -1,38 +1,40 @@
|
||||||
package morph
|
package notary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
"github.com/nspcc-dev/neo-go/cli/input"
|
"github.com/nspcc-dev/neo-go/cli/input"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/gas"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// defaultNotaryDepositLifetime is an amount of blocks notary deposit stays valid.
|
const (
|
||||||
// https://github.com/nspcc-dev/neo-go/blob/master/pkg/core/native/notary.go#L48
|
// defaultNotaryDepositLifetime is an amount of blocks notary deposit stays valid.
|
||||||
const defaultNotaryDepositLifetime = 5760
|
// https://github.com/nspcc-dev/neo-go/blob/master/pkg/core/native/notary.go#L48
|
||||||
|
defaultNotaryDepositLifetime = 5760
|
||||||
|
|
||||||
|
walletAccountFlag = "account"
|
||||||
|
notaryDepositTillFlag = "till"
|
||||||
|
)
|
||||||
|
|
||||||
func depositNotary(cmd *cobra.Command, _ []string) error {
|
func depositNotary(cmd *cobra.Command, _ []string) error {
|
||||||
p, err := cmd.Flags().GetString(storageWalletFlag)
|
w, err := openWallet(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if p == "" {
|
|
||||||
return fmt.Errorf("missing wallet path (use '--%s <out.json>')", storageWalletFlag)
|
|
||||||
}
|
|
||||||
|
|
||||||
w, err := wallet.NewWalletFromFile(p)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't open wallet: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accHash := w.GetChangeAddress()
|
accHash := w.GetChangeAddress()
|
||||||
|
@ -59,11 +61,11 @@ func depositNotary(cmd *cobra.Command, _ []string) error {
|
||||||
return fmt.Errorf("can't unlock account: %v", err)
|
return fmt.Errorf("can't unlock account: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gasStr, err := cmd.Flags().GetString(refillGasAmountFlag)
|
gasStr, err := cmd.Flags().GetString(commonflags.RefillGasAmountFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
gasAmount, err := parseGASAmount(gasStr)
|
gasAmount, err := helper.ParseGASAmount(gasStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -80,12 +82,16 @@ func depositNotary(cmd *cobra.Command, _ []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := getN3Client(viper.GetViper())
|
return transferGas(cmd, acc, accHash, gasAmount, till)
|
||||||
|
}
|
||||||
|
|
||||||
|
func transferGas(cmd *cobra.Command, acc *wallet.Account, accHash util.Uint160, gasAmount fixedn.Fixed8, till int64) error {
|
||||||
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := checkNotaryEnabled(c); err != nil {
|
if err := helper.CheckNotaryEnabled(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,5 +123,20 @@ func depositNotary(cmd *cobra.Command, _ []string) error {
|
||||||
return fmt.Errorf("could not send tx: %w", err)
|
return fmt.Errorf("could not send tx: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return awaitTx(cmd, c, []hashVUBPair{{hash: txHash, vub: vub}})
|
return helper.AwaitTx(cmd, c, []helper.HashVUBPair{{Hash: txHash, Vub: vub}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func openWallet(cmd *cobra.Command) (*wallet.Wallet, error) {
|
||||||
|
p, err := cmd.Flags().GetString(commonflags.StorageWalletFlag)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if p == "" {
|
||||||
|
return nil, fmt.Errorf("missing wallet path (use '--%s <out.json>')", commonflags.StorageWalletFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := wallet.NewWalletFromFile(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't open wallet: %v", err)
|
||||||
|
}
|
||||||
|
return w, nil
|
||||||
}
|
}
|
28
cmd/frostfs-adm/internal/modules/morph/notary/root.go
Normal file
28
cmd/frostfs-adm/internal/modules/morph/notary/root.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package notary
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DepositCmd = &cobra.Command{
|
||||||
|
Use: "deposit-notary",
|
||||||
|
Short: "Deposit GAS for notary service",
|
||||||
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||||
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
||||||
|
},
|
||||||
|
RunE: depositNotary,
|
||||||
|
}
|
||||||
|
|
||||||
|
func initDepositoryNotaryCmd() {
|
||||||
|
DepositCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||||
|
DepositCmd.Flags().String(commonflags.StorageWalletFlag, "", "Path to storage node wallet")
|
||||||
|
DepositCmd.Flags().String(walletAccountFlag, "", "Wallet account address")
|
||||||
|
DepositCmd.Flags().String(commonflags.RefillGasAmountFlag, "", "Amount of GAS to deposit")
|
||||||
|
DepositCmd.Flags().String(notaryDepositTillFlag, "", "Notary deposit duration in blocks")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
initDepositoryNotaryCmd()
|
||||||
|
}
|
|
@ -1,54 +0,0 @@
|
||||||
package morph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/policy"
|
|
||||||
"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 (
|
|
||||||
execFeeParam = "ExecFeeFactor"
|
|
||||||
storagePriceParam = "StoragePrice"
|
|
||||||
setFeeParam = "FeePerByte"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setPolicyCmd(cmd *cobra.Command, args []string) error {
|
|
||||||
wCtx, err := newInitializeContext(cmd, viper.GetViper())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't to initialize context: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bw := io.NewBufBinWriter()
|
|
||||||
for i := range args {
|
|
||||||
k, v, found := strings.Cut(args[i], "=")
|
|
||||||
if !found {
|
|
||||||
return fmt.Errorf("invalid parameter format, must be Parameter=Value")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch k {
|
|
||||||
case execFeeParam, storagePriceParam, setFeeParam:
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("parameter must be one of %s, %s and %s", execFeeParam, storagePriceParam, setFeeParam)
|
|
||||||
}
|
|
||||||
|
|
||||||
value, err := strconv.ParseUint(v, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't parse parameter value '%s': %w", args[1], err)
|
|
||||||
}
|
|
||||||
|
|
||||||
emit.AppCall(bw.BinWriter, policy.Hash, "set"+k, callflag.All, int64(value))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return wCtx.awaitTx()
|
|
||||||
}
|
|
88
cmd/frostfs-adm/internal/modules/morph/policy/policy.go
Normal file
88
cmd/frostfs-adm/internal/modules/morph/policy/policy.go
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
package policy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
||||||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/policy"
|
||||||
|
"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 (
|
||||||
|
execFeeParam = "ExecFeeFactor"
|
||||||
|
storagePriceParam = "StoragePrice"
|
||||||
|
setFeeParam = "FeePerByte"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetPolicyCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't to initialize context: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
for i := range args {
|
||||||
|
k, v, found := strings.Cut(args[i], "=")
|
||||||
|
if !found {
|
||||||
|
return fmt.Errorf("invalid parameter format, must be Parameter=Value")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch k {
|
||||||
|
case execFeeParam, storagePriceParam, setFeeParam:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("parameter must be one of %s, %s and %s", execFeeParam, storagePriceParam, setFeeParam)
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := strconv.ParseUint(v, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("can't parse parameter value '%s': %w", args[1], err)
|
||||||
|
}
|
||||||
|
|
||||||
|
emit.AppCall(bw.BinWriter, policy.Hash, "set"+k, callflag.All, int64(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := wCtx.SendCommitteeTx(bw.Bytes(), false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return wCtx.AwaitTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpPolicyCmd(cmd *cobra.Command, _ []string) error {
|
||||||
|
c, err := helper.GetN3Client(viper.GetViper())
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't create N3 client:", err)
|
||||||
|
|
||||||
|
inv := invoker.New(c, nil)
|
||||||
|
policyContract := policy.NewReader(inv)
|
||||||
|
|
||||||
|
execFee, err := policyContract.GetExecFeeFactor()
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't get execution fee factor:", err)
|
||||||
|
|
||||||
|
feePerByte, err := policyContract.GetFeePerByte()
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't get fee per byte:", err)
|
||||||
|
|
||||||
|
storagePrice, err := policyContract.GetStoragePrice()
|
||||||
|
commonCmd.ExitOnErr(cmd, "can't get storage price:", err)
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0)
|
||||||
|
|
||||||
|
_, _ = tw.Write([]byte(fmt.Sprintf("Execution Fee Factor:\t%d (int)\n", execFee)))
|
||||||
|
_, _ = tw.Write([]byte(fmt.Sprintf("Fee Per Byte:\t%d (int)\n", feePerByte)))
|
||||||
|
_, _ = tw.Write([]byte(fmt.Sprintf("Storage Price:\t%d (int)\n", storagePrice)))
|
||||||
|
|
||||||
|
_ = tw.Flush()
|
||||||
|
cmd.Print(buf.String())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue