Skip to content

Instantly share code, notes, and snippets.

@ilamanov
Created May 2, 2022 16:21
Show Gist options
  • Save ilamanov/f9ec62e6a4a9c2e2d5a4542cc088fc43 to your computer and use it in GitHub Desktop.
Save ilamanov/f9ec62e6a4a9c2e2d5a4542cc088fc43 to your computer and use it in GitHub Desktop.
/**
* @title CanonicalTransactionChain
* @dev The Canonical Transaction Chain (CTC) contract is an append-only log of transactions
* which must be applied to the rollup state. It defines the ordering of rollup transactions by
* writing them to the 'CTC:batches' instance of the Chain Storage Container.
* The CTC also allows any account to 'enqueue' an L2 transaction, which will require that the
* Sequencer will eventually append it to the rollup state.
*
*/
contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressResolver {
uint40 private _nextQueueIndex; // index of the first queue element not yet included
Lib_OVMCodec.QueueElement[] queueElements;
/**
* Adds a transaction to the queue.
* @param _target Target L2 contract to send the transaction to.
* @param _gasLimit Gas limit for the enqueued L2 transaction.
* @param _data Transaction data.
*/
function enqueue(
address _target,
uint256 _gasLimit,
bytes memory _data
) external {
// ...a bunch of unimportant stuff omitted
bytes32 transactionHash = keccak256(abi.encode(sender, _target, _gasLimit, _data));
queueElements.push(
Lib_OVMCodec.QueueElement({
transactionHash: transactionHash,
timestamp: uint40(block.timestamp),
blockNumber: uint40(block.number)
})
);
uint256 queueIndex = queueElements.length - 1;
emit TransactionEnqueued(sender, _target, _gasLimit, _data, queueIndex, block.timestamp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment