From cf1c9faa09e05c94e59ac9aa41c3d3beb68a2c4f Mon Sep 17 00:00:00 2001 From: Kane Wallmann Date: Wed, 13 Mar 2024 15:16:17 +1000 Subject: [PATCH] Remove unused storage write --- contracts/contract/node/RocketNodeStaking.sol | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/contracts/contract/node/RocketNodeStaking.sol b/contracts/contract/node/RocketNodeStaking.sol index 0b2875bb..657e8051 100644 --- a/contracts/contract/node/RocketNodeStaking.sol +++ b/contracts/contract/node/RocketNodeStaking.sol @@ -85,20 +85,18 @@ contract RocketNodeStaking is RocketBase, RocketNodeStakingInterface { /// @param _amount How much to increase by function increaseNodeRPLStake(address _nodeAddress, uint256 _amount) private { bytes32 key = keccak256(abi.encodePacked("rpl.staked.node.amount", _nodeAddress)); - uint256 value = getUint(key); - setUint(key, value + _amount); RocketNetworkSnapshotsInterface rocketNetworkSnapshots = RocketNetworkSnapshotsInterface(getContractAddress("rocketNetworkSnapshots")); - rocketNetworkSnapshots.push(key, uint32(block.number), uint224(value + _amount)); + uint224 value = rocketNetworkSnapshots.latestValue(key); + rocketNetworkSnapshots.push(key, uint32(block.number), value + uint224(_amount)); } /// @dev Decrease a node operator's RPL stake /// @param _amount How much to decrease by function decreaseNodeRPLStake(address _nodeAddress, uint256 _amount) private { bytes32 key = keccak256(abi.encodePacked("rpl.staked.node.amount", _nodeAddress)); - uint256 value = getUint(key); - setUint(key, value - _amount); RocketNetworkSnapshotsInterface rocketNetworkSnapshots = RocketNetworkSnapshotsInterface(getContractAddress("rocketNetworkSnapshots")); - rocketNetworkSnapshots.push(key, uint32(block.number), uint224(value - _amount)); + uint224 value = rocketNetworkSnapshots.latestValue(key); + rocketNetworkSnapshots.push(key, uint32(block.number), value - uint224(_amount)); } /// @notice Returns a node's matched ETH amount (amount taken from protocol to stake) @@ -372,8 +370,7 @@ contract RocketNodeStaking is RocketBase, RocketNodeStakingInterface { /// @param _amount The amount of RPL to transfer function transferRPL(address _from, address _to, uint256 _amount) override external onlyLatestContract("rocketNodeStaking", address(this)) onlyLatestNetworkContract() onlyRegisteredNode(_from) { // Check sender has enough RPL - bytes32 key = keccak256(abi.encodePacked("rpl.staked.node.amount", _from)); - require(getUint(key) >= _amount, "Sender has insufficient RPL"); + require(getNodeRPLStake(_from) >= _amount, "Sender has insufficient RPL"); // Transfer the stake decreaseNodeRPLStake(_from, _amount); increaseNodeRPLStake(_to, _amount);