Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
DogLooksGood committed Jan 5, 2024
1 parent 041f466 commit 23edd7e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
11 changes: 5 additions & 6 deletions core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/types/transactor_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions js/sdk-core/src/app-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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');
Expand Down
10 changes: 0 additions & 10 deletions js/sdk-core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
16 changes: 7 additions & 9 deletions js/sdk-core/src/game-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions transactor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
Expand Down

0 comments on commit 23edd7e

Please sign in to comment.