Skip to content

Commit

Permalink
Add a way to distinguish between setting deletion events (#339)
Browse files Browse the repository at this point in the history
There is no way to distinguish between `deleteConfiguration` and
`deleteConfigurationOnBlock` on block 0 by emitted events. This adds
special value to `deleteConfiguration` event.
  • Loading branch information
sergekh2 authored Jul 5, 2024
1 parent 0d3d4bf commit 44af0e5
Show file tree
Hide file tree
Showing 56 changed files with 95 additions and 104 deletions.
8 changes: 6 additions & 2 deletions contracts/src/river/registry/facets/config/IRiverConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IRiverConfigBase {

/**
* @notice Emitted when a setting is changed
* @dev if deleted is true and block is max value of uint64, the setting is deleted on all blocks
* @param key The setting key that is changed
* @param block The block number on which the setting becomes active
* @param value The new setting value
Expand Down Expand Up @@ -50,9 +51,10 @@ interface IRiverConfig is IRiverConfigBase {

/**
* @notice Set a bytes setting for the given key
* @dev Emits ConfigurationChanged event
* @param key The setting key
* @param blockNumber The block number on which the setting becomes active
* @param value The setting value (value must be its ABI representation)
* @param blockNumber The block number on which the setting becomes active, can't be max value of uint64
* @param value The setting value (value must be its ABI representation), can't be empty
*/
function setConfiguration(
bytes32 key,
Expand All @@ -62,12 +64,14 @@ interface IRiverConfig is IRiverConfigBase {

/**
* @notice Deletes the setting for the given key on all blocks
* @dev Emits ConfigurationChanged event with deleted flag set to true and block number set to max value of uint64
* @param key The setting key
*/
function deleteConfiguration(bytes32 key) external;

/**
* @notice Deletes the setting for the given key at the given block
* @dev Emits ConfigurationChanged event with deleted flag set to true
* @param key The setting key
* @param blockNumber The block number on which the setting becomes active
*/
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/river/registry/facets/config/RiverConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract RiverConfig is IRiverConfig, RegistryModifiers, OwnableBase, Facet {
uint64 blockNumber,
bytes calldata value
) external onlyConfigurationManager(msg.sender) {
if (blockNumber == type(uint64).max) revert(RiverRegistryErrors.BAD_ARG);
if (value.length == 0) revert(RiverRegistryErrors.BAD_ARG);

if (!ds.configurationKeys.contains(key)) {
Expand Down Expand Up @@ -78,7 +79,7 @@ contract RiverConfig is IRiverConfig, RegistryModifiers, OwnableBase, Facet {

ds.configurationKeys.remove(key);

emit ConfigurationChanged(key, 0, "", true);
emit ConfigurationChanged(key, type(uint64).max, "", true);
}

/// Deletes the setting for the given key at the given block
Expand Down
4 changes: 3 additions & 1 deletion contracts/test/river/registry/config/RiverConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ contract RiverConfigTest is
bytes memory value
) {
vm.assume(key != bytes32(0));
vm.assume(blockNumber != type(uint64).max);
vm.assume(value.length > 0);

vm.prank(deployer);
Expand Down Expand Up @@ -67,6 +68,7 @@ contract RiverConfigTest is
bytes32 key,
uint64 blockNumber
) external givenConfigurationManagerIsApproved(configManager) {
vm.assume(blockNumber != type(uint64).max);
vm.prank(configManager);
riverConfig.setConfiguration(key, blockNumber, "hello");
vm.prank(configManager);
Expand Down Expand Up @@ -136,7 +138,7 @@ contract RiverConfigTest is

vm.prank(deployer);
vm.expectEmit(address(riverConfig));
emit ConfigurationChanged(key, 0, "", true);
emit ConfigurationChanged(key, type(uint64).max, "", true);

riverConfig.deleteConfiguration(key);
}
Expand Down
2 changes: 1 addition & 1 deletion core/contracts/river/deploy/mock_river_registry.go

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions core/node/crypto/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,18 @@ func (ocs *onChainSettings) Remove(ctx context.Context, key chainKeyImpl, active
ocs.mu.Lock()
defer ocs.mu.Unlock()

for i, v := range ocs.s[keyID] {
if v.ActiveFromBlockNumber == activeOnBlockNumber {
ocs.s[keyID][len(ocs.s[keyID])-1], ocs.s[keyID][i] = ocs.s[keyID][i], ocs.s[keyID][len(ocs.s[keyID])-1]
ocs.s[keyID] = ocs.s[keyID][:len(ocs.s[keyID])-1]
log.Info("dropped chain config", "key", key.Name(), "activationBlock", activeOnBlockNumber)
return
if activeOnBlockNumber != math.MaxUint64 {
for i, v := range ocs.s[keyID] {
if v.ActiveFromBlockNumber == activeOnBlockNumber {
ocs.s[keyID][len(ocs.s[keyID])-1], ocs.s[keyID][i] = ocs.s[keyID][i], ocs.s[keyID][len(ocs.s[keyID])-1]
ocs.s[keyID] = ocs.s[keyID][:len(ocs.s[keyID])-1]
log.Info("dropped chain config", "key", key.Name(), "activationBlock", activeOnBlockNumber)
return
}
}
} else {
delete(ocs.s, keyID)
log.Info("dropped chain config for all blocks", "key", key.Name())
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/Architect.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/generated/dev/abis/Architect.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,10 @@
"license": "MIT"
},
"contracts/src/spaces/facets/Permissions.sol": {
"keccak256": "0x543fa893d7fb2f612c253dd5894c2b1176ae19cf79f9275b7234327ffb5bf0fa",
"keccak256": "0xaeec9c70d231be9debb15660bf6939746532d0012c80d5518e8207dd33653de2",
"urls": [
"bzz-raw://7e9c3e20122f6179b5fc3fb00085d506c979e4f237b003fa8c9c5df50644f182",
"dweb:/ipfs/QmSdpvxbz6NKFoumbCv6tzfXqo7kSrp1VrgeTp8nPxDnfm"
"bzz-raw://bab7c5dd8f55f03f48d3908b8d6732b3e2d93f36312a0c3408ff10be258c165a",
"dweb:/ipfs/QmevmAc6tzP3kFoH84cRtipSq4ryqbrP3H4VB8mRZgnRxn"
],
"license": "MIT"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/Channels.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/generated/dev/abis/Channels.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,10 @@
"license": "MIT"
},
"contracts/src/spaces/facets/Permissions.sol": {
"keccak256": "0x543fa893d7fb2f612c253dd5894c2b1176ae19cf79f9275b7234327ffb5bf0fa",
"keccak256": "0xaeec9c70d231be9debb15660bf6939746532d0012c80d5518e8207dd33653de2",
"urls": [
"bzz-raw://7e9c3e20122f6179b5fc3fb00085d506c979e4f237b003fa8c9c5df50644f182",
"dweb:/ipfs/QmSdpvxbz6NKFoumbCv6tzfXqo7kSrp1VrgeTp8nPxDnfm"
"bzz-raw://bab7c5dd8f55f03f48d3908b8d6732b3e2d93f36312a0c3408ff10be258c165a",
"dweb:/ipfs/QmevmAc6tzP3kFoH84cRtipSq4ryqbrP3H4VB8mRZgnRxn"
],
"license": "MIT"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/Diamond.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/generated/dev/abis/DiamondCutFacet.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"abi":[{"type":"function","name":"onERC721Received","inputs":[{"name":"operator","type":"address","internalType":"address"},{"name":"from","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"},{"name":"data","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"","type":"bytes4","internalType":"bytes4"}],"stateMutability":"nonpayable"}],"bytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"deployedBytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"methodIdentifiers":{"onERC721Received(address,address,uint256,bytes)":"150b7a02"},"rawMetadata":"{\"compiler\":{\"version\":\"0.8.24+commit.e11b9ed9\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"onERC721Received\",\"outputs\":[{\"internalType\":\"bytes4\",\"name\":\"\",\"type\":\"bytes4\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"details\":\"Interface of ERC721 token receiver.\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol\":\"ERC721A__IERC721ReceiverUpgradeable\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"appendCBOR\":false,\"bytecodeHash\":\"none\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@openzeppelin/=lib/@openzeppelin/\",\":@prb/math/=lib/@prb/math/src/\",\":@prb/test/=lib/@prb/test/src/\",\":account-abstraction/=lib/account-abstraction/contracts/\",\":base64/=lib/base64/\",\":ds-test/=lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hardhat-deploy/=lib/hardhat-deploy/\"]},\"sources\":{\"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol\":{\"keccak256\":\"0xb57dee608d37c98c32ac38fa3c84e77f5962cf39a0697815ad209edf55593782\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://092750f101ae80c5bace9fd53ae87547a0aac6109cd58290609acd2ef489ce9d\",\"dweb:/ipfs/QmREM18vUEQmcmnTSyR4XxHB9Ykqomc9RuCFZcWNiovgbz\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.8.24+commit.e11b9ed9"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"function","name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}]}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@openzeppelin/=lib/@openzeppelin/","@prb/math/=lib/@prb/math/src/","@prb/test/=lib/@prb/test/src/","account-abstraction/=lib/account-abstraction/contracts/","base64/=lib/base64/","ds-test/=lib/ds-test/src/","forge-std/=lib/forge-std/src/","hardhat-deploy/=lib/hardhat-deploy/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"none","appendCBOR":false},"compilationTarget":{"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol":"ERC721A__IERC721ReceiverUpgradeable"},"evmVersion":"paris","libraries":{}},"sources":{"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol":{"keccak256":"0xb57dee608d37c98c32ac38fa3c84e77f5962cf39a0697815ad209edf55593782","urls":["bzz-raw://092750f101ae80c5bace9fd53ae87547a0aac6109cd58290609acd2ef489ce9d","dweb:/ipfs/QmREM18vUEQmcmnTSyR4XxHB9Ykqomc9RuCFZcWNiovgbz"],"license":"MIT"}},"version":1},"id":153}
{"abi":[{"type":"function","name":"onERC721Received","inputs":[{"name":"operator","type":"address","internalType":"address"},{"name":"from","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"},{"name":"data","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"","type":"bytes4","internalType":"bytes4"}],"stateMutability":"nonpayable"}],"bytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"deployedBytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"methodIdentifiers":{"onERC721Received(address,address,uint256,bytes)":"150b7a02"},"rawMetadata":"{\"compiler\":{\"version\":\"0.8.24+commit.e11b9ed9\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"onERC721Received\",\"outputs\":[{\"internalType\":\"bytes4\",\"name\":\"\",\"type\":\"bytes4\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"details\":\"Interface of ERC721 token receiver.\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol\":\"ERC721A__IERC721ReceiverUpgradeable\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"appendCBOR\":false,\"bytecodeHash\":\"none\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@openzeppelin/=lib/@openzeppelin/\",\":@prb/math/=lib/@prb/math/src/\",\":@prb/test/=lib/@prb/test/src/\",\":account-abstraction/=lib/account-abstraction/contracts/\",\":base64/=lib/base64/\",\":ds-test/=lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hardhat-deploy/=lib/hardhat-deploy/\"]},\"sources\":{\"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol\":{\"keccak256\":\"0xb57dee608d37c98c32ac38fa3c84e77f5962cf39a0697815ad209edf55593782\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://092750f101ae80c5bace9fd53ae87547a0aac6109cd58290609acd2ef489ce9d\",\"dweb:/ipfs/QmREM18vUEQmcmnTSyR4XxHB9Ykqomc9RuCFZcWNiovgbz\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.8.24+commit.e11b9ed9"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"function","name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}]}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@openzeppelin/=lib/@openzeppelin/","@prb/math/=lib/@prb/math/src/","@prb/test/=lib/@prb/test/src/","account-abstraction/=lib/account-abstraction/contracts/","base64/=lib/base64/","ds-test/=lib/ds-test/src/","forge-std/=lib/forge-std/src/","hardhat-deploy/=lib/hardhat-deploy/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"none","appendCBOR":false},"compilationTarget":{"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol":"ERC721A__IERC721ReceiverUpgradeable"},"evmVersion":"paris","libraries":{}},"sources":{"contracts/src/diamond/facets/token/ERC721A/IERC721A.sol":{"keccak256":"0xb57dee608d37c98c32ac38fa3c84e77f5962cf39a0697815ad209edf55593782","urls":["bzz-raw://092750f101ae80c5bace9fd53ae87547a0aac6109cd58290609acd2ef489ce9d","dweb:/ipfs/QmREM18vUEQmcmnTSyR4XxHB9Ykqomc9RuCFZcWNiovgbz"],"license":"MIT"}},"version":1},"id":150}
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/EntitlementsManager.json

Large diffs are not rendered by default.

Loading

0 comments on commit 44af0e5

Please sign in to comment.