From 20baf6e112e8e91a06a372c78e0f4d5604f2b282 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Fri, 26 Apr 2024 17:27:56 +0300 Subject: [PATCH] [#1108] ape: Update policy-engine version for listing by iteration * Update go.mod with a new version of policy-engine pacakge. * Adapt SwitchRPCGuardedActor to ContractStorage interface. * Fix `frostfs-adm` util. Signed-off-by: Airat Arifullin --- .../internal/modules/morph/ape/ape_util.go | 17 ++++++++++++++++- .../internal/modules/morph/helper/actor.go | 18 ++++++++++++------ go.mod | 4 ++-- go.sum | Bin 43435 -> 43495 bytes pkg/morph/client/actor.go | 10 ++++++++++ pkg/morph/client/client.go | 7 +++++++ 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go b/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go index 42307e78f..dfa7c6392 100644 --- a/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go +++ b/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go @@ -98,6 +98,16 @@ func parseChainName(cmd *cobra.Command) apechain.Name { return apeChainName } +// invokerAdapter adapats invoker.Invoker to ContractStorageInvoker interface. +type invokerAdapter struct { + *invoker.Invoker + rpcActor invoker.RPCInvoke +} + +func (n *invokerAdapter) GetRPCInvoker() invoker.RPCInvoke { + return n.rpcActor +} + func newPolicyContractReaderInterface(cmd *cobra.Command) (*morph.ContractStorageReader, *invoker.Invoker) { c, err := helper.GetN3Client(viper.GetViper()) commonCmd.ExitOnErr(cmd, "unable to create NEO rpc client: %w", err) @@ -111,7 +121,12 @@ func newPolicyContractReaderInterface(cmd *cobra.Command) (*morph.ContractStorag ch, err = helper.NNSResolveHash(inv, nnsCs.Hash, helper.DomainOf(constants.PolicyContract)) commonCmd.ExitOnErr(cmd, "unable to resolve policy contract hash: %w", err) - return morph.NewContractStorageReader(inv, ch), inv + invokerAdapter := &invokerAdapter{ + Invoker: inv, + rpcActor: c, + } + + return morph.NewContractStorageReader(invokerAdapter, ch), inv } func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *helper.LocalActor) { diff --git a/cmd/frostfs-adm/internal/modules/morph/helper/actor.go b/cmd/frostfs-adm/internal/modules/morph/helper/actor.go index f920aa5ba..1ca246f9f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/helper/actor.go +++ b/cmd/frostfs-adm/internal/modules/morph/helper/actor.go @@ -23,9 +23,10 @@ import ( // LocalActor is a kludge, do not use it outside of the morph commands. type LocalActor struct { - neoActor *actor.Actor - accounts []*wallet.Account - Invoker *invoker.Invoker + neoActor *actor.Actor + accounts []*wallet.Account + Invoker *invoker.Invoker + rpcInvoker invoker.RPCInvoke } // NewLocalActor create LocalActor with accounts form provided wallets. @@ -68,9 +69,10 @@ func NewLocalActor(cmd *cobra.Command, c actor.RPCActor) (*LocalActor, error) { } } return &LocalActor{ - neoActor: act, - accounts: accounts, - Invoker: &act.Invoker, + neoActor: act, + accounts: accounts, + Invoker: &act.Invoker, + rpcInvoker: c, }, nil } @@ -167,3 +169,7 @@ func (a *LocalActor) MakeUnsignedRun(_ []byte, _ []transaction.Attribute) (*tran func (a *LocalActor) MakeCall(_ util.Uint160, _ string, _ ...any) (*transaction.Transaction, error) { panic("unimplemented") } + +func (a *LocalActor) GetRPCInvoker() invoker.RPCInvoke { + return a.rpcInvoker +} diff --git a/go.mod b/go.mod index 08a59581d..142ce02cc 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.21 require ( code.gitea.io/sdk/gitea v0.17.1 git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240427200446-67c6f305b21f - git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.0 + git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.3-0.20240409111539-e7a05a49ff45 git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240507063414-99e02858af12 git.frostfs.info/TrueCloudLab/hrw v1.2.1 - git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20240412130734-0e69e485115a + git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20240426062043-c5397286410f git.frostfs.info/TrueCloudLab/tzhash v1.8.0 git.frostfs.info/TrueCloudLab/zapjournald v0.0.0-20240124114243-cb2e66427d02 github.com/cheggaaa/pb v1.0.29 diff --git a/go.sum b/go.sum index 6200022c7134e6ceb478cf0db641b73a6d6bd15b..241e25d8fc56259b9a3eb1ce64017d51034afdb9 100644 GIT binary patch delta 291 zcmZ2|nd$jurVZ~I{fu=D^o$IQObkp6EDa3}O^q#eQ_T|%OcPBk)6z^#6*3I1LJCYg zwIlp}3XH>?z5IjHDuNSp152`ugQEOAgOd_{d`-e#Ofx;JA}Z1+e`L~}?7_q*Pr%sC z;Y^||E=FbsW<~}k#=6NsYt4-;%uEao(m*y=X*(8%6=a2bMulZq8m4-dXy-VEcpEyF zhnHj-xjL0;N4gpXczKtVm1a*iWV80hYLI?<$j@l7c`}nIi;JO=p|OFvv5Brhs+nb~iG``5p=lz>%<`nX z6z?*Rq;i+Q%wXTZa36Eipo+|pDCgABO6N>-ztAkhoZ_?;NB8VxpqUDjd)cJDu^OhI zp0Agip8_(|L*Fsn!ZfHPvLY-bDLK8|Bi!7~r7$AZJEu6)+0#GOFTx|Bu+qh;C@paE Nd3L?c3)tNk0RWB}N|OKp diff --git a/pkg/morph/client/actor.go b/pkg/morph/client/actor.go index 8c283a672..b6718dea5 100644 --- a/pkg/morph/client/actor.go +++ b/pkg/morph/client/actor.go @@ -6,12 +6,14 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/neorpc/result" "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/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) type actorProvider interface { GetActor() *actor.Actor + GetRPCActor() actor.RPCActor } // Client switches an established connection with neo-go if it is broken. @@ -132,3 +134,11 @@ func (a *SwitchRPCGuardedActor) TerminateSession(sessionID uuid.UUID) error { func (a *SwitchRPCGuardedActor) TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error) { return a.actorProvider.GetActor().TraverseIterator(sessionID, iterator, num) } + +func (a *SwitchRPCGuardedActor) GetRPCActor() actor.RPCActor { + return a.actorProvider.GetRPCActor() +} + +func (a *SwitchRPCGuardedActor) GetRPCInvoker() invoker.RPCInvoke { + return a.actorProvider.GetRPCActor() +} diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 2570bc2c9..c9f819f04 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -579,3 +579,10 @@ func (c *Client) GetActor() *actor.Actor { return c.rpcActor } + +func (c *Client) GetRPCActor() actor.RPCActor { + c.switchLock.RLock() + defer c.switchLock.RUnlock() + + return c.client +}