Skip to content

Commit

Permalink
feat(ethexe): Extend programs mapping with code id (#4152)
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx authored Aug 14, 2024
1 parent 32254f6 commit 6557bc6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions ethexe/contracts/src/IRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IRouter {
address[] validatorsKeys;
mapping(bytes32 => CodeState) codes;
uint256 validatedCodesCount;
mapping(address => bool) programs;
mapping(address => bytes32) programs;
uint256 programsCount;
}

Expand Down Expand Up @@ -180,7 +180,10 @@ interface IRouter {

function programsCount() external view returns (uint256);

function programExists(address program) external view returns (bool);
/**
* @dev Returns bytes32(0) in case of inexistent program.
*/
function programCodeId(address program) external view returns (bytes32);

/* Validators' set related functions */

Expand Down
8 changes: 5 additions & 3 deletions ethexe/contracts/src/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract Router is IRouter, OwnableUpgradeable, ReentrancyGuardTransient {
return router.programsCount;
}

function programExists(address program) public view returns (bool) {
function programCodeId(address program) public view returns (bytes32) {
Storage storage router = _getStorage();
return router.programs[program];
}
Expand Down Expand Up @@ -207,9 +207,11 @@ contract Router is IRouter, OwnableUpgradeable, ReentrancyGuardTransient {

_retrieveValue(totalValue);

// Check for duplicate isn't necessary, because `Clones.cloneDeterministic`
// reverts execution in case of address is already taken.
address actorId = Clones.cloneDeterministic(router.mirrorProxy, keccak256(abi.encodePacked(codeId, salt)));

router.programs[actorId] = true;
router.programs[actorId] = codeId;
router.programsCount++;

emit ProgramCreated(actorId, codeId);
Expand Down Expand Up @@ -334,7 +336,7 @@ contract Router is IRouter, OwnableUpgradeable, ReentrancyGuardTransient {
function _doStateTransition(StateTransition calldata stateTransition) private returns (bytes32) {
Storage storage router = _getStorage();

require(router.programs[stateTransition.actorId], "couldn't perform transition for unknown program");
require(router.programs[stateTransition.actorId] != 0, "couldn't perform transition for unknown program");

IWrappedVara wrappedVaraActor = IWrappedVara(router.wrappedVara);
wrappedVaraActor.transfer(stateTransition.actorId, stateTransition.valueToReceive);
Expand Down
2 changes: 1 addition & 1 deletion ethexe/ethereum/Mirror.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/MirrorProxy.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/Router.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/WrappedVara.json

Large diffs are not rendered by default.

0 comments on commit 6557bc6

Please sign in to comment.