Skip to content

Commit

Permalink
sidechain/deploy: Make contracts' update transactions valid for an epoch
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cthulhu-rider committed Nov 10, 2023
1 parent 073754c commit 3dad944
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/innerring/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package innerring
import (
"encoding/json"
"fmt"
"math"
"sync"

"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/morph/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"sort"
"strconv"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3dad944

Please sign in to comment.