Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions packages/neuron-wallet/src/startup/sync-block-task/init-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,31 @@ export class InitDatabase {

this.inProcess = true

let hash: string = network.genesisHash
let chain: string = network.chain
let hash: string = EMPTY_GENESIS_HASH
let chain: string = ''
while (!this.stopped && !this.success) {
try {
if (hash === EMPTY_GENESIS_HASH) {
hash = await genesisBlockHash(network.remote)
}
hash = await genesisBlockHash(network.remote)
await initConnection(hash)
if (chain === '') {
chain = await getChain(network.remote)
}
chain = await getChain(network.remote)

try {
const systemScriptInfo = await LockUtils.systemScript(network.remote)
const daoScriptInfo = await DaoUtils.daoScript(network.remote)
updateMetaInfo({ genesisBlockHash: hash, systemScriptInfo, chain, daoScriptInfo })
} catch (err) {
logger.error('update systemScriptInfo failed:', err)
}
if (hash === network.genesisHash && chain === network.chain) {
try {
const systemScriptInfo = await LockUtils.systemScript(network.remote)
const daoScriptInfo = await DaoUtils.daoScript(network.remote)
updateMetaInfo({ genesisBlockHash: hash, systemScriptInfo, chain, daoScriptInfo })
} catch (err) {
logger.error('update systemScriptInfo failed:', err)
}

this.success = true
this.success = true
} else {
logger.error('network genesis hash and chain do not match data fetched')
this.stopped = true
this.killed = true // Do not process as successful to let sync start with wrong genesis hash or chain
}
} catch (err) {
logger.debug('initDatabase error:', err)
logger.error('initDatabase error:', err)
try {
const metaInfo = getMetaInfo()
await initConnection(metaInfo.genesisBlockHash)
Expand All @@ -67,6 +69,7 @@ export class InitDatabase {
hash = metaInfo.genesisBlockHash
this.success = true
} catch (error) {
logger.error('get cached meta info error:', err)
Utils.sleep(5000)
}
}
Expand Down