Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1bb41eb
Make it clear that settings apply only to list view
cmichi Mar 19, 2019
138b4af
Add Jdenticon
cmichi Mar 21, 2019
8c26dc8
Add Grandpa consensus visualisation
cmichi Apr 3, 2019
3c830af
Remove fade-in animation
cmichi Apr 4, 2019
c570cbc
Update packages and yarn.lock
cmichi Apr 4, 2019
e4de35c
Broadcast only delta of what changed
cmichi Apr 6, 2019
1e824c7
Minor code improvements
cmichi Apr 7, 2019
a7ba531
Use NodeId instead of Address in first dimension
cmichi Apr 8, 2019
672a33f
Refactoring and improving naming
cmichi Apr 8, 2019
e4b4916
Display boxes only after size has been detected
cmichi Apr 8, 2019
b2253e0
Fix cache
cmichi Apr 8, 2019
a3e9f06
Send consensus info on first subscribe
cmichi Apr 8, 2019
4b5505b
Increase cache size
cmichi Apr 8, 2019
5c48daa
Send deltas only if block in cache
cmichi Apr 8, 2019
0623e5b
Adjust cache size
cmichi Apr 8, 2019
064506a
Make cache sizes dependent
cmichi Apr 8, 2019
bde604a
Ensure authority caches are aligned
cmichi Apr 8, 2019
5b590ba
Extract function
cmichi Apr 10, 2019
062866a
Handle restarts on authority set changes properly
cmichi Apr 10, 2019
a569f54
Fix backfill mechanism
cmichi Apr 10, 2019
003aace
Display only blocks since last authority set change
cmichi Apr 10, 2019
b3d3507
Handle authority set sent on connect
cmichi Apr 12, 2019
03b3ae4
Introduce Authority type
cmichi Apr 12, 2019
fdc86c5
Handle corner case
cmichi Apr 15, 2019
b8d689b
Display placeholder if name not yet available
cmichi Apr 15, 2019
0a0acce
Replace with camelCase
cmichi Apr 23, 2019
23c254e
Replace with correct types
cmichi May 6, 2019
44bf2a5
Replace grandpa icon
cmichi May 6, 2019
3a4ea63
Merge branch 'master' into cmichi-display-state-of-consensus
maciejhirsz May 6, 2019
3a6427a
Change consensus icon to cube (finalized block icon)
cmichi May 13, 2019
bf4d9ea
Upgrade dependencies
cmichi May 15, 2019
7040545
Implement thin backend instead of thick
cmichi May 15, 2019
ca5d29b
Cleanup and minor improvements
cmichi May 16, 2019
0bc61dc
Minor refactoring
cmichi May 16, 2019
019d1f5
Extract common code into function
cmichi May 16, 2019
ed429c6
Switch module to class
cmichi May 16, 2019
6fe140a
Remove unused code
cmichi May 16, 2019
4e73e8f
Clean markup
cmichi May 16, 2019
5e0dbdf
Remove unused code
cmichi May 16, 2019
174eba4
Revert "Upgrade dependencies"
cmichi May 19, 2019
0da0c44
Update polkadot-identicon in frontend
cmichi May 19, 2019
64d08c3
Run yarn install
cmichi May 19, 2019
acd1218
Update react-measure to 2.3.0
cmichi May 19, 2019
f198278
Improve typing by introducing partial type
cmichi May 19, 2019
5da7937
Reduce indexing operations
cmichi May 19, 2019
b02f72d
Shorten function
cmichi May 19, 2019
12fd5c9
Shorten function
cmichi May 19, 2019
770b10f
Introduce initialiseConsensusViewByRef
cmichi May 19, 2019
0bafe84
Remove dead conditional branch
cmichi May 19, 2019
bce0576
Return consensusView ref from initialiseConsensusView
cmichi May 19, 2019
44863a5
Handle consensusView ref returned from initialiseConsensusView
cmichi May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use NodeId instead of Address in first dimension
By using the NodeId instead of the Address in the first
dimension of the consensus matrice we save quite some
space in the payload which is sent to the browser.

The commit also contains some minor refactoring.
  • Loading branch information
cmichi committed Apr 8, 2019
commit a7ba53101682b48ed17652c4d2fd2101c3d63b62
16 changes: 8 additions & 8 deletions packages/backend/src/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,24 @@ export default class Chain {
this.updateConsensusInfo(node);
}

private initialiseConsensusView(height: BlockNumber, id1: string, id2: string) {
private initialiseConsensusView(height: BlockNumber, id_node1: string, addr_node2: string) {
if (this.chainConsensusCache[height] === undefined) {
this.chainConsensusCache[height] = {};
}
if (this.chainConsensusCache[height][id1] === undefined) {
this.chainConsensusCache[height][id1] = {};
this.chainConsensusCache[height][id1][id2] = {} as Types.ConsensusInfo;
if (this.chainConsensusCache[height][id_node1] === undefined) {
this.chainConsensusCache[height][id_node1] = {};
this.chainConsensusCache[height][id_node1][addr_node2] = {} as Types.ConsensusInfo;
}
if (this.chainConsensusCache[height][id1][id2] === undefined) {
this.chainConsensusCache[height][id1][id2] = {} as Types.ConsensusInfo;
if (this.chainConsensusCache[height][id_node1][addr_node2] === undefined) {
this.chainConsensusCache[height][id_node1][addr_node2] = {} as Types.ConsensusInfo;
}
}

private updateConsensusInfo(node: Node) {
for (let height in node.consensusCache) {
if (height !== undefined) {
this.initialiseConsensusView(parseInt(height) as BlockNumber, String(node.address), String(node.address));
this.chainConsensusCache[height][String(node.address)] = node.consensusCache[height];
this.initialiseConsensusView(parseInt(height) as BlockNumber, String(node.id), String(node.address));
this.chainConsensusCache[height][String(node.id)] = node.consensusCache[height];
}
}

Expand Down
84 changes: 43 additions & 41 deletions packages/backend/src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,12 @@ export default class Node {
}
}

public initialiseConsensusView(height: BlockNumber, id1_: string) {
let id1 = id1_;
public initialiseConsensusView(height: Types.BlockNumber, addr: Maybe<Types.Address>) {
if (!(height in this.consensusCache)) {
this.consensusCache[height] = {};
}
if (!(id1 in this.consensusCache[height])) {
this.consensusCache[height][id1] = {} as Types.ConsensusInfo;
if (addr && !(addr in this.consensusCache[height])) {
this.consensusCache[height][addr] = {} as Types.ConsensusInfo;
}
}

Expand All @@ -348,16 +347,15 @@ export default class Node {
height: height,
} = message;

let addr = String(this.address);
this.initialiseConsensusView(height as BlockNumber, addr);
this.consensusCache[height as BlockNumber][addr].FinalizedHash = best;
this.initialiseConsensusView(height as BlockNumber, this.address);
this.consensusCache[height as BlockNumber][String(this.address)].FinalizedHash = best;
this.events.emit('consensus-info');
}

public markFinalized(finalizedHeight: BlockNumber, finalizedHash: BlockHash) {
let addr = String(this.address);

this.initialiseConsensusView(finalizedHeight, addr);
this.initialiseConsensusView(finalizedHeight, this.address);
this.consensusCache[finalizedHeight][addr].Finalized = true;
this.consensusCache[finalizedHeight][addr].FinalizedHash = finalizedHash;
this.consensusCache[finalizedHeight][addr].FinalizedHeight = finalizedHeight;
Expand All @@ -373,7 +371,7 @@ export default class Node {
public markImplicitlyFinalized(finalizedHeight: BlockNumber) {
let addr = String(this.address);

this.initialiseConsensusView(finalizedHeight, addr);
this.initialiseConsensusView(finalizedHeight, this.address);
this.consensusCache[finalizedHeight][addr].Finalized = true;
this.consensusCache[finalizedHeight][addr].FinalizedHeight = finalizedHeight;
this.consensusCache[finalizedHeight][addr].ImplicitFinalized = true;
Expand Down Expand Up @@ -402,8 +400,7 @@ export default class Node {
target_number: targetNumber,
target_hash: targetHash,
} = message;
const voter = String(message.voter.replace(/"/g, ''));

const voter = this.extractVoter(message.voter);
this.initialiseConsensusView(targetNumber as BlockNumber, voter);
this.consensusCache[targetNumber as BlockNumber][voter].Precommit = true;

Expand Down Expand Up @@ -438,8 +435,7 @@ export default class Node {
target_number: targetNumber,
target_hash: targetHash,
} = message;
const voter = String(message.voter.replace(/"/g, ''));

const voter = this.extractVoter(message.voter);
this.initialiseConsensusView(targetNumber as BlockNumber, voter);
this.consensusCache[targetNumber as BlockNumber][voter].Prevote = true;

Expand Down Expand Up @@ -485,28 +481,6 @@ export default class Node {
}
}

// fill the block cache back from the `to` number to the last block.
// the function `f` is used to evaluate if we should continue backfilling.
private backfill(voter_: string, to: BlockNumber, f: Maybe<(i: BlockNumber) => boolean>) {
// if this is the first block in the cache then we don't fill latter blocks
if (Object.keys(this.consensusCache).length < 1) {
return to;
}

let cont = true;
while (cont && to-- > 0) {
if (this.consensusCache[to] !== undefined) {
// we reached the next block prior to this
return to;
}

this.initialiseConsensusView(to, voter_);
cont = f ? f(to) : true;
}

return to;
}

private onAfgFinalized(message: AfgFinalized) {
const {
finalized_number: finalizedNumber,
Expand All @@ -516,17 +490,15 @@ export default class Node {
this.markFinalized(finalizedNumber, finalizedHash);

let to = finalizedNumber;
let addr = String(this.address);
this.backfill(addr, to as BlockNumber, (i) => {
this.backfill(this.address, to as BlockNumber, (i) => {
i = i as BlockNumber;
let addr = String(this.address);
const info = this.consensusCache[i][addr];
const info = this.consensusCache[i][String(this.address)];
if (info.Finalized || info.ImplicitFinalized) {
return false;
}

this.markImplicitlyFinalized(i);
this.consensusCache[i][addr].ImplicitPointer = to;
this.consensusCache[i][String(this.address)].ImplicitPointer = to;

let firstBlockReached = String(i) === Object.keys(this.consensusCache)[0];
if (!this.alreadyFinalized && firstBlockReached) {
Expand All @@ -540,6 +512,36 @@ export default class Node {
this.events.emit('consensus-info');
}

// fill the block cache back from the `to` number to the last block.
// the function `f` is used to evaluate if we should continue backfilling.
private backfill(voter: Maybe<Types.Address>, to: BlockNumber, f: Maybe<(i: BlockNumber) => boolean>) {
if (!voter) {
return false;
}

// if this is the first block in the cache then we don't fill latter blocks
if (Object.keys(this.consensusCache).length < 1) {
return to;
}

let cont = true;
while (cont && to-- > 0) {
if (this.consensusCache[to] !== undefined) {
// we reached the next block prior to this
return to;
}

this.initialiseConsensusView(to, voter);
cont = f ? f(to) : true;
}

return to;
}

private extractVoter(message_voter: String): Types.Address {
return String(message_voter.replace(/"/g, '')) as Types.Address;
}

private updateLatency(now: Types.Timestamp) {
// if (this.pingStart) {
// console.error(`${this.name} timed out on ping message.`);
Expand Down Expand Up @@ -582,7 +584,7 @@ export default class Node {
}

const target = this.best.number as BlockNumber;
this.backfill(String(this.address), target, null);
this.backfill(this.address, target, null);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export declare type ConsensusInfo = {
BlockNumber: ConsensusView;
};
export declare type ConsensusView = {
Address: ConsensusState;
NodeId: ConsensusState;
};
export declare type ConsensusState = {
Address: ConsensusDetail;
Expand Down
26 changes: 13 additions & 13 deletions packages/frontend/src/components/Consensus/ConsensusBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ export class ConsensusBlock extends React.Component<ConsensusBlock.Props, {}> {
}

private isFinalized(node: Node): boolean {
const { address } = node;
const { address, id } = node;
const consensus = this.props.consensusView;

return consensus !== undefined &&
address in consensus &&
address in consensus[address] &&
consensus[address][address].Finalized === true;
id in consensus &&
address in consensus[id] &&
consensus[id][address].Finalized === true;
}

private getFinalizedHash(node: Node): Types.BlockHash {
const { address } = node;
const { address, id } = node;
const consensus = this.props.consensusView;

if (consensus !== undefined &&
address in consensus &&
address in consensus[address] &&
consensus[address][address].Finalized === true) {
return consensus[address][address].FinalizedHash;
id in consensus &&
address in consensus[id] &&
consensus[id][address].Finalized === true) {
return consensus[id][address].FinalizedHash;
}
return '' as Types.BlockHash;
}
Expand All @@ -132,7 +132,7 @@ export class ConsensusBlock extends React.Component<ConsensusBlock.Props, {}> {
let finalizedHash;

if (this.isFinalized(node)) {
const matrice = this.props.consensusView[node.address][node.address];
const matrice = this.props.consensusView[node.id][node.address];
finalizedInfo = matrice.ImplicitFinalized ?
<Tooltip text={`${node.name} finalized this block in ${matrice.ImplicitPointer}`}>
<Icon className="implicit" src={finalizedIcon} alt="" />
Expand Down Expand Up @@ -196,9 +196,9 @@ export class ConsensusBlock extends React.Component<ConsensusBlock.Props, {}> {

private getMatriceContent(rowNode: Node, columnNode: Node) {
const consensusInfo = this.props.consensusView &&
rowNode.address in this.props.consensusView &&
columnNode.address in this.props.consensusView[rowNode.address] ?
this.props.consensusView[rowNode.address][columnNode.address] : null;
rowNode.id in this.props.consensusView &&
columnNode.address in this.props.consensusView[rowNode.id] ?
this.props.consensusView[rowNode.id][columnNode.address] : null;

let tooltipText = consensusInfo ?
rowNode.name + ' has seen this of ' + columnNode.name + ': ' +
Expand Down