Commit 48cfb704 authored by Karl Floersch's avatar Karl Floersch

Add enqueue functionality

parent 7ab3f1a2
...@@ -75,7 +75,8 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { / ...@@ -75,7 +75,8 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
{ {
sequencerAddress = resolve("OVM_Sequencer"); sequencerAddress = resolve("OVM_Sequencer");
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds; forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
queue.init(100, 50, 0); // TODO: Update once we have arbitrary condition queue.init(100, 50, 10000000000); // TODO: Update once we have arbitrary condition
batches.init(100, 50, 10000000000); // TODO: Update once we have arbitrary condition
} }
...@@ -100,7 +101,7 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { / ...@@ -100,7 +101,7 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
_data.length <= MAX_ROLLUP_TX_SIZE, _data.length <= MAX_ROLLUP_TX_SIZE,
"Transaction exceeds maximum rollup data size." "Transaction exceeds maximum rollup data size."
); );
require(_gasLimit >= 20000, "Gas limit too low."); require(_gasLimit >= 20000, "Layer 2 gas limit too low to enqueue.");
// Consume l1 gas rate limit queued transactions // Consume l1 gas rate limit queued transactions
uint gasToConsume = _gasLimit/L2_GAS_DISCOUNT_DIVISOR; uint gasToConsume = _gasLimit/L2_GAS_DISCOUNT_DIVISOR;
...@@ -110,35 +111,35 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { / ...@@ -110,35 +111,35 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
i++; // TODO: Replace this dumb work with minting gas token. (not today) i++; // TODO: Replace this dumb work with minting gas token. (not today)
} }
// This struct shows the form of the queueElement but isn't how we store it bytes32 batchRoot = keccak256(abi.encode(
// Lib_OVMCodec.QueueElement memory element = Lib_OVMCodec.QueueElement({ _target,
// timestamp: uint40(block.timestamp), _gasLimit,
// blockNumber: uint32(block.number), _data
// batchRoot: keccak256(abi.encodePacked( ));
// _target, // bytes is left aligned, uint is right aligned - use this to encode them together
// _gasLimit, bytes32 timestampAndBlockNumber = bytes32(bytes4(uint32(block.number))) | bytes32(uint256(uint40(block.timestamp)));
// _data // bytes32 timestampAndBlockNumber = bytes32(bytes4(uint32(999))) | bytes32(uint256(uint40(777)));
// )) queue.push2(batchRoot, timestampAndBlockNumber, bytes28(0));
// });
// bytes28 timestampBlockNumber = concat(timestamp, blockNumber)
// We need access to the timestamp and blocknumber for EVERY queue tx
// So we use push2 to push both the batchRoot and timestampAndBlocknumber
// This way we have all the info we need for calling appendSequencerMultiBatch
// queue.push2(batchRoot, timestampBlocknNumber);
} }
// function getQueueIndex(uint queueIndex) { function getQueueElement(uint queueIndex) public view returns(Lib_OVMCodec.QueueElement memory) {
// uint realIndex = queueIndex * 2; uint32 trueIndex = uint32(queueIndex * 2);
// uint timestampBlockNumber = queueIndex * 2 + 1; bytes32 batchRoot = queue.get(trueIndex);
// } bytes32 timestampAndBlockNumber = queue.get(trueIndex + 1);
uint40 timestamp = uint40(uint256(timestampAndBlockNumber & 0x000000000000000000000000000000000000000000000000000000ffffffffff));
uint32 blockNumber = uint32(bytes4(timestampAndBlockNumber & 0xffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000));
return Lib_OVMCodec.QueueElement({
batchRoot: batchRoot,
timestamp: timestamp,
blockNumber: blockNumber
});
}
/**************************************** /****************************************
* Public Functions: Batch Manipulation * * Public Functions: Batch Manipulation *
****************************************/ ****************************************/
// TODO: allow the sequencer/users to append queue batches independently // TODO: allow the sequencer/users to append queue batches independently
......
...@@ -63,12 +63,16 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -63,12 +63,16 @@ describe('OVM_CanonicalTransactionChain', () => {
) )
}) })
describe('appendSequencerMultiBatch', () => { describe('enqueue', () => {
before(() => { it.only('should store queued elements correctly', async () => {
Mock__OVM_L1ToL2TransactionQueue.smocked.size.will.return.with(0) await OVM_CanonicalTransactionChain.enqueue('0x' + '01'.repeat(20), 25000, '0x1234')
Mock__OVM_L1ToL2TransactionQueue.smocked.dequeue.will.return() const firstQueuedElement = await OVM_CanonicalTransactionChain.getQueueElement(0)
console.log(firstQueuedElement)
}) })
it('should append a multi-batch with just one batch', async () =>{ })
describe('appendSequencerMultiBatch', () => {
it('should append a multi-batch with just one batch', async () => {
// Try out appending // Try out appending
const testBatchContext: sequencerBatchContext = { const testBatchContext: sequencerBatchContext = {
numSequencedTransactions: 1, numSequencedTransactions: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment