Skip to content

Commit

Permalink
Add Stream Registry API for fetching the nodes a batch of streams are…
Browse files Browse the repository at this point in the history
… on to use in the notification service to optimize startup (#611)

This will allow the notification service to efficiently fetch the stream
nodes it should route syncStreams requests to.

---------

Signed-off-by: Brian Meek <[email protected]>
Co-authored-by: John Terzis <[email protected]>
  • Loading branch information
brianathere and jterzis authored Aug 8, 2024
1 parent e5fa21b commit 6237b4d
Show file tree
Hide file tree
Showing 136 changed files with 968 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract DeployStreamRegistry is FacetHelper, Deployer {
constructor() {
addSelector(StreamRegistry.allocateStream.selector);
addSelector(StreamRegistry.getStream.selector);
addSelector(StreamRegistry.getStreams.selector);
addSelector(StreamRegistry.getStreamByIndex.selector);
addSelector(StreamRegistry.getStreamWithGenesis.selector);
addSelector(StreamRegistry.setStreamLastMiniblock.selector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ interface IStreamRegistry {
uint256 stop
) external view returns (StreamWithId[] memory, bool);

/**
* @dev Fetch a batch of streams. Returns how many were found, and the streams found.
* Results may be a subset of requested streams.
*/
function getStreams(
bytes32[] calldata streamIds
) external view returns (uint256 foundCount, StreamWithId[] memory);

function getStreamsOnNode(
address nodeAddress
) external view returns (StreamWithId[] memory);
Expand Down
14 changes: 14 additions & 0 deletions contracts/src/river/registry/facets/stream/StreamRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ contract StreamRegistry is IStreamRegistry, RegistryModifiers {
return (streams, stop >= streamCount);
}

function getStreams(
bytes32[] calldata streamIds
) external view returns (uint256 foundCount, StreamWithId[] memory) {
uint256 streamCount = streamIds.length;
StreamWithId[] memory streams = new StreamWithId[](streamCount);
for (uint256 i = 0; i < streamCount; ++i) {
bytes32 streamId = streamIds[i];
Stream storage stream = ds.streamById[streamId];
if (stream.nodes.length == 0) continue;
streams[foundCount++] = StreamWithId({id: streamId, stream: stream});
}
return (foundCount, streams);
}

function getStreamsOnNode(
address nodeAddress
) external view returns (StreamWithId[] memory) {
Expand Down
66 changes: 63 additions & 3 deletions contracts/test/river/registry/stream/StreamRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ pragma solidity ^0.8.23;
import {IOwnableBase} from "contracts/src/diamond/facets/ownable/IERC173.sol";
// structs
// libraries
import {StreamWithId} from "contracts/src/river/registry/libraries/RegistryStorage.sol";

// contracts
// deployments
import {RiverRegistryBaseSetup} from "contracts/test/river/registry/RiverRegistryBaseSetup.t.sol";

contract StreamRegistryTest is RiverRegistryBaseSetup, IOwnableBase {
string url1 = "https://node1.com";
string url2 = "https://node2.com";
address node1 = address(0x1);
address node2 = address(0x2);

// =============================================================
// allocateStream
// =============================================================

function test_streamCount(
address nodeOperator,
address node1,
address node2
address nodeOperator
)
external
givenNodeOperatorIsApproved(nodeOperator)
Expand Down Expand Up @@ -58,6 +60,64 @@ contract StreamRegistryTest is RiverRegistryBaseSetup, IOwnableBase {
assertEq(streamRegistry.getStreamCount(), 2);
}

function test_getStreams(
address nodeOperator
)
external
givenNodeOperatorIsApproved(nodeOperator)
givenNodeIsRegistered(nodeOperator, node1, url1)
givenNodeIsRegistered(nodeOperator, node2, url2)
{
address[] memory nodes = new address[](1);
nodes[0] = node1;
bytes memory genesisMiniblock = abi.encodePacked("genesisMiniblock");
bytes32 streamIdOne = 0x0000000000000000000000000000000000000000000000000000000000000001;
bytes32 genesisMiniblockHash = 0;

assertEq(streamRegistry.getStreamCount(), 0);

vm.prank(node1);
streamRegistry.allocateStream(
streamIdOne,
nodes,
genesisMiniblockHash,
genesisMiniblock
);

assertEq(streamRegistry.getStreamCount(), 1);

nodes[0] = node2;
bytes32 streamIdTwo = 0x0000000000000000000000000000000000000000000000000000000000000002;

vm.prank(node2);
streamRegistry.allocateStream(
streamIdTwo,
nodes,
genesisMiniblockHash,
genesisMiniblock
);

bytes32 streamIdThree = 0x0000000000000000000000000000000000000000000000000000000000000003;

bytes32[] memory dynamicStreamIds = new bytes32[](
[streamIdOne, streamIdTwo, streamIdThree].length
);
for (
uint256 i = 0;
i < [streamIdOne, streamIdTwo, streamIdThree].length;
i++
) {
dynamicStreamIds[i] = [streamIdOne, streamIdTwo, streamIdThree][i];
}
assertEq(streamRegistry.getStreamCount(), 2);
(uint256 foundCount, StreamWithId[] memory foundStreams) = streamRegistry
.getStreams(dynamicStreamIds);

assertEq(foundCount, 2);
assertEq(foundStreams[0].id, streamIdOne);
assertEq(foundStreams[1].id, streamIdTwo);
}

function test_streamCountOnNode(
address nodeOperator,
address node
Expand Down
2 changes: 1 addition & 1 deletion core/contracts/base/deploy/entitlement_checker.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/contracts/base/deploy/mock_entitlement_checker.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/contracts/base/deploy/mock_entitlement_gated.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/contracts/base/deploy/mock_erc20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/contracts/base/deploy/wallet_link.go

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions core/contracts/river/deploy/mock_river_registry.go

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion core/contracts/river/stream_registry_v1.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/generated/dev/abis/Architect.bin

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

49 changes: 29 additions & 20 deletions packages/generated/dev/abis/Architect.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@
"base64/=lib/base64/",
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"hardhat-deploy/=lib/hardhat-deploy/"
"hardhat-deploy/=lib/hardhat-deploy/",
"solady/=lib/solady/src/"
],
"optimizer": {
"enabled": true,
Expand Down Expand Up @@ -577,19 +578,19 @@
],
"license": "MIT"
},
"contracts/src/diamond/facets/introspection/IERC165.sol": {
"keccak256": "0x486758ee326820b0dd468c6a7a90fda8d67d48d3114792c587cee0e8417b366b",
"contracts/src/diamond/facets/introspection/IIntrospectionBase.sol": {
"keccak256": "0x51e706ab1184a3a5b353b87cfee07d471b9a5ef93897022bbcd1085b39a0c762",
"urls": [
"bzz-raw://b695090abcec8c2d487d73961265030fa4f64ecd84f6d80b85c6c7d4d9142ea0",
"dweb:/ipfs/QmQTKuV2WEoy6vTCRxL39zEqubLUf9NhoC2BGB19CiYqRq"
"bzz-raw://3df386912c5cc759faee161b7825b2014040d04bf06528e74f4d759f06f2eb19",
"dweb:/ipfs/QmP5AnGGNY4gsV1ABJ3WaueAsAwJVQ229ZfGjGxW8rSbEL"
],
"license": "MIT"
},
"contracts/src/diamond/facets/introspection/IntrospectionBase.sol": {
"keccak256": "0x93ac0d2f738615e69dbcfd5fa6ac5840ec48329ac92094605638bcf2abd6708f",
"keccak256": "0x35f27aa0a4b64673a2648110422f31de0c5a71c68df562eccb9c4f2a27ee6647",
"urls": [
"bzz-raw://fbcb2cd0e47b6ef39bec6cbdeedf6e292e8849d4e25f4bb6c72ee574446b02f1",
"dweb:/ipfs/QmcDwxFALaQBLbsGsjdttkQkE48PdKWq43XY7f34MxqZSw"
"bzz-raw://2eb1f2ff2e2d7222bf8fe2cf7558a2e47925e3d4557208362b1f50e63cb43006",
"dweb:/ipfs/QmNcJZSAEPreUy66tt5brPrauVnUb4tqvcxej5Uc4SZZWz"
],
"license": "MIT"
},
Expand Down Expand Up @@ -794,18 +795,18 @@
"license": "MIT"
},
"contracts/src/factory/facets/architect/Architect.sol": {
"keccak256": "0x546e407119ca047d99f622d77fe017f893e4148a0ab1b32938113815083204af",
"keccak256": "0xd420da847daaa9b8d7b1b2f67188c5fe995f9dfd54f89fffac2bfa1231b894d2",
"urls": [
"bzz-raw://f32d3dbaa7f2317db849eae44be1a1408abbb461e667ad08087ee220ac577888",
"dweb:/ipfs/Qmf4cmkXNY4Wh8vrk1S39LGr35JkHTR7Mdr4MXXETqt7fW"
"bzz-raw://8290230b72271aa78ebb2cb261682b65c896e2207b09a75cd0cc76c92b5f1d60",
"dweb:/ipfs/QmYUiitoXPeiEBSwrYjvBBbXam6UM1tGovpb7oNvbZHEAM"
],
"license": "MIT"
},
"contracts/src/factory/facets/architect/ArchitectBase.sol": {
"keccak256": "0x4676216deb8678864044c22050d05c0860a6b0a9e324aa232167f88dbe79c0ad",
"keccak256": "0x00a7ee4796e86d046fae5d08330892b327503fd31f8983f1445dc98ff4c44c9a",
"urls": [
"bzz-raw://e16ca2c87ccf1fb7761694353586b1f712e29b2def92edbb2eb429792b08bfe4",
"dweb:/ipfs/QmbfsL35mBjHuq9bwMnhB9UdZ2dqpuopPNSDBYRf2ATkhP"
"bzz-raw://e8ee9ae60f33d8426592312b5382f84fc92e83d50e3bfaeae9872bfa4947c53b",
"dweb:/ipfs/QmRQ6dGMSVQk1GdbBGZMsK76R6y64fgFWmPMUQUwHLXF4e"
],
"license": "MIT"
},
Expand Down Expand Up @@ -914,10 +915,10 @@
"license": "MIT"
},
"contracts/src/spaces/facets/gated/EntitlementGatedBase.sol": {
"keccak256": "0xcefa5c3c81c73fefaa7da433ddd5c419dc4c31cd86e8c31f47894663ca7269e8",
"keccak256": "0x5aa47a7b7e20e9bb71d34da61e80b700f63dcbb22bde4f37c53cb3a5b6145650",
"urls": [
"bzz-raw://27fe60a48a69d5be67fdf17f5aac1e90ef0234da564ec4f6e2cbfe53fbb9ba0c",
"dweb:/ipfs/QmPemsjAUmjjjyLWbHzVmqLxyBAN7CFi6DViy9uQEM3wjt"
"bzz-raw://6a4e52243d6b4422a7b4e3473eb2763a6a2b0e3d0c8c21103f79c462e6534adf",
"dweb:/ipfs/QmYif2azG6AYpUBkomvSMt659sXqo3CrnXDzHEh4VcYaT4"
],
"license": "MIT"
},
Expand Down Expand Up @@ -1002,10 +1003,10 @@
"license": "MIT"
},
"contracts/src/utils/Factory.sol": {
"keccak256": "0x150045213e6284abce967c3f6abc8989952d181c43540acf92709486aebec3ce",
"keccak256": "0xb85beb5f8320a8a1e860690391d9b34187570c6f22e586b662fcf131f8b24e4c",
"urls": [
"bzz-raw://282730a1c005f83c5eb11d2f19ca5a8c2ab1bba4e4a403eb651f6a232a874791",
"dweb:/ipfs/QmcPLz1uWkCukNsSwu69i8BVmjF7g9pg47cAmD3swaaFTY"
"bzz-raw://e9bfdf5d51b2d9e4c0b74248281fbcc0bd62201421f05539f3fa4673ae909e5c",
"dweb:/ipfs/Qmd6JNfs3sRcQxdKS9sfvNsRyLtJU5farA1YvaFULxugF4"
],
"license": "MIT"
},
Expand Down Expand Up @@ -1144,6 +1145,14 @@
"dweb:/ipfs/QmNqYc8To2NdnpP6E1tGz7t6A7beuENde5yovwov5pW1fA"
],
"license": "MIT"
},
"lib/solady/src/utils/LibClone.sol": {
"keccak256": "0x87e7107cd0dd0b0a4842f705bde584e8aa5149b678654d3b438e6683b1b90314",
"urls": [
"bzz-raw://f33b424b3d85944e32c9dace9939f9faa4d30ef7f2d2b0b9f8238f956c8ed89d",
"dweb:/ipfs/QmYpf82Ufq9bEr3vaz7HYSkrjB1pryYYFP4pALqnGbhUgi"
],
"license": "MIT"
}
},
"version": 1
Expand Down
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/Channels.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions packages/generated/dev/abis/Channels.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,8 @@
"base64/=lib/base64/",
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"hardhat-deploy/=lib/hardhat-deploy/"
"hardhat-deploy/=lib/hardhat-deploy/",
"solady/=lib/solady/src/"
],
"optimizer": {
"enabled": true,
Expand Down Expand Up @@ -915,19 +916,19 @@
],
"license": "MIT"
},
"contracts/src/diamond/facets/introspection/IERC165.sol": {
"keccak256": "0x486758ee326820b0dd468c6a7a90fda8d67d48d3114792c587cee0e8417b366b",
"contracts/src/diamond/facets/introspection/IIntrospectionBase.sol": {
"keccak256": "0x51e706ab1184a3a5b353b87cfee07d471b9a5ef93897022bbcd1085b39a0c762",
"urls": [
"bzz-raw://b695090abcec8c2d487d73961265030fa4f64ecd84f6d80b85c6c7d4d9142ea0",
"dweb:/ipfs/QmQTKuV2WEoy6vTCRxL39zEqubLUf9NhoC2BGB19CiYqRq"
"bzz-raw://3df386912c5cc759faee161b7825b2014040d04bf06528e74f4d759f06f2eb19",
"dweb:/ipfs/QmP5AnGGNY4gsV1ABJ3WaueAsAwJVQ229ZfGjGxW8rSbEL"
],
"license": "MIT"
},
"contracts/src/diamond/facets/introspection/IntrospectionBase.sol": {
"keccak256": "0x93ac0d2f738615e69dbcfd5fa6ac5840ec48329ac92094605638bcf2abd6708f",
"keccak256": "0x35f27aa0a4b64673a2648110422f31de0c5a71c68df562eccb9c4f2a27ee6647",
"urls": [
"bzz-raw://fbcb2cd0e47b6ef39bec6cbdeedf6e292e8849d4e25f4bb6c72ee574446b02f1",
"dweb:/ipfs/QmcDwxFALaQBLbsGsjdttkQkE48PdKWq43XY7f34MxqZSw"
"bzz-raw://2eb1f2ff2e2d7222bf8fe2cf7558a2e47925e3d4557208362b1f50e63cb43006",
"dweb:/ipfs/QmNcJZSAEPreUy66tt5brPrauVnUb4tqvcxej5Uc4SZZWz"
],
"license": "MIT"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/Diamond.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/generated/dev/abis/Diamond.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@
"base64/=lib/base64/",
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"hardhat-deploy/=lib/hardhat-deploy/"
"hardhat-deploy/=lib/hardhat-deploy/",
"solady/=lib/solady/src/"
],
"optimizer": {
"enabled": true,
Expand Down
Loading

0 comments on commit 6237b4d

Please sign in to comment.