-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Use namespaced storage #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ecd4a36
b75885d
c49b4c1
8d9f564
27a6d0a
b1c3c62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,58 +17,92 @@ import "./registries/IRegistry.sol"; | |
/**************************************************************************** | ||
* WARNING: Be carefull when editing this file. * | ||
* * | ||
* If you want add new variables for expanded features, add them at the * | ||
* end, or (better?) create a Store_v2 that inherits from this Store. * | ||
* If you want to add new variables, add them to the end of the * | ||
* struct `PocoStorage`. * | ||
* Read more about: * | ||
* - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 * | ||
* - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 * | ||
* * | ||
* If in doubt, read about Diamond proxy storage. * | ||
****************************************************************************/ | ||
|
||
// TODO replace with diamond AppStorage using namespaced storage. | ||
// TODO check storage padding. | ||
abstract contract Store { | ||
// Registries | ||
IRegistry internal m_appregistry; | ||
IRegistry internal m_datasetregistry; | ||
IRegistry internal m_workerpoolregistry; | ||
// Poco - Constants | ||
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7; | ||
uint256 public constant REVEAL_DEADLINE_RATIO = 2; | ||
uint256 public constant FINAL_DEADLINE_RATIO = 10; | ||
uint256 public constant WORKERPOOL_STAKE_RATIO = 30; | ||
uint256 public constant KITTY_RATIO = 10; | ||
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE | ||
|
||
// Escrow | ||
IERC20 internal m_baseToken; | ||
string internal m_name; | ||
string internal m_symbol; | ||
uint8 internal m_decimals; | ||
uint256 internal m_totalSupply; | ||
mapping(address => uint256) internal m_balances; | ||
mapping(address => uint256) internal m_frozens; | ||
mapping(address => mapping(address => uint256)) internal m_allowances; | ||
// Seized funds of workerpools that do not honor their deals are sent | ||
// out to this kitty address. | ||
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). | ||
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not having a variable ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
||
// Poco - Constants | ||
uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7; | ||
uint256 internal constant REVEAL_DEADLINE_RATIO = 2; | ||
uint256 internal constant FINAL_DEADLINE_RATIO = 10; | ||
uint256 internal constant WORKERPOOL_STAKE_RATIO = 30; | ||
uint256 internal constant KITTY_RATIO = 10; | ||
uint256 internal constant KITTY_MIN = 1000000000; // ADJUSTEMENT VARIABLE | ||
address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; // address(uint256(keccak256(bytes('iExecKitty'))) - 1); | ||
uint256 internal constant GROUPMEMBER_PURPOSE = 4; | ||
bytes32 internal EIP712DOMAIN_SEPARATOR; | ||
// Used with ERC-734 Key Manager identity contract for authorization management. | ||
uint256 public constant GROUPMEMBER_PURPOSE = 4; | ||
|
||
// Poco - Storage | ||
mapping(bytes32 => address) internal m_presigned; // per order | ||
mapping(bytes32 => uint256) internal m_consumed; // per order | ||
mapping(bytes32 => IexecLibCore_v5.Deal) internal m_deals; // per deal | ||
mapping(bytes32 => IexecLibCore_v5.Task) internal m_tasks; // per task | ||
mapping(bytes32 => IexecLibCore_v5.Consensus) internal m_consensus; // per task | ||
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) internal m_contributions; // per task-worker | ||
mapping(address => uint256) internal m_workerScores; // per worker | ||
// keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant POCO_STORAGE_LOCATION = | ||
0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; | ||
|
||
// Poco - Settings | ||
address internal m_teebroker; | ||
uint256 internal m_callbackgas; | ||
/// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage | ||
struct PocoStorage { | ||
// Registries | ||
IRegistry m_appregistry; | ||
IRegistry m_datasetregistry; | ||
IRegistry m_workerpoolregistry; | ||
// Escrow | ||
IERC20 m_baseToken; | ||
string m_name; | ||
string m_symbol; | ||
uint8 m_decimals; | ||
uint256 m_totalSupply; | ||
// In order to use the protocol, users have to deposit RLC | ||
// and allow PoCo smart contracts to manage them. This state | ||
// variable keeps track of users balances. | ||
mapping(address => uint256) m_balances; | ||
// When a deal is created, the protocol temporarily locks an amount | ||
// of RLC tokens from the balances of both the requester and the workerpool owners. | ||
// This is to guarantee the payment of different actors later. Frozen funds | ||
// are released when the computation is completed and the result is pushed. | ||
mapping(address => uint256) m_frozens; | ||
mapping(address => mapping(address => uint256)) m_allowances; | ||
// EIP-712 domain hash. | ||
// Modified in IexecConfigurationFacet.updateDomainSeparator | ||
bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename | ||
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Poco - Storage | ||
|
||
// Categories | ||
IexecLibCore_v5.Category[] internal m_categories; | ||
// Mapping an order hash to its owner. Since a smart contract cannot sign orders | ||
// with a private key, it adds an entry to this mapping to provide presigned orders. | ||
mapping(bytes32 => address) m_presigned; | ||
// Each order has a volume (>=1). This tracks how much is consumed from | ||
// the volume of each order. Mapping an order hash to its consumed amount. | ||
mapping(bytes32 => uint256) m_consumed; | ||
// a mapping to store PoCo classic deals. | ||
mapping(bytes32 => IexecLibCore_v5.Deal) m_deals; | ||
mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task | ||
mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task | ||
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker | ||
mapping(address => uint256) m_workerScores; // per worker | ||
Comment on lines
+78
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think using the same format of commentary before each mapping like : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes done in this PR Add comments to store mappings |
||
// Poco - Settings | ||
// Address of a trusted TEE authority that manages enclave challenges. | ||
// Modified in IexecConfigurationFacet.setTeeBroker | ||
address m_teebroker; | ||
// Max amount of gas to be used with callbacks. | ||
// Modified in IexecConfigurationFacet.setCallbackGas | ||
uint256 m_callbackgas; | ||
// List of defined computation categories. | ||
IexecLibCore_v5.Category[] m_categories; | ||
// Backward compatibility | ||
// Modified in IexecConfigurationFacet.configure | ||
IexecHubInterface m_v3_iexecHub; | ||
mapping(address => bool) m_v3_scoreImported; | ||
} | ||
|
||
// Backward compatibility | ||
IexecHubInterface internal m_v3_iexecHub; | ||
mapping(address => bool) internal m_v3_scoreImported; | ||
function getPocoStorage() internal pure returns (PocoStorage storage $) { | ||
assembly { | ||
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$_slot := POCO_STORAGE_LOCATION | ||
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
Le-Caignec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,144 +11,100 @@ import {IexecLibCore_v5} from "./libs/IexecLibCore_v5.sol"; | |
/**************************************************************************** | ||
* WARNING: Be carefull when editing this file. * | ||
* * | ||
* If you want add new variables for expanded features, add them at the * | ||
* end, or (better?) create a Store_v2 that inherits from this Store. * | ||
* If you want to add new variables, add them to the end of the * | ||
* struct `PocoStorage`. * | ||
* Read more about: * | ||
* - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 * | ||
* - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 * | ||
* * | ||
* If in doubt, read about Diamond proxy storage. * | ||
****************************************************************************/ | ||
|
||
/// @dev registries | ||
interface IRegistry is IERC721Enumerable { | ||
function isRegistered(address _entry) external view returns (bool); | ||
} | ||
|
||
/// @dev Poco store | ||
/** | ||
* @title Central storage of all modules contracts. It follows the Diamond | ||
* pattern aka ERC-2535. | ||
* @dev note the new added state variable "m_dealsBoost" that holds a new type | ||
* of deals for the PoCo Boost workflow. | ||
*/ | ||
// TODO replace with diamond AppStorage using namespaced storage. | ||
// TODO check storage padding. | ||
abstract contract Store { | ||
// Registries | ||
//slither-disable-next-line constable-states | ||
IRegistry internal m_appregistry; | ||
//slither-disable-next-line constable-states | ||
IRegistry internal m_datasetregistry; | ||
//slither-disable-next-line constable-states | ||
IRegistry internal m_workerpoolregistry; | ||
|
||
// Escrow | ||
//slither-disable-next-line constable-states | ||
IERC20 internal m_baseToken; | ||
//slither-disable-next-line constable-states | ||
string internal m_name; | ||
//slither-disable-next-line constable-states | ||
string internal m_symbol; | ||
//slither-disable-next-line constable-states | ||
uint8 internal m_decimals; | ||
//slither-disable-next-line constable-states | ||
uint256 internal m_totalSupply; | ||
|
||
/** | ||
* @dev In order to use the protocol, users have to deposit RLC | ||
* and allow PoCo smart contracts to manage them. This state | ||
* variable keeps track of users balances. | ||
*/ | ||
mapping(address => uint256) internal m_balances; | ||
|
||
/** | ||
* @dev When a deal is created, the protocol temporarily locks an amount | ||
* of RLC tokens from the balances of both the requester and the workerpool owners. | ||
* This is to guarantee the payment of different actors later. Frozen funds | ||
* are released when the computation is completed and the result is pushed. | ||
*/ | ||
mapping(address => uint256) internal m_frozens; | ||
|
||
mapping(address => mapping(address => uint256)) internal m_allowances; | ||
|
||
// Poco - Constants | ||
uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7; | ||
uint256 internal constant REVEAL_DEADLINE_RATIO = 2; | ||
uint256 internal constant FINAL_DEADLINE_RATIO = 10; | ||
uint256 internal constant WORKERPOOL_STAKE_RATIO = 30; | ||
uint256 internal constant KITTY_RATIO = 10; | ||
uint256 internal constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE | ||
|
||
/** | ||
* @dev Seized funds of workerpools that do not honor their deals are sent | ||
* out to this kitty address. | ||
* It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). | ||
*/ | ||
address internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; | ||
|
||
/** | ||
* @dev Used with ERC-734 Key Manager identity contract for authorization management. | ||
*/ | ||
uint256 internal constant GROUPMEMBER_PURPOSE = 4; | ||
|
||
/** | ||
* @dev EIP-712 domain hash. | ||
*/ | ||
// Modified in IexecConfigurationFacet.updateDomainSeparator | ||
//slither-disable-next-line constable-states | ||
bytes32 internal EIP712DOMAIN_SEPARATOR; | ||
|
||
// Poco - Storage | ||
|
||
/** | ||
* @dev Mapping an order hash to its owner. Since a smart contract cannot sign orders | ||
* with a private key, it adds an entry to this mapping to provide presigned orders. | ||
*/ | ||
mapping(bytes32 => address) internal m_presigned; | ||
|
||
/** | ||
* @dev Each order has a volume (>=1). This tracks how much is consumed from | ||
* the volume of each order. Mapping an order hash to its consumed amount. | ||
*/ | ||
mapping(bytes32 => uint256) internal m_consumed; | ||
|
||
/** | ||
* @dev a mapping to store PoCo classic deals. | ||
*/ | ||
mapping(bytes32 => IexecLibCore_v5.Deal) internal m_deals; | ||
|
||
mapping(bytes32 => IexecLibCore_v5.Task) internal m_tasks; // per task | ||
mapping(bytes32 => IexecLibCore_v5.Consensus) internal m_consensus; // per task | ||
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) internal m_contributions; // per task-worker | ||
mapping(address => uint256) internal m_workerScores; // per worker | ||
|
||
// Poco - Settings | ||
|
||
/** | ||
* @dev Address of a trusted TEE authority that manages enclave challenges. | ||
*/ | ||
// Modified in IexecConfigurationFacet.setTeeBroker | ||
//slither-disable-next-line constable-states | ||
address internal m_teebroker; | ||
|
||
/** | ||
* @dev Max amount of gas to be used with callbacks. | ||
*/ | ||
// Modified in IexecConfigurationFacet.setCallbackGas | ||
//slither-disable-next-line constable-states | ||
uint256 internal m_callbackgas; | ||
|
||
/** | ||
* @dev List of defined computation categories. | ||
*/ | ||
IexecLibCore_v5.Category[] internal m_categories; | ||
|
||
// Backward compatibility | ||
// Modified in IexecConfigurationFacet.configure | ||
//slither-disable-next-line constable-states | ||
address internal m_v3_iexecHub; // IexecHubInterface | ||
mapping(address => bool) internal m_v3_scoreImported; | ||
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7; | ||
uint256 public constant REVEAL_DEADLINE_RATIO = 2; | ||
uint256 public constant FINAL_DEADLINE_RATIO = 10; | ||
uint256 public constant WORKERPOOL_STAKE_RATIO = 30; | ||
uint256 public constant KITTY_RATIO = 10; | ||
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE | ||
|
||
// Seized funds of workerpools that do not honor their deals are sent | ||
// out to this kitty address. | ||
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). | ||
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; | ||
|
||
// Used with ERC-734 Key Manager identity contract for authorization management. | ||
uint256 public constant GROUPMEMBER_PURPOSE = 4; | ||
|
||
// keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant POCO_STORAGE_LOCATION = | ||
0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; | ||
|
||
/// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage | ||
struct PocoStorage { | ||
// Registries | ||
IRegistry m_appregistry; | ||
IRegistry m_datasetregistry; | ||
IRegistry m_workerpoolregistry; | ||
// Escrow | ||
IERC20 m_baseToken; | ||
string m_name; | ||
string m_symbol; | ||
uint8 m_decimals; | ||
uint256 m_totalSupply; | ||
// In order to use the protocol, users have to deposit RLC | ||
// and allow PoCo smart contracts to manage them. This state | ||
// variable keeps track of users balances. | ||
mapping(address => uint256) m_balances; | ||
// When a deal is created, the protocol temporarily locks an amount | ||
// of RLC tokens from the balances of both the requester and the workerpool owners. | ||
// This is to guarantee the payment of different actors later. Frozen funds | ||
// are released when the computation is completed and the result is pushed. | ||
mapping(address => uint256) m_frozens; | ||
mapping(address => mapping(address => uint256)) m_allowances; | ||
// EIP-712 domain hash. | ||
// Modified in IexecConfigurationFacet.updateDomainSeparator | ||
bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename | ||
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Poco - Storage | ||
|
||
// Mapping an order hash to its owner. Since a smart contract cannot sign orders | ||
// with a private key, it adds an entry to this mapping to provide presigned orders. | ||
mapping(bytes32 => address) m_presigned; | ||
// Each order has a volume (>=1). This tracks how much is consumed from | ||
// the volume of each order. Mapping an order hash to its consumed amount. | ||
mapping(bytes32 => uint256) m_consumed; | ||
// a mapping to store PoCo classic deals. | ||
mapping(bytes32 => IexecLibCore_v5.Deal) m_deals; | ||
mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task | ||
mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task | ||
mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker | ||
mapping(address => uint256) m_workerScores; // per worker | ||
// Poco - Settings | ||
// Address of a trusted TEE authority that manages enclave challenges. | ||
// Modified in IexecConfigurationFacet.setTeeBroker | ||
address m_teebroker; | ||
// Max amount of gas to be used with callbacks. | ||
// Modified in IexecConfigurationFacet.setCallbackGas | ||
uint256 m_callbackgas; | ||
// List of defined computation categories. | ||
IexecLibCore_v5.Category[] m_categories; | ||
// Backward compatibility | ||
// Modified in IexecConfigurationFacet.configure | ||
address m_v3_iexecHub; // IexecHubInterface | ||
mapping(address => bool) m_v3_scoreImported; | ||
// /!\ New storage variables not present in v6 store. | ||
// A mapping to store PoCo Boost deals. | ||
mapping(bytes32 => IexecLibCore_v5.DealBoost) m_dealsBoost; | ||
} | ||
|
||
function getPocoStorage() internal pure returns (PocoStorage storage $) { | ||
assembly ("memory-safe") { | ||
$.slot := POCO_STORAGE_LOCATION | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @dev A mapping to store PoCo Boost deals. | ||
*/ | ||
mapping(bytes32 => IexecLibCore_v5.DealBoost) internal m_dealsBoost; | ||
// Use in registries. | ||
interface IRegistry is IERC721Enumerable { | ||
function isRegistered(address _entry) external view returns (bool); | ||
} | ||
Comment on lines
+107
to
110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we move that into a dedicated file instead ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed because it's only used here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using this type of comment to split the storage and make it more readable ? => https://github.com/iExecBlockchainComputing/rlc-multichain/blob/09761d4bb9c252a6ca9a0020d2ad7979ec9ae75f/src/RLCLiquidityUnifier.sol#L62
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fan of these comments personally, we use it in other projects.
We can enhance later.