forked from cerc-io/cosmos-explorer
add group
This commit is contained in:
parent
efbf2731e0
commit
43e403c061
@ -1,5 +1,7 @@
|
||||
<template>
|
||||
<div class="px-0">
|
||||
<b-tabs>
|
||||
<b-tab title="Group By Validator">
|
||||
<b-card>
|
||||
<b-alert
|
||||
variant="danger"
|
||||
@ -13,12 +15,11 @@
|
||||
no-body
|
||||
class="mb-1"
|
||||
>
|
||||
<b-button
|
||||
to="./uptime/my"
|
||||
variant="primary"
|
||||
>
|
||||
Browse favorite only
|
||||
</b-button>
|
||||
<b-row>
|
||||
<b-col md="3">
|
||||
<h4>#{{ height }}</h4>
|
||||
</b-col>
|
||||
<b-col md="9">
|
||||
<b-input-group>
|
||||
<b-input-group-prepend is-text>
|
||||
<b-form-checkbox
|
||||
@ -32,7 +33,17 @@
|
||||
v-model="query"
|
||||
placeholder="Keywords to filter validators"
|
||||
/>
|
||||
<b-input-group-append>
|
||||
<b-button
|
||||
to="./uptime/my"
|
||||
variant="primary"
|
||||
>
|
||||
Favorite
|
||||
</b-button>
|
||||
</b-input-group-append>
|
||||
</b-input-group>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-card>
|
||||
<b-row>
|
||||
<b-col
|
||||
@ -96,12 +107,57 @@
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-card>
|
||||
</b-tab>
|
||||
<b-tab title="Group By Proposer">
|
||||
<b-card>
|
||||
<b-row>
|
||||
<b-col
|
||||
md="3"
|
||||
sm="12"
|
||||
>
|
||||
<h4>#{{ height }}</h4>
|
||||
</b-col>
|
||||
<b-col
|
||||
sm="12"
|
||||
md="9"
|
||||
>
|
||||
<b-input-group
|
||||
prepend="Qty of absent validators"
|
||||
>
|
||||
<b-form-input
|
||||
id="threshold"
|
||||
v-model="threshold"
|
||||
placeholder="Absent validator number in blocks"
|
||||
/>
|
||||
</b-input-group>
|
||||
</b-col>
|
||||
</b-row>
|
||||
|
||||
</b-card>
|
||||
|
||||
<b-row>
|
||||
<b-col
|
||||
v-for="(x, i) in proposerViewData"
|
||||
:key="i"
|
||||
md="4"
|
||||
sm="12"
|
||||
class="text-truncate"
|
||||
>
|
||||
{{ x.name }}
|
||||
<b-badge :variant="x.counter > 0 ? 'light-danger': 'light-success'">
|
||||
{{ x.counter }} / {{ x.proposed }}
|
||||
</b-badge>
|
||||
</b-col>
|
||||
</b-row>
|
||||
|
||||
</b-tab>
|
||||
</b-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
BSkeleton, BSkeletonWrapper,
|
||||
BSkeleton, BSkeletonWrapper, BInputGroupAppend, BTabs, BTab, BFormGroup,
|
||||
BRow, BCol, VBTooltip, BFormInput, BCard, BAlert, BFormCheckbox, BButton, BBadge, BInputGroup, BInputGroupPrepend,
|
||||
} from 'bootstrap-vue'
|
||||
|
||||
@ -115,6 +171,7 @@ export default {
|
||||
BRow,
|
||||
BCol,
|
||||
BFormInput,
|
||||
BFormGroup,
|
||||
BCard,
|
||||
BAlert,
|
||||
BButton,
|
||||
@ -124,6 +181,9 @@ export default {
|
||||
BSkeleton,
|
||||
BSkeletonWrapper,
|
||||
BInputGroupPrepend,
|
||||
BInputGroupAppend,
|
||||
BTabs,
|
||||
BTab,
|
||||
},
|
||||
directives: {
|
||||
'b-tooltip': VBTooltip,
|
||||
@ -132,6 +192,7 @@ export default {
|
||||
const { chain } = this.$route.params
|
||||
const pinned = localStorage.getItem('pinned') ? localStorage.getItem('pinned').split(',') : ''
|
||||
return {
|
||||
height: 0,
|
||||
loading: true,
|
||||
missedFilter: false,
|
||||
pinned,
|
||||
@ -142,6 +203,11 @@ export default {
|
||||
blocks: Array.from('0'.repeat(50)).map(x => ({ sigs: {}, height: Number(x) })),
|
||||
syncing: false,
|
||||
latestTime: '',
|
||||
threshold: 10,
|
||||
proposers: {},
|
||||
absentValsInBlock: {},
|
||||
numOfBlock: 1000,
|
||||
temp: 0,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -157,10 +223,30 @@ export default {
|
||||
}
|
||||
return rets
|
||||
},
|
||||
// Compose data for group by proposer
|
||||
proposerViewData() {
|
||||
const valCounter = {}
|
||||
this.validators.forEach(x => {
|
||||
valCounter[this.hex2base64(consensusPubkeyToHexAddress(x.consensus_pubkey))] = {
|
||||
name: x.description.moniker,
|
||||
counter: 0,
|
||||
proposed: 0,
|
||||
}
|
||||
})
|
||||
Object.keys(this.proposers).forEach(height => {
|
||||
const num = this.absentValsInBlock[height] || 0
|
||||
if (valCounter[this.proposers[height]]) {
|
||||
if (num > this.threshold) {
|
||||
valCounter[this.proposers[height]].counter += 1 // (num >= Number(this.threshold) ? 1 : 0)
|
||||
}
|
||||
valCounter[this.proposers[height]].proposed += 1
|
||||
}
|
||||
})
|
||||
return Object.values(valCounter).sort((a, b) => b.counter - a.counter)
|
||||
},
|
||||
},
|
||||
created() {
|
||||
const cached = JSON.parse(getCachedValidators(this.$route.params.chain))
|
||||
|
||||
if (cached) {
|
||||
this.validators = cached
|
||||
}
|
||||
@ -216,7 +302,7 @@ export default {
|
||||
blocks.push({ sigs, height })
|
||||
this.blocks = blocks
|
||||
|
||||
this.timer = setInterval(this.fetch_latest, 6000)
|
||||
this.timer = setInterval(this.fetch_latest, 1000)
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
@ -231,16 +317,30 @@ export default {
|
||||
return toBase64(fromHex(v))
|
||||
},
|
||||
fetch_status(height, resolve) {
|
||||
const block = this.blocks.find(b => b.height === height)
|
||||
if (block) {
|
||||
this.$http.getBlockByHeight(height).then(res => {
|
||||
resolve()
|
||||
const block = this.blocks.find(b => b.height === height)
|
||||
// update valiators states
|
||||
if (block) {
|
||||
const sigs = this.initColor()
|
||||
res.block.last_commit.signatures.forEach(x => {
|
||||
if (x.validator_address) sigs[x.validator_address] = 'bg-success'
|
||||
})
|
||||
this.$set(block, 'sigs', sigs)
|
||||
}
|
||||
|
||||
// update proposer states
|
||||
this.count(res.block)
|
||||
})
|
||||
},
|
||||
/// count how many absent valiators in a block
|
||||
count(block) {
|
||||
const count = block.last_commit.signatures.reduce((p, c) => (c.block_id_flag !== 'BLOCK_ID_FLAG_COMMIT' ? p + 1 : p), 0)
|
||||
// Notes: block.header.height == last_commint.height + 1
|
||||
this.$set(this.proposers, block.header.height, block.header.proposer_address)
|
||||
this.$set(this.absentValsInBlock, block.last_commit.height, count)
|
||||
if (count >= this.threshold) {
|
||||
this.temp += 1
|
||||
}
|
||||
},
|
||||
fetch_latest() {
|
||||
@ -249,12 +349,14 @@ export default {
|
||||
res.block.last_commit.signatures.forEach(x => {
|
||||
if (x.validator_address) sigs[x.validator_address] = 'bg-success'
|
||||
})
|
||||
this.height = res.block.header.height
|
||||
const block = this.blocks.find(b => b.height === res.block.last_commit.height)
|
||||
if (typeof block === 'undefined') { // mei
|
||||
// this.$set(block, 0, typeof sigs !== 'undefined')
|
||||
if (this.blocks.length >= 50) this.blocks.shift()
|
||||
this.blocks.push({ sigs, height: res.block.last_commit.height })
|
||||
}
|
||||
this.count(res.block)
|
||||
})
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user