lisk-sdk
lisk-sdk copied to clipboard
Update `createTerminatedStateAccount` of baseInteroperabilityStore
Description
The createTerminatedStateAccount
function creates an entry in the terminated state substore.
def createTerminatedStateAccount(chainID: ChainID, stateRoot: bytes = EMPTY_BYTES) -> None:
if chainAccount(chainID) exists:
chainAccount(chainID).status = CHAIN_STATUS_TERMINATED
remove the entry with storeKey = chainID from the outbox root substore
# If no stateRoot is given as input, get it from the state
if len(stateRoot) == 0:
stateRoot = chainAccount(chainID).lastCertificate.stateRoot
terminatedState = {
"stateRoot": stateRoot,
"mainchainStateRoot": EMPTY_BYTES,
"initialized": True
}
# Emit chain status updated event.
emitEvent(
module = MODULE_NAME_INTEROPERABILITY,
name = EVENT_NAME_CHAIN_ACCOUNT_UPDATED,
data = chainAccount(chainID),
topics = [chainID]
)
# State root is not available, set it to empty bytes temporarily.
# This should only happen on a sidechain.
else:
# Processing on the mainchain
if ownChainAccount.chainID == CHAIN_ID_MAINCHAIN:
# If the account does not exist on the mainchain, the input chainID is invalid.
raise Exception('Chain to be terminated is not valid.')
terminatedState = {
"stateRoot": EMPTY_BYTES,
"mainchainStateRoot": chainAccount(CHAIN_ID_MAINCHAIN).lastCertificate.stateRoot,
"initialized": False
}
create an entry in the terminated state substore with
storeKey = chainID
storeValue = encode(terminatedStateAccountSchema, terminatedState)
emitEvent(
module = MODULE_NAME_INTEROPERABILITY,
name = EVENT_NAME_TERMINATED_STATE_CREATED,
data = terminatedState,
topics = [chainID]
)
Acceptance Criteria
- Should pass its unit test
Additional Information
- Related https://github.com/LiskHQ/lips/pull/148