From 9059d2bd1e16e84845421cac82f624fe93b3991c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 6 Sep 2023 17:54:40 +0300 Subject: [PATCH 1/5] added remove code leaf builin func name --- core/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/constants.go b/core/constants.go index bff20dd6..a2ec6fbd 100644 --- a/core/constants.go +++ b/core/constants.go @@ -132,6 +132,9 @@ const BuiltInFunctionUnGuardAccount = "UnGuardAccount" // BuiltInFunctionMigrateDataTrie is the built-in function key for migrating the data trie const BuiltInFunctionMigrateDataTrie = "MigrateDataTrie" +// BuiltInFunctionRemoveCodeLeaf is the built-in function key for removing code leaf +const BuiltInFunctionRemoveCodeLeaf = "RemoveCodeLeaf" + // ESDTRoleLocalMint is the constant string for the local role of mint for ESDT tokens const ESDTRoleLocalMint = "ESDTRoleLocalMint" From 39b55d11d54a4868d88329867f52d4ba7e1e7677 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 8 Nov 2023 15:57:58 +0200 Subject: [PATCH 2/5] added without code leaf trie node type --- core/trie.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/trie.go b/core/trie.go index 84331e5c..037fad20 100644 --- a/core/trie.go +++ b/core/trie.go @@ -15,6 +15,10 @@ const ( // AutoBalanceEnabled is used for data tries, and only after the activation of AutoBalanceDataTriesEnableEpoch flag AutoBalanceEnabled + + // WithoutCodeLeaf is used for account with code, it specifies that the trie code leaf has been moved to storage, + // it is enabled only after the activation of RemoveCodeLeafEnableEpoch flag + WithoutCodeLeaf ) const ( @@ -24,7 +28,11 @@ const ( // AutoBalanceEnabledString is the string representation of AutoBalanceEnabled trie node version AutoBalanceEnabledString = "auto balanced" + // WithoutCodeLeafString is the string representation of WithoutCodeLeaf trie node version + WithoutCodeLeafString = "without code leaf" + autoBalanceDataTriesFlag = EnableEpochFlag("AutoBalanceDataTriesFlag") + withoutCodeLeafFlag = EnableEpochFlag("RemoveCodeLeafFlag") ) func (version TrieNodeVersion) String() string { @@ -33,6 +41,8 @@ func (version TrieNodeVersion) String() string { return NotSpecifiedString case AutoBalanceEnabled: return AutoBalanceEnabledString + case WithoutCodeLeaf: + return WithoutCodeLeafString default: return "unknown: " + strconv.Itoa(int(version)) } @@ -59,6 +69,9 @@ func NewTrieNodeVersionVerifier(enableEpochsHandler EnableEpochsHandler) (*trieN // IsValidVersion returns true if the given trie node version is valid func (vv *trieNodeVersionVerifier) IsValidVersion(version TrieNodeVersion) bool { + if vv.enableEpochsHandler.IsFlagEnabled(withoutCodeLeafFlag) { + return version <= WithoutCodeLeaf + } if vv.enableEpochsHandler.IsFlagEnabled(autoBalanceDataTriesFlag) { return version <= AutoBalanceEnabled } @@ -73,6 +86,9 @@ func (vv *trieNodeVersionVerifier) IsInterfaceNil() bool { // GetVersionForNewData returns the trie node version that should be used for new data func GetVersionForNewData(handler EnableEpochsHandler) TrieNodeVersion { + if handler.IsFlagEnabled(withoutCodeLeafFlag) { + return WithoutCodeLeaf + } if handler.IsFlagEnabled(autoBalanceDataTriesFlag) { return AutoBalanceEnabled } From 5fa7b56106e356a38c005f0ed0288aaad5368b83 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 8 Nov 2023 19:10:02 +0200 Subject: [PATCH 3/5] add version to key value holder --- core/interface.go | 1 + core/keyValStorage/keyValStorage.go | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/interface.go b/core/interface.go index 27888e2b..5aa1780a 100644 --- a/core/interface.go +++ b/core/interface.go @@ -68,6 +68,7 @@ type Throttler interface { type KeyValueHolder interface { Key() []byte Value() []byte + Version() TrieNodeVersion } // EpochSubscriberHandler defines the behavior of a component that can be notified if a new epoch was confirmed diff --git a/core/keyValStorage/keyValStorage.go b/core/keyValStorage/keyValStorage.go index 963f6245..06baa4f1 100644 --- a/core/keyValStorage/keyValStorage.go +++ b/core/keyValStorage/keyValStorage.go @@ -1,16 +1,20 @@ package keyValStorage +import "github.com/multiversx/mx-chain-core-go/core" + // KeyValStorage holds a key and an associated value type keyValStorage struct { - key []byte - value []byte + key []byte + value []byte + version core.TrieNodeVersion } // NewKeyValStorage creates a new key-value storage -func NewKeyValStorage(key []byte, val []byte) *keyValStorage { +func NewKeyValStorage(key []byte, val []byte, version core.TrieNodeVersion) *keyValStorage { return &keyValStorage{ - key: key, - value: val, + key: key, + value: val, + version: version, } } @@ -23,3 +27,8 @@ func (k *keyValStorage) Key() []byte { func (k *keyValStorage) Value() []byte { return k.value } + +// Version returns the version in the key-value storage +func (k *keyValStorage) Version() core.TrieNodeVersion { + return k.version +} From 9e19668167cfff8d579016244e17ad73b5f3c9e5 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 10 Nov 2023 09:00:00 +0200 Subject: [PATCH 4/5] rename builtinfunc to migrate code leaf --- core/constants.go | 4 ++-- core/keyValStorage/keyValStorage_test.go | 3 ++- core/trie.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/constants.go b/core/constants.go index a2ec6fbd..25a1893e 100644 --- a/core/constants.go +++ b/core/constants.go @@ -132,8 +132,8 @@ const BuiltInFunctionUnGuardAccount = "UnGuardAccount" // BuiltInFunctionMigrateDataTrie is the built-in function key for migrating the data trie const BuiltInFunctionMigrateDataTrie = "MigrateDataTrie" -// BuiltInFunctionRemoveCodeLeaf is the built-in function key for removing code leaf -const BuiltInFunctionRemoveCodeLeaf = "RemoveCodeLeaf" +// BuiltInFunctionMigrateCodeLeaf is the built-in function key for migrating code leaf +const BuiltInFunctionMigrateCodeLeaf = "MigrateCodeLeaf" // ESDTRoleLocalMint is the constant string for the local role of mint for ESDT tokens const ESDTRoleLocalMint = "ESDTRoleLocalMint" diff --git a/core/keyValStorage/keyValStorage_test.go b/core/keyValStorage/keyValStorage_test.go index 7c57cb02..4d579285 100644 --- a/core/keyValStorage/keyValStorage_test.go +++ b/core/keyValStorage/keyValStorage_test.go @@ -3,6 +3,7 @@ package keyValStorage_test import ( "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/keyValStorage" "github.com/stretchr/testify/assert" ) @@ -13,7 +14,7 @@ func TestNewKeyValStorage_GetKeyAndVal(t *testing.T) { key := []byte("key") value := []byte("value") - keyVal := keyValStorage.NewKeyValStorage(key, value) + keyVal := keyValStorage.NewKeyValStorage(key, value, core.NotSpecified) assert.NotNil(t, keyVal) assert.Equal(t, key, keyVal.Key()) assert.Equal(t, value, keyVal.Value()) diff --git a/core/trie.go b/core/trie.go index 037fad20..1de0a8f5 100644 --- a/core/trie.go +++ b/core/trie.go @@ -17,7 +17,7 @@ const ( AutoBalanceEnabled // WithoutCodeLeaf is used for account with code, it specifies that the trie code leaf has been moved to storage, - // it is enabled only after the activation of RemoveCodeLeafEnableEpoch flag + // it is enabled only after the activation of MigrateCodeLeafEnableEpoch flag WithoutCodeLeaf ) From bac3dac5f4bbea7003acfa35f0168f33167a3786 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 23 Jan 2024 22:07:52 +0200 Subject: [PATCH 5/5] fix migrate code leaf flag --- core/trie.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/trie.go b/core/trie.go index 1de0a8f5..d9a0d2c1 100644 --- a/core/trie.go +++ b/core/trie.go @@ -32,7 +32,7 @@ const ( WithoutCodeLeafString = "without code leaf" autoBalanceDataTriesFlag = EnableEpochFlag("AutoBalanceDataTriesFlag") - withoutCodeLeafFlag = EnableEpochFlag("RemoveCodeLeafFlag") + migrateCodeLeafFlag = EnableEpochFlag("MigrateCodeLeafFlag") ) func (version TrieNodeVersion) String() string { @@ -69,7 +69,7 @@ func NewTrieNodeVersionVerifier(enableEpochsHandler EnableEpochsHandler) (*trieN // IsValidVersion returns true if the given trie node version is valid func (vv *trieNodeVersionVerifier) IsValidVersion(version TrieNodeVersion) bool { - if vv.enableEpochsHandler.IsFlagEnabled(withoutCodeLeafFlag) { + if vv.enableEpochsHandler.IsFlagEnabled(migrateCodeLeafFlag) { return version <= WithoutCodeLeaf } if vv.enableEpochsHandler.IsFlagEnabled(autoBalanceDataTriesFlag) { @@ -86,7 +86,7 @@ func (vv *trieNodeVersionVerifier) IsInterfaceNil() bool { // GetVersionForNewData returns the trie node version that should be used for new data func GetVersionForNewData(handler EnableEpochsHandler) TrieNodeVersion { - if handler.IsFlagEnabled(withoutCodeLeafFlag) { + if handler.IsFlagEnabled(migrateCodeLeafFlag) { return WithoutCodeLeaf } if handler.IsFlagEnabled(autoBalanceDataTriesFlag) {