Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open connections and channels when adding a new chain #2

Closed
gamarin2 opened this issue Apr 26, 2021 · 0 comments
Closed

Open connections and channels when adding a new chain #2

gamarin2 opened this issue Apr 26, 2021 · 0 comments
Labels

Comments

@gamarin2
Copy link
Contributor

gamarin2 commented Apr 26, 2021

When we add a new chain to Demeris backend by adding an entry to the CNS, we need to make sure that it has a connection/port/channel with all the chains we currently support.

In other words, we need a process that does the following:

// Process that needs to be followed when trying to enable a new chain NewChain with id newchain-id

// get list of clientIDs on NewChain 
clientIDSNewChain := db.getClientIDs(newchain-id)

for each chain-id in CNS {

    // matchingClientIDs contains a list of matching client IDs between NewChain and chain 
    matchingClientIDs := []string


    // this loop attemps to find out the list of matching clients between chain and NewChain 
    for each clientID in clientIDSNewChain
        clientState := db.getClientState(newchain-id, clientID)
        if clientState.chainID == chain-id
            // there is a client on newchain that matches the chain-id of a chain in the CNS
            // we now need to verify that there is a matching client on the other side

            counterpartyClientID = clientState.counterparty.ClientID 
            (found, counterPartyClientState) := db.getClientState(chain-id, counterpartyClientID) // find clientState where ChaindID == chain-id AND ClientID = counterpartyClientID
            if (found) && (counterPartyClientState.chainID == newchain-id) && (counterPartyClientState.counterparty.clientID == clientID)
                matchingClientIDs.add(clientID)
                
    
    if matchingClientIDs.isEmpty 
        // no matching client IDs, we need to create client, connection and channel

        (success, channelToChain, channelToNewChain) = hermes.createChannel(chain-id, newchain-id)
        if success 
            cns.PrimaryChannel(chain-id, newchain-id) = channelToNewChain 
            cns.PrimaryChannel(newchain-id, chain-id) = channelToChain 
        
        return 
    
    else 
        // there is at least one matching client 

        // matchingConnectionIDs contains a list of matching connection IDs between NewChain and chain 
        matchingConnectionIDs := []string

        for each clientID in matchingClientIDs

            // get list of connectionIDs on NewChain associated with clientID
            connectionIDSNewChain := db.getConnectionIDsFromClientID(newchain-id, clientID)

            // this loop attemps to find out the list of matching connections between chain and NewChain 
            for each connectionID in connectionIDsNewChain
                counterPartyConnectionID = db.getCounterpartyConnectionID(newchain-id, connectionID)
                if db.getCounterpartyConnectionID(chain-id, counterPartyConnectionID) == connectionID
                    // there is a matching connection on both sides 
                    macthingConnectionIDs.add(connectionID)
            
        if matchingConnectionIDs.isEmpty
            // there is at least a matching client on each side but no connection 

            // we open a new client, connection and channel to be safe
            (success, channelToChain, channelToNewChain) = hermes.createChannel(chain-id, newchain-id)
            if success 
                cns.PrimaryChannel(chain-id, newchain-id) = channelToNewChain 
                cns.PrimaryChannel(newchain-id, chain-id) = channelToChain 
        
            return  
        
        else 
            // at least one of the matching clients has a matching connection 
            
            // matchingChannelIDs contains a list of matching channelIDs (of unordered channels) between NewChain and chain 
            matchingChannelIDs := []{string, string}

            for each connectionID in matchingConnectionIDs

                // get list of channelIDs on NewChain associated with connectionID
                channelIDSNewChain := db.getChannelIDsFromConnexionID(newchain-id, connectionID)

                // this loop attemps to find out the list of matching channels between chain and NewChain 
                for each channelID in channelIDSNewChain
                    if channelID.isUNORDERED
                        counterPartyChannelID = db.getCounterpartyChannelID(newchain-id, channelID)
                        if db.getCounterpartyChannelID(chain-id, counterPartyChannelID) == channelID
                            // there is a matching unordered channel on both sides 
                            macthingChannelIDs.add(channelID, counterPartyChannelID)
                
            if matchingChannelIDs.isEmpty
                // there is at least a matching connection on each side but no matching unordered channel 

                // we open a new client, connection and channel to be safe
                (success, channelToChain, channelToNewChain) = hermes.createChannel(chain-id, newchain-id)
                if success 
                    cns.PrimaryChannel(chain-id, newchain-id) = channelToNewChain 
                    cns.PrimaryChannel(newchain-id, chain-id) = channelToChain 
            
                return  
            
            else 
                // at least one of the matching connections has a matching unordered channel

                // pick the first matching unordered channel as the primary channel  
                cns.PrimaryChannel(newchain-id, chain-id) = matchingChannelIDs[0]{0} 
                cns.PrimaryChannel(chain-id, newchain-id) = matchingChannelIDs[0]{1}  

                return
}
@gamarin2 gamarin2 added the MVP label Apr 30, 2021
@gamarin2 gamarin2 assigned gsora and unassigned nodebreaker0-0 Jun 3, 2021
@gsora gsora closed this as completed Jun 30, 2021
@gsora gsora removed their assignment Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants