Skip to content

Commit

Permalink
Replace bincode with borsh (#452)
Browse files Browse the repository at this point in the history
* Add SignalsConfig to chain_spec

* Correct multiexp feature flagging for rand_core std

* Remove bincode for borsh

Replaces a non-canonical encoding with a canonical encoding which additionally
should be faster.

Also fixes an issue where we used bincode in transcripts where it cannot be
trusted.

This ended up fixing a myriad of other bugs observed, unfortunately.
Accordingly, it either has to be merged or the bug fixes from it must be ported
to a new PR.

* Make serde optional, minimize usage

* Make borsh an optional dependency of substrate/ crates

* Remove unused dependencies

* Use [u8; 64] where possible in the processor messages

* Correct borsh feature flagging
  • Loading branch information
kayabaNerve authored Nov 25, 2023
1 parent 6b28763 commit b296be8
Show file tree
Hide file tree
Showing 52 changed files with 468 additions and 309 deletions.
105 changes: 82 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions common/db/src/create_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn serai_db_key(
/// Creates a unit struct and a default implementation for the `key`, `get`, and `set`. The macro
/// uses a syntax similar to defining a function. Parameters are concatenated to produce a key,
/// they must be `scale` encodable. The return type is used to auto encode and decode the database
/// value bytes using `bincode`.
/// value bytes using `borsh`.
///
/// # Arguments
///
Expand Down Expand Up @@ -52,14 +52,14 @@ macro_rules! create_db {
)
}
#[allow(dead_code)]
pub fn set(txn: &mut impl DbTxn $(, $arg: $arg_type)*, data: &impl serde::Serialize) {
pub fn set(txn: &mut impl DbTxn $(, $arg: $arg_type)*, data: &$field_type) {
let key = $field_name::key($($arg),*);
txn.put(&key, bincode::serialize(data).unwrap());
txn.put(&key, borsh::to_vec(data).unwrap());
}
#[allow(dead_code)]
pub fn get(getter: &impl Get, $($arg: $arg_type),*) -> Option<$field_type> {
getter.get($field_name::key($($arg),*)).map(|data| {
bincode::deserialize(data.as_ref()).unwrap()
borsh::from_slice(data.as_ref()).unwrap()
})
}
#[allow(dead_code)]
Expand Down
4 changes: 1 addition & 3 deletions coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ sp-application-crypto = { git = "https://github.com/serai-dex/substrate", defaul
serai-client = { path = "../substrate/client", default-features = false, features = ["serai"] }

hex = { version = "0.4", default-features = false, features = ["std"] }
bincode = { version = "1", default-features = false }
serde = "1"
serde_json = { version = "1", default-features = false, features = ["std"] }
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }

log = { version = "0.4", default-features = false, features = ["std"] }
env_logger = { version = "0.10", default-features = false, features = ["humantime"] }
Expand Down
Loading

0 comments on commit b296be8

Please sign in to comment.