Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Revert AlreadyHaveKey
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkonrad committed Apr 4, 2024
1 parent 3141bda commit 2065172
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions predeploy/contracts.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/EonKeyPublish.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ contract EonKeyPublish is EonKeyPublisher {
revert AlreadyVoted();
}
if (eonKeyConfirmed(eonKey)) {
// broadcast
broadcaster.broadcastEonKey(eon, eonKey);
//exit
return;
try broadcaster.broadcastEonKey(eon, eonKey) {
return;
} catch Error(string memory) {
return;
}
}
}
}
5 changes: 2 additions & 3 deletions src/KeyBroadcastContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "src/KeyperSet.sol";

error InvalidKey();
error NotAllowed();
error AlreadyHaveKey();

interface EonKeyPublisher {
function eonKeyConfirmed(bytes memory eonKey) external returns (bool);
Expand All @@ -16,7 +17,6 @@ contract KeyBroadcastContract {
KeyperSetManager private keyperSetManager;

event EonKeyBroadcast(uint64 eon, bytes key);
event AlreadyHaveKey(uint64 eon, bytes key);

constructor(address keyperSetManagerAddress) {
keyperSetManager = KeyperSetManager(keyperSetManagerAddress);
Expand All @@ -27,8 +27,7 @@ contract KeyBroadcastContract {
revert InvalidKey();
}
if (keys[eon].length > 0) {
emit AlreadyHaveKey(eon, key);
return;
revert AlreadyHaveKey();
}
KeyperSet keyperSet = KeyperSet(
keyperSetManager.getKeyperSetAddress(eon)
Expand Down
4 changes: 1 addition & 3 deletions test/EonKeyPublish.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ contract EonKeyPublishTest is Test {

event EonVoteRegistered(uint64 eon, bytes key);
event EonKeyBroadcast(uint64 eon, bytes key);
event AlreadyHaveKey(uint64 eon, bytes key);

function setUp() public {
initializer = address(19);
Expand Down Expand Up @@ -122,8 +121,7 @@ contract EonKeyPublishTest is Test {
emit EonKeyBroadcast(eon, key);
// after Broadcast we should see AlreadyHaveKey
} else {
vm.expectEmit(address(broadcastContract));
emit AlreadyHaveKey(eon, key);
vm.expectRevert(AlreadyHaveKey.selector);
}
eonKeyPublish.publishEonKey(key, uint64(idx));
// members can't change their vote
Expand Down
6 changes: 2 additions & 4 deletions test/KeyBroadcastContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../src/KeyperSetManager.sol";
import "../src/KeyperSet.sol";

contract MockPublisher is EonKeyPublisher {
function eonKeyConfirmed(bytes memory eonKey) external returns (bool) {
function eonKeyConfirmed(bytes memory) external returns (bool) {
return true;
}
}
Expand All @@ -25,7 +25,6 @@ contract KeyBroadcastTest is Test {
MockPublisher public publisher1;

event EonKeyBroadcast(uint64 eon, bytes key);
event AlreadyHaveKey(uint64 eon, bytes key);

function setUp() public {
address initializer = address(69);
Expand Down Expand Up @@ -77,8 +76,7 @@ contract KeyBroadcastTest is Test {
keyBroadcastContract.broadcastEonKey(1, key);

vm.prank(address(publisher1));
vm.expectEmit(address(keyBroadcastContract));
emit AlreadyHaveKey(1, key);
vm.expectRevert(AlreadyHaveKey.selector);
keyBroadcastContract.broadcastEonKey(1, key);
}

Expand Down

0 comments on commit 2065172

Please sign in to comment.