diff --git a/Cargo.lock b/Cargo.lock index 788e2c2f44..bc6e53b5c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1045,6 +1045,25 @@ dependencies = [ "serde", ] +[[package]] +name = "bincode" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95" +dependencies = [ + "bincode_derive", + "serde", +] + +[[package]] +name = "bincode_derive" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c" +dependencies = [ + "virtue", +] + [[package]] name = "bindgen" version = "0.65.1" @@ -8215,7 +8234,7 @@ dependencies = [ name = "pallet-liquidity-pools" version = "0.0.1" dependencies = [ - "bincode", + "bincode 2.0.0-rc.3", "cfg-mocks", "cfg-primitives", "cfg-traits", @@ -15862,6 +15881,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "virtue" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314" + [[package]] name = "void" version = "1.0.2" @@ -16125,7 +16150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f907fdead3153cb9bfb7a93bbd5b62629472dc06dee83605358c64c52ed3dda9" dependencies = [ "anyhow", - "bincode", + "bincode 1.3.3", "cfg-if", "indexmap 1.9.3", "libc", @@ -16163,7 +16188,7 @@ checksum = "c86437fa68626fe896e5afc69234bb2b5894949083586535f200385adfd71213" dependencies = [ "anyhow", "base64 0.21.7", - "bincode", + "bincode 1.3.3", "directories-next", "file-per-thread-logger", "log", @@ -16239,7 +16264,7 @@ checksum = "0de48df552cfca1c9b750002d3e07b45772dd033b0b206d5c0968496abf31244" dependencies = [ "addr2line 0.19.0", "anyhow", - "bincode", + "bincode 1.3.3", "cfg-if", "cpp_demangle", "gimli 0.27.3", diff --git a/Cargo.toml b/Cargo.toml index 64d66f68cb..9b760218ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ smallvec = "1.11.0" serde = { version = "1.0.195", default-features = false, features = ["derive"] } serde_json = { version = "1.0.111" } serde-big-array = { version = "0.5" } -bincode = { version = "1.3.3" } +bincode = { version = "2.0.0-rc.3", features-features = false, features = ["alloc", "serde"] } parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } log = { version = "0.4.20", default-features = false } diff --git a/pallets/liquidity-pools/Cargo.toml b/pallets/liquidity-pools/Cargo.toml index d6467c376b..153e23f233 100644 --- a/pallets/liquidity-pools/Cargo.toml +++ b/pallets/liquidity-pools/Cargo.toml @@ -54,6 +54,7 @@ std = [ "staging-xcm/std", "scale-info/std", "serde/std", + "bincode/std", ] runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 28499c1ade..8d33dfff3b 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -1,4 +1,10 @@ -use bincode::Options; +//! A message requires a custom decoding & encoding, meeting the +//! LiquidityPool Generic Message Passing Format (GMPF): Every message is +//! encoded with a u8 at head flagging the message type, followed by its field. +//! Integers are big-endian encoded and enum values (such as `[crate::Domain]`) +//! also have a custom GMPF implementation, aiming for a fixed-size encoded +//! representation for each message variant. + use cfg_traits::Seconds; use cfg_types::domain_address::Domain; use frame_support::pallet_prelude::RuntimeDebug; @@ -58,28 +64,28 @@ impl TryInto for SerializableDomain { } } -/// A message requires a custom decoding & encoding, meeting the -/// LiquidityPool Generic Message Passing Format (GMPF): Every message is -/// encoded with a u8 at head flagging the message type, followed by its field. -/// Integers are big-endian encoded and enum values (such as `[crate::Domain]`) -/// also have a custom GMPF implementation, aiming for a fixed-size encoded -/// representation for each message variant. -/// +fn bincode_config() -> bincode::config::Configuration< + bincode::config::BigEndian, + bincode::config::Fixint, + bincode::config::NoLimit, +> { + Default::default() +} + /// Inverse of [`solidity_deserialization()`] +/// Note that the enum tags as treat as u32 by bincode instead of the expected +/// u8. Only use this function if you can handle that. fn solidity_serialization(ty: &T) -> Result, DispatchError> { - bincode::DefaultOptions::new() - .with_fixint_encoding() - .with_big_endian() - .serialize(ty) + bincode::serde::encode_to_vec(ty, bincode_config()) .map_err(|_| DispatchError::Other("Type can not be serialized")) } /// Inverse of [`solidity_serialization()`] +/// Note that the enum tags as treat as u32 by bincode instead of the expected +/// u8. Only use this function if you can handle that. fn solidity_deserialization(data: &[u8]) -> Result { - bincode::DefaultOptions::new() - .with_fixint_encoding() - .with_big_endian() - .deserialize(data) + bincode::serde::decode_from_slice(data, bincode_config()) + .map(|(ty, _)| ty) .map_err(|_| DispatchError::Other("Type can not be deserialized")) }