Commit c1b06a35 authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

refactor(contracts): Only save transactionHash for queueElements

parent 8487adb9
...@@ -53,7 +53,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -53,7 +53,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
***************/ ***************/
uint40 private _nextQueueIndex; // index of the first queue element not yet included uint40 private _nextQueueIndex; // index of the first queue element not yet included
Lib_OVMCodec.QueueElement[] queueElements; bytes32[] queueElements;
/*************** /***************
...@@ -195,10 +195,15 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -195,10 +195,15 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
public public
view view
returns ( returns (
Lib_OVMCodec.QueueElement memory _element Lib_OVMCodec.QueueElement memory
) )
{ {
return queueElements[_index]; bytes32 transactionHash = queueElements[_index];
return Lib_OVMCodec.QueueElement({
transactionHash: transactionHash,
timestamp: 0,
blockNumber: 0
});
} }
/** /**
...@@ -303,14 +308,9 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -303,14 +308,9 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
) )
); );
queueElements.push( queueElements.push(transactionHash);
Lib_OVMCodec.QueueElement({
transactionHash: transactionHash,
timestamp: uint40(block.timestamp),
blockNumber: uint40(block.number)
})
);
uint256 queueIndex = queueElements.length - 1; uint256 queueIndex = queueElements.length - 1;
emit TransactionEnqueued( emit TransactionEnqueued(
sender, sender,
_target, _target,
...@@ -389,24 +389,8 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -389,24 +389,8 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
// Generate the required metadata that we need to append this batch // Generate the required metadata that we need to append this batch
uint40 numQueuedTransactions = totalElementsToAppend - numSequencerTransactions; uint40 numQueuedTransactions = totalElementsToAppend - numSequencerTransactions;
uint40 blockTimestamp; uint40 blockTimestamp = uint40(curContext.timestamp);
uint40 blockNumber; uint40 blockNumber = uint40(curContext.blockNumber);
if (curContext.numSubsequentQueueTransactions == 0) {
// The last element is a sequencer tx, therefore pull timestamp and block number from
// the last context.
blockTimestamp = uint40(curContext.timestamp);
blockNumber = uint40(curContext.blockNumber);
} else {
// The last element is a queue tx, therefore pull timestamp and block number from the
// queue element.
// curContext.numSubsequentQueueTransactions > 0 which means that we've processed at
// least one queue element. We increment nextQueueIndex after processing each queue
// element, so the index of the last element we processed is nextQueueIndex - 1.
Lib_OVMCodec.QueueElement memory lastElement = queueElements[nextQueueIndex - 1];
blockTimestamp = lastElement.timestamp;
blockNumber = lastElement.blockNumber;
}
// Cache the previous blockhash to ensure all transaction data can be retrieved efficiently. // Cache the previous blockhash to ensure all transaction data can be retrieved efficiently.
_appendBatch( _appendBatch(
......
...@@ -146,7 +146,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => { ...@@ -146,7 +146,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
const receipt = await res.wait() const receipt = await res.wait()
const gasUsed = receipt.gasUsed.toNumber() const gasUsed = receipt.gasUsed.toNumber()
console.log(' - Gas used:', gasUsed) console.log(' - Gas used:', gasUsed)
expectApprox(gasUsed, 116_003, { expectApprox(gasUsed, 95_017, {
absoluteUpperDeviation: 500, absoluteUpperDeviation: 500,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your // Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value! // contracts are too efficient, consider updating the target value!
...@@ -173,7 +173,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => { ...@@ -173,7 +173,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
const receipt = await res.wait() const receipt = await res.wait()
const gasUsed = receipt.gasUsed.toNumber() const gasUsed = receipt.gasUsed.toNumber()
console.log(' - Gas used:', gasUsed) console.log(' - Gas used:', gasUsed)
expectApprox(gasUsed, 163_844, { expectApprox(gasUsed, 142_858, {
absoluteUpperDeviation: 500, absoluteUpperDeviation: 500,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your // Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value! // contracts are too efficient, consider updating the target value!
......
...@@ -293,7 +293,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => { ...@@ -293,7 +293,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
console.log('Benchmark complete.') console.log('Benchmark complete.')
expectApprox(gasUsed, 187_081, { expectApprox(gasUsed, 166_094, {
absoluteUpperDeviation: 500, absoluteUpperDeviation: 500,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your // Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value! // contracts are too efficient, consider updating the target value!
...@@ -314,7 +314,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => { ...@@ -314,7 +314,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
console.log('Benchmark complete.') console.log('Benchmark complete.')
expectApprox(gasUsed, 126_700, { expectApprox(gasUsed, 105_713, {
absoluteUpperDeviation: 500, absoluteUpperDeviation: 500,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your // Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value! // contracts are too efficient, consider updating the target value!
......
...@@ -301,8 +301,8 @@ describe('CanonicalTransactionChain', () => { ...@@ -301,8 +301,8 @@ describe('CanonicalTransactionChain', () => {
) )
).to.deep.include({ ).to.deep.include({
transactionHash, transactionHash,
timestamp, timestamp: 0,
blockNumber, blockNumber: 0,
}) })
}) })
} }
...@@ -345,8 +345,8 @@ describe('CanonicalTransactionChain', () => { ...@@ -345,8 +345,8 @@ describe('CanonicalTransactionChain', () => {
) )
).to.deep.include({ ).to.deep.include({
transactionHash, transactionHash,
timestamp, timestamp: 0,
blockNumber, blockNumber: 0,
}) })
}) })
} }
...@@ -388,8 +388,8 @@ describe('CanonicalTransactionChain', () => { ...@@ -388,8 +388,8 @@ describe('CanonicalTransactionChain', () => {
) )
).to.deep.include({ ).to.deep.include({
transactionHash, transactionHash,
timestamp, timestamp: 0,
blockNumber, blockNumber: 0,
}) })
}) })
} }
......
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