Fixed serializiation determinacy problems.
This commit is contained in:
@@ -39,14 +39,14 @@ impl SideNode {
|
||||
let transaction = utils::fake_transaction_json(stdin);
|
||||
let json = serde_json::to_value(transaction).unwrap();
|
||||
let signed_op = self.add_transaction_local(json);
|
||||
println!("STDIN: {}", shappy(signed_op.clone()));
|
||||
println!("STDIN: {}", utils::shappy(signed_op.clone()));
|
||||
self.send_to_network(signed_op).await;
|
||||
}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
}
|
||||
match self.incoming_receiver.try_recv() {
|
||||
Ok(incoming) => {
|
||||
println!("INCOMING");
|
||||
println!("INCOMING: {}", utils::shappy(incoming.clone()));
|
||||
self.handle_incoming(incoming);
|
||||
}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
@@ -60,7 +60,6 @@ impl SideNode {
|
||||
}
|
||||
|
||||
pub fn handle_incoming(&mut self, incoming: SignedOp) {
|
||||
println!("handle_incoming: {}", shappy(incoming.clone()));
|
||||
self.crdt.apply(incoming);
|
||||
// self.trace_crdt();
|
||||
}
|
||||
@@ -95,8 +94,3 @@ impl SideNode {
|
||||
self.crdt.doc.view_sha()
|
||||
}
|
||||
}
|
||||
|
||||
fn shappy(op: SignedOp) -> String {
|
||||
let b = serde_json::to_string(&op).unwrap().into_bytes();
|
||||
sha256::digest(b).to_string()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bft_json_crdt::json_crdt::SignedOp;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
pub(crate) const KEY_FILE: &str = "keys.pem";
|
||||
@@ -31,3 +32,13 @@ pub fn fake_transaction_json(from: String) -> Value {
|
||||
"amount": 1
|
||||
})
|
||||
}
|
||||
|
||||
pub fn shappy(op: SignedOp) -> String {
|
||||
let b = serde_json::to_string(&op).unwrap().into_bytes();
|
||||
sha256::digest(b).to_string()
|
||||
}
|
||||
|
||||
pub fn shassy(text: String) -> String {
|
||||
let b = text.into_bytes();
|
||||
sha256::digest(b).to_string()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ use bft_json_crdt::json_crdt::SignedOp;
|
||||
use ezsockets::ClientConfig;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::utils;
|
||||
|
||||
pub struct WebSocketClient {
|
||||
incoming_sender: mpsc::Sender<SignedOp>,
|
||||
handle: ezsockets::Client<WebSocketClient>,
|
||||
@@ -39,7 +41,16 @@ impl ezsockets::ClientExt for WebSocketClient {
|
||||
/// When we receive a text message, apply the crdt operation contained in it to our
|
||||
/// local crdt.
|
||||
async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> {
|
||||
let string_sha = utils::shassy(text.clone());
|
||||
println!("received text, sha: {string_sha}");
|
||||
let incoming: bft_json_crdt::json_crdt::SignedOp = serde_json::from_str(&text).unwrap();
|
||||
let object_sha = utils::shappy(incoming.clone());
|
||||
println!("deserialized: {}", object_sha);
|
||||
if string_sha != object_sha {
|
||||
println!("SHA mismatch: {string_sha} != {object_sha}");
|
||||
println!("text: {text}");
|
||||
println!("incoming: {incoming:?}");
|
||||
}
|
||||
self.incoming_sender.send(incoming).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user