diff --git a/CHANGELOG.md b/CHANGELOG.md index df9c6b2df6..4f06263aea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - [#1029](https://github.com/crypto-org-chain/cronos/pull/1029) Change config `async-commit` to `async-commit-buffer`, make the channel size configurable. - [#1034](https://github.com/crypto-org-chain/cronos/pull/1034) Support memiavl snapshot strategy configuration. - [#1035](https://github.com/crypto-org-chain/cronos/pull/1035) Support caching in memiavl directly, ignore inter-block cache silently. +- [#1050](https://github.com/crypto-org-chain/cronos/pull/1050) nativebyteorder mode will check endianness on startup, binaries are built with nativebyteorder by default. *April 13, 2023* diff --git a/Makefile b/Makefile index 91ad2afe36..1eee442cf3 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,9 @@ ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS))) BUILD_TAGS += boltdb endif +# nativebyteorder mode will panic on big endian machines +BUILD_TAGS += nativebyteorder + ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS))) ldflags += -w -s endif diff --git a/default.nix b/default.nix index 9dcef46711..92e4b9b3f2 100644 --- a/default.nix +++ b/default.nix @@ -8,11 +8,12 @@ , network ? "mainnet" # mainnet|testnet , rev ? "dirty" , static ? stdenv.hostPlatform.isStatic +, nativeByteOrder ? true # nativeByteOrder mode will panic on big endian machines }: let version = "v1.0.4"; pname = "cronosd"; - tags = [ "ledger" "netgo" network "rocksdb" "grocksdb_no_link" ]; + tags = [ "ledger" "netgo" network "rocksdb" "grocksdb_no_link" ] ++ lib.optionals nativeByteOrder [ "nativebyteorder" ]; ldflags = lib.concatStringsSep "\n" ([ "-X github.com/cosmos/cosmos-sdk/version.Name=cronos" "-X github.com/cosmos/cosmos-sdk/version.AppName=${pname}" diff --git a/memiavl/layout_native.go b/memiavl/layout_native.go index b14161aeef..34b61345d1 100644 --- a/memiavl/layout_native.go +++ b/memiavl/layout_native.go @@ -8,6 +8,15 @@ import ( "unsafe" ) +func init() { + buf := [2]byte{} + *(*uint16)(unsafe.Pointer(&buf[0])) = uint16(0xABCD) + + if buf != [2]byte{0xCD, 0xAB} { + panic("native byte order is not little endian, please build without nativebyteorder") + } +} + type NodeLayout = *nodeLayout // Nodes is a continuously stored IAVL nodes