Remove deprecated neo-go items from the frostfs-adm #750
19 changed files with 180 additions and 269 deletions
|
@ -16,6 +16,7 @@ import (
|
||||||
"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/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/rolemgmt"
|
"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/rpcclient/unwrap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
@ -56,7 +57,8 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
|
||||||
inv := invoker.New(c, nil)
|
inv := invoker.New(c, nil)
|
||||||
|
|
||||||
if dumpStorage || dumpAlphabet || dumpProxy {
|
if dumpStorage || dumpAlphabet || dumpProxy {
|
||||||
nnsCs, err = c.GetContractStateByID(1)
|
r := management.NewReader(inv)
|
||||||
|
nnsCs, 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
"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"
|
||||||
|
@ -29,8 +30,9 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +89,8 @@ func setConfigCmd(cmd *cobra.Command, args []string) error {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"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,14 +23,15 @@ 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)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +80,7 @@ func dumpContainers(cmd *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,7 @@ func listContainers(cmd *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -298,7 +300,8 @@ func parseContainers(filename string) ([]Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchContainerContractHash(wCtx *initializeContext) (util.Uint160, error) {
|
func fetchContainerContractHash(wCtx *initializeContext) (util.Uint160, error) {
|
||||||
nnsCs, err := wCtx.Client.GetContractStateByID(1)
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,8 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nnsCs, err := c.Client.GetContractStateByID(1)
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't fetch NNS contract state: %w", err)
|
return fmt.Errorf("can't fetch NNS contract state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
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/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"
|
||||||
|
@ -36,7 +37,8 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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/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"
|
||||||
|
@ -20,7 +21,8 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error {
|
||||||
return fmt.Errorf("can't to initialize context: %w", err)
|
return fmt.Errorf("can't to 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"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/rpcclient/actor"
|
"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/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/vmstate"
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
@ -312,7 +313,8 @@ func (c *initializeContext) nnsContractState() (*state.Contract, error) {
|
||||||
return c.nnsCs, nil
|
return c.nnsCs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cs, err := c.Client.GetContractStateByID(1)
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,8 @@ import (
|
||||||
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
||||||
"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/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
io2 "github.com/nspcc-dev/neo-go/pkg/io"
|
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/actor"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
"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"
|
||||||
|
@ -33,7 +31,6 @@ import (
|
||||||
"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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -94,7 +91,10 @@ func (c *initializeContext) deployNNS(method string) error {
|
||||||
h := cs.Hash
|
h := cs.Hash
|
||||||
|
|
||||||
nnsCs, err := c.nnsContractState()
|
nnsCs, err := c.nnsContractState()
|
||||||
if err == nil {
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if nnsCs != nil {
|
||||||
if nnsCs.NEF.Checksum == cs.NEF.Checksum {
|
if nnsCs.NEF.Checksum == cs.NEF.Checksum {
|
||||||
if method == deployMethodName {
|
if method == deployMethodName {
|
||||||
c.Command.Println("NNS contract is already deployed.")
|
c.Command.Println("NNS contract is already deployed.")
|
||||||
|
@ -112,28 +112,13 @@ func (c *initializeContext) deployNNS(method string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
params := getContractDeployParameters(cs, nil)
|
params := getContractDeployParameters(cs, nil)
|
||||||
signer := transaction.Signer{
|
|
||||||
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
}
|
|
||||||
|
|
||||||
invokeHash := management.Hash
|
invokeHash := management.Hash
|
||||||
if method == updateMethodName {
|
if method == updateMethodName {
|
||||||
invokeHash = nnsCs.Hash
|
invokeHash = nnsCs.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := invokeFunction(c.Client, invokeHash, method, params, []transaction.Signer{signer})
|
tx, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
|
||||||
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create deploy tx for %s: %w", nnsContract, err)
|
return fmt.Errorf("failed to create deploy tx for %s: %w", nnsContract, err)
|
||||||
}
|
}
|
||||||
|
@ -366,8 +351,9 @@ func (c *initializeContext) deployContracts() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) isUpdated(ctrHash util.Uint160, cs *contractState) bool {
|
func (c *initializeContext) isUpdated(ctrHash util.Uint160, cs *contractState) bool {
|
||||||
realCs, err := c.Client.GetContractStateByHash(ctrHash)
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
return err == nil && realCs.NEF.Checksum == cs.NEF.Checksum
|
realCs, err := r.GetContract(ctrHash)
|
||||||
|
return err == nil && realCs != nil && realCs.NEF.Checksum == cs.NEF.Checksum
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) getContract(ctrName string) *contractState {
|
func (c *initializeContext) getContract(ctrName string) *contractState {
|
||||||
|
@ -536,7 +522,8 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
||||||
case containerContract:
|
case containerContract:
|
||||||
// In case if NNS is updated multiple times, we can't calculate
|
// In case if NNS is updated multiple times, we can't calculate
|
||||||
// it's actual hash based on local data, thus query chain.
|
// it's actual hash based on local data, thus query chain.
|
||||||
nnsCs, err := c.Client.GetContractStateByID(1)
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("NNS is not yet deployed")
|
panic("NNS is not yet deployed")
|
||||||
}
|
}
|
||||||
|
@ -590,7 +577,8 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) {
|
func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) {
|
||||||
cs, err := c.Client.GetContractStateByID(1)
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
cs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("NNS is not yet deployed: %w", err)
|
return nil, fmt.Errorf("NNS is not yet deployed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
"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/management"
|
||||||
nnsClient "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
|
nnsClient "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/rpcclient/unwrap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
@ -30,7 +31,8 @@ const defaultExpirationTime = 10 * 365 * 24 * time.Hour / time.Second
|
||||||
const frostfsOpsEmail = "ops@frostfs.info"
|
const frostfsOpsEmail = "ops@frostfs.info"
|
||||||
|
|
||||||
func (c *initializeContext) setNNS() error {
|
func (c *initializeContext) setNNS() error {
|
||||||
nnsCs, err := c.Client.GetContractStateByID(1)
|
r := management.NewReader(c.ReadOnlyInvoker)
|
||||||
|
nnsCs, err := r.GetContractByID(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,17 @@ package morph
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"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/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/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"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/invoker"
|
"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/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/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"
|
||||||
|
@ -41,12 +44,12 @@ func (c *initializeContext) registerCandidateRange(start, end int) error {
|
||||||
panic(fmt.Sprintf("BUG: %v", w.Err))
|
panic(fmt.Sprintf("BUG: %v", w.Err))
|
||||||
}
|
}
|
||||||
|
|
||||||
signers := []rpcclient.SignerAccount{{
|
signers := []actor.SignerAccount{{
|
||||||
Signer: c.getSigner(false, c.CommitteeAcc),
|
Signer: c.getSigner(false, c.CommitteeAcc),
|
||||||
Account: c.CommitteeAcc,
|
Account: c.CommitteeAcc,
|
||||||
}}
|
}}
|
||||||
for _, acc := range c.Accounts[start:end] {
|
for _, acc := range c.Accounts[start:end] {
|
||||||
signers = append(signers, rpcclient.SignerAccount{
|
signers = append(signers, actor.SignerAccount{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: acc.Contract.ScriptHash(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CustomContracts,
|
Scopes: transaction.CustomContracts,
|
||||||
|
@ -56,7 +59,11 @@ func (c *initializeContext) registerCandidateRange(start, end int) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := c.Client.CreateTxFromScript(w.Bytes(), c.CommitteeAcc, -1, 0, signers)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create tx: %w", err)
|
return fmt.Errorf("can't create tx: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -134,8 +141,9 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) transferNEOFinished(neoHash util.Uint160) (bool, error) {
|
func (c *initializeContext) transferNEOFinished(neoHash util.Uint160) (bool, error) {
|
||||||
bal, err := c.Client.NEP17BalanceOf(neoHash, c.CommitteeAcc.Contract.ScriptHash())
|
r := nep17.NewReader(c.ReadOnlyInvoker, neoHash)
|
||||||
return bal < native.NEOTotalSupply, err
|
bal, err := r.BalanceOf(c.CommitteeAcc.Contract.ScriptHash())
|
||||||
|
return bal.Cmp(big.NewInt(native.NEOTotalSupply)) == -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var errGetPriceInvalid = errors.New("`getRegisterPrice`: invalid response")
|
var errGetPriceInvalid = errors.New("`getRegisterPrice`: invalid response")
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
contractsPath = "../../../../../../frostfs-contract/frostfs-contract-v0.16.0.tar.gz"
|
contractsPath = "../../../../../../contract/frostfs-contract-v0.18.0.tar.gz"
|
||||||
protoFileName = "proto.yml"
|
protoFileName = "proto.yml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,7 +58,9 @@ func testInitialize(t *testing.T, committeeSize int) {
|
||||||
|
|
||||||
// Set to the path or remove the next statement to download from the network.
|
// Set to the path or remove the next statement to download from the network.
|
||||||
require.NoError(t, initCmd.Flags().Set(contractsInitFlag, contractsPath))
|
require.NoError(t, initCmd.Flags().Set(contractsInitFlag, contractsPath))
|
||||||
v.Set(localDumpFlag, filepath.Join(testdataDir, "out"))
|
|
||||||
|
dumpPath := filepath.Join(testdataDir, "out")
|
||||||
|
require.NoError(t, initCmd.Flags().Set(localDumpFlag, dumpPath))
|
||||||
v.Set(alphabetWalletsFlag, testdataDir)
|
v.Set(alphabetWalletsFlag, testdataDir)
|
||||||
v.Set(epochDurationInitFlag, 1)
|
v.Set(epochDurationInitFlag, 1)
|
||||||
v.Set(maxObjectSizeInitFlag, 1024)
|
v.Set(maxObjectSizeInitFlag, 1024)
|
||||||
|
@ -67,12 +69,15 @@ func testInitialize(t *testing.T, committeeSize int) {
|
||||||
require.NoError(t, initializeSideChainCmd(initCmd, nil))
|
require.NoError(t, initializeSideChainCmd(initCmd, nil))
|
||||||
|
|
||||||
t.Run("force-new-epoch", func(t *testing.T) {
|
t.Run("force-new-epoch", func(t *testing.T) {
|
||||||
|
require.NoError(t, forceNewEpoch.Flags().Set(localDumpFlag, dumpPath))
|
||||||
require.NoError(t, forceNewEpochCmd(forceNewEpoch, nil))
|
require.NoError(t, forceNewEpochCmd(forceNewEpoch, nil))
|
||||||
})
|
})
|
||||||
t.Run("set-config", func(t *testing.T) {
|
t.Run("set-config", func(t *testing.T) {
|
||||||
|
require.NoError(t, setConfig.Flags().Set(localDumpFlag, dumpPath))
|
||||||
require.NoError(t, setConfigCmd(setConfig, []string{"MaintenanceModeAllowed=true"}))
|
require.NoError(t, setConfigCmd(setConfig, []string{"MaintenanceModeAllowed=true"}))
|
||||||
})
|
})
|
||||||
t.Run("set-policy", func(t *testing.T) {
|
t.Run("set-policy", func(t *testing.T) {
|
||||||
|
require.NoError(t, setPolicy.Flags().Set(localDumpFlag, dumpPath))
|
||||||
require.NoError(t, setPolicyCmd(setPolicy, []string{"ExecFeeFactor=1"}))
|
require.NoError(t, setPolicyCmd(setPolicy, []string{"ExecFeeFactor=1"}))
|
||||||
})
|
})
|
||||||
t.Run("remove-node", func(t *testing.T) {
|
t.Run("remove-node", func(t *testing.T) {
|
||||||
|
@ -80,6 +85,7 @@ func testInitialize(t *testing.T, committeeSize int) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
pub := hex.EncodeToString(pk.PublicKey().Bytes())
|
pub := hex.EncodeToString(pk.PublicKey().Bytes())
|
||||||
|
require.NoError(t, removeNodes.Flags().Set(localDumpFlag, dumpPath))
|
||||||
require.NoError(t, removeNodesCmd(removeNodes, []string{pub}))
|
require.NoError(t, removeNodesCmd(removeNodes, []string{pub}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,18 @@ package morph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"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/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"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/gas"
|
"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/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/smartcontract/callflag"
|
||||||
scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context"
|
scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context"
|
||||||
|
"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"
|
||||||
"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/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
@ -33,11 +36,11 @@ func (c *initializeContext) transferFunds() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var transfers []rpcclient.TransferTarget
|
var transfers []transferTarget
|
||||||
for _, acc := range c.Accounts {
|
for _, acc := range c.Accounts {
|
||||||
to := acc.Contract.ScriptHash()
|
to := acc.Contract.ScriptHash()
|
||||||
transfers = append(transfers,
|
transfers = append(transfers,
|
||||||
rpcclient.TransferTarget{
|
transferTarget{
|
||||||
Token: gas.Hash,
|
Token: gas.Hash,
|
||||||
Address: to,
|
Address: to,
|
||||||
Amount: initialAlphabetGASAmount,
|
Amount: initialAlphabetGASAmount,
|
||||||
|
@ -47,25 +50,19 @@ func (c *initializeContext) transferFunds() error {
|
||||||
|
|
||||||
// It is convenient to have all funds at the committee account.
|
// It is convenient to have all funds at the committee account.
|
||||||
transfers = append(transfers,
|
transfers = append(transfers,
|
||||||
rpcclient.TransferTarget{
|
transferTarget{
|
||||||
Token: gas.Hash,
|
Token: gas.Hash,
|
||||||
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
Amount: (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2,
|
Amount: (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2,
|
||||||
},
|
},
|
||||||
rpcclient.TransferTarget{
|
transferTarget{
|
||||||
Token: neo.Hash,
|
Token: neo.Hash,
|
||||||
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
Amount: native.NEOTotalSupply,
|
Amount: native.NEOTotalSupply,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
tx, err := createNEP17MultiTransferTx(c.Client, c.ConsensusAcc, 0, transfers, []rpcclient.SignerAccount{{
|
tx, err := createNEP17MultiTransferTx(c.Client, c.ConsensusAcc, transfers)
|
||||||
Signer: transaction.Signer{
|
|
||||||
Account: c.ConsensusAcc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
},
|
|
||||||
Account: c.ConsensusAcc,
|
|
||||||
}})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create transfer transaction: %w", err)
|
return fmt.Errorf("can't create transfer transaction: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -80,8 +77,9 @@ func (c *initializeContext) transferFunds() error {
|
||||||
func (c *initializeContext) transferFundsFinished() (bool, error) {
|
func (c *initializeContext) transferFundsFinished() (bool, error) {
|
||||||
acc := c.Accounts[0]
|
acc := c.Accounts[0]
|
||||||
|
|
||||||
res, err := c.Client.NEP17BalanceOf(gas.Hash, acc.Contract.ScriptHash())
|
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
||||||
return res > initialAlphabetGASAmount/2, err
|
res, err := r.BalanceOf(acc.Contract.ScriptHash())
|
||||||
|
return res.Cmp(big.NewInt(initialAlphabetGASAmount/2)) == 1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accType string) error {
|
func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accType string) error {
|
||||||
|
@ -93,12 +91,13 @@ func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) multiSign(tx *transaction.Transaction, accType string) error {
|
func (c *initializeContext) multiSign(tx *transaction.Transaction, accType string) error {
|
||||||
network, err := c.Client.GetNetwork()
|
version, err := c.Client.GetVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// error appears only if client
|
// error appears only if client
|
||||||
// has not been initialized
|
// has not been initialized
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
network := version.Protocol.Network
|
||||||
|
|
||||||
// Use parameter context to avoid dealing with signature order.
|
// Use parameter context to avoid dealing with signature order.
|
||||||
pc := scContext.NewParameterContext("", network, tx)
|
pc := scContext.NewParameterContext("", network, tx)
|
||||||
|
@ -146,16 +145,17 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin
|
||||||
func (c *initializeContext) transferGASToProxy() error {
|
func (c *initializeContext) transferGASToProxy() error {
|
||||||
proxyCs := c.getContract(proxyContract)
|
proxyCs := c.getContract(proxyContract)
|
||||||
|
|
||||||
bal, err := c.Client.NEP17BalanceOf(gas.Hash, proxyCs.Hash)
|
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
||||||
if err != nil || bal > 0 {
|
bal, err := r.BalanceOf(proxyCs.Hash)
|
||||||
|
if err != nil || bal.Sign() > 0 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := createNEP17MultiTransferTx(c.Client, c.CommitteeAcc, 0, []rpcclient.TransferTarget{{
|
tx, err := createNEP17MultiTransferTx(c.Client, c.CommitteeAcc, []transferTarget{{
|
||||||
Token: gas.Hash,
|
Token: gas.Hash,
|
||||||
Address: proxyCs.Hash,
|
Address: proxyCs.Hash,
|
||||||
Amount: initialProxyGASAmount,
|
Amount: initialProxyGASAmount,
|
||||||
}}, nil)
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,14 @@ func (c *initializeContext) transferGASToProxy() error {
|
||||||
return c.awaitTx()
|
return c.awaitTx()
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNEP17MultiTransferTx(c Client, acc *wallet.Account, netFee int64,
|
type transferTarget struct {
|
||||||
recipients []rpcclient.TransferTarget, cosigners []rpcclient.SignerAccount) (*transaction.Transaction, error) {
|
Token util.Uint160
|
||||||
|
Address util.Uint160
|
||||||
|
Amount int64
|
||||||
|
Data any
|
||||||
|
}
|
||||||
|
|
||||||
|
func createNEP17MultiTransferTx(c Client, acc *wallet.Account, recipients []transferTarget) (*transaction.Transaction, error) {
|
||||||
from := acc.Contract.ScriptHash()
|
from := acc.Contract.ScriptHash()
|
||||||
|
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
|
@ -180,11 +186,18 @@ func createNEP17MultiTransferTx(c Client, acc *wallet.Account, netFee int64,
|
||||||
if w.Err != nil {
|
if w.Err != nil {
|
||||||
return nil, fmt.Errorf("failed to create transfer script: %w", w.Err)
|
return nil, fmt.Errorf("failed to create transfer script: %w", w.Err)
|
||||||
}
|
}
|
||||||
return c.CreateTxFromScript(w.Bytes(), acc, -1, netFee, append([]rpcclient.SignerAccount{{
|
|
||||||
|
signers := []actor.SignerAccount{{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: from,
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
},
|
},
|
||||||
Account: acc,
|
Account: acc,
|
||||||
}}, cosigners...))
|
}}
|
||||||
|
|
||||||
|
act, err := actor.New(c, signers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't create actor: %w", err)
|
||||||
|
}
|
||||||
|
return act.MakeRun(w.Bytes())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,33 +10,28 @@ import (
|
||||||
|
|
||||||
"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"
|
||||||
|
@ -119,29 +114,10 @@ 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) {
|
|
||||||
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) {
|
func (l *localClient) GetNativeContracts() ([]state.NativeContract, error) {
|
||||||
return l.bc.GetNatives(), nil
|
return l.bc.GetNatives(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *localClient) GetNetwork() (netmode.Magic, error) {
|
|
||||||
return l.bc.GetConfig().Magic, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) GetApplicationLog(h util.Uint256, t *trigger.Type) (*result.ApplicationLog, error) {
|
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 {
|
||||||
|
@ -152,34 +128,6 @@ 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) {
|
|
||||||
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) {
|
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")
|
||||||
|
@ -200,21 +148,6 @@ 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) {
|
|
||||||
// not used by `morph init` command
|
|
||||||
panic("unexpected call")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *localClient) SignAndPushP2PNotaryRequest(_ *transaction.Transaction, _ []byte, _ int64, _ int64, _ uint32, _ *wallet.Account) (*payload.P2PNotaryRequest, 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) {
|
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")
|
||||||
|
@ -254,110 +187,76 @@ func (l *localClient) InvokeContractVerify(util.Uint160, []smartcontract.Paramet
|
||||||
|
|
||||||
// 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)
|
||||||
}
|
}
|
||||||
return bi.Int64(), nil
|
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)
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
|
|
@ -6,13 +6,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
|
||||||
"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,21 +26,12 @@ 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 {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
"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"
|
||||||
)
|
)
|
||||||
|
@ -14,8 +15,9 @@ func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) {
|
||||||
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 := nnsResolveHash(inv, cs.Hash, netmapContract+".frostfs")
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
||||||
"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"
|
||||||
|
@ -33,7 +34,8 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,6 +320,7 @@ func initSetConfigCmd() {
|
||||||
setConfig.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
setConfig.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
||||||
setConfig.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
setConfig.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
||||||
setConfig.Flags().Bool(forceConfigSet, false, "Force setting not well-known configuration key")
|
setConfig.Flags().Bool(forceConfigSet, false, "Force setting not well-known configuration key")
|
||||||
|
setConfig.Flags().String(localDumpFlag, "", "Path to the blocks dump file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDumpNetworkConfigCmd() {
|
func initDumpNetworkConfigCmd() {
|
||||||
|
@ -337,18 +338,21 @@ func initSetPolicyCmd() {
|
||||||
RootCmd.AddCommand(setPolicy)
|
RootCmd.AddCommand(setPolicy)
|
||||||
setPolicy.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
setPolicy.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
||||||
setPolicy.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
setPolicy.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
||||||
|
setPolicy.Flags().String(localDumpFlag, "", "Path to the blocks dump file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRemoveNodesCmd() {
|
func initRemoveNodesCmd() {
|
||||||
RootCmd.AddCommand(removeNodes)
|
RootCmd.AddCommand(removeNodes)
|
||||||
removeNodes.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
removeNodes.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
||||||
removeNodes.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
removeNodes.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
||||||
|
removeNodes.Flags().String(localDumpFlag, "", "Path to the blocks dump file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initForceNewEpochCmd() {
|
func initForceNewEpochCmd() {
|
||||||
RootCmd.AddCommand(forceNewEpoch)
|
RootCmd.AddCommand(forceNewEpoch)
|
||||||
forceNewEpoch.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
forceNewEpoch.Flags().String(alphabetWalletsFlag, "", "Path to alphabet wallets dir")
|
||||||
forceNewEpoch.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
forceNewEpoch.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
|
||||||
|
forceNewEpoch.Flags().String(localDumpFlag, "", "Path to the blocks dump file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGenerateStorageCmd() {
|
func initGenerateStorageCmd() {
|
||||||
|
|
|
@ -527,15 +527,6 @@ func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (val
|
||||||
return res.State == vmstate.Halt.String(), nil
|
return res.State == vmstate.Halt.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationChannel returns channel than receives subscribed
|
|
||||||
// notification from the connected RPC node.
|
|
||||||
// Channel is closed when connection to the RPC node is lost.
|
|
||||||
func (c *Client) NotificationChannel() <-chan rpcclient.Notification {
|
|
||||||
c.switchLock.RLock()
|
|
||||||
defer c.switchLock.RUnlock()
|
|
||||||
return c.client.Notifications //lint:ignore SA1019 waits for neo-go v0.102.0 https://github.com/nspcc-dev/neo-go/pull/2980
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) Metrics() morphmetrics.Register {
|
func (c *Client) Metrics() morphmetrics.Register {
|
||||||
return c.metrics
|
return c.metrics
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"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/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"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/rpcclient"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -183,8 +182,6 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
|
||||||
|
|
||||||
func (s *subscriber) routeNotifications(ctx context.Context) {
|
func (s *subscriber) routeNotifications(ctx context.Context) {
|
||||||
var (
|
var (
|
||||||
// TODO: not needed after nspcc-dev/neo-go#2980.
|
|
||||||
cliCh = s.client.NotificationChannel()
|
|
||||||
restoreCh = make(chan bool)
|
restoreCh = make(chan bool)
|
||||||
restoreInProgress bool
|
restoreInProgress bool
|
||||||
)
|
)
|
||||||
|
@ -220,8 +217,6 @@ routeloop:
|
||||||
} else {
|
} else {
|
||||||
connLost = true
|
connLost = true
|
||||||
}
|
}
|
||||||
case _, ok := <-cliCh:
|
|
||||||
connLost = !ok
|
|
||||||
case ok := <-restoreCh:
|
case ok := <-restoreCh:
|
||||||
restoreInProgress = false
|
restoreInProgress = false
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -230,7 +225,7 @@ routeloop:
|
||||||
}
|
}
|
||||||
if connLost {
|
if connLost {
|
||||||
if !restoreInProgress {
|
if !restoreInProgress {
|
||||||
restoreInProgress, cliCh = s.switchEndpoint(ctx, restoreCh)
|
restoreInProgress = s.switchEndpoint(ctx, restoreCh)
|
||||||
if !restoreInProgress {
|
if !restoreInProgress {
|
||||||
break routeloop
|
break routeloop
|
||||||
}
|
}
|
||||||
|
@ -249,15 +244,13 @@ routeloop:
|
||||||
close(s.notaryChan)
|
close(s.notaryChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) (bool, <-chan rpcclient.Notification) {
|
func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) bool {
|
||||||
s.log.Info(logs.RPConnectionLost)
|
s.log.Info(logs.RPConnectionLost)
|
||||||
if !s.client.SwitchRPC(ctx) {
|
if !s.client.SwitchRPC(ctx) {
|
||||||
s.log.Error(logs.RPCNodeSwitchFailure)
|
s.log.Error(logs.RPCNodeSwitchFailure)
|
||||||
return false, nil
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
cliCh := s.client.NotificationChannel()
|
|
||||||
|
|
||||||
s.Lock()
|
s.Lock()
|
||||||
chs := newSubChannels()
|
chs := newSubChannels()
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -267,7 +260,7 @@ func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) (
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
|
||||||
s.client.Metrics().IncSwitchCount()
|
s.client.Metrics().IncSwitchCount()
|
||||||
return true, cliCh
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSubChannels() subChannels {
|
func newSubChannels() subChannels {
|
||||||
|
|
Loading…
Reference in a new issue