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
79f4c3ca
Commit
79f4c3ca
authored
Oct 10, 2020
by
Karl Floersch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up & start to add tests
parent
ba8fe478
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
127 additions
and
24 deletions
+127
-24
NEW_OVM_CanonicalTransactionChain.sol
...-ethereum/OVM/chain/NEW_OVM_CanonicalTransactionChain.sol
+39
-24
OVM_NewCanonicalTransactionChain.spec.ts
...tracts/OVM/chain/OVM_NewCanonicalTransactionChain.spec.ts
+88
-0
No files found.
packages/contracts/contracts/optimistic-ethereum/OVM/chain/NEW_OVM_CanonicalTransactionChain.sol
View file @
79f4c3ca
...
@@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2;
...
@@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2;
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import { Lib_MerkleUtils } from "../../libraries/utils/Lib_MerkleUtils.sol";
import { Lib_MerkleUtils } from "../../libraries/utils/Lib_MerkleUtils.sol";
import { console } from "@nomiclabs/buidler/console.sol";
/* Interface Imports */
/* Interface Imports */
import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalTransactionChain.sol";
import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalTransactionChain.sol";
...
@@ -19,7 +20,7 @@ import { OVM_BaseChain } from "./OVM_BaseChain.sol";
...
@@ -19,7 +20,7 @@ import { OVM_BaseChain } from "./OVM_BaseChain.sol";
*/
*/
contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { // TODO: re-add iOVM_CanonicalTransactionChain
contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { // TODO: re-add iOVM_CanonicalTransactionChain
struct
Seqeuncer
BatchContext {
struct
Multi
BatchContext {
uint numSequencedTransactions;
uint numSequencedTransactions;
uint numSubsequentQueueTransactions;
uint numSubsequentQueueTransactions;
uint timestamp;
uint timestamp;
...
@@ -28,10 +29,10 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -28,10 +29,10 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
struct TransactionChainElement {
struct TransactionChainElement {
bool isSequenced;
bool isSequenced;
uint queueIndex;
// unused if isSequenced
uint queueIndex;
// QUEUED TX ONLY
uint timestamp;
// unused if !isSequenced
uint timestamp;
// SEQUENCER TX ONLY
uint blocknumber; //
unused if !isSequenced
uint blocknumber; //
SEQUENCER TX ONLY
bytes txData;
// unused if !isSequenced
bytes txData;
// SEQUENCER TX ONLY
}
}
/*******************************************
/*******************************************
...
@@ -47,6 +48,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -47,6 +48,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
uint256 internal forceInclusionPeriodSeconds;
uint256 internal forceInclusionPeriodSeconds;
uint256 internal lastOVMTimestamp;
uint256 internal lastOVMTimestamp;
address internal sequencerAddress;
/***************
/***************
...
@@ -64,6 +66,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -64,6 +66,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
Lib_AddressResolver(_libAddressManager)
Lib_AddressResolver(_libAddressManager)
{
{
ovmL1ToL2TransactionQueue = iOVM_L1ToL2TransactionQueue(resolve("OVM_L1ToL2TransactionQueue"));
ovmL1ToL2TransactionQueue = iOVM_L1ToL2TransactionQueue(resolve("OVM_L1ToL2TransactionQueue"));
sequencerAddress = resolve("OVM_Sequencer");
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
}
}
...
@@ -79,11 +82,11 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -79,11 +82,11 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
/**
/**
* Appends a sequencer batch.
* Appends a sequencer batch.
*/
*/
function appendSequencer
Batches
(
function appendSequencer
MultiBatch
(
bytes[] memory _rawTransactions,
bytes[] memory _rawTransactions,
// 2 byte prefix for how many elements, per element 3 byte prefix.
SeqeuncerBatchContext[] memory _multiBatchContext,
MultiBatchContext[] memory _multiBatchContexts, // 2 byte prefix for how many elements, fixed size elements
uint256 _shouldStartAtBatch,
uint256 _shouldStartAtBatch,
// 6 bytes
uint _totalElementsToAppend
uint _totalElementsToAppend
// 2 btyes
)
)
// override
// override
public // TODO: can we make external? Hopefully so
public // TODO: can we make external? Hopefully so
...
@@ -94,7 +97,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -94,7 +97,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
);
);
require(
require(
msg.sender ==
resolve("Sequencer")
,
msg.sender ==
sequencerAddress
,
"Function can only be called by the Sequencer."
"Function can only be called by the Sequencer."
);
);
...
@@ -105,28 +108,33 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -105,28 +108,33 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
);
);
}
}
// Initialize an array which will contain the leaves of the merkle tree commitment
bytes32[] memory leaves = new bytes32[](_totalElementsToAppend);
bytes32[] memory leaves = new bytes32[](_totalElementsToAppend);
uint numBatchContexts = _multiBatchContexts.length;
uint numBatches = _multiBatchContext.length;
uint transactionIndex = 0;
uint transactionIndex = 0;
uint numSequencerTransactionsProcessed = 0;
uint numSequencerTransactionsProcessed = 0;
for (uint batchIndex = 0; batchIndex < numBatches; batchIndex++) {
for (uint batchContextIndex = 0; batchContextIndex < numBatchContexts; batchContextIndex++) {
SeqeuncerBatchContext memory curBatch = _multiBatchContext[batchIndex];
uint numSequencedTransactions = curBatch.numSequencedTransactions;
// Process Sequencer Transactions
MultiBatchContext memory curContext = _multiBatchContexts[batchContextIndex];
uint numSequencedTransactions = curContext.numSequencedTransactions;
for (uint txIndex = 0; txIndex < numSequencedTransactions; txIndex++) {
for (uint txIndex = 0; txIndex < numSequencedTransactions; txIndex++) {
TransactionChainElement memory element = TransactionChainElement({
TransactionChainElement memory element = TransactionChainElement({
isSequenced: true,
isSequenced: true,
queueIndex: 0,
queueIndex: 0,
timestamp: cur
Batch
.timestamp,
timestamp: cur
Context
.timestamp,
blocknumber: cur
Batch
.blocknumber,
blocknumber: cur
Context
.blocknumber,
txData: _rawTransactions[numSequencerTransactionsProcessed]
txData: _rawTransactions[numSequencerTransactionsProcessed]
});
});
leaves[transactionIndex] = _hashTransactionChainElement(element);
leaves[transactionIndex] = _hashTransactionChainElement(element);
numSequencerTransactionsProcessed++;
numSequencerTransactionsProcessed++;
transactionIndex++;
transactionIndex++;
console.log("Processed a sequencer transaction");
console.logBytes32(_hashTransactionChainElement(element));
}
}
uint numQueuedTransactions = curBatch.numSubsequentQueueTransactions;
// Process Queue Transactions
uint numQueuedTransactions = curContext.numSubsequentQueueTransactions;
for (uint queueTxIndex = 0; queueTxIndex < numQueuedTransactions; queueTxIndex++) {
for (uint queueTxIndex = 0; queueTxIndex < numQueuedTransactions; queueTxIndex++) {
TransactionChainElement memory element = TransactionChainElement({
TransactionChainElement memory element = TransactionChainElement({
isSequenced: false,
isSequenced: false,
...
@@ -137,13 +145,20 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -137,13 +145,20 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
});
});
leaves[transactionIndex] = _hashTransactionChainElement(element);
leaves[transactionIndex] = _hashTransactionChainElement(element);
transactionIndex++;
transactionIndex++;
// todo: dequeue however it works now (peeked?)
ovmL1ToL2TransactionQueue.dequeue();
}
}
}
}
console.log("We reached the end!");
bytes32 root;
bytes32 root;
// todo: get root from merkle utils on leaves
_appendQueueBatch(root, _batch.length);
// Make sure the correct number of leaves were calculated
require(transactionIndex == _totalElementsToAppend, "Not enough transactions supplied!");
// TODO: get root from merkle utils on leaves
// merklize(leaves);
// _appendQueueBatch(root, _batch.length);
}
}
...
@@ -153,7 +168,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -153,7 +168,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
/**
/**
* Appends a queue batch to the chain.
* Appends a queue batch to the chain.
* @param _
queueElement Queue element to append.
* @param _
batchRoot Root of the batch
* @param _batchSize Number of elements in the batch.
* @param _batchSize Number of elements in the batch.
*/
*/
function _appendQueueBatch(
function _appendQueueBatch(
...
@@ -171,7 +186,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
...
@@ -171,7 +186,7 @@ contract NEW_OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver
});
});
_appendBatch(batchHeader);
_appendBatch(batchHeader);
lastOVMTimestamp = _queueElement.timestamp;
//
lastOVMTimestamp = _queueElement.timestamp;
}
}
// TODO docstring
// TODO docstring
...
...
packages/contracts/test/contracts/OVM/chain/OVM_NewCanonicalTransactionChain.spec.ts
0 → 100644
View file @
79f4c3ca
import
{
expect
}
from
'
../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Signer
,
ContractFactory
,
Contract
}
from
'
ethers
'
import
{
smockit
,
MockContract
}
from
'
@eth-optimism/smock
'
/* Internal Imports */
import
{
makeAddressManager
,
setProxyTarget
,
FORCE_INCLUSION_PERIOD_SECONDS
,
// getEthTime,
// setEthTime,
// NON_NULL_BYTES32,
// ZERO_ADDRESS,
}
from
'
../../../helpers
'
interface
sequencerBatchContext
{
numSequencedTransactions
:
Number
numSubsequentQueueTransactions
:
Number
timestamp
:
Number
blocknumber
:
Number
}
describe
.
only
(
'
NEW_OVM_CanonicalTransactionChain
'
,
()
=>
{
let
signer
:
Signer
before
(
async
()
=>
{
;[
signer
]
=
await
ethers
.
getSigners
()
})
let
AddressManager
:
Contract
before
(
async
()
=>
{
AddressManager
=
await
makeAddressManager
()
await
AddressManager
.
setAddress
(
'
OVM_Sequencer
'
,
await
signer
.
getAddress
())
})
let
Mock__OVM_L1ToL2TransactionQueue
:
MockContract
before
(
async
()
=>
{
Mock__OVM_L1ToL2TransactionQueue
=
smockit
(
await
ethers
.
getContractFactory
(
'
OVM_L1ToL2TransactionQueue
'
)
)
await
setProxyTarget
(
AddressManager
,
'
OVM_L1ToL2TransactionQueue
'
,
Mock__OVM_L1ToL2TransactionQueue
)
})
let
Factory__OVM_CanonicalTransactionChain
:
ContractFactory
before
(
async
()
=>
{
Factory__OVM_CanonicalTransactionChain
=
await
ethers
.
getContractFactory
(
'
NEW_OVM_CanonicalTransactionChain
'
)
})
let
OVM_CanonicalTransactionChain
:
Contract
beforeEach
(
async
()
=>
{
OVM_CanonicalTransactionChain
=
await
Factory__OVM_CanonicalTransactionChain
.
deploy
(
AddressManager
.
address
,
FORCE_INCLUSION_PERIOD_SECONDS
)
})
describe
(
'
appendSequencerMultiBatch
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_L1ToL2TransactionQueue
.
smocked
.
size
.
will
.
return
.
with
(
0
)
Mock__OVM_L1ToL2TransactionQueue
.
smocked
.
dequeue
.
will
.
return
()
})
it
(
'
should append a multi-batch with just one batch
'
,
async
()
=>
{
// Try out appending
const
testBatchContext
:
sequencerBatchContext
=
{
numSequencedTransactions
:
1
,
numSubsequentQueueTransactions
:
0
,
timestamp
:
0
,
blocknumber
:
0
}
await
OVM_CanonicalTransactionChain
.
appendSequencerMultiBatch
(
[
'
0x1212
'
],
[
testBatchContext
],
0
,
1
)
})
})
})
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