A contract is an account, it has an address and balance like any other account. But additionally, it has code and storage. The transactions it received, can have value and invocation data. And each transaction has a cost, as it is saved in the blockchain.
In this post series, I will describe a possible implementation of support for offchain transactions and state. The idea is that a contract could be in another states, others than normal one:
When a contract is at offline state, it is executed in a designated running node, only ONE node, not in EVERY node of the network. The transactions it receives are execute only in the RUNNING NODE, and they are not added to the blockchain. So, the cost of the transactions could be free or near to free. Only when the contract decided to commit the new storage state, the state is published in the blockchain using a delta onchain transaction.
The change of state from normal to offchain is triggered by the contract itself. In its code, there is a new instruction (translated to new Ethereum VM opcode), to switch to offchain status. Then, all onchain transaction are rejected for this contract, no miner could add those transactions. But new offchain transactions should be routed to the running node (the only node that is running the offchain contract instance). An offchain transaction could be identified, ie, by a nonce of -1 (it is an implementation detail: the users can send onchain and offchain transactions: the former are processed only when the target contract is in normal state; the later only when it is in offchain state),
Again, the contract code could decide, when being in offchain state, to commit its state to the blockchain, or to rollback to the previous published state. If it decides to commit, then it switch to a temporary frozen state, until a delta onchain transaction is mined and accepted by the rest of the network. The delta transaction has the mission to update the published state to the new one, hosted by the running node.
In the next posts, I will describe the delta transaction with more detail, and I will discuss also the value transfer in case of offchain transactions. Maybe, now the RSK main code is public, I would publish a light implementation of these ideas.
Angel “Java” Lopez