morph: Cleanup InvocationScript before sign #776

Merged
fyrchik merged 1 commit from acid-ant/frostfs-node:bugfix/clean-inv-script into support/v0.37 2023-12-11 16:46:46 +00:00
5 changed files with 30 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import (
configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config" 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/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -67,6 +68,7 @@ func watchForSignal(cancel func()) {
if err != nil { if err != nil {
log.Error(logs.FrostFSNodeConfigurationReading, zap.Error(err)) log.Error(logs.FrostFSNodeConfigurationReading, zap.Error(err))
} }
client.KeepInvScript = cfg.GetBool("morph.keepinvscript")
log.Info(logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully) log.Info(logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
case syscall.SIGTERM, syscall.SIGINT: case syscall.SIGTERM, syscall.SIGINT:
log.Info(logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping) log.Info(logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)

View file

@ -10,6 +10,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/misc" "git.frostfs.info/TrueCloudLab/frostfs-node/misc"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring" "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" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/zap" "go.uber.org/zap"
@ -60,6 +61,7 @@ func main() {
var err error var err error
cfg, err = newConfig() cfg, err = newConfig()
exitErr(err) exitErr(err)
client.KeepInvScript = cfg.GetBool("morph.keepinvscript")
logPrm.MetricsNamespace = "frostfs_ir" logPrm.MetricsNamespace = "frostfs_ir"
err = logPrm.SetLevelString( err = logPrm.SetLevelString(

View file

@ -24,6 +24,7 @@ import (
blobovniczaconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza" 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" 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" 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" nodeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/node"
objectconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/object" objectconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/object"
replicatorconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/replicator" 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.lowMem = engineconfig.EngineLowMemoryConsumption(c)
a.EngineCfg.rebuildWorkers = engineconfig.EngineRebuildWorkersCount(c) a.EngineCfg.rebuildWorkers = engineconfig.EngineRebuildWorkersCount(c)
// Kludge
client.KeepInvScript = morphconfig.KeepInvocationScript(c)
Review

Do we read this with SIGHUP? Could be a data race.

Do we read this with SIGHUP? Could be a data race.
Review

Yes, we read it at SIGHUP too, and yes it is possible for data race. But we use this variable when react on events which happens not so far. Also, when system upgraded, it works in both scenarios as I remember - when kludged enabled/disabled.

Yes, we read it at SIGHUP too, and yes it is possible for data race. But we use this variable when react on events which happens not so far. Also, when system upgraded, it works in both scenarios as I remember - when kludged enabled/disabled.
return engineconfig.IterateShards(c, false, func(sc *shardconfig.Config) error { return a.updateShardConfig(c, sc) }) return engineconfig.IterateShards(c, false, func(sc *shardconfig.Config) error { return a.updateShardConfig(c, sc) })
} }

View file

@ -97,3 +97,8 @@ func SwitchInterval(c *config.Config) time.Duration {
return SwitchIntervalDefault 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")
}

View file

@ -67,6 +67,9 @@ const (
var errUnexpectedItems = errors.New("invalid number of NEO VM arguments on stack") 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 { func defaultNotaryConfig(c *Client) *notaryCfg {
return &notaryCfg{ return &notaryCfg{
txValidTime: defaultNotaryValidTime, txValidTime: defaultNotaryValidTime,
@ -418,6 +421,20 @@ func (c *Client) NotarySignAndInvokeTX(mainTx *transaction.Transaction) error {
return err return err
fyrchik marked this conversation as resolved Outdated

Can we mention that this is a kludge purely for update to work?

Can we mention that this is a kludge purely for update to work?

Updated.

Updated.
} }
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. // Sign exactly the same transaction we've got from the received Notary request.
err = nAct.Sign(mainTx) err = nAct.Sign(mainTx)
if err != nil { if err != nil {