From 23edd7e1d717a072ab28aabf6a6da4b001d7daa1 Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Fri, 5 Jan 2024 22:47:58 +0800 Subject: [PATCH] Bugfix --- core/src/context.rs | 11 +++++------ core/src/types/transactor_params.rs | 2 +- js/sdk-core/src/app-client.ts | 9 +++++---- js/sdk-core/src/connection.ts | 10 ---------- js/sdk-core/src/game-context.ts | 16 +++++++--------- transactor/src/server.rs | 4 ++-- 6 files changed, 20 insertions(+), 32 deletions(-) diff --git a/core/src/context.rs b/core/src/context.rs index 452da87f..a14ab195 100644 --- a/core/src/context.rs +++ b/core/src/context.rs @@ -10,8 +10,8 @@ use race_api::event::{CustomEvent, Event}; use race_api::prelude::BridgeEvent; use race_api::random::{RandomSpec, RandomState, RandomStatus}; use race_api::types::{ - Addr, Ciphertext, DecisionId, GameStatus, RandomId, SecretDigest, SecretShare, - Settle, SettleOp, Transfer, + Addr, Ciphertext, DecisionId, GameStatus, RandomId, SecretDigest, SecretShare, Settle, + SettleOp, Transfer, }; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -478,10 +478,9 @@ impl GameContext { } pub fn add_node(&mut self, node_addr: String, access_version: u64, mode: ClientMode) { - if !self.nodes.iter().any(|n| n.addr.eq(&node_addr)) { - self.nodes - .push(Node::new_pending(node_addr, access_version, mode)) - } + self.nodes.retain(|n| n.addr.ne(&node_addr)); + self.nodes + .push(Node::new_pending(node_addr, access_version, mode)) } pub fn set_access_version(&mut self, access_version: u64) { diff --git a/core/src/types/transactor_params.rs b/core/src/types/transactor_params.rs index 9f31697f..98de72a1 100644 --- a/core/src/types/transactor_params.rs +++ b/core/src/types/transactor_params.rs @@ -128,7 +128,7 @@ impl Display for BroadcastFrame { write!(f, "BroadcastFrame::TxState: {:?}", tx_state) } BroadcastFrame::Sync { access_version, .. } => { - write!(f, "BroadcastFrame::UpdateNodes: access_version {}", access_version) + write!(f, "BroadcastFrame::Sync: access_version {}", access_version) } } } diff --git a/js/sdk-core/src/app-client.ts b/js/sdk-core/src/app-client.ts index 73ce2bb2..3ca6560f 100644 --- a/js/sdk-core/src/app-client.ts +++ b/js/sdk-core/src/app-client.ts @@ -301,7 +301,7 @@ export class AppClient { async processSubscription(sub: ConnectionSubscription) { for await (const frame of sub) { if (frame instanceof BroadcastFrameMessage) { - console.group('Receive message'); + console.group('Receive message broadcast'); try { if (this.#onMessage !== undefined) { const { message } = frame; @@ -311,7 +311,7 @@ export class AppClient { console.groupEnd(); } } else if (frame instanceof BroadcastFrameTxState) { - console.group('Receive tx state'); + console.group('Receive transaction state broadcast'); try { if (this.#onTxState !== undefined) { const { txState } = frame; @@ -324,10 +324,11 @@ export class AppClient { console.groupEnd(); } } else if (frame instanceof BroadcastFrameSync) { - console.group('Update nodes'); + console.group('Receive sync broadcast'); try { for (const node of frame.newServers) { - this.#gameContext.addNode(node.addr, node.accessVersion, node.addr === frame.transactor_addr ? 'transactor' : 'validator'); + this.#gameContext.addNode(node.addr, node.accessVersion, + node.addr === frame.transactor_addr ? 'transactor' : 'validator'); } for (const node of frame.newPlayers) { this.#gameContext.addNode(node.addr, node.accessVersion, 'player'); diff --git a/js/sdk-core/src/connection.ts b/js/sdk-core/src/connection.ts index 6e421c8d..6abddfa5 100644 --- a/js/sdk-core/src/connection.ts +++ b/js/sdk-core/src/connection.ts @@ -123,16 +123,6 @@ export class BroadcastFrameTxState extends BroadcastFrame { } } -export class NodeJoin { - @field('string') - addr!: string; - @field('u64') - accessVersion!: bigint; - constructor(fields: any) { - Object.assign(this, fields) - } -} - @variant(3) export class BroadcastFrameSync extends BroadcastFrame { @field(array(struct(PlayerJoin))) diff --git a/js/sdk-core/src/game-context.ts b/js/sdk-core/src/game-context.ts index 0b1873f1..f80e3329 100644 --- a/js/sdk-core/src/game-context.ts +++ b/js/sdk-core/src/game-context.ts @@ -265,15 +265,13 @@ export class GameContext { } addNode(nodeAddr: string, accessVersion: bigint, mode: ClientMode) { - const exist = this.nodes.find(n => n.addr === nodeAddr); - if (exist === undefined) { - this.nodes.push({ - addr: nodeAddr, - id: accessVersion, - mode, - status: { kind: 'pending', accessVersion } - }) - } + this.nodes = this.nodes.filter(n => n.addr !== nodeAddr); + this.nodes.push({ + addr: nodeAddr, + id: accessVersion, + mode, + status: { kind: 'pending', accessVersion } + }); } setAccessVersion(accessVersion: bigint) { diff --git a/transactor/src/server.rs b/transactor/src/server.rs index 14b60dbd..36463f08 100644 --- a/transactor/src/server.rs +++ b/transactor/src/server.rs @@ -144,7 +144,7 @@ fn subscribe_event( histories.len() ); histories.into_iter().for_each(|x| { - // info!("Push history event: {}", x); + info!("Broadcast history: {}", x); let v = x.try_to_vec().unwrap(); let s = utils::base64_encode(&v); sink.send(&s) @@ -160,7 +160,7 @@ fn subscribe_event( Ok(x) => { let v = x.try_to_vec().unwrap(); let s = utils::base64_encode(&v); - // info!("Push new event: {}", x); + info!("Broadcast: {}", x); Ok(s) } Err(e) => Err(e),