Skip to content

Commit 8a96990

Browse files
fredojannikluhn
authored andcommitted
add tx index per eon
1 parent 4e3d522 commit 8a96990

File tree

4 files changed

+104
-20
lines changed

4 files changed

+104
-20
lines changed

gnoshcontracts/sequencer/sequencer.go

Lines changed: 61 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ISequencer.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface ISequencer {
1414
function submitDecryptionProgress(bytes memory message) external;
1515

1616
event TransactionSubmitted(
17-
uint64 eon,
17+
uint64 indexed eon,
18+
uint64 indexed txIndex,
1819
bytes32 identityPrefix,
1920
address sender,
2021
bytes encryptedTransaction,

src/Sequencer.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pragma solidity ^0.8.20;
44
import "src/ISequencer.sol";
55

66
contract Sequencer is ISequencer {
7+
mapping(uint64 eon => uint64 txCount) private txCounters;
8+
79
function submitEncryptedTransaction(
810
uint64 eon,
911
bytes32 identityPrefix,
@@ -14,8 +16,12 @@ contract Sequencer is ISequencer {
1416
revert InsufficientFee();
1517
}
1618

19+
uint64 index = txCounters[eon];
20+
txCounters[eon] = index + 1;
21+
1722
emit TransactionSubmitted(
1823
eon,
24+
index,
1925
identityPrefix,
2026
msg.sender,
2127
encryptedTransaction,
@@ -26,4 +32,8 @@ contract Sequencer is ISequencer {
2632
function submitDecryptionProgress(bytes memory message) external {
2733
emit DecryptionProgressSubmitted(message);
2834
}
35+
36+
function getTxCountForEon(uint64 eon) external view returns (uint64) {
37+
return txCounters[eon];
38+
}
2939
}

test/Sequencer.t.sol

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import "../src/Sequencer.sol";
88
contract SequencerTest is Test {
99
Sequencer public sequencer;
1010

11-
event TransactionSubmitted(
12-
uint64 eon,
13-
bytes32 identityPrefix,
14-
address sender,
15-
bytes encryptedTransaction,
16-
uint256 gasLimit
17-
);
1811
event DecryptionProgressSubmitted(bytes message);
1912

2013
function setUp() public {
@@ -23,14 +16,16 @@ contract SequencerTest is Test {
2316

2417
function testSubmitTransaction() public {
2518
uint64 eon = 5;
19+
uint64 txIndex = 0;
2620
bytes32 identityPrefix = hex"001122";
2721
address sender = makeAddr("sender");
2822
bytes memory encryptedTransaction = "aabbcc";
2923
uint256 gasLimit = 8;
3024

3125
vm.expectEmit(address(sequencer));
32-
emit TransactionSubmitted(
26+
emit ISequencer.TransactionSubmitted(
3327
eon,
28+
txIndex,
3429
identityPrefix,
3530
sender,
3631
encryptedTransaction,
@@ -72,4 +67,32 @@ contract SequencerTest is Test {
7267
emit DecryptionProgressSubmitted(message);
7368
sequencer.submitDecryptionProgress(message);
7469
}
70+
71+
function testTxCount() public {
72+
uint64 eon = 5;
73+
bytes32 identityPrefix = hex"001122";
74+
address sender = makeAddr("sender");
75+
bytes memory encryptedTransaction = "aabbcc";
76+
uint256 gasLimit = 8;
77+
78+
assertEqUint(sequencer.getTxCountForEon(eon), 0);
79+
vm.fee(20);
80+
hoax(sender);
81+
sequencer.submitEncryptedTransaction{value: 160}(
82+
eon,
83+
identityPrefix,
84+
encryptedTransaction,
85+
gasLimit
86+
);
87+
assertEqUint(sequencer.getTxCountForEon(eon), 1);
88+
assertEqUint(sequencer.getTxCountForEon(eon + 1), 0);
89+
sequencer.submitEncryptedTransaction{value: 160}(
90+
eon + 1,
91+
identityPrefix,
92+
encryptedTransaction,
93+
gasLimit
94+
);
95+
assertEqUint(sequencer.getTxCountForEon(eon), 1);
96+
assertEqUint(sequencer.getTxCountForEon(eon + 1), 1);
97+
}
7598
}

0 commit comments

Comments
 (0)