Skip to content

Commit

Permalink
- new vm common
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Jan 16, 2024
1 parent 0876737 commit cd71db6
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@
# AutoBalanceDataTriesEnableEpoch represents the epoch when the data tries are automatically balanced by inserting at the hashed key instead of the normal key
AutoBalanceDataTriesEnableEpoch = 1

# MigrateDataTrieEnableEpoch represents the epoch when the data tries migration is enabled
MigrateDataTrieEnableEpoch = 999999

# KeepExecOrderOnCreatedSCRsEnableEpoch represents the epoch when the execution order of created SCRs is ensured
KeepExecOrderOnCreatedSCRsEnableEpoch = 1

Expand Down
1 change: 1 addition & 0 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) {
handler.setFlagValue(epoch >= handler.enableEpochsConfig.NFTStopCreateEnableEpoch, handler.nftStopCreateFlag, "nftStopCreateFlag", epoch, handler.enableEpochsConfig.NFTStopCreateEnableEpoch)
handler.setFlagValue(epoch >= handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch, handler.changeOwnerAddressCrossShardThroughSCFlag, "changeOwnerAddressCrossShardThroughSCFlag", epoch, handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch)
handler.setFlagValue(epoch >= handler.enableEpochsConfig.FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch, handler.fixGasRemainingForSaveKeyValueFlag, "fixGasRemainingForSaveKeyValueFlag", epoch, handler.enableEpochsConfig.FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch)
handler.setFlagValue(epoch >= handler.enableEpochsConfig.MigrateDataTrieEnableEpoch, handler.migrateDataTrieFlag, "migrateDataTrieFlag", epoch, handler.enableEpochsConfig.MigrateDataTrieEnableEpoch)
}

func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string, epoch uint32, flagEpoch uint32) {
Expand Down
16 changes: 16 additions & 0 deletions common/enablers/enableEpochsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func createEnableEpochsConfig() config.EnableEpochs {
ScToScLogEventEnableEpoch: 88,
NFTStopCreateEnableEpoch: 89,
FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch: 90,
MigrateDataTrieEnableEpoch: 91,
}
}

Expand Down Expand Up @@ -251,6 +252,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) {
assert.True(t, handler.FixDelegationChangeOwnerOnAccountEnabled())
assert.True(t, handler.NFTStopCreateEnabled())
assert.True(t, handler.FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled())
assert.True(t, handler.IsMigrateDataTrieEnabled())
})
t.Run("flags with == condition should not be set, the ones with >= should be set", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -372,6 +374,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) {
assert.True(t, handler.FixDelegationChangeOwnerOnAccountEnabled())
assert.True(t, handler.NFTStopCreateEnabled())
assert.True(t, handler.FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled())
assert.True(t, handler.IsMigrateDataTrieEnabled())
})
t.Run("flags with < should be set", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -488,6 +491,19 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) {
assert.False(t, handler.FixDelegationChangeOwnerOnAccountEnabled())
assert.False(t, handler.NFTStopCreateEnabled())
assert.False(t, handler.FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled())
assert.False(t, handler.IsMigrateDataTrieEnabled())
})
t.Run("test for migrate data tries", func(t *testing.T) {
t.Parallel()

epoch := uint32(90)
cfg := createEnableEpochsConfig()
handler, _ := NewEnableEpochsHandler(cfg, &epochNotifier.EpochNotifierStub{})

handler.EpochConfirmed(epoch, 0)

assert.True(t, handler.IsAutoBalanceDataTriesEnabled())
assert.False(t, handler.IsMigrateDataTrieEnabled())
})
}

Expand Down
7 changes: 7 additions & 0 deletions common/enablers/epochFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type epochFlagsHolder struct {
changeUsernameFlag *atomic.Flag
consistentTokensValuesCheckFlag *atomic.Flag
autoBalanceDataTriesFlag *atomic.Flag
migrateDataTrieFlag *atomic.Flag
fixDelegationChangeOwnerOnAccountFlag *atomic.Flag
dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag
nftStopCreateFlag *atomic.Flag
Expand Down Expand Up @@ -209,6 +210,7 @@ func newEpochFlagsHolder() *epochFlagsHolder {
nftStopCreateFlag: &atomic.Flag{},
changeOwnerAddressCrossShardThroughSCFlag: &atomic.Flag{},
fixGasRemainingForSaveKeyValueFlag: &atomic.Flag{},
migrateDataTrieFlag: &atomic.Flag{},
}
}

Expand Down Expand Up @@ -740,6 +742,11 @@ func (holder *epochFlagsHolder) IsAutoBalanceDataTriesEnabled() bool {
return holder.autoBalanceDataTriesFlag.IsSet()
}

// IsMigrateDataTrieEnabled returns true if the migrateDataTrieFlag is enabled
func (holder *epochFlagsHolder) IsMigrateDataTrieEnabled() bool {
return holder.migrateDataTrieFlag.IsSet()
}

// FixDelegationChangeOwnerOnAccountEnabled returns true if the fix for the delegation change owner on account is enabled
func (holder *epochFlagsHolder) FixDelegationChangeOwnerOnAccountEnabled() bool {
return holder.fixDelegationChangeOwnerOnAccountFlag.IsSet()
Expand Down
1 change: 1 addition & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ type EnableEpochsHandler interface {
IsChangeUsernameEnabled() bool
IsConsistentTokensValuesLengthCheckEnabled() bool
IsAutoBalanceDataTriesEnabled() bool
IsMigrateDataTrieEnabled() bool
IsDynamicGasCostForDataTrieStorageLoadEnabled() bool
FixDelegationChangeOwnerOnAccountEnabled() bool
NFTStopCreateEnabled() bool
Expand Down
1 change: 1 addition & 0 deletions config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type EnableEpochs struct {
MultiClaimOnDelegationEnableEpoch uint32
ChangeUsernameEnableEpoch uint32
AutoBalanceDataTriesEnableEpoch uint32
MigrateDataTrieEnableEpoch uint32
ConsistentTokensValuesLengthCheckEnableEpoch uint32
FixDelegationChangeOwnerOnAccountEnableEpoch uint32
DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32
Expand Down
4 changes: 4 additions & 0 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ func TestEnableEpochConfig(t *testing.T) {
# FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch represents the epoch when the fix for the remaining gas in the SaveKeyValue builtin function is enabled
FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch = 91
# MigrateDataTrieEnableEpoch represents the epoch when the data tries migration is enabled
MigrateDataTrieEnableEpoch = 92
# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MaxNodesChangeEnableEpoch = [
Expand Down Expand Up @@ -954,6 +957,7 @@ func TestEnableEpochConfig(t *testing.T) {
NFTStopCreateEnableEpoch: 89,
ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 90,
FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch: 91,
MigrateDataTrieEnableEpoch: 92,
MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{
{
EpochEnable: 44,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-scenario-go v1.2.1
github.com/multiversx/mx-chain-storage-go v1.0.14
github.com/multiversx/mx-chain-vm-common-go v1.5.9
github.com/multiversx/mx-chain-vm-go v1.5.23
github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240116165528-e13d057575c2
github.com/multiversx/mx-chain-vm-go v1.5.24-0.20240116171344-b97ba9e3078e
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.64
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.65
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.92
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ github.com/multiversx/mx-chain-scenario-go v1.2.1 h1:9eC6VcOEAKRRKZ7EbSWPLzCdNIM
github.com/multiversx/mx-chain-scenario-go v1.2.1/go.mod h1:EuZY7DpNFHVNSxJR8dKE1z2I8gBYfEFFPSwNUOXptqE=
github.com/multiversx/mx-chain-storage-go v1.0.14 h1:h0acoqPS3FKJ4S3cKBEriTU0OabSQnpxai5WKhi1YCs=
github.com/multiversx/mx-chain-storage-go v1.0.14/go.mod h1:sJ2q49tgjxNpMpsHysjABqCAB0FLBmDblbjBkQ8XfmA=
github.com/multiversx/mx-chain-vm-common-go v1.5.9 h1:PnGimbMScV5WXFjumzAmcAcnWrw5e9PQABuIcKKUgZw=
github.com/multiversx/mx-chain-vm-common-go v1.5.9/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c=
github.com/multiversx/mx-chain-vm-go v1.5.23 h1:FNkEstebRtQWQNlyQbR2yGSpgGTpiwCMnl4MYVYEy2Q=
github.com/multiversx/mx-chain-vm-go v1.5.23/go.mod h1:T03t+in5jqeTuFZKDt2wH/Sl9MSRczvWhmG+tQEIfec=
github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240116165528-e13d057575c2 h1:Gzq8OEYp8JTqj7Mfs9/kUQuS5ANS9W3hQ8r5r6cBmYk=
github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240116165528-e13d057575c2/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c=
github.com/multiversx/mx-chain-vm-go v1.5.24-0.20240116171344-b97ba9e3078e h1:Nl4JmMDPIMnT4L4C394b6z6jt1R5WhLa1tcednFXE5k=
github.com/multiversx/mx-chain-vm-go v1.5.24-0.20240116171344-b97ba9e3078e/go.mod h1:T03t+in5jqeTuFZKDt2wH/Sl9MSRczvWhmG+tQEIfec=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.64 h1:3BEpSxEQibMMi4LXBjpo2y5vUa1LS7olDC2eDkmUfFQ=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.64/go.mod h1:MUO2E4aEIu3siDkvjraO/WaBh/FxVeQyPWfsrZE+MTU=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.65 h1:H0Duuoz6lR6KapqLqMspWTojaVtQRiLA5lIm6XV9H04=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type EnableEpochsHandlerStub struct {
IsChangeUsernameEnabledField bool
IsConsistentTokensValuesLengthCheckEnabledField bool
IsAutoBalanceDataTriesEnabledField bool
IsMigrateDataTrieEnabledField bool
FixDelegationChangeOwnerOnAccountEnabledField bool
IsDynamicGasCostForDataTrieStorageLoadEnabledField bool
IsNFTStopCreateEnabledField bool
Expand Down Expand Up @@ -1119,6 +1120,14 @@ func (stub *EnableEpochsHandlerStub) IsAutoBalanceDataTriesEnabled() bool {
return stub.IsAutoBalanceDataTriesEnabledField
}

// IsMigrateDataTrieEnabled -
func (stub *EnableEpochsHandlerStub) IsMigrateDataTrieEnabled() bool {
stub.RLock()
defer stub.RUnlock()

return stub.IsMigrateDataTrieEnabledField
}

// FixDelegationChangeOwnerOnAccountEnabled -
func (stub *EnableEpochsHandlerStub) FixDelegationChangeOwnerOnAccountEnabled() bool {
stub.RLock()
Expand Down

0 comments on commit cd71db6

Please sign in to comment.