Skip to content

Commit

Permalink
added without code leaf trie node type
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Nov 8, 2023
1 parent f388af8 commit 39b55d1
Showing 1 changed file with 16 additions and 0 deletions.
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 RemoveCodeLeafEnableEpoch flag
WithoutCodeLeaf
)

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")
withoutCodeLeafFlag = EnableEpochFlag("RemoveCodeLeafFlag")
)

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(withoutCodeLeafFlag) {
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(withoutCodeLeafFlag) {
return WithoutCodeLeaf
}
if handler.IsFlagEnabled(autoBalanceDataTriesFlag) {
return AutoBalanceEnabled
}
Expand Down

0 comments on commit 39b55d1

Please sign in to comment.