From 3dad944a2e4a34ae89aae7d44a0c23e5118a6f80 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 23 Oct 2023 12:37:48 +0400 Subject: [PATCH] sidechain/deploy: Make contracts' update transactions valid for an epoch Previously, updating transactions of the NeoFS smart contracts (calling `update` method) were sent with ValidUntilBlock set to last epoch block + 100 by the sidechain auto-deployment procedure. This could cause the update idleness when epoch duration was more than 100 Sidechain blocks. To prevent this, the transaction should be valid at least one epoch time. Refs #2195. Signed-off-by: Leonard Lyubich --- pkg/innerring/deploy.go | 12 ++++++++++++ pkg/morph/deploy/deploy.go | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/innerring/deploy.go b/pkg/innerring/deploy.go index 3af20bcba4..ab4caf270d 100644 --- a/pkg/innerring/deploy.go +++ b/pkg/innerring/deploy.go @@ -3,6 +3,7 @@ package innerring import ( "encoding/json" "fmt" + "math" "sync" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -66,6 +67,17 @@ func (x *neoFSSidechain) CurrentState() (deploy.NeoFSState, error) { return res, fmt.Errorf("get last epoch block from Netmap contract: %w", err) } + epochDur, err := netmapContract.EpochDuration() + if err != nil { + return res, fmt.Errorf("get epoch duration from Netmap contract: %w", err) + } + + if epochDur > math.MaxUint32 { + return res, fmt.Errorf("epoch duration from Netmap contract overflows uint32: %d", epochDur) + } + + res.EpochDuration = uint32(epochDur) + return res, nil } diff --git a/pkg/morph/deploy/deploy.go b/pkg/morph/deploy/deploy.go index d2ddd408e5..f2891c8df2 100644 --- a/pkg/morph/deploy/deploy.go +++ b/pkg/morph/deploy/deploy.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "math" "math/big" "sort" "strconv" @@ -78,6 +79,8 @@ type NeoFSState struct { CurrentEpoch uint64 // Height of the NeoFS Sidechain at which CurrentEpoch began. CurrentEpochBlock uint32 + // Duration of the single NeoFS epoch measured in Sidechain blocks. + EpochDuration uint32 } // NeoFS provides access to the running NeoFS network. @@ -773,7 +776,11 @@ func neoFSRuntimeTransactionModifier(neoFS NeoFS) actor.TransactionCheckerModifi } tx.Nonce = uint32(neoFSState.CurrentEpoch) - tx.ValidUntilBlock = neoFSState.CurrentEpochBlock + 100 + if math.MaxUint32-neoFSState.CurrentEpochBlock > neoFSState.EpochDuration { + tx.ValidUntilBlock = neoFSState.CurrentEpochBlock + neoFSState.EpochDuration + } else { + tx.ValidUntilBlock = math.MaxUint32 + } return nil }