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

refactor(contracts): add prefix '_' to private storage var _nextQueueIndex

parent fc7de380
...@@ -52,7 +52,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -52,7 +52,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
* Queue State * * Queue State *
***************/ ***************/
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; Lib_OVMCodec.QueueElement[] queueElements;
...@@ -151,7 +151,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -151,7 +151,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
uint40 uint40
) )
{ {
return nextQueueIndex; return _nextQueueIndex;
} }
/** /**
...@@ -212,7 +212,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -212,7 +212,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
uint40 uint40
) )
{ {
return uint40(queueElements.length) - nextQueueIndex; return uint40(queueElements.length) - _nextQueueIndex;
} }
/** /**
...@@ -363,10 +363,10 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -363,10 +363,10 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
// Counter for number of sequencer transactions appended so far. // Counter for number of sequencer transactions appended so far.
uint32 numSequencerTransactions = 0; uint32 numSequencerTransactions = 0;
// Cache the nextQueueIndex. // Cache the _nextQueueIndex storage variable to a temporary stack variable.
// This is safe as long as nothing reads or writes to the nextQueueIndex // This is safe as long as nothing reads or writes to the storage variable
// storage variable until it is updated with the value from nextQueueIndexCached. // until it is updated by the temp variable.
uint40 nextQueueIndexCached = nextQueueIndex; uint40 nextQueueIndex = _nextQueueIndex;
BatchContext memory curContext; BatchContext memory curContext;
for (uint32 i = 0; i < numContexts; i++) { for (uint32 i = 0; i < numContexts; i++) {
...@@ -379,11 +379,11 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -379,11 +379,11 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
numSequencerTransactions += uint32(curContext.numSequencedTransactions); numSequencerTransactions += uint32(curContext.numSequencedTransactions);
// Now process any subsequent queue transactions. // Now process any subsequent queue transactions.
nextQueueIndexCached += uint40(curContext.numSubsequentQueueTransactions); nextQueueIndex += uint40(curContext.numSubsequentQueueTransactions);
} }
require( require(
nextQueueIndexCached <= queueElements.length, nextQueueIndex <= queueElements.length,
"Attempted to append more elements than are available in the queue." "Attempted to append more elements than are available in the queue."
); );
...@@ -402,7 +402,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -402,7 +402,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
// curContext.numSubsequentQueueTransactions > 0 which means that we've processed at // curContext.numSubsequentQueueTransactions > 0 which means that we've processed at
// least one queue element. We increment nextQueueIndex after processing each queue // least one queue element. We increment nextQueueIndex after processing each queue
// element, so the index of the last element we processed is nextQueueIndex - 1. // element, so the index of the last element we processed is nextQueueIndex - 1.
Lib_OVMCodec.QueueElement memory lastElement = queueElements[nextQueueIndexCached - 1]; Lib_OVMCodec.QueueElement memory lastElement = queueElements[nextQueueIndex - 1];
blockTimestamp = lastElement.timestamp; blockTimestamp = lastElement.timestamp;
blockNumber = lastElement.blockNumber; blockNumber = lastElement.blockNumber;
...@@ -418,13 +418,13 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -418,13 +418,13 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
); );
emit SequencerBatchAppended( emit SequencerBatchAppended(
nextQueueIndexCached - numQueuedTransactions, nextQueueIndex - numQueuedTransactions,
numQueuedTransactions, numQueuedTransactions,
getTotalElements() getTotalElements()
); );
// Update the nextQueueIndex storage variable. // Update the _nextQueueIndex storage variable.
nextQueueIndex = nextQueueIndexCached; _nextQueueIndex = nextQueueIndex;
} }
/********************** /**********************
...@@ -484,7 +484,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -484,7 +484,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
bytes27 extraData = batches().getGlobalMetadata(); bytes27 extraData = batches().getGlobalMetadata();
uint40 totalElements; uint40 totalElements;
uint40 nextQueueIdx; uint40 nextQueueIndex;
uint40 lastTimestamp; uint40 lastTimestamp;
uint40 lastBlockNumber; uint40 lastBlockNumber;
...@@ -492,7 +492,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -492,7 +492,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
assembly { assembly {
extraData := shr(40, extraData) extraData := shr(40, extraData)
totalElements := and(extraData, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF) totalElements := and(extraData, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF)
nextQueueIdx := shr(40, and(extraData, 0x00000000000000000000000000000000000000000000FFFFFFFFFF0000000000)) nextQueueIndex := shr(40, and(extraData, 0x00000000000000000000000000000000000000000000FFFFFFFFFF0000000000))
lastTimestamp := shr(80, and(extraData, 0x0000000000000000000000000000000000FFFFFFFFFF00000000000000000000)) lastTimestamp := shr(80, and(extraData, 0x0000000000000000000000000000000000FFFFFFFFFF00000000000000000000))
lastBlockNumber := shr(120, and(extraData, 0x000000000000000000000000FFFFFFFFFF000000000000000000000000000000)) lastBlockNumber := shr(120, and(extraData, 0x000000000000000000000000FFFFFFFFFF000000000000000000000000000000))
} }
...@@ -500,7 +500,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -500,7 +500,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
return ( return (
totalElements, totalElements,
nextQueueIdx, nextQueueIndex,
lastTimestamp, lastTimestamp,
lastBlockNumber lastBlockNumber
); );
...@@ -509,14 +509,14 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -509,14 +509,14 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
/** /**
* Encodes the batch context for the extra data. * Encodes the batch context for the extra data.
* @param _totalElements Total number of elements submitted. * @param _totalElements Total number of elements submitted.
* @param _nextQueueIndex Index of the next queue element. * @param _nextQueueIdx Index of the next queue element.
* @param _timestamp Timestamp for the last batch. * @param _timestamp Timestamp for the last batch.
* @param _blockNumber Block number of the last batch. * @param _blockNumber Block number of the last batch.
* @return Encoded batch context. * @return Encoded batch context.
*/ */
function _makeBatchExtraData( function _makeBatchExtraData(
uint40 _totalElements, uint40 _totalElements,
uint40 _nextQueueIndex, uint40 _nextQueueIdx,
uint40 _timestamp, uint40 _timestamp,
uint40 _blockNumber uint40 _blockNumber
) )
...@@ -529,7 +529,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -529,7 +529,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
bytes27 extraData; bytes27 extraData;
assembly { assembly {
extraData := _totalElements extraData := _totalElements
extraData := or(extraData, shl(40, _nextQueueIndex)) extraData := or(extraData, shl(40, _nextQueueIdx))
extraData := or(extraData, shl(80, _timestamp)) extraData := or(extraData, shl(80, _timestamp))
extraData := or(extraData, shl(120, _blockNumber)) extraData := or(extraData, shl(120, _blockNumber))
extraData := shl(40, extraData) extraData := shl(40, extraData)
...@@ -556,7 +556,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -556,7 +556,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
internal internal
{ {
IChainStorageContainer batchesRef = batches(); IChainStorageContainer batchesRef = batches();
(uint40 totalElements, uint40 nextQueueIdx,,) = _getBatchExtraData(); (uint40 totalElements, uint40 nextQueueIndex,,) = _getBatchExtraData();
Lib_OVMCodec.ChainBatchHeader memory header = Lib_OVMCodec.ChainBatchHeader({ Lib_OVMCodec.ChainBatchHeader memory header = Lib_OVMCodec.ChainBatchHeader({
batchIndex: batchesRef.length(), batchIndex: batchesRef.length(),
...@@ -577,7 +577,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -577,7 +577,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
bytes32 batchHeaderHash = Lib_OVMCodec.hashBatchHeader(header); bytes32 batchHeaderHash = Lib_OVMCodec.hashBatchHeader(header);
bytes27 latestBatchContext = _makeBatchExtraData( bytes27 latestBatchContext = _makeBatchExtraData(
totalElements + uint40(header.batchSize), totalElements + uint40(header.batchSize),
nextQueueIdx + uint40(_numQueuedTransactions), nextQueueIndex + uint40(_numQueuedTransactions),
_timestamp, _timestamp,
_blockNumber _blockNumber
); );
......
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