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

Update createTerminatedStateAccount of baseInteroperabilityStore #7559

Closed
Tracked by #7211
ishantiw opened this issue Sep 22, 2022 · 0 comments
Closed
Tracked by #7211

Update createTerminatedStateAccount of baseInteroperabilityStore #7559

ishantiw opened this issue Sep 22, 2022 · 0 comments
Assignees
Labels
framework/module/interoperability Interoperability module
Milestone

Comments

@ishantiw
Copy link
Contributor

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

@ishantiw ishantiw added the framework/module/interoperability Interoperability module label Sep 22, 2022
@shuse2 shuse2 added this to the Sprint 79 milestone Sep 26, 2022
@shuse2 shuse2 modified the milestones: Sprint 79, Sprint 80 Oct 10, 2022
@mitsuaki-u mitsuaki-u self-assigned this Oct 13, 2022
@shuse2 shuse2 modified the milestones: Sprint 80, Sprint 81 Oct 24, 2022
ishantiw added a commit that referenced this issue Oct 26, 2022
  (#7675)

### What was the problem?

This PR resolves #7559 

### How was it solved?

- Updated `createTerminatedState`

### How was it tested?

Added unit tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework/module/interoperability Interoperability module
Projects
None yet
Development

No branches or pull requests

3 participants