Skip to content

Commit 575062f

Browse files
committed
define WasmPrefix type as [3]byte
1 parent abc46c6 commit 575062f

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

core/rawdb/accessors_state_arbitrum.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func LocalTarget() Target {
4646
return TargetHost
4747
}
4848

49-
func (t Target) keyPrefix() ([]byte, error) {
50-
var prefix []byte
49+
func (t Target) keyPrefix() (WasmPrefix, error) {
50+
var prefix WasmPrefix
5151
switch t {
5252
case TargetWavm:
5353
prefix = activatedAsmWavmPrefix
@@ -58,7 +58,7 @@ func (t Target) keyPrefix() ([]byte, error) {
5858
case TargetHost:
5959
prefix = activatedAsmHostPrefix
6060
default:
61-
return nil, fmt.Errorf("invalid target: %v", t)
61+
return WasmPrefix{}, fmt.Errorf("invalid target: %v", t)
6262
}
6363
return prefix, nil
6464
}

core/rawdb/schema_arbitrum.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ import (
2424

2525
const WasmSchemaVersion byte = 0x01
2626

27+
const WasmPrefixLen = 3
28+
29+
// WasmKeyLen = CompiledWasmCodePrefix + moduleHash
30+
const WasmKeyLen = WasmPrefixLen + common.HashLength
31+
32+
type WasmPrefix = [WasmPrefixLen]byte
33+
type WasmKey = [WasmKeyLen]byte
34+
2735
var (
2836
wasmSchemaVersionKey = []byte("WasmSchemaVersion")
2937

3038
// 0x00 prefix to avoid conflicts when wasmdb is not separate database
31-
activatedAsmWavmPrefix = []byte{0x00, 'w', 'w'} // (prefix, moduleHash) -> stylus module (wavm)
32-
activatedAsmArmPrefix = []byte{0x00, 'w', 'r'} // (prefix, moduleHash) -> stylus asm for ARM system
33-
activatedAsmX86Prefix = []byte{0x00, 'w', 'x'} // (prefix, moduleHash) -> stylus asm for x86 system
34-
activatedAsmHostPrefix = []byte{0x00, 'w', 'h'} // (prefix, moduleHash) -> stylus asm for system other then ARM and x86
39+
activatedAsmWavmPrefix = WasmPrefix{0x00, 'w', 'w'} // (prefix, moduleHash) -> stylus module (wavm)
40+
activatedAsmArmPrefix = WasmPrefix{0x00, 'w', 'r'} // (prefix, moduleHash) -> stylus asm for ARM system
41+
activatedAsmX86Prefix = WasmPrefix{0x00, 'w', 'x'} // (prefix, moduleHash) -> stylus asm for x86 system
42+
activatedAsmHostPrefix = WasmPrefix{0x00, 'w', 'h'} // (prefix, moduleHash) -> stylus asm for system other then ARM and x86
3543
)
3644

3745
func DeprecatedPrefixesV0() (keyPrefixes [][]byte, keyLength int) {
@@ -42,15 +50,10 @@ func DeprecatedPrefixesV0() (keyPrefixes [][]byte, keyLength int) {
4250
}, 3 + 32
4351
}
4452

45-
// WasmKeyLen = CompiledWasmCodePrefix + moduleHash
46-
const WasmKeyLen = 3 + common.HashLength
47-
48-
type WasmKey = [WasmKeyLen]byte
49-
5053
// key = prefix + moduleHash
51-
func activatedKey(prefix []byte, moduleHash common.Hash) WasmKey {
54+
func activatedKey(prefix WasmPrefix, moduleHash common.Hash) WasmKey {
5255
var key WasmKey
53-
copy(key[:3], prefix)
54-
copy(key[3:], moduleHash[:])
56+
copy(key[:WasmPrefixLen], prefix[:])
57+
copy(key[WasmPrefixLen:], moduleHash[:])
5558
return key
5659
}

0 commit comments

Comments
 (0)