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
0b6c2dd0
Commit
0b6c2dd0
authored
Oct 13, 2020
by
Karl Floersch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish appendSequencerBatch
parent
44c51b54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
60 deletions
+76
-60
OVM_CanonicalTransactionChain.sol
...stic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol
+47
-48
OVM_CanonicalTransactionChain.spec.ts
...contracts/OVM/chain/OVM_CanonicalTransactionChain.spec.ts
+29
-12
No files found.
packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol
View file @
0b6c2dd0
...
...
@@ -35,14 +35,14 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
uint numSequencedTransactions;
uint numSubsequentQueueTransactions;
uint timestamp;
uint block
n
umber;
uint block
N
umber;
}
struct TransactionChainElement {
bool isSequenced;
uint queueIndex; // QUEUED TX ONLY
uint timestamp; // SEQUENCER TX ONLY
uint block
n
umber; // SEQUENCER TX ONLY
uint block
N
umber; // SEQUENCER TX ONLY
bytes txData; // SEQUENCER TX ONLY
}
...
...
@@ -189,7 +189,7 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
isSequenced: false,
queueIndex: queueIndex,
timestamp: 0,
block
n
umber: 0,
block
N
umber: 0,
txData: hex""
});
require(
...
...
@@ -241,70 +241,70 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
_shouldStartAtBatch == getTotalBatches(),
"Batch submission failed: chain length has become larger than expected"
);
require(
msg.sender == sequencerAddress,
"Function can only be called by the Sequencer."
);
// TODO: Verify that there are no outstanding queue transactions which need to be processed
// require(
// block.timestamp < queue.getQueueElement(lastQueueIndex).timestamp + forceInclusionPeriodSeconds,
// "Older queue batches must be processed before a new sequencer batch."
// );
// Initialize an array which will contain the leaves of the merkle tree commitment
bytes32[] memory leaves = new bytes32[](_totalElementsToAppend);
uint numBatchContexts = _batchContexts.length;
uint transactionIndex = 0;
uint numSequencerTransactionsProcessed = 0;
for (uint batchContextIndex = 0; batchContextIndex < numBatchContexts; batchContextIndex++) {
// Process Sequencer Transactions
uint32 transactionIndex = 0;
uint32 numSequencerTransactionsProcessed = 0;
(, uint32 nextQueueIndex) = getLatestBatchContext();
for (uint32 batchContextIndex = 0; batchContextIndex < _batchContexts.length; batchContextIndex++) {
//////////////////// Process Sequencer Transactions \\\\\\\\\\\\\\\\\\\\
BatchContext memory curContext = _batchContexts[batchContextIndex];
_validateBatchContext(curContext, nextQueueIndex);
uint numSequencedTransactions = curContext.numSequencedTransactions;
for (uint txIndex = 0; txIndex < numSequencedTransactions; txIndex++) {
TransactionChainElement memory element = TransactionChainElement({
isSequenced: true,
queueIndex: 0,
timestamp: curContext.timestamp,
blocknumber: curContext.blocknumber,
txData: _rawTransactions[numSequencerTransactionsProcessed]
});
leaves[transactionIndex] = _hashTransactionChainElement(element);
for (uint32 i = 0; i < numSequencedTransactions; i++) {
leaves[transactionIndex] = keccak256(abi.encode(
false,
0,
curContext.timestamp,
curContext.blockNumber,
_rawTransactions[numSequencerTransactionsProcessed]
));
numSequencerTransactionsProcessed++;
transactionIndex++;
console.log("Processed a sequencer transaction");
console.logBytes32(_hashTransactionChainElement(element));
}
//
Process Queue Transactions
//
////////////////// Process Queue Transactions \\\\\\\\\\\\\\\\\\\\
uint numQueuedTransactions = curContext.numSubsequentQueueTransactions;
for (uint queueTxIndex = 0; queueTxIndex < numQueuedTransactions; queueTxIndex++) {
TransactionChainElement memory element = TransactionChainElement({
isSequenced: false,
queueIndex: queue.getLength(),
timestamp: 0,
blocknumber: 0,
txData: hex""
});
leaves[transactionIndex] = _hashTransactionChainElement(element);
for (uint i = 0; i < numQueuedTransactions; i++) {
leaves[transactionIndex] = _getQueueLeafHash(nextQueueIndex);
nextQueueIndex++;
transactionIndex++;
// TODO: Increment our lastQueueIndex
// lastQueueIndex++;
}
}
console.log("We reached the end!");
bytes32 root;
// 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);
// _appendQueueTransaction(root, _batch.length);
bytes32 root = _getRoot(leaves);
_appendBatch(
root,
_totalElementsToAppend,
_totalElementsToAppend - numSequencerTransactionsProcessed
);
}
function _validateBatchContext(BatchContext memory context, uint32 nextQueueIndex) internal {
if (nextQueueIndex == 0) {
return;
}
Lib_OVMCodec.QueueElement memory nextQueueElement = getQueueElement(nextQueueIndex);
require(
block.timestamp < nextQueueElement.timestamp + forceInclusionPeriodSeconds,
"Older queue batches must be processed before a new sequencer batch."
);
require(
context.timestamp <= nextQueueElement.timestamp,
"Sequencer transactions timestamp too high"
);
require(
context.blockNumber <= nextQueueElement.blockNumber,
"Sequencer transactions blockNumber too high"
);
}
function getTotalElements()
...
...
@@ -324,7 +324,6 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
* Internal Functions: Batch Manipulation *
******************************************/
// TODO docstring
function _hashTransactionChainElement(
TransactionChainElement memory _element
...
...
@@ -337,7 +336,7 @@ contract OVM_CanonicalTransactionChain is OVM_BaseChain, Lib_AddressResolver { /
_element.isSequenced,
_element.queueIndex,
_element.timestamp,
_element.block
n
umber,
_element.block
N
umber,
_element.txData
));
}
...
...
packages/contracts/test/contracts/OVM/chain/OVM_CanonicalTransactionChain.spec.ts
View file @
0b6c2dd0
...
...
@@ -19,10 +19,10 @@ interface sequencerBatchContext {
numSequencedTransactions
:
Number
numSubsequentQueueTransactions
:
Number
timestamp
:
Number
block
n
umber
:
Number
block
N
umber
:
Number
}
describe
(
'
OVM_CanonicalTransactionChain
'
,
()
=>
{
describe
.
only
(
'
OVM_CanonicalTransactionChain
'
,
()
=>
{
let
signer
:
Signer
before
(
async
()
=>
{
;[
signer
]
=
await
ethers
.
getSigners
()
...
...
@@ -62,7 +62,7 @@ describe('OVM_CanonicalTransactionChain', () => {
)
})
describe
.
only
(
'
enqueue
'
,
()
=>
{
describe
(
'
enqueue
'
,
()
=>
{
it
(
'
should store queued elements correctly
'
,
async
()
=>
{
await
OVM_CanonicalTransactionChain
.
enqueue
(
'
0x
'
+
'
01
'
.
repeat
(
20
),
25000
,
'
0x1234
'
)
const
firstQueuedElement
=
await
OVM_CanonicalTransactionChain
.
getQueueElement
(
0
)
...
...
@@ -90,22 +90,39 @@ describe('OVM_CanonicalTransactionChain', () => {
})
})
describe
(
'
appendSequencer
Multi
Batch
'
,
()
=>
{
it
(
'
should append a
multi-
batch with just one batch
'
,
async
()
=>
{
describe
(
'
appendSequencerBatch
'
,
()
=>
{
it
(
'
should append a batch with just one batch
'
,
async
()
=>
{
// Try out appending
const
testBatchContext
:
sequencerBatchContext
=
{
numSequencedTransactions
:
1
,
numSubsequentQueueTransactions
:
0
,
timestamp
:
0
,
block
n
umber
:
0
block
N
umber
:
0
}
await
OVM_CanonicalTransactionChain
.
appendSequencerMultiBatch
(
[
'
0x1212
'
],
[
testBatchContext
],
0
,
1
)
await
OVM_CanonicalTransactionChain
.
appendSequencerBatch
(
[
'
0x1212
'
],
[
testBatchContext
],
0
,
1
)
expect
(
await
OVM_CanonicalTransactionChain
.
getTotalElements
()).
to
.
equal
(
1
)
})
it
(
'
should append a batch with 1 sequencer tx and a queue tx
'
,
async
()
=>
{
const
testBatchContext
:
sequencerBatchContext
=
{
numSequencedTransactions
:
1
,
numSubsequentQueueTransactions
:
1
,
timestamp
:
3
,
blockNumber
:
3
}
await
OVM_CanonicalTransactionChain
.
enqueue
(
'
0x
'
+
'
01
'
.
repeat
(
20
),
25000
,
'
0x1234
'
)
await
OVM_CanonicalTransactionChain
.
appendSequencerBatch
(
[
'
0x1212
'
],
[
testBatchContext
],
0
,
2
)
expect
(
await
OVM_CanonicalTransactionChain
.
getTotalElements
()).
to
.
equal
(
2
)
})
})
})
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