[#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 <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-11-01 14:57:23 +03:00
parent 08fdab7bc7
commit 7d9fe03f28
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"
"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)

View file

@ -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(

View file

@ -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) })
}

View file

@ -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")
}

View file

@ -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 &notaryCfg{
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 {