morph: Introduce switch rpc guarded rpc actor #925

Merged
fyrchik merged 1 commit from aarifullin/frostfs-node:fix/rpc-actor-guard into master 2024-01-25 13:24:18 +00:00
2 changed files with 121 additions and 1 deletions

View file

@ -1061,7 +1061,7 @@ func initAccessPolicyEngine(_ context.Context, c *cfg) {
} }
morphRuleStorage := policy_client.NewContractStorage( morphRuleStorage := policy_client.NewContractStorage(
c.cfgMorph.client.GetActor(), client.NewSwitchRPCGuardedActor(c.cfgMorph.client),
c.cfgObject.cfgAccessPolicyEngine.policyContractHash) c.cfgObject.cfgAccessPolicyEngine.policyContractHash)
ape := newAccessPolicyEngine(morphRuleStorage, localOverrideDB) ape := newAccessPolicyEngine(morphRuleStorage, localOverrideDB)

120
pkg/morph/client/actor.go Normal file
View file

@ -0,0 +1,120 @@
package client
import (
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"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/util"
)
type actorProvider interface {
GetActor() *actor.Actor
}
// Client switches an established connection with neo-go if it is broken.
// This leads to an invalidation of an rpc actor within Client. That means the
// components that are initilized with the rpc actor may unintentionally use
// it when it is already invalidated. SwitchRPCGuardedActor is used to prevent
// this situation, getting the rpc actor from Client.
type SwitchRPCGuardedActor struct {
actorProvider actorProvider
}
func NewSwitchRPCGuardedActor(c *Client) *SwitchRPCGuardedActor {
return &SwitchRPCGuardedActor{
actorProvider: c,
}
}
func (a *SwitchRPCGuardedActor) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) {
return a.actorProvider.GetActor().Call(contract, operation, params...)
}
func (a *SwitchRPCGuardedActor) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
return a.actorProvider.GetActor().CalculateNetworkFee(tx)
}
func (a *SwitchRPCGuardedActor) CalculateValidUntilBlock() (uint32, error) {
return a.actorProvider.GetActor().CalculateValidUntilBlock()
}
func (a *SwitchRPCGuardedActor) GetBlockCount() (uint32, error) {
return a.actorProvider.GetActor().GetBlockCount()
}
func (a *SwitchRPCGuardedActor) GetNetwork() netmode.Magic {
return a.actorProvider.GetActor().GetNetwork()
}
func (a *SwitchRPCGuardedActor) GetVersion() result.Version {
return a.actorProvider.GetActor().GetVersion()
}
func (a *SwitchRPCGuardedActor) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeCall(contract, method, params...)
}
func (a *SwitchRPCGuardedActor) MakeRun(script []byte) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeRun(script)
}
func (a *SwitchRPCGuardedActor) MakeTunedCall(contract util.Uint160, method string, attrs []transaction.Attribute, txHook actor.TransactionCheckerModifier, params ...any) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeTunedCall(contract, method, attrs, txHook, params...)
}
func (a *SwitchRPCGuardedActor) MakeTunedRun(script []byte, attrs []transaction.Attribute, txHook actor.TransactionCheckerModifier) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeTunedRun(script, attrs, txHook)
}
func (a *SwitchRPCGuardedActor) MakeUncheckedRun(script []byte, sysfee int64, attrs []transaction.Attribute, txHook actor.TransactionModifier) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeUncheckedRun(script, sysfee, attrs, txHook)
}
func (a *SwitchRPCGuardedActor) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeUnsignedCall(contract, method, attrs, params...)
}
func (a *SwitchRPCGuardedActor) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeUnsignedRun(script, attrs)
}
func (a *SwitchRPCGuardedActor) MakeUnsignedUncheckedRun(script []byte, sysFee int64, attrs []transaction.Attribute) (*transaction.Transaction, error) {
return a.actorProvider.GetActor().MakeUnsignedUncheckedRun(script, sysFee, attrs)
}
func (a *SwitchRPCGuardedActor) Send(tx *transaction.Transaction) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().Send(tx)
}
func (a *SwitchRPCGuardedActor) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().SendCall(contract, method, params...)
}
func (a *SwitchRPCGuardedActor) SendRun(script []byte) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().SendRun(script)
}
func (a *SwitchRPCGuardedActor) SendTunedCall(contract util.Uint160, method string, attrs []transaction.Attribute, txHook actor.TransactionCheckerModifier, params ...any) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().SendTunedCall(contract, method, attrs, txHook, params...)
}
func (a *SwitchRPCGuardedActor) SendTunedRun(script []byte, attrs []transaction.Attribute, txHook actor.TransactionCheckerModifier) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().SendTunedRun(script, attrs, txHook)
}
func (a *SwitchRPCGuardedActor) SendUncheckedRun(script []byte, sysfee int64, attrs []transaction.Attribute, txHook actor.TransactionModifier) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().SendUncheckedRun(script, sysfee, attrs, txHook)
}
func (a *SwitchRPCGuardedActor) Sender() util.Uint160 {
return a.actorProvider.GetActor().Sender()
}
func (a *SwitchRPCGuardedActor) Sign(tx *transaction.Transaction) error {
return a.actorProvider.GetActor().Sign(tx)
}
func (a *SwitchRPCGuardedActor) SignAndSend(tx *transaction.Transaction) (util.Uint256, uint32, error) {
return a.actorProvider.GetActor().SignAndSend(tx)
}