From 575062fad7ff4db9d7c235f49472f658be29e2fe Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Fri, 16 Aug 2024 13:55:57 +0200 Subject: [PATCH] define WasmPrefix type as [3]byte --- core/rawdb/accessors_state_arbitrum.go | 6 +++--- core/rawdb/schema_arbitrum.go | 27 ++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/rawdb/accessors_state_arbitrum.go b/core/rawdb/accessors_state_arbitrum.go index 7ff21efd84..455ba6f4f6 100644 --- a/core/rawdb/accessors_state_arbitrum.go +++ b/core/rawdb/accessors_state_arbitrum.go @@ -46,8 +46,8 @@ func LocalTarget() Target { return TargetHost } -func (t Target) keyPrefix() ([]byte, error) { - var prefix []byte +func (t Target) keyPrefix() (WasmPrefix, error) { + var prefix WasmPrefix switch t { case TargetWavm: prefix = activatedAsmWavmPrefix @@ -58,7 +58,7 @@ func (t Target) keyPrefix() ([]byte, error) { case TargetHost: prefix = activatedAsmHostPrefix default: - return nil, fmt.Errorf("invalid target: %v", t) + return WasmPrefix{}, fmt.Errorf("invalid target: %v", t) } return prefix, nil } diff --git a/core/rawdb/schema_arbitrum.go b/core/rawdb/schema_arbitrum.go index e4648b60e4..5f364892c7 100644 --- a/core/rawdb/schema_arbitrum.go +++ b/core/rawdb/schema_arbitrum.go @@ -24,14 +24,22 @@ import ( const WasmSchemaVersion byte = 0x01 +const WasmPrefixLen = 3 + +// WasmKeyLen = CompiledWasmCodePrefix + moduleHash +const WasmKeyLen = WasmPrefixLen + common.HashLength + +type WasmPrefix = [WasmPrefixLen]byte +type WasmKey = [WasmKeyLen]byte + var ( wasmSchemaVersionKey = []byte("WasmSchemaVersion") // 0x00 prefix to avoid conflicts when wasmdb is not separate database - activatedAsmWavmPrefix = []byte{0x00, 'w', 'w'} // (prefix, moduleHash) -> stylus module (wavm) - activatedAsmArmPrefix = []byte{0x00, 'w', 'r'} // (prefix, moduleHash) -> stylus asm for ARM system - activatedAsmX86Prefix = []byte{0x00, 'w', 'x'} // (prefix, moduleHash) -> stylus asm for x86 system - activatedAsmHostPrefix = []byte{0x00, 'w', 'h'} // (prefix, moduleHash) -> stylus asm for system other then ARM and x86 + activatedAsmWavmPrefix = WasmPrefix{0x00, 'w', 'w'} // (prefix, moduleHash) -> stylus module (wavm) + activatedAsmArmPrefix = WasmPrefix{0x00, 'w', 'r'} // (prefix, moduleHash) -> stylus asm for ARM system + activatedAsmX86Prefix = WasmPrefix{0x00, 'w', 'x'} // (prefix, moduleHash) -> stylus asm for x86 system + activatedAsmHostPrefix = WasmPrefix{0x00, 'w', 'h'} // (prefix, moduleHash) -> stylus asm for system other then ARM and x86 ) func DeprecatedPrefixesV0() (keyPrefixes [][]byte, keyLength int) { @@ -42,15 +50,10 @@ func DeprecatedPrefixesV0() (keyPrefixes [][]byte, keyLength int) { }, 3 + 32 } -// WasmKeyLen = CompiledWasmCodePrefix + moduleHash -const WasmKeyLen = 3 + common.HashLength - -type WasmKey = [WasmKeyLen]byte - // key = prefix + moduleHash -func activatedKey(prefix []byte, moduleHash common.Hash) WasmKey { +func activatedKey(prefix WasmPrefix, moduleHash common.Hash) WasmKey { var key WasmKey - copy(key[:3], prefix) - copy(key[3:], moduleHash[:]) + copy(key[:WasmPrefixLen], prefix[:]) + copy(key[WasmPrefixLen:], moduleHash[:]) return key }