Skip to content

Commit

Permalink
remove pushTwo and getTwo (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Ho authored Mar 13, 2021
1 parent 6ac40ba commit 6693d3a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,12 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad

iOVM_ChainStorageContainer queueRef = queue();

queueRef.pushTwo(
transactionHash,
timestampAndBlockNumber
);
queueRef.push(transactionHash);
queueRef.push(timestampAndBlockNumber);

// The underlying queue data structure stores 2 elements
// per insertion, so to get the real queue length we need
// to divide by 2 and subtract 1. See the usage of `pushTwo(..)`.
// to divide by 2 and subtract 1.
uint256 queueIndex = queueRef.length() / 2 - 1;
emit TransactionEnqueued(
msg.sender,
Expand Down Expand Up @@ -751,11 +749,10 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
{
// The underlying queue data structure stores 2 elements
// per insertion, so to get the actual desired queue index
// we need to multiply by 2. See the usage of `pushTwo(..)`.
(
bytes32 transactionHash,
bytes32 timestampAndBlockNumber
) = _queueRef.getTwo(uint40(_index * 2));
// we need to multiply by 2.
uint40 trueIndex = uint40(_index * 2);
bytes32 transactionHash = _queueRef.get(trueIndex);
bytes32 timestampAndBlockNumber = _queueRef.get(trueIndex + 1);

uint40 elementTimestamp;
uint40 elementBlockNumber;
Expand Down Expand Up @@ -786,7 +783,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
{
// The underlying queue data structure stores 2 elements
// per insertion, so to get the real queue length we need
// to divide by 2. See the usage of `pushTwo(..)`.
// to divide by 2.
return uint40(_queueRef.length() / 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,6 @@ contract OVM_ChainStorageContainer is iOVM_ChainStorageContainer, Lib_AddressRes
buffer.push(_object, _globalMetadata);
}

/**
* @inheritdoc iOVM_ChainStorageContainer
*/
function pushTwo(
bytes32 _objectA,
bytes32 _objectB
)
override
public
onlyOwner
{
buffer.pushTwo(_objectA, _objectB);
}

/**
* @inheritdoc iOVM_ChainStorageContainer
*/
function pushTwo(
bytes32 _objectA,
bytes32 _objectB,
bytes27 _globalMetadata
)
override
public
onlyOwner
{
buffer.pushTwo(_objectA, _objectB, _globalMetadata);
}

/**
* @inheritdoc iOVM_ChainStorageContainer
*/
Expand All @@ -186,23 +157,6 @@ contract OVM_ChainStorageContainer is iOVM_ChainStorageContainer, Lib_AddressRes
{
return buffer.get(uint40(_index));
}

/**
* @inheritdoc iOVM_ChainStorageContainer
*/
function getTwo(
uint256 _index
)
override
public
view
returns (
bytes32,
bytes32
)
{
return buffer.getTwo(uint40(_index));
}

/**
* @inheritdoc iOVM_ChainStorageContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,6 @@ interface iOVM_ChainStorageContainer {
)
external;

/**
* Pushes two objects into the container at the same time. A useful optimization.
* @param _objectA First 32 byte value to insert into the container.
* @param _objectB Second 32 byte value to insert into the container.
*/
function pushTwo(
bytes32 _objectA,
bytes32 _objectB
)
external;

/**
* Pushes two objects into the container at the same time. Also allows setting the global
* metadata field.
* @param _objectA First 32 byte value to insert into the container.
* @param _objectB Second 32 byte value to insert into the container.
* @param _globalMetadata New global metadata for the container.
*/
function pushTwo(
bytes32 _objectA,
bytes32 _objectB,
bytes27 _globalMetadata
)
external;

/**
* Retrieves an object from the container.
* @param _index Index of the particular object to access.
Expand All @@ -104,22 +79,6 @@ interface iOVM_ChainStorageContainer {
bytes32
);

/**
* Retrieves two consecutive objects from the container.
* @param _index Index of the particular objects to access.
* @return 32 byte object value at index `_index`.
* @return 32 byte object value at index `_index + 1`.
*/
function getTwo(
uint256 _index
)
external
view
returns (
bytes32,
bytes32
);

/**
* Removes all objects after and including a given index.
* @param _index Object index to delete from.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,6 @@ library Lib_RingBuffer {
);
}

/**
* Pushes a two elements to the buffer.
* @param _self Buffer to access.
* @param _valueA First value to push to the buffer.
* @param _valueA Second value to push to the buffer.
* @param _extraData Optional global extra data.
*/
function pushTwo(
RingBuffer storage _self,
bytes32 _valueA,
bytes32 _valueB,
bytes27 _extraData
)
internal
{
_self.push(_valueA, _extraData);
_self.push(_valueB, _extraData);
}

/**
* Pushes a two elements to the buffer.
* @param _self Buffer to access.
* @param _valueA First value to push to the buffer.
* @param _valueA Second value to push to the buffer.
*/
function pushTwo(
RingBuffer storage _self,
bytes32 _valueA,
bytes32 _valueB
)
internal
{
RingBufferContext memory ctx = _self.getContext();

_self.pushTwo(
_valueA,
_valueB,
ctx.extraData
);
}

/**
* Retrieves an element from the buffer.
* @param _self Buffer to access.
Expand Down Expand Up @@ -211,30 +170,6 @@ library Lib_RingBuffer {
}
}

/**
* Retrieves two consecutive elements from the buffer.
* @param _self Buffer to access.
* @param _index Element index to retrieve.
* @return Value of the element at index `_index`.
* @return Value of the element at index `_index + 1`.
*/
function getTwo(
RingBuffer storage _self,
uint256 _index
)
internal
view
returns (
bytes32,
bytes32
)
{
return (
_self.get(_index),
_self.get(_index + 1)
);
}

/**
* Deletes all elements after (and including) a given index.
* @param _self Buffer to access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ contract TestLib_RingBuffer {
);
}

function pushTwo(
bytes32 _valueA,
bytes32 _valueB,
bytes27 _extraData
)
public
{
buf.pushTwo(
_valueA,
_valueB,
_extraData
);
}

function get(
uint256 _index
)
Expand Down

0 comments on commit 6693d3a

Please sign in to comment.