-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6685ed5
commit 00dd379
Showing
8 changed files
with
89 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package layout | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/utils/set" | ||
) | ||
|
||
const ( | ||
defaultHeightStatePrefix byte = 0x0 | ||
defaultTimestampStatePrefix byte = 0x1 | ||
defaultFeeStatePrefix byte = 0x2 | ||
lowestAvailablePrefix byte = 0x3 | ||
) | ||
|
||
var ErrConflictingKey = errors.New("conflicting key") | ||
|
||
func IsValidLayout(vmSpecificPrefixes []byte) error { | ||
prefixes := []byte{ | ||
defaultHeightStatePrefix, | ||
defaultTimestampStatePrefix, | ||
defaultFeeStatePrefix, | ||
} | ||
|
||
prefixes = append(prefixes, vmSpecificPrefixes...) | ||
|
||
verifiedPrefixes := set.Set[string]{} | ||
|
||
for _, k := range prefixes { | ||
keyString := string(k) | ||
|
||
for prefix := range verifiedPrefixes { | ||
if prefix == keyString { | ||
return fmt.Errorf("invalid state key %s: %w", string(k), ErrConflictingKey) | ||
} | ||
} | ||
|
||
verifiedPrefixes.Add(keyString) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func HeightPrefix() []byte { | ||
return []byte{defaultHeightStatePrefix} | ||
} | ||
|
||
func TimestampPrefix() []byte { | ||
return []byte{defaultTimestampStatePrefix} | ||
} | ||
|
||
func FeePrefix() []byte { | ||
return []byte{defaultFeeStatePrefix} | ||
} | ||
|
||
func ConflictingPrefix(prefix byte) bool { | ||
return defaultHeightStatePrefix == prefix || defaultTimestampStatePrefix == prefix || defaultFeeStatePrefix == prefix | ||
} | ||
|
||
func LowestAvailablePrefix() byte { | ||
return lowestAvailablePrefix | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters