Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Fix LIP0054 open issues #285

Merged
merged 10 commits into from
Mar 10, 2023
Merged
46 changes: 27 additions & 19 deletions proposals/lip-0045.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Discussions-To: https://research.lisk.com/t/introduce-interoperability-module/29
Status: Draft
Type: Standards Track
Created: 2021-05-21
Updated: 2023-02-24
Updated: 2023-03-10
Requires: 0043, 0049, 0053, 0054
```

Expand Down Expand Up @@ -236,6 +236,7 @@ In this section, we specify the substores that are part of the Interoperability
| `MAX_CROSS_CHAIN_COMMAND_NAME_LENGTH` | uint32 | 32 | The maximum length of a string specifying the name of a command. |
| `MIN_CHAIN_NAME_LENGTH` | uint32 | 1 | The minimum length of a string specifying the name of a chain. |
| `MAX_CHAIN_NAME_LENGTH` | uint32 | 32 | The maximum length of a string specifying the name of a chain. |
| `SUBSTORE_PREFIX_LENGTH` | uint32 | 2 | Length in bytes of a substore prefix. |

We further use the utility function `getMainchainID` defined in [LIP 0037][lip-0037#getMainchainID] to obtain the chain ID of the mainchain.

Expand Down Expand Up @@ -618,8 +619,8 @@ terminatedStateAccountSchema = {
```
##### Properties

* `stateRoot`: The state root of the terminated chain, initialized to `chainAccount(chainID).lastCertificate.stateRoot`, where `chainID` is the chain ID of the terminated chain. If the account is not initialized, it is set to `EMPTY_HASH` instead.
* `mainchainStateRoot`: The state root of the mainchain at the moment in which the chain was terminated, set to `chainAccount(getMainchainID()).lastCertificate.stateRoot` for non-initialized terminated state accounts. If the account is initialized, it is set to `EMPTY_HASH` instead.
* `stateRoot`: The state root of the terminated chain. If the terminated state account is initialized, this property is set to either `chainAccount(chainID).lastCertificate.stateRoot`, where `chainID` is the chain ID of the terminated chain, or to the state root given in the parameters of the sidechain terminated CCM. If the account is not initialized, it is set to `EMPTY_HASH` instead.
* `mainchainStateRoot`: If the terminated state account is *not* initialized, this property is set to the last certified state root of the mainchain at the moment in which the chain was terminated, i.e. to `chainAccount(getMainchainID()).lastCertificate.stateRoot`. If the account is initialized, it is set to `EMPTY_HASH` instead.
* `initialized`: A boolean value, indicating whether the terminated state account has been initialized, i.e. if the `stateRoot` property has been set.

A terminated state account is created as part of the `terminateChain` function, as part of the processing of a sidechain terminated CCM, as part of the processing of a channel terminated CCM, or as part of the processing of a state recovery initialization command.
Expand Down Expand Up @@ -980,6 +981,14 @@ The `createTerminatedStateAccount` function creates an entry in the terminated s
def createTerminatedStateAccount(chainID: ChainID, stateRoot: bytes = EMPTY_HASH) -> None:
if chainAccount(chainID) exists:
chainAccount(chainID).status = CHAIN_STATUS_TERMINATED
# Emit chain status updated event.
emitEvent(
module = MODULE_NAME_INTEROPERABILITY,
name = EVENT_NAME_CHAIN_ACCOUNT_UPDATED,
data = chainAccount(chainID),
topics = [chainID]
)

remove the entry with storeKey = chainID from the outbox root substore

# If no stateRoot is given as input, get it from the state.
Expand All @@ -991,28 +1000,27 @@ def createTerminatedStateAccount(chainID: ChainID, stateRoot: bytes = EMPTY_HASH
"mainchainStateRoot": EMPTY_HASH,
"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 hash temporarily.
# This should only happen on a sidechain.

gkoumout marked this conversation as resolved.
Show resolved Hide resolved
else:
# Processing on the mainchain.
if ownChainAccount.chainID == getMainchainID():
# 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_HASH,
"mainchainStateRoot": chainAccount(getMainchainID()).lastCertificate.stateRoot,
"initialized": False
}
# If no stateRoot is given as input, the terminated state account is not initialized.
# This can only happen on a sidechain.
if stateRoot == EMPTY_HASH:
terminatedState = {
"stateRoot": EMPTY_HASH,
"mainchainStateRoot": chainAccount(getMainchainID()).lastCertificate.stateRoot,
"initialized": False
}
else:
terminatedState = {
"stateRoot": stateRoot,
"mainchainStateRoot": EMPTY_HASH,
"initialized": True
}

create an entry in the terminated state substore with
storeKey = chainID
Expand Down
Loading