lisk-sdk icon indicating copy to clipboard operation
lisk-sdk copied to clipboard

Update isLive function for mainchain/sidechain

Open ishantiw opened this issue 2 years ago • 0 comments

Description

Update isLive function for mainchain/sidechain as per LIP.

def isLive(chainID: ChainID) -> bool:
    if chainID == ownChainAccount.chainID:
        return True
    
    # Processing on the mainchain
    if ownChainAccount.chainID == CHAIN_ID_MAINCHAIN:
        if chainAccount(chainID) exists:
            # Check if chain has been already terminated.
            if chainAccount(chainID).status == CHAIN_TERMINATED:
                return False
            # Check liveness condition
            elif chainAccount(chainID).status == CHAIN_ACTIVE:
                timestamp = timestamp of the block where this state transition is processed
                if timestamp - chainAccount(chainID).lastCertificate.timestamp > LIVENESS_LIMIT:
                    return False
            
            return True
        # Account has to exist on the mainchain
        return False
    # Processing on a sidechain
    else:
        if chainAccount(chainID) exists:
            # Check if chain has been already terminated.
            # Liveness condition is not checked on sidechains.
            # Account may not exist on a sidechain.
            if chainAccount(chainID).status == CHAIN_TERMINATED:
                return False
        if terminatedStateAccount(chainID) exists:
            return False
        return True

Acceptance Criteria

  • Should have unit test updated and passing

Additional Information

  • Related https://github.com/LiskHQ/lips/pull/148
  • Depends on #7555

ishantiw avatar Sep 22 '22 21:09 ishantiw