Commit 85423394 authored by Karl Floersch's avatar Karl Floersch Committed by GitHub

Add getPendingQueueElements (#38)

parent fa5a2598
...@@ -167,6 +167,20 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad ...@@ -167,6 +167,20 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
}); });
} }
/**
* @inheritdoc iOVM_CanonicalTransactionChain
*/
function getNumPendingQueueElements()
override
public
view
returns (
uint40
)
{
return _getQueueLength() - getNextQueueIndex();
}
/** /**
* @inheritdoc iOVM_CanonicalTransactionChain * @inheritdoc iOVM_CanonicalTransactionChain
*/ */
...@@ -248,15 +262,14 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad ...@@ -248,15 +262,14 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
override override
public public
{ {
uint40 nextQueueIndex = getNextQueueIndex(); _numQueuedTransactions = Math.min(_numQueuedTransactions, getNumPendingQueueElements());
uint40 queueLength = _getQueueLength();
_numQueuedTransactions = Math.min(_numQueuedTransactions, queueLength - nextQueueIndex);
require( require(
_numQueuedTransactions > 0, _numQueuedTransactions > 0,
"Must append more than zero transactions." "Must append more than zero transactions."
); );
bytes32[] memory leaves = new bytes32[](_numQueuedTransactions); bytes32[] memory leaves = new bytes32[](_numQueuedTransactions);
uint40 nextQueueIndex = getNextQueueIndex();
for (uint256 i = 0; i < _numQueuedTransactions; i++) { for (uint256 i = 0; i < _numQueuedTransactions; i++) {
if (msg.sender != sequencer) { if (msg.sender != sequencer) {
...@@ -683,7 +696,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad ...@@ -683,7 +696,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
internal internal
view view
{ {
if (queue.getLength() == 0) { if (getNumPendingQueueElements() == 0) {
return; return;
} }
......
...@@ -85,6 +85,17 @@ interface iOVM_CanonicalTransactionChain { ...@@ -85,6 +85,17 @@ interface iOVM_CanonicalTransactionChain {
uint40 uint40
); );
/**
* Get the number of queue elements which have not yet been included.
* @return Length of the queue.
*/
function getNumPendingQueueElements()
external
view
returns (
uint40
);
/** /**
* Gets the queue element at a particular index. * Gets the queue element at a particular index.
* @param _index Index of the queue element to access. * @param _index Index of the queue element to access.
......
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