I can't understand the channel concept.
How does channel keep transactions' order? Is there a channel account for a special operation or any channel account can do any operation?
Stellar Stack Exchange is a question and answer site for developers and users of Stellar and the Stellar Distributed Exchange. It only takes a minute to sign up.Sign up to join this community
You need to understand how transaction sequence numbers first.
Every transaction has a source account, which pays for the operations contained inside it. To stop replay attacks, every transaction also has a sequence number, which must match the sequence number of the source account. (To be more specific the transaction sequence number has to be equal to the source account sequence number PLUS one).
This becomes an issue when you're submitting lots of transactions fast -- The transactions are created in a specific order, but might be accepted in a different order, where some of them ultimately fail because the sequence numbers don't match any longer.
This is where using channels enter the picture.
The transaction source account can be any account, as long as the sequence numbers match up, and it has enough funds to pay for the fees.
A channel is simply an account only used as a transaction source. It is used for its sequence number, for paying fees, and signing transactions.
By using channel accounts, you can increase your transaction throughput. E.g., ten channels can submit ten transactions per ledger update, with no dependence on what order they get executed in.
Additionally, to address this specific question:
how does channel keep transactions' order?
It doesn't I believe. In fact, the introduction of channels creates a potential race condition for operations that are sequence sensitive. Or at least I think it would. I haven't tested it.
Given operations A & B, where A must be considered before B can succeed (e.g. establish a trust line then pay using the trusted asset), then A must precede B in the operations list when they appear in the same transaction. But if they are in separate transactions, then the transaction with operation A must be processed before the transaction with operation B can be considered.
A naive channel implementation may simply bucket operations into concurrent transactions without considering how operations should be grouped.
In addition to Johan's excellent answer, please see my article on the topic.
Channel accounts are also very useful to handle preseigned transactions on foreign accounts.
If somebody presignes a transaction the sequence number must be correct. As you don't know if the user performs other transactions meanwhile (and increases the sequence number). You can't be sure the presigned transaction is valid any more.
Here you can use a channel account to avoid that issue.
I like to explain it like this:
Imagine you want to send 100 letters in the mail (transactions), however, the receptionist(stellar) will only accept one letter from you at a time (1 sequence per ledger).
So you give the other 99 letters to 99 of your friends (channels), and each of them sends a letter from you.
So basically they use their "1 letter at once" for you.
This is how channels work, they use their sequence number and fee for this ledger, to send a transaction from you.