From 7b8c2463d1f19532c794f86f1aa3885de187d414 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Tue, 28 Nov 2023 10:14:26 +0800 Subject: [PATCH] dynamic load state sync block --- src/modules/[chain]/statesync/index.vue | 72 +++++++++++++------------ 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/modules/[chain]/statesync/index.vue b/src/modules/[chain]/statesync/index.vue index 69cc5cb3..3878ede2 100644 --- a/src/modules/[chain]/statesync/index.vue +++ b/src/modules/[chain]/statesync/index.vue @@ -10,15 +10,20 @@ const blockchain = useBlockchain(); const base = useBaseStore(); const nodeInfo = ref({} as NodeInfo); -const height = ref(Number(base.latest.block?.header?.height|| 2001)) +const height = ref(0) const hash = ref("") -if(height.value > 2000) { - height.value = Math.round((height.value - 2000) / 1000) * 1000 - base.fetchBlock(height.value).then(res => { - hash.value = toHex(fromBase64(res.block_id.hash)).toUpperCase() - }) -} +base.$subscribe((m, { latest }) => { + let h = Number(latest.block?.header?.height) + h = Math.round((h - 2000) / 1000) * 1000 + if (h > height.value) { + height.value = h + base.fetchBlock(h).then(res => { + hash.value = toHex(fromBase64(res.block_id.hash)).toUpperCase() + }) + } +}) + const rpcs = computed(() => { return blockchain.current?.endpoints?.rpc ?.map((x) => x.address) @@ -41,14 +46,10 @@ onMounted(() => {
[state-sync]
- enable = true
-
- rpc_servers = "{{ rpcs }}"
- trust_height = {{ height }}
- trust_hash = "{{hash}}"
-
- # 2/3 of unbonding time
- trust_period = "168h"
+ [state-sync]
+ enable = true
+
+ rpc_servers = "{{ rpcs }}"
+ trust_height = {{ height }}
+ trust_hash = "{{ hash }}"
+
+ # 2/3 of unbonding time
+ trust_period = "168h"
{{ appName }} start
+ 3. {{ $t('statesync.text_3') }}: {{ appName }} start
{{ appName }} unsafe-reset-all or
- {{ appName }} tendermint unsafe-reset-all --home ~/.HOME
+ {{ appName }} tendermint unsafe-reset-all --home ~/.HOME
{{ $t('statesync.text_3_2') }}.
@@ -93,13 +96,16 @@ onMounted(() => {
{{ $t('statesync.text_title_3') }}
[state-sync]
- # snapshot-interval specifies the block interval at which local state sync snapshots are
- # taken (0 to disable). Must be a multiple of pruning-keep-every.
- snapshot-interval = 1000
-
- # snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). Each snapshot is about 500MiB
- snapshot-keep-recent = 2
+ [state-sync]
+ # snapshot-interval specifies the block interval at which local state sync snapshots are
+ # taken (0 to disable). Must be a multiple of pruning-keep-every.
+ snapshot-interval = 1000
+
+ # snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). Each snapshot is about 500MiB
+ snapshot-keep-recent = 2