Skip to content

Commit

Permalink
match genesis of light client to api for Health
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Oct 28, 2024
1 parent d931a8f commit 76b144c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
22 changes: 21 additions & 1 deletion components/ui/HealthDetailsOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<p class="text-sm text-gray-400">
Shielding Target: <b>{{ chainConfigs[shieldingTarget].name }}</b>
</p>

<p
:class="[
'text-sm',
Expand All @@ -60,6 +59,27 @@
<b>{{ shieldingTargetBlockNumberAge }}s</b>
</p>
<br />
<p class="text-sm text-gray-400 wrap">
genesis hash for api vs enclave light client:
</p>
<p
:class="[
'text-sm',
'text-gray-400',
healthColor(systemHealth.getSidechainSystemHealth.genesisMatch),
]"
>
{{
systemHealth.getShieldingTargetApiGenesisHashHex.slice(0, 8)
}}... vs
{{
systemHealth.getShieldingTargetLightClientGenesisHashHex.slice(
0,
8,
)
}}...
</p>
<br />
<p class="text-sm text-gray-400">
Sidechain import of finalized target blocks
</p>
Expand Down
13 changes: 10 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1458,18 +1458,22 @@ const fetchNetworkStatus = async () => {
incogniteeShard.value,
);
getter.send().then((info) => {
console.log(`parentchains info: ${info}`);
console.debug(`parentchains info: ${info}`);
const shielding_target_id = info.shielding_target
.toString()
.replace(/([A-Z])/g, "_$1")
.toLowerCase()
.replace(/^_/, "");
console.log("shielding target: " + shielding_target_id);
const block_number = info[shielding_target_id]?.block_number;
console.log("shielding target last imported block number: " + block_number);
const genesis_hash = info[shielding_target_id]?.genesis_hash
.toHex()
.toString();
if (block_number !== null && block_number !== undefined) {
systemHealth.observeShieldingTargetImportedBlockNumber(block_number);
}
if (genesis_hash?.length > 0) {
systemHealth.setShieldingTargetLightClientGenesisHashHex(genesis_hash);
}
});
api.rpc.chain.getFinalizedHead().then((head) => {
api.rpc.chain.getBlock(head).then((block) => {
Expand Down Expand Up @@ -1510,6 +1514,9 @@ watch(accountStore, async () => {
accountStore.setDecimals(Number(api.registry.chainDecimals));
accountStore.setSS58Format(Number(api.registry.chainSS58));
accountStore.setSymbol(String(api.registry.chainTokens));
systemHealth.setShieldingTargetApiGenesisHashHex(
api.genesisHash.toHex().toString(),
);
if (accountStore.hasInjector) {
router.push({
query: { address: accountStore.getAddress },
Expand Down
5 changes: 5 additions & 0 deletions store/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const useAccount = defineStore("account", {
balanceFrozen: <Record<ChainId, BigInt>>{},
// nonce per chain
nonce: <Record<ChainId, number>>{},
// genesis hash
genesisHash: <Record<String, number>>{},
// decimals (we assume it's the same for all used chains as it's the token we're shielding
decimals: <number>0,
// native token symbol (we assume it's the same for all used chains as it's the token we're shielding
Expand Down Expand Up @@ -130,6 +132,9 @@ export const useAccount = defineStore("account", {
//console.debug(`Setting nonce for chain ${chain} to ${nonce}`);
this.nonce[chain] = nonce;
},
setGenesisHash(genesisHash: String, chain: ChainId) {
this.genesisHash[chain] = genesisHash;
},
setDecimals(decimals: number) {
this.decimals = decimals;
},
Expand Down
37 changes: 36 additions & 1 deletion store/systemHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ export enum Health {
export class SidechainHealth {
shieldingTargetProgress: Health;
shieldingTargetImportProgress: Health;
genesisMatch: Health;

constructor(
shieldingTargetProgress: Health,
shieldingTargetImportProgress: Health,
genesisMatch: Health,
) {
this.shieldingTargetProgress = shieldingTargetProgress;
this.shieldingTargetImportProgress = shieldingTargetImportProgress;
this.genesisMatch = genesisMatch;
}
overall(): Health {
return Math.min(
this.shieldingTargetProgress,
this.shieldingTargetImportProgress,
this.genesisMatch,
);
}
}
Expand All @@ -67,12 +71,16 @@ export const useSystemHealth = defineStore("system-health", {
state: () => ({
shieldingTargetLastBlockNumber: <ObservableNumber | null>null,
shieldingTargetImportedBlockNumber: <ObservableNumber | null>null,
shieldingTargetApiGenesisHashHex: <string | null>null,
shieldingTargetLightClientGenesisHashHex: <string | null>null,
integriteeLastBlockNumber: <ObservableNumber | null>null,
}),
getters: {
getSidechainSystemHealth({
shieldingTargetLastBlockNumber,
shieldingTargetImportedBlockNumber,
shieldingTargetApiGenesisHashHex,
shieldingTargetLightClientGenesisHashHex,
}): SidechainHealth {
const lag =
shieldingTargetLastBlockNumber?.value -
Expand All @@ -90,7 +98,18 @@ export const useSystemHealth = defineStore("system-health", {
const targetHealth = parachainBlockAgeToHealth(
shieldingTargetLastBlockNumber?.age(),
);
return new SidechainHealth(targetHealth, importHealth);
let genesisMatch = Health.Unknown;
if (
shieldingTargetApiGenesisHashHex?.length > 0 &&
shieldingTargetLightClientGenesisHashHex?.length > 0
) {
genesisMatch =
shieldingTargetApiGenesisHashHex ===
shieldingTargetLightClientGenesisHashHex
? Health.Healthy
: Health.Critical;
}
return new SidechainHealth(targetHealth, importHealth, genesisMatch);
},
getIntegriteeSystemHealth({ integriteeLastBlockNumber }): IntegriteeHealth {
const progressHealth = parachainBlockAgeToHealth(
Expand All @@ -113,6 +132,16 @@ export const useSystemHealth = defineStore("system-health", {
}): ObservableNumber {
return shieldingTargetImportedBlockNumber;
},
getShieldingTargetApiGenesisHashHex({
shieldingTargetApiGenesisHashHex,
}): string {
return shieldingTargetApiGenesisHashHex;
},
getShieldingTargetLightClientGenesisHashHex({
shieldingTargetLightClientGenesisHashHex,
}): string {
return shieldingTargetLightClientGenesisHashHex;
},
},
actions: {
observeShieldingTargetBlockNumber(block_number: number) {
Expand All @@ -134,6 +163,12 @@ export const useSystemHealth = defineStore("system-health", {
? this.integriteeLastBlockNumber?.observe(block_number)
: (this.integriteeLastBlockNumber = new ObservableNumber(block_number));
},
setShieldingTargetApiGenesisHashHex(genesis_hash_hex: string) {
this.shieldingTargetApiGenesisHashHex = genesis_hash_hex;
},
setShieldingTargetLightClientGenesisHashHex(genesis_hash_hex: string) {
this.shieldingTargetLightClientGenesisHashHex = genesis_hash_hex;
},
},
});

Expand Down

0 comments on commit 76b144c

Please sign in to comment.