-
Notifications
You must be signed in to change notification settings - Fork 35
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
Unable to fund state sync relayer when using rootchain originated native token #411
Unable to fund state sync relayer when using rootchain originated native token #411
Conversation
Pull Request Test Coverage Report for Build 6678652174
💛 - Coveralls |
ec746dd
to
366c197
Compare
@@ -13,8 +13,9 @@ enum GenesisStatus { | |||
} | |||
|
|||
struct GenesisValidator { | |||
address validator; | |||
address addr; |
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.
@ZeroEkkusu Is this change safe to be made? The expectation for this PR is that the chain needs to be started from the genesis in order to be able to use the premine functionality however, I'm wondering what would happen for the already running chains when they apply this change and is it ok to rename it or revert it just in case to be backward compatible. WDYT?
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.
Only in the sense that if someone's using the struct in their code, they'd need to update all .validator
occurrences to .addr
, but it doesn't change anything on the bytecode level.
The actual issue is that appending the uint256 balance
shifts the storage layout. Maybe we could create a mapping
somewhere instead and record it there.
See my following comment as well.
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.
WDYT about such change? I've introduced an array which stores premine balances and exposed a function that retrieves it (because we are going to need it on the client-side, it is easier that way than having mapping and fetching balances by address
key, one by one):
9f63d58
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.
Re your comment/post at the end:
Do you mean that a restart will be required anyway? If so, different storage layouts don't matter because those would be fresh deployments with clean state.
If not:
This also shifts the storage layout of CustomSupernetManager
(because there's GenesisSet private _genesis
in it).
We can have the array defined and updated in the CustomSupernetManager
directly (after all other storage variables and 1 subtracted from the gap), if that works for you.
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.
Do you mean that a restart will be required anyway?
It will be required in case one uses rootchain originated token as a native token. Otherwise we don't expect chain reset (redeployment is not expected in that case).
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.
In that case we'll need to align the storage layouts. Does the solution I proposed work for you?
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.
We can have the array defined and updated in the CustomSupernetManager directly (after all other storage variables and 1 subtracted from the gap), if that works for you.
Yes, that should work. I'll change it that way most likely. 👍
@@ -13,8 +13,9 @@ enum GenesisStatus { | |||
} | |||
|
|||
struct GenesisValidator { | |||
address validator; | |||
address addr; |
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.
Only in the sense that if someone's using the struct in their code, they'd need to update all .validator
occurrences to .addr
, but it doesn't change anything on the bytecode level.
The actual issue is that appending the uint256 balance
shifts the storage layout. Maybe we could create a mapping
somewhere instead and record it there.
See my following comment as well.
If I'm not mistaken, I can introduce |
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.
Re: Failing tests 96f761f
The tests failed because initialized
checked nativeTokenRoot
(the state variable) was not address(0)
, when it should have checked newNativeTokenRoot
(the initialization parameter) instead.
Also, let's rename premine
to something like addGenesisBalance
, or similar.
@@ -13,8 +13,9 @@ enum GenesisStatus { | |||
} | |||
|
|||
struct GenesisValidator { | |||
address validator; | |||
address addr; |
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.
In that case we'll need to align the storage layouts. Does the solution I proposed work for you?
@@ -21,6 +21,7 @@ interface ICustomSupernetManager { | |||
event RemovedFromWhitelist(address indexed validator); | |||
event ValidatorRegistered(address indexed validator, uint256[4] blsKey); | |||
event ValidatorDeactivated(address indexed validator); | |||
event AccountPremined(address indexed account, uint256 amount); |
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.
Update the event name.
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.
Fixed and added the amount
also as an indexed parameter 2d1dcc0
|
||
/// @notice getGenesisBalance returns balance for the given account address. | ||
/// @param account address of the account | ||
function getGenesisBalance(address account) external view returns (uint256); |
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.
See below.
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.
Fixed 485e3c6
@@ -27,6 +28,8 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl | |||
|
|||
GenesisSet private _genesis; | |||
mapping(address => Validator) public validators; | |||
IRootERC20Predicate private _rootERC20Predicate; | |||
mapping(address => uint256) private _genesisBalances; |
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.
We can expose the variable (make it public
), and can remove the getter function below.
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.
Fixed 485e3c6
} | ||
|
||
/// @inheritdoc ICustomSupernetManager | ||
function getGenesisBalance(address account) external view returns (uint256) { |
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.
See above.
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.
Fixed 485e3c6
Kudos, SonarCloud Quality Gate passed! |
This PR introduces
addGenesisBalance
function inCustomSupernetManager
, which allows Supernets users who are using rootchain-originated token as native token to be able to make bridge transactions. It enables the genesis premine mechanism and is similar to what has been done for staking. Accounts that are about to be premined in the genesis time on the Supernets, need to lock their funds on root erc 20 predicate and then when Supernets is started from the genesis block, we are going to premine exactly the same amount of tokens, which prevents premining out of thin air.