Skip to content

Commit 0aeada4

Browse files
committed
fixed caching error in StateGossipAgent (a state was cached while a sync agent was not active, and was not being passed when it became active)
1 parent c52f221 commit 0aeada4

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

src/data/model/immutable/HashedObject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ abstract class HashedObject {
7474

7575
setId(id: string) {
7676
this.id = id;
77-
77+
this._lastHash = undefined;
78+
7879
for (const fieldName of this._derivedFields) {
7980
const obj = (this as any)[fieldName];
8081
obj?.setId(this.getDerivedFieldId(fieldName));

src/mesh/agents/peer/PeerGroupAgent.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ class PeerGroupAgent implements Agent {
196196
peerConnectionTimeout: params.peerConnectionTimeout || 20,
197197
peerConnectionAttemptInterval: params.peerConnectionAttemptInterval || 10,
198198
peerDiscoveryAttemptInterval: params.peerDiscoveryAttemptInterval || 15,
199-
tickInterval: params.tickInterval || 10
199+
tickInterval: params.tickInterval || 30
200200
};
201201

202202
this.tick = async () => {
203203

204204
if (this.tickLock.acquire()) {
205205
try {
206206

207-
console.log(this.peerGroupId + ' has ' + this.getPeers().length + ' peers')
207+
//console.log(this.peerGroupId + ' has ' + this.getPeers().length + ' peers')
208208

209209
this.cleanUp();
210210
this.queryForOnlinePeers();
@@ -333,15 +333,15 @@ class PeerGroupAgent implements Agent {
333333
peerMsg
334334
);
335335

336-
this.controlLog.trace(this.peerGroupId + '/' + this.localPeer.endpoint + ': sending peer message to ' + ep);
336+
this.controlLog.trace(this.peerGroupId + '/' + this.localPeer.endpoint + ': sending peer message to ' + ep + ' for agent ' + agentId + ' over connection ' + connId);
337337
return true;
338338
} catch (e) {
339339

340-
this.controlLog.warning(this.peerGroupId + '/' + this.localPeer.endpoint + ': Could not send message', e);
340+
this.controlLog.warning(this.peerGroupId + '/' + this.localPeer.endpoint + ' (for agent ' + agentId + '): Could not send message to ' + ep + ': error', e);
341341
return false;
342342
}
343343
} else {
344-
this.controlLog.trace(this.peerGroupId + '/' + this.localPeer.endpoint + ': could not send peer message to ' + ep);
344+
this.controlLog.trace(this.peerGroupId + '/' + this.localPeer.endpoint + ' (for agent ' + agentId + '): could not send peer message to ' + ep);
345345
return false;
346346
}
347347
}

src/mesh/agents/state/HeaderBasedSyncAgent.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
109109

110110
this.emitSyncState();
111111

112-
this.controlLog.debug('Started agent for ' + this.mutableObjHash);
112+
this.controlLog.debug('Started sync agent for ' + this.mutableObjHash);
113+
113114
}
114115

115116
shutdown(): void {
@@ -134,7 +135,9 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
134135

135136
async receiveRemoteState(sender: string, stateHash: string, state: HashedObject): Promise<boolean> {
136137

137-
if (this.terminated) return false;
138+
if (this.terminated) {
139+
return false;
140+
}
138141

139142
let isNew = false;
140143

src/mesh/agents/state/StateGossipAgent.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,22 +529,19 @@ class StateGossipAgent extends PeeringAgentBase {
529529

530530
if (stateHash !== this.getRemoteState(sender, agentId)) {
531531
if (await stateObj.validate(new Map())) {
532-
533-
534-
this.setRemoteState(sender, agentId, stateHash, stateObj);
535-
this.cachePreviousState(agentId, stateHash, stateObj);
536532

537533
let receivedOldState = false;
538534

539535
try {
540536
receivedOldState = ! (await this.notifyAgentOfStateArrival(sender, agentId, stateHash, stateObj));
537+
this.setRemoteState(sender, agentId, stateHash, stateObj);
538+
this.cachePreviousState(agentId, stateHash, stateObj);
539+
StateGossipAgent.controlLog.trace('Received state for ' + agentId + ': (' + stateHash + '-' + (receivedOldState? 'old' : 'new') + ')');
541540
} catch (e) {
542541
// maybe cache erroneous states so we don't process them over and over?
543542
StateGossipAgent.controlLog.warning('Received erroneous state from ' + sender + ' for ' + agentId, e);
544543
}
545544

546-
StateGossipAgent.controlLog.trace('Received state for ' + agentId + ': (' + stateHash + '-' + (receivedOldState? 'old' : 'new') + ')');
547-
548545
if (receivedOldState && this.localState.get(agentId) !== stateHash && this.localStateObjects.get(agentId) !== undefined) {
549546
this.peerMessageLog.trace('Received old state for ' + agentId + ' from ' + sender + ', sending our own state over there.');
550547
this.sendStateObject(sender, agentId);
@@ -643,7 +640,7 @@ class StateGossipAgent extends PeeringAgentBase {
643640

644641
this.sentStateCache.set(lastSentKey, {timestamp: newTimestamp, stateHash: stateLiteral.hash, repeats: newRepeats});
645642
} else {
646-
this.controlLog.debug('Sending state failed!');
643+
this.controlLog.debug('Sending state failed for ' + agentId + '!');
647644
}
648645
} else {
649646
this.controlLog.warning('not gossiping: repeats = ' + lastSent?.repeats + ' for agent ' + agentId);

src/mesh/agents/state/history/HistorySynchronizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class HistorySynchronizer {
129129

130130
this.lastCancelledRequests = [];
131131

132-
this.logPrefix = 'On peer ' + this.syncAgent.peerGroupAgent.localPeer.identity?.hash() as Hash + ':';
132+
this.logPrefix = 'On peer ' + this.syncAgent.peerGroupAgent.localPeer.identity?.hash() as Hash + ' for mut ' + this.syncAgent.mutableObj.getLastHash() + ':';
133133

134134
this.controlLog = HistorySynchronizer.controlLog;
135135
this.sourcesLog = HistorySynchronizer.sourcesLog;

src/net/transport/remoting/WebRTCConnectionsHost.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ class WebRTCConnectionsHost {
147147
remoteInstanceId: conn.remoteInstanceId
148148
};
149149

150-
console.log('SENDING CONN STATUS CHANGE:', ev);
151-
152150
this.eventCallback(ev);
153151
};
154152

0 commit comments

Comments
 (0)