From 7d9fe03f28ae64c81a8be5ac6fbae90b5a96edee Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Wed, 1 Nov 2023 14:57:23 +0300 Subject: [PATCH] [#776] morph: Cleanup `InvocationScript` before sign Necessary to skip check on the neo-go side. This is a kludge purely for update to work. Signed-off-by: Anton Nikiforov --- cmd/frostfs-ir/config.go | 2 ++ cmd/frostfs-ir/main.go | 2 ++ cmd/frostfs-node/config.go | 4 ++++ cmd/frostfs-node/config/morph/config.go | 5 +++++ pkg/morph/client/notary.go | 17 +++++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/cmd/frostfs-ir/config.go b/cmd/frostfs-ir/config.go index 54c7d18e3..0e1c5567c 100644 --- a/cmd/frostfs-ir/config.go +++ b/cmd/frostfs-ir/config.go @@ -7,6 +7,7 @@ import ( configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client" "github.com/spf13/viper" "go.uber.org/zap" ) @@ -67,6 +68,7 @@ func watchForSignal(cancel func()) { if err != nil { log.Error(logs.FrostFSNodeConfigurationReading, zap.Error(err)) } + client.KeepInvScript = cfg.GetBool("morph.keepinvscript") log.Info(logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully) case syscall.SIGTERM, syscall.SIGINT: log.Info(logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping) diff --git a/cmd/frostfs-ir/main.go b/cmd/frostfs-ir/main.go index 70199b094..d1b1fc5fb 100644 --- a/cmd/frostfs-ir/main.go +++ b/cmd/frostfs-ir/main.go @@ -10,6 +10,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-node/misc" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "github.com/spf13/viper" "go.uber.org/zap" @@ -60,6 +61,7 @@ func main() { var err error cfg, err = newConfig() exitErr(err) + client.KeepInvScript = cfg.GetBool("morph.keepinvscript") logPrm.MetricsNamespace = "frostfs_ir" err = logPrm.SetLevelString( diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 51d39c22b..1a591de32 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -24,6 +24,7 @@ import ( blobovniczaconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza" fstreeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/fstree" loggerconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/logger" + morphconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/morph" nodeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/node" objectconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/object" replicatorconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/replicator" @@ -212,6 +213,9 @@ func (a *applicationConfiguration) readConfig(c *config.Config) error { a.EngineCfg.lowMem = engineconfig.EngineLowMemoryConsumption(c) a.EngineCfg.rebuildWorkers = engineconfig.EngineRebuildWorkersCount(c) + // Kludge + client.KeepInvScript = morphconfig.KeepInvocationScript(c) + return engineconfig.IterateShards(c, false, func(sc *shardconfig.Config) error { return a.updateShardConfig(c, sc) }) } diff --git a/cmd/frostfs-node/config/morph/config.go b/cmd/frostfs-node/config/morph/config.go index 4ab608ef3..2384ad7fb 100644 --- a/cmd/frostfs-node/config/morph/config.go +++ b/cmd/frostfs-node/config/morph/config.go @@ -97,3 +97,8 @@ func SwitchInterval(c *config.Config) time.Duration { return SwitchIntervalDefault } + +// KeepInvocationScript this is a kludge purely for update to work. +func KeepInvocationScript(c *config.Config) bool { + return config.Bool(c.Sub(subsection), "keepinvscript") +} diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index 17644361a..817a9f498 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -67,6 +67,9 @@ const ( var errUnexpectedItems = errors.New("invalid number of NEO VM arguments on stack") +// This is a kludge purely for update to work. +var KeepInvScript bool + func defaultNotaryConfig(c *Client) *notaryCfg { return ¬aryCfg{ txValidTime: defaultNotaryValidTime, @@ -418,6 +421,20 @@ func (c *Client) NotarySignAndInvokeTX(mainTx *transaction.Transaction) error { return err } + if !KeepInvScript { + // This is necessary to suppress this check on neo-go side: + // https://github.com/nspcc-dev/neo-go/blob/8ed6d97085d3229d4faf56a47bbd6cf73c132a76/pkg/services/notary/notary.go#L538 + // This is a kludge purely for update to work. + for i := range mainTx.Signers { + for _, sig := range cosigners { + if mainTx.Signers[i].Account.Equals(sig.Account.ScriptHash()) { + mainTx.Scripts[i].InvocationScript = []byte{} + break + } + } + } + } + // Sign exactly the same transaction we've got from the received Notary request. err = nAct.Sign(mainTx) if err != nil {