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

refactor(contracts): Remove unused or unecessary internal function in the CTC

This commit removes _hashTransactionChainElement which was no longer used, and _getQueueElement,
which is now replaced with a lookup in the mapping.
Other areas of the code are simplified, and a local variable is renamed to avoid shadowing
parent fb5df373
...@@ -198,9 +198,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -198,9 +198,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
Lib_OVMCodec.QueueElement memory _element Lib_OVMCodec.QueueElement memory _element
) )
{ {
return _getQueueElement( return queueElements[_index];
_index
);
} }
/** /**
...@@ -214,7 +212,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -214,7 +212,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
uint40 uint40
) )
{ {
return getQueueLength() - getNextQueueIndex(); return uint40(queueElements.length) - nextQueueIndex;
} }
/** /**
...@@ -366,7 +364,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -366,7 +364,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
uint32 numSequencerTransactions = 0; uint32 numSequencerTransactions = 0;
// Cache the nextQueueIndex. // Cache the nextQueueIndex.
// In order to be safe, nothing should read or write to the nextQueueIndex // This is safe as long as nothing reads or writes to the nextQueueIndex
// storage variable until it is updated with the value from nextQueueIndexCached. // storage variable until it is updated with the value from nextQueueIndexCached.
uint40 nextQueueIndexCached = nextQueueIndex; uint40 nextQueueIndexCached = nextQueueIndex;
...@@ -404,9 +402,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -404,9 +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 = _getQueueElement( Lib_OVMCodec.QueueElement memory lastElement = queueElements[nextQueueIndexCached - 1];
nextQueueIndexCached - 1
);
blockTimestamp = lastElement.timestamp; blockTimestamp = lastElement.timestamp;
blockNumber = lastElement.blockNumber; blockNumber = lastElement.blockNumber;
...@@ -488,7 +484,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -488,7 +484,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
bytes27 extraData = batches().getGlobalMetadata(); bytes27 extraData = batches().getGlobalMetadata();
uint40 totalElements; uint40 totalElements;
uint40 nextQueueIndex; uint40 nextQueueIdx;
uint40 lastTimestamp; uint40 lastTimestamp;
uint40 lastBlockNumber; uint40 lastBlockNumber;
...@@ -496,7 +492,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -496,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)
nextQueueIndex := shr(40, and(extraData, 0x00000000000000000000000000000000000000000000FFFFFFFFFF0000000000)) nextQueueIdx := 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))
} }
...@@ -504,7 +500,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -504,7 +500,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
return ( return (
totalElements, totalElements,
nextQueueIndex, nextQueueIdx,
lastTimestamp, lastTimestamp,
lastBlockNumber lastBlockNumber
); );
...@@ -542,24 +538,6 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -542,24 +538,6 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
return extraData; return extraData;
} }
/**
* Gets the queue element at a particular index.
* @param _index Index of the queue element to access.
* @return _element Queue element at the given index.
*/
function _getQueueElement(
uint256 _index
)
internal
view
returns (
Lib_OVMCodec.QueueElement memory _element
)
{
// solhint-enable max-line-length
return queueElements[_index];
}
/** /**
* Inserts a batch into the chain of batches. * Inserts a batch into the chain of batches.
* @param _transactionRoot Root of the transaction tree for this batch. * @param _transactionRoot Root of the transaction tree for this batch.
...@@ -578,7 +556,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -578,7 +556,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
internal internal
{ {
IChainStorageContainer batchesRef = batches(); IChainStorageContainer batchesRef = batches();
(uint40 totalElements, uint40 nextQueueIndex,,) = _getBatchExtraData(); (uint40 totalElements, uint40 nextQueueIdx,,) = _getBatchExtraData();
Lib_OVMCodec.ChainBatchHeader memory header = Lib_OVMCodec.ChainBatchHeader({ Lib_OVMCodec.ChainBatchHeader memory header = Lib_OVMCodec.ChainBatchHeader({
batchIndex: batchesRef.length(), batchIndex: batchesRef.length(),
...@@ -599,37 +577,11 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes ...@@ -599,37 +577,11 @@ 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),
nextQueueIndex + uint40(_numQueuedTransactions), nextQueueIdx + uint40(_numQueuedTransactions),
_timestamp, _timestamp,
_blockNumber _blockNumber
); );
batchesRef.push(batchHeaderHash, latestBatchContext); batchesRef.push(batchHeaderHash, latestBatchContext);
} }
/**
* Hashes a transaction chain element.
* @param _element Chain element to hash.
* @return Hash of the chain element.
*/
function _hashTransactionChainElement(
Lib_OVMCodec.TransactionChainElement memory _element
)
internal
pure
returns (
bytes32
)
{
return keccak256(
abi.encode(
_element.isSequenced,
_element.queueIndex,
_element.timestamp,
_element.blockNumber,
_element.txData
)
);
}
} }
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