Skip to content

Commit 761a4a8

Browse files
committed
feat: Always load genesis hash and chain info when
starting block syncing
1 parent b9a5fca commit 761a4a8

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

packages/neuron-wallet/src/startup/sync-block-task/init-database.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,30 @@ export class InitDatabase {
3535

3636
this.inProcess = true
3737

38-
let hash: string = network.genesisHash
39-
let chain: string = network.chain
38+
let hash: string = EMPTY_GENESIS_HASH
39+
let chain: string = ''
4040
while (!this.stopped && !this.success) {
4141
try {
42-
if (hash === EMPTY_GENESIS_HASH) {
43-
hash = await genesisBlockHash(network.remote)
44-
}
42+
hash = await genesisBlockHash(network.remote)
4543
await initConnection(hash)
46-
if (chain === '') {
47-
chain = await getChain(network.remote)
48-
}
44+
chain = await getChain(network.remote)
4945

50-
try {
51-
const systemScriptInfo = await LockUtils.systemScript(network.remote)
52-
const daoScriptInfo = await DaoUtils.daoScript(network.remote)
53-
updateMetaInfo({ genesisBlockHash: hash, systemScriptInfo, chain, daoScriptInfo })
54-
} catch (err) {
55-
logger.error('update systemScriptInfo failed:', err)
56-
}
46+
if (hash === network.genesisHash && chain === network.chain) {
47+
try {
48+
const systemScriptInfo = await LockUtils.systemScript(network.remote)
49+
const daoScriptInfo = await DaoUtils.daoScript(network.remote)
50+
updateMetaInfo({ genesisBlockHash: hash, systemScriptInfo, chain, daoScriptInfo })
51+
} catch (err) {
52+
logger.error('update systemScriptInfo failed:', err)
53+
}
5754

58-
this.success = true
55+
this.success = true
56+
} else {
57+
logger.error('network genesis hash and chain do not match data fetched')
58+
this.stopped = true
59+
}
5960
} catch (err) {
60-
logger.debug('initDatabase error:', err)
61+
logger.error('initDatabase error:', err)
6162
try {
6263
const metaInfo = getMetaInfo()
6364
await initConnection(metaInfo.genesisBlockHash)
@@ -67,6 +68,7 @@ export class InitDatabase {
6768
hash = metaInfo.genesisBlockHash
6869
this.success = true
6970
} catch (error) {
71+
logger.error('get cached meta info error:', err)
7072
Utils.sleep(5000)
7173
}
7274
}

0 commit comments

Comments
 (0)