LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 454 forks source link

[base_interoperability_store.ts] duplicated code block inside `createTerminatedStateAccount` #7508

Closed sitetester closed 9 months ago

sitetester commented 2 years ago

Description

if (stateRoot) {
    if (isExist) {
        const chainAccount = await chainSubstore.get(this.context, chainID);
        chainAccount.status = CHAIN_TERMINATED;
        await chainSubstore.set(this.context as StoreGetter, chainID, chainAccount);
        const outboxRootSubstore = this.stores.get(OutboxRootStore);
        await outboxRootSubstore.del(this.context as StoreGetter, chainID);
    }
    terminatedState = {
        stateRoot,
        mainchainStateRoot: EMPTY_BYTES,
        initialized: true,
    };
} else if (isExist) {
    const chainAccount = await chainSubstore.get(this.context, chainID);
    chainAccount.status = CHAIN_TERMINATED;
    await chainSubstore.set(this.context as StoreGetter, chainID, chainAccount);
    const outboxRootSubstore = this.stores.get(OutboxRootStore);
    await outboxRootSubstore.del(this.context as StoreGetter, chainID);

    terminatedState = {
        stateRoot: chainAccount.lastCertificate.stateRoot,
        mainchainStateRoot: EMPTY_BYTES,
        initialized: true,
    };
}

Here following code block is duplicated, should be moved to outside of ifs

const chainAccount = await chainSubstore.get(this.context, chainID);
chainAccount.status = CHAIN_TERMINATED;
await chainSubstore.set(this.context as StoreGetter, chainID, chainAccount);
const outboxRootSubstore = this.stores.get(OutboxRootStore);
await outboxRootSubstore.del(this.context as StoreGetter, chainID);

Motivation

Please describe why it is needed

Additional Information

shuse2 commented 9 months ago

Closing this issue for no activity