Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
68f886ec
Commit
68f886ec
authored
Oct 12, 2020
by
Karl Floersch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ring buffer for chain contracts
parent
f6c20be2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
14 deletions
+22
-14
OVM_BaseChain.sol
...contracts/optimistic-ethereum/OVM/chain/OVM_BaseChain.sol
+22
-11
TestLib_TimeboundRingBuffer.sol
...acts/test-libraries/utils/TestLib_TimeboundRingBuffer.sol
+0
-3
No files found.
packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_BaseChain.sol
View file @
68f886ec
...
@@ -8,6 +8,7 @@ import { iOVM_BaseChain } from "../../iOVM/chain/iOVM_BaseChain.sol";
...
@@ -8,6 +8,7 @@ import { iOVM_BaseChain } from "../../iOVM/chain/iOVM_BaseChain.sol";
/* Library Imports */
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_MerkleUtils } from "../../libraries/utils/Lib_MerkleUtils.sol";
import { Lib_MerkleUtils } from "../../libraries/utils/Lib_MerkleUtils.sol";
import { TimeboundRingBuffer, Lib_TimeboundRingBuffer } from "../../libraries/utils/Lib_TimeboundRingBuffer.sol";
/**
/**
* @title OVM_BaseChain
* @title OVM_BaseChain
...
@@ -18,11 +19,23 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -18,11 +19,23 @@ contract OVM_BaseChain is iOVM_BaseChain {
* Contract Variables: Batches *
* Contract Variables: Batches *
*******************************/
*******************************/
bytes32[] internal batches;
using Lib_TimeboundRingBuffer for TimeboundRingBuffer;
TimeboundRingBuffer internal batches;
uint256 internal totalBatches;
uint256 internal totalBatches;
uint256 internal totalElements;
uint256 internal totalElements;
/***************
* Constructor *
***************/
constructor()
{
// TODO: Add propper customization
batches.init(4, 2, 100000);
}
/*************************************
/*************************************
* Public Functions: Batch Retrieval *
* Public Functions: Batch Retrieval *
*************************************/
*************************************/
...
@@ -39,7 +52,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -39,7 +52,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
uint256 _totalElements
uint256 _totalElements
)
)
{
{
return
totalElements
;
return
uint256(uint224(batches.getExtraData()))
;
}
}
/**
/**
...
@@ -54,7 +67,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -54,7 +67,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
uint256 _totalBatches
uint256 _totalBatches
)
)
{
{
return
totalBatches
;
return
uint256(batches.getLength())
;
}
}
...
@@ -82,7 +95,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -82,7 +95,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
)
)
{
{
require(
require(
_hashBatchHeader(_batchHeader) == batches
[_batchHeader.batchIndex]
,
_hashBatchHeader(_batchHeader) == batches
.get(uint32(_batchHeader.batchIndex))
,
"Invalid batch header."
"Invalid batch header."
);
);
...
@@ -114,9 +127,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -114,9 +127,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
internal
internal
{
{
bytes32 batchHeaderHash = _hashBatchHeader(_batchHeader);
bytes32 batchHeaderHash = _hashBatchHeader(_batchHeader);
batches.push(batchHeaderHash);
batches.push(batchHeaderHash, bytes28(uint224(getTotalElements() + _batchHeader.batchSize)));
totalBatches += 1;
totalElements += _batchHeader.batchSize;
}
}
/**
/**
...
@@ -131,7 +142,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -131,7 +142,7 @@ contract OVM_BaseChain is iOVM_BaseChain {
internal
internal
{
{
Lib_OVMCodec.ChainBatchHeader memory batchHeader = Lib_OVMCodec.ChainBatchHeader({
Lib_OVMCodec.ChainBatchHeader memory batchHeader = Lib_OVMCodec.ChainBatchHeader({
batchIndex:
batches.length
,
batchIndex:
uint(batches.getLength())
,
batchRoot: Lib_MerkleUtils.getMerkleRoot(_elements),
batchRoot: Lib_MerkleUtils.getMerkleRoot(_elements),
batchSize: _elements.length,
batchSize: _elements.length,
prevTotalElements: totalElements,
prevTotalElements: totalElements,
...
@@ -166,17 +177,17 @@ contract OVM_BaseChain is iOVM_BaseChain {
...
@@ -166,17 +177,17 @@ contract OVM_BaseChain is iOVM_BaseChain {
internal
internal
{
{
require(
require(
_batchHeader.batchIndex < batches.
length
,
_batchHeader.batchIndex < batches.
getLength()
,
"Invalid batch index."
"Invalid batch index."
);
);
require(
require(
_hashBatchHeader(_batchHeader) == batches
[_batchHeader.batchIndex]
,
_hashBatchHeader(_batchHeader) == batches
.get(uint32(_batchHeader.batchIndex))
,
"Invalid batch header."
"Invalid batch header."
);
);
totalBatches = _batchHeader.batchIndex;
totalElements = _batchHeader.prevTotalElements;
totalElements = _batchHeader.prevTotalElements;
batches.deleteElementsAfter(uint32(_batchHeader.batchIndex - 1), bytes28(uint224(totalElements)));
}
}
...
...
packages/contracts/contracts/test-libraries/utils/TestLib_TimeboundRingBuffer.sol
View file @
68f886ec
...
@@ -2,9 +2,6 @@
...
@@ -2,9 +2,6 @@
pragma solidity ^0.7.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
pragma experimental ABIEncoderV2;
/* Logging */
import { console } from "@nomiclabs/buidler/console.sol";
/* Library Imports */
/* Library Imports */
import { TimeboundRingBuffer, Lib_TimeboundRingBuffer } from "../../optimistic-ethereum/libraries/utils/Lib_TimeboundRingBuffer.sol";
import { TimeboundRingBuffer, Lib_TimeboundRingBuffer } from "../../optimistic-ethereum/libraries/utils/Lib_TimeboundRingBuffer.sol";
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment