Skip to content

Commit 2b937e0

Browse files
authored
feat: quality of service (#58)
* feat(qos): heartbeat functions and events wip * feat(qos): heartbeat implementation
1 parent b48a92b commit 2b937e0

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

bytecode/src/lib.rs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/BlueprintServiceManagerBase.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
5959
virtual
6060
onlyFromMaster
6161
{ }
62+
63+
/// @inheritdoc IBlueprintServiceManager
64+
function getHeartbeatInterval(uint64 serviceId) external view virtual returns (bool useDefault, uint64 interval) {
65+
// Uses the on-chain default interval by default
66+
return (true, 0);
67+
}
68+
69+
/// @inheritdoc IBlueprintServiceManager
70+
function getHeartbeatThreshold(uint64 serviceId) external view virtual returns (bool useDefault, uint8 threshold) {
71+
// Uses the on-chain default threshold by default
72+
return (true, 0);
73+
}
74+
75+
/// @inheritdoc IBlueprintServiceManager
76+
function getSlashingWindow(uint64 serviceId) external view virtual returns (bool useDefault, uint64 window) {
77+
// Uses the on-chain default window by default
78+
return (true, 0);
79+
}
6280

6381
/// @inheritdoc IBlueprintServiceManager
6482
function onRequest(ServiceOperators.RequestParams calldata params) external payable virtual onlyFromMaster { }

src/IBlueprintServiceManager.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ interface IBlueprintServiceManager {
3535
/// @dev Hook for updating RPC address. Called when an operator updates their RPC address.
3636
/// @param operator The operator's details with the updated RPC address.
3737
function onUpdateRpcAddress(ServiceOperators.OperatorPreferences calldata operator) external payable;
38+
39+
/// @dev Get the heartbeat interval for a service.
40+
/// @param serviceId The ID of the service.
41+
/// @return useDefault Whether to use the default value.
42+
/// @return interval The heartbeat interval in blocks. 0 means heartbeats are disabled.
43+
function getHeartbeatInterval(uint64 serviceId) external view returns (bool useDefault, uint64 interval);
44+
45+
/// @dev Get the heartbeat threshold for a service.
46+
/// @param serviceId The ID of the service.
47+
/// @return useDefault Whether to use the default value.
48+
/// @return threshold The heartbeat threshold percentage (0-100).
49+
function getHeartbeatThreshold(uint64 serviceId) external view returns (bool useDefault, uint8 threshold);
50+
51+
/// @dev Get the slashing window for a service.
52+
/// @param serviceId The ID of the service.
53+
/// @return useDefault Whether to use the default value.
54+
/// @return window The slashing window in blocks.
55+
function getSlashingWindow(uint64 serviceId) external view returns (bool useDefault, uint64 window);
3856

3957
/// @dev Hook for service instance requests. Called when a user requests a service
4058
/// instance from the blueprint but this does not mean the service is initiated yet.

src/MasterBlueprintServiceManager.sol

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,60 @@ contract MasterBlueprintServiceManager is RootChainEnabled, AccessControl, Pausa
317317
IBlueprintServiceManager(manager).onUpdateRpcAddress(operator);
318318
emit RpcAddressUpdated(blueprintId, operator);
319319
}
320+
321+
/// @dev Get the heartbeat interval for a service.
322+
/// @param blueprintId The unique identifier of the blueprint.
323+
/// @param serviceId The ID of the service.
324+
/// @return useDefault Whether to use the default value.
325+
/// @return interval The heartbeat interval in blocks.
326+
function getHeartbeatInterval(
327+
uint64 blueprintId,
328+
uint64 serviceId
329+
)
330+
public
331+
view
332+
onlyFromRootChain
333+
returns (bool useDefault, uint64 interval)
334+
{
335+
address manager = blueprints.get(blueprintId);
336+
return IBlueprintServiceManager(manager).getHeartbeatInterval(serviceId);
337+
}
338+
339+
/// @dev Get the heartbeat threshold for a service.
340+
/// @param blueprintId The unique identifier of the blueprint.
341+
/// @param serviceId The ID of the service.
342+
/// @return useDefault Whether to use the default value.
343+
/// @return threshold The heartbeat threshold percentage (0-100).
344+
function getHeartbeatThreshold(
345+
uint64 blueprintId,
346+
uint64 serviceId
347+
)
348+
public
349+
view
350+
onlyFromRootChain
351+
returns (bool useDefault, uint8 threshold)
352+
{
353+
address manager = blueprints.get(blueprintId);
354+
return IBlueprintServiceManager(manager).getHeartbeatThreshold(serviceId);
355+
}
356+
357+
/// @dev Get the slashing window for a service.
358+
/// @param blueprintId The unique identifier of the blueprint.
359+
/// @param serviceId The ID of the service.
360+
/// @return useDefault Whether to use the default value.
361+
/// @return window The slashing window in blocks.
362+
function getSlashingWindow(
363+
uint64 blueprintId,
364+
uint64 serviceId
365+
)
366+
public
367+
view
368+
onlyFromRootChain
369+
returns (bool useDefault, uint64 window)
370+
{
371+
address manager = blueprints.get(blueprintId);
372+
return IBlueprintServiceManager(manager).getSlashingWindow(serviceId);
373+
}
320374

321375
/// @dev Called when a user requests a service instance from the blueprint.
322376
/// @param blueprintId The blueprint unique identifier.

0 commit comments

Comments
 (0)