Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added remove code leaf builin func name #267

Open
wants to merge 7 commits into
base: feat/remove-code-leaf
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ const BuiltInFunctionUnGuardAccount = "UnGuardAccount"
// BuiltInFunctionMigrateDataTrie is the built-in function key for migrating the data trie
const BuiltInFunctionMigrateDataTrie = "MigrateDataTrie"

// 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"

Expand Down
1 change: 1 addition & 0 deletions core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Throttler interface {
type KeyValueHolder interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we target the branch towards a feat branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Key() []byte
Value() []byte
Version() TrieNodeVersion
}

// EpochSubscriberHandler defines the behavior of a component that can be notified if a new epoch was confirmed
Expand Down
19 changes: 14 additions & 5 deletions core/keyValStorage/keyValStorage.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

Expand All @@ -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
}
3 changes: 2 additions & 1 deletion core/keyValStorage/keyValStorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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())
Expand Down
16 changes: 16 additions & 0 deletions core/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 MigrateCodeLeafEnableEpoch flag
WithoutCodeLeaf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all nodes with version "without code leaf" are assumed to be also with auto balance enabled right?

Just to confirm, it would not be possible to move from NotSpecified directly to WithoutCodeLeaf right?
If this is the case we should take care of the testing process to allow enough time (and actively do the first migration - auto balance) before this and ensure everything is migrated to auto balance before, or directly start with AutoBalanceEnabled active.

Also would this version change affect the logic for auto balancing since the version will be different but auto balancing will still need to be done? (I am asking here if there are checks in the code for the specific AutoBalanceEnabled version)

)

const (
Expand All @@ -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")
migrateCodeLeafFlag = EnableEpochFlag("MigrateCodeLeafFlag")
)

func (version TrieNodeVersion) String() string {
Expand All @@ -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))
}
Expand All @@ -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(migrateCodeLeafFlag) {
return version <= WithoutCodeLeaf
}
if vv.enableEpochsHandler.IsFlagEnabled(autoBalanceDataTriesFlag) {
return version <= AutoBalanceEnabled
}
Expand All @@ -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(migrateCodeLeafFlag) {
return WithoutCodeLeaf
}
if handler.IsFlagEnabled(autoBalanceDataTriesFlag) {
return AutoBalanceEnabled
}
Expand Down