-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: automatic system alerts #141
Changes from 3 commits
6a60119
e390b52
7ddacc1
829e4d5
41b1ec7
d7b1f08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<template> | ||
<SystemAlert v-if="isIndexerDelayed"> | ||
<span | ||
v-if="latestTPS > MIN_TPS_TO_SHOW_HEAVY_LOAD_ALERT" | ||
v-html="t('systemAlert.indexerDelayedDueToHeavyLoad', { indexerDelayInHours })" | ||
/> | ||
<span v-else v-html="t('systemAlert.indexerDelayed', { indexerDelayInHours })" /> | ||
</SystemAlert> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, ref } from "vue"; | ||
import { useI18n } from "vue-i18n"; | ||
|
||
import SystemAlert from "@/components/common/SystemAlert.vue"; | ||
|
||
import useBlocks from "@/composables/useBlocks"; | ||
import useContext from "@/composables/useContext"; | ||
|
||
import type { types } from "zksync-web3"; | ||
|
||
const { t } = useI18n(); | ||
const context = useContext(); | ||
|
||
const MIN_DELAY_TO_SHOW_ALERT = 900_000; // 15 mins | ||
const MIN_TPS_TO_SHOW_HEAVY_LOAD_ALERT = 70; | ||
|
||
const provider = context.getL2Provider(); | ||
const latestBlock = ref<types.Block | null>(null); | ||
(async () => { | ||
const block = await provider.getBlock("latest"); | ||
latestBlock.value = block; | ||
})(); | ||
|
||
const { load: getLatestIndexedBlocks, data: latestIndexedBlocks } = useBlocks(context); | ||
getLatestIndexedBlocks(1); | ||
|
||
const indexerDelay = computed(() => { | ||
if (!latestBlock.value?.number || !latestIndexedBlocks.value?.length) { | ||
return 0; | ||
} | ||
const latestBlockDate = new Date(latestBlock.value.timestamp * 1000); | ||
const latestIndexedBlockDate = new Date(latestIndexedBlocks.value[0].timestamp); | ||
const delay = latestBlockDate.getTime() - latestIndexedBlockDate.getTime(); | ||
return delay; | ||
}); | ||
|
||
const indexerDelayInHours = computed(() => (indexerDelay.value / (1000 * 60 * 60)).toFixed(1)); | ||
|
||
const isIndexerDelayed = computed(() => { | ||
if (!latestBlock.value?.number || !latestIndexedBlocks.value?.length) { | ||
return false; | ||
} | ||
if (indexerDelay.value > MIN_DELAY_TO_SHOW_ALERT) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
|
||
const latestTPS = computed(() => { | ||
if (!latestIndexedBlocks.value?.length) { | ||
return 0; | ||
} | ||
const numberOfTransactions = latestIndexedBlocks.value.reduce((acc, block) => acc + block.size, 0); | ||
const latestBlockDate = new Date(latestIndexedBlocks.value[0].timestamp); | ||
const firstBlockDate = new Date(latestIndexedBlocks.value[latestIndexedBlocks.value.length - 1].timestamp); | ||
const numberOfSeconds = Math.floor((latestBlockDate.getTime() - firstBlockDate.getTime()) / 1000); | ||
const tps = numberOfSeconds ? numberOfTransactions / numberOfSeconds : 0; | ||
return tps; | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
a { | ||
@apply text-inherit; | ||
} | ||
</style> |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<div class="system-alert"> | ||
<IconError class="icon" color="#FFC81A" /> | ||
<span class="system-alert-body"> | ||
<slot /> | ||
</span> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import IconError from "@/components/icons/IconError.vue"; | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.system-alert { | ||
@apply flex items-center text-white rounded-2xl border border-amber-400/50 bg-amber-400/10 mb-6 py-3 px-4; | ||
|
||
.system-alert-body { | ||
@apply ml-3 w-full; | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,10 +305,6 @@ const hasContent = computed(() => { | |
.hero-banner-container { | ||
@apply absolute left-0 top-full flex h-64 w-full items-end justify-end overflow-hidden bg-primary-900; | ||
|
||
&.mainnet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hack was needed to increase the height of the header background (which has a fixed size) when a warning message is shown. Otherwise the header text is pushed down and is not visible: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally don't support mobile, but this should be fixed properly. Out of scope of this PR I'd say. |
||
@apply h-[27rem] md:h-[23rem] lg:h-[20rem]; | ||
} | ||
|
||
&.goerli { | ||
@apply h-[25rem] md:h-[23rem] lg:h-[19rem]; | ||
} | ||
|
@@ -320,10 +316,6 @@ const hasContent = computed(() => { | |
.home-banner { | ||
@apply h-80; | ||
|
||
&.mainnet { | ||
@apply h-[32rem] md:h-[28rem] lg:h-[25rem]; | ||
} | ||
|
||
&.goerli { | ||
@apply h-[30rem] md:h-[27rem] lg:h-[24rem]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -721,5 +721,9 @@ | |
"callData": "calldata" | ||
} | ||
} | ||
}, | ||
"systemAlert": { | ||
"indexerDelayed": "Transaction indexing is {indexerDelayInHours} hours behind. Transactions are being processed normally and will gradually show up. You can also use other explorers like <a href=\"https://hyperscan.xyz/\">hyperscan.xyz</a> meanwhile.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned about the wording here. Users may misunderstand that Indexing is N hours behind means that only in N hours they will see the data they have just submitted. But in fact, it's a delay at the moment, but the Explorer may catch up much quicker. Not sure what is the better option, I'm just thinking out loud. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, but I think it's more or less good to start with. I think showing number of blocks behind might be confusing. |
||
"indexerDelayedDueToHeavyLoad": "The network is under a heavy load at the moment and transaction indexing on the explorer is {indexerDelayInHours} hours behind. Transactions are being processed normally and will gradually show up. You can also use other explorers like <a href=\"https://hyperscan.xyz/\">hyperscan.xyz</a> meanwhile." | ||
} | ||
} |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not needed, since it is already handled in
indexerDelay
computed. It seems thatreturn indexerDelay.value > MIN_DELAY_TO_SHOW_ALERT;
is enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed