Subscribe to chains by genesis hash (#395)

* Handle subscription by hash in the frontend

* Forward-ported backend changes

* Fix unit tests

* Remove unused `chains_by_label`

* fmt

* Updated but failing E2E tests

* subscribe by genesis hash in tests

* fmt

* Copy `BlockHash` instead of returning a ref

* Pin chains by genesisHash

Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Maciej Hirsz
2021-09-02 17:54:19 +02:00
committed by GitHub
parent ec5db0fbbf
commit a4069e4b3d
16 changed files with 156 additions and 140 deletions
+8 -8
View File
@@ -119,7 +119,7 @@ export class Connection {
// timestamp at which the last ping has been sent
private pingSent: Maybe<Types.Timestamp> = null;
// chain label to resubsribe to on reconnect
private resubscribeTo: Maybe<Types.ChainLabel> = getHashData().chain;
private resubscribeTo: Maybe<Types.GenesisHash> = getHashData().chain;
// flag whether or not FE should subscribe to consensus updates on reconnect
private resubscribeSendFinality: boolean = getHashData().tab === 'consensus';
@@ -132,7 +132,7 @@ export class Connection {
this.bindSocket();
}
public subscribe(chain: Types.ChainLabel) {
public subscribe(chain: Types.GenesisHash) {
if (
this.appState.subscribed != null &&
this.appState.subscribed !== chain
@@ -148,7 +148,7 @@ export class Connection {
this.socket.send(`subscribe:${chain}`);
}
public subscribeConsensus(chain: Types.ChainLabel) {
public subscribeConsensus(chain: Types.GenesisHash) {
if (this.appState.authorities.length <= VIS_AUTHORITIES_LIMIT) {
setHashData({ chain });
this.resubscribeSendFinality = true;
@@ -165,7 +165,7 @@ export class Connection {
});
}
public unsubscribeConsensus(chain: Types.ChainLabel) {
public unsubscribeConsensus(chain: Types.GenesisHash) {
this.resubscribeSendFinality = true;
this.socket.send(`no-more-finality:${chain}`);
}
@@ -334,13 +334,13 @@ export class Connection {
}
case ACTIONS.AddedChain: {
const [label, nodeCount] = message.payload;
const chain = chains.get(label);
const [label, genesisHash, nodeCount] = message.payload;
const chain = chains.get(genesisHash);
if (chain) {
chain.nodeCount = nodeCount;
} else {
chains.set(label, { label, nodeCount });
chains.set(genesisHash, { label, genesisHash, nodeCount });
}
this.appUpdate({ chains });
@@ -552,7 +552,7 @@ export class Connection {
}
if (topChain) {
this.subscribe(topChain.label);
this.subscribe(topChain.genesisHash);
}
}