forked from TrueCloudLab/frostfs-node
[#1294] neofs-adm: Use Global scope where needed
Provide explicit argument to `sendCommitteeTx` signifying whether a tx should try to use group signer. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
7d670129c9
commit
82fda42316
9 changed files with 22 additions and 19 deletions
|
@ -190,7 +190,7 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
|
||||||
panic(bw.Err)
|
panic(bw.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func forceNewEpochCmd(cmd *cobra.Command, args []string) error {
|
||||||
// transaction locally.
|
// transaction locally.
|
||||||
bw := io.NewBufBinWriter()
|
bw := io.NewBufBinWriter()
|
||||||
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
|
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) 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(), -1); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,8 +250,8 @@ func (c *initializeContext) nnsContractState() (*state.Contract, error) {
|
||||||
return cs, nil
|
return cs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) getSigner() transaction.Signer {
|
func (c *initializeContext) getSigner(tryGroup bool) transaction.Signer {
|
||||||
if c.groupKey != nil {
|
if tryGroup && c.groupKey != nil {
|
||||||
return transaction.Signer{
|
return transaction.Signer{
|
||||||
Scopes: transaction.CustomGroups,
|
Scopes: transaction.CustomGroups,
|
||||||
AllowedGroups: keys.PublicKeys{c.groupKey},
|
AllowedGroups: keys.PublicKeys{c.groupKey},
|
||||||
|
@ -263,6 +263,10 @@ func (c *initializeContext) getSigner() transaction.Signer {
|
||||||
Scopes: transaction.Global, // Scope is important, as we have nested call to container contract.
|
Scopes: transaction.Global, // Scope is important, as we have nested call to container contract.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !tryGroup {
|
||||||
|
return signer
|
||||||
|
}
|
||||||
|
|
||||||
nnsCs, err := c.nnsContractState()
|
nnsCs, err := c.nnsContractState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return signer
|
return signer
|
||||||
|
@ -325,9 +329,12 @@ loop:
|
||||||
return retErr
|
return retErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) sendCommitteeTx(script []byte, sysFee int64) error {
|
// sendCommitteeTx creates transaction from script and sends it to RPC.
|
||||||
|
// If sysFee is -1, it is calculated automatically. If tryGroup is false,
|
||||||
|
// global scope is used for the signer (useful when working with native contracts).
|
||||||
|
func (c *initializeContext) sendCommitteeTx(script []byte, sysFee int64, tryGroup bool) error {
|
||||||
tx, err := c.Client.CreateTxFromScript(script, c.CommitteeAcc, sysFee, 0, []client.SignerAccount{{
|
tx, err := c.Client.CreateTxFromScript(script, c.CommitteeAcc, sysFee, 0, []client.SignerAccount{{
|
||||||
Signer: c.getSigner(),
|
Signer: c.getSigner(tryGroup),
|
||||||
Account: c.CommitteeAcc,
|
Account: c.CommitteeAcc,
|
||||||
}})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -278,7 +278,7 @@ func (c *initializeContext) updateContracts() error {
|
||||||
c.Command.Printf("NNS: Set %s -> %s\n", morphClient.NNSGroupKeyName, hex.EncodeToString(groupKey.Bytes()))
|
c.Command.Printf("NNS: Set %s -> %s\n", morphClient.NNSGroupKeyName, hex.EncodeToString(groupKey.Bytes()))
|
||||||
|
|
||||||
totalGasCost += sysFee
|
totalGasCost += sysFee
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), totalGasCost); err != nil {
|
if err := c.sendCommitteeTx(w.Bytes(), totalGasCost, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.awaitTx()
|
return c.awaitTx()
|
||||||
|
@ -360,7 +360,7 @@ func (c *initializeContext) deployContracts() error {
|
||||||
return fmt.Errorf("can't deploy %s contract: %s", ctrName, res.FaultException)
|
return fmt.Errorf("can't deploy %s contract: %s", ctrName, res.FaultException)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(res.Script, res.GasConsumed); err != nil {
|
if err := c.sendCommitteeTx(res.Script, res.GasConsumed, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (c *initializeContext) setNNS() error {
|
||||||
"neofs", c.CommitteeAcc.Contract.ScriptHash(),
|
"neofs", c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(604800), int64(3600))
|
"ops@nspcc.ru", int64(3600), int64(600), int64(604800), int64(3600))
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
if err := c.sendCommitteeTx(bw.Bytes(), -1); err != nil {
|
if err := c.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
||||||
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
||||||
}
|
}
|
||||||
if err := c.awaitTx(); err != nil {
|
if err := c.awaitTx(); err != nil {
|
||||||
|
@ -86,7 +86,7 @@ func (c *initializeContext) updateNNSGroup(nnsHash util.Uint160, pub *keys.Publi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.sendCommitteeTx(bw.Bytes(), sysFee)
|
return c.sendCommitteeTx(bw.Bytes(), sysFee, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) emitUpdateNNSGroupScript(bw *io.BufBinWriter, nnsHash util.Uint160, pub *keys.PublicKey) (int64, error) {
|
func (c *initializeContext) emitUpdateNNSGroupScript(bw *io.BufBinWriter, nnsHash util.Uint160, pub *keys.PublicKey) (int64, error) {
|
||||||
|
@ -161,7 +161,7 @@ func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sysFee := int64(defaultRegisterSysfee + native.GASFactor)
|
sysFee := int64(defaultRegisterSysfee + native.GASFactor)
|
||||||
return c.sendCommitteeTx(script, sysFee)
|
return c.sendCommitteeTx(script, sysFee, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160) (bool, error) {
|
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160) (bool, error) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error {
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(bw.Bytes(), -1); err != nil {
|
if err := c.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
||||||
emit.AppCall(w.BinWriter, designateHash, "designateAsRole",
|
emit.AppCall(w.BinWriter, designateHash, "designateAsRole",
|
||||||
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), -1); err != nil {
|
if err := c.sendCommitteeTx(w.Bytes(), -1, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,7 @@ func setPolicyCmd(cmd *cobra.Command, args []string) error {
|
||||||
emit.AppCall(bw.BinWriter, policyHash, "set"+kv[0], callflag.All, int64(value))
|
emit.AppCall(bw.BinWriter, policyHash, "set"+kv[0], callflag.All, int64(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset group key to use `Global` signer scope. This function is unusual, because we
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
|
||||||
// work with native contract, not NeoFS one.
|
|
||||||
wCtx.groupKey = nil
|
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue