WIP: hash inequality seems to be happening from something on the wire
This commit is contained in:
@@ -4,7 +4,7 @@ use tokio::sync::mpsc;
|
||||
|
||||
use crate::{crdt::TransactionList, utils, websocket::WebSocketClient};
|
||||
|
||||
pub(crate) struct SideNode {
|
||||
pub struct SideNode {
|
||||
crdt: BaseCrdt<TransactionList>,
|
||||
keys: fastcrypto::ed25519::Ed25519KeyPair,
|
||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||
@@ -13,7 +13,7 @@ pub(crate) struct SideNode {
|
||||
}
|
||||
|
||||
impl SideNode {
|
||||
pub(crate) fn new(
|
||||
pub fn new(
|
||||
crdt: BaseCrdt<TransactionList>,
|
||||
keys: Ed25519KeyPair,
|
||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||
@@ -39,12 +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()));
|
||||
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");
|
||||
self.handle_incoming(incoming);
|
||||
}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
@@ -57,12 +59,13 @@ impl SideNode {
|
||||
self.handle.call(to_send).unwrap();
|
||||
}
|
||||
|
||||
fn handle_incoming(&mut self, incoming: SignedOp) {
|
||||
pub fn handle_incoming(&mut self, incoming: SignedOp) {
|
||||
println!("handle_incoming: {}", shappy(incoming.clone()));
|
||||
self.crdt.apply(incoming);
|
||||
self.trace_crdt();
|
||||
// self.trace_crdt();
|
||||
}
|
||||
|
||||
pub(crate) fn add_transaction_local(
|
||||
pub fn add_transaction_local(
|
||||
&mut self,
|
||||
transaction: serde_json::Value,
|
||||
) -> bft_json_crdt::json_crdt::SignedOp {
|
||||
@@ -79,12 +82,21 @@ impl SideNode {
|
||||
.list
|
||||
.insert(last.id, transaction)
|
||||
.sign(&self.keys);
|
||||
self.trace_crdt();
|
||||
// self.trace_crdt();
|
||||
signed_op
|
||||
}
|
||||
|
||||
/// Print the current state of the CRDT, can be used to debug
|
||||
pub(crate) fn trace_crdt(&self) {
|
||||
pub fn trace_crdt(&self) {
|
||||
println!("{:?}", self.crdt.doc.view_sha());
|
||||
}
|
||||
|
||||
pub fn current_sha(&self) -> String {
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user