Skip to content

Commit

Permalink
Add support for announcing market hours (ark-network#380)
Browse files Browse the repository at this point in the history
* feat: add market hour configuration for optimal payment timing

This commit adds market hour configuration to help users determine optimal
times for making payments with lower fees. The configuration is managed
through environment variables and exposed via the GetInfo RPC.

Changes:
- Add MarketHour message type to protobuf service definition
- Add market hour configuration fields to Config struct
- Update covenant and covenantless services to handle market hour data
- Extend GetInfo RPC response to include market hour information
- Set default market hour period to 24 hours
- Initialize market hour fields after other service fields

Configuration:
- ARK_FIRST_MARKET_HOUR: Initial market hour timestamp
  (default: current server start time)
- ARK_MARKET_HOUR_PERIOD: Time between market hours in seconds
  (default: 86400)
- ARK_MARKET_HOUR_ROUND_LIFETIME: Round lifetime for market hours
  (default: 0, falls back to ARK_ROUND_LIFETIME)

* feat: add admin RPC for updating market hour configuration

Add new UpdateMarketHour RPC to AdminService for configuring market hour parameters:
- Add request/response messages to admin.proto
- Add UpdateMarketHour method to Service interface
- Implement market hour updates in covenant and covenantless services
- Add validation for market hour parameters
- Implement admin gRPC handler

The RPC allows updating:
- First market hour timestamp
- Market hour period
- Market hour round lifetime (optional, defaults to round lifetime

* feat: add market hour persistence with sqlite

- Add MarketHourRepo interface in domain layer
- Implement market hour persistence using SQLite
- Add market hour queries to sqlc/query.sql
- Update service initialization to load market hours from DB
- Add fallback to config values if no DB entry exists
- Update RepoManager interface with new MarketHourRepo method
  • Loading branch information
sekulicd authored Nov 22, 2024
1 parent d6b8508 commit ae3ccb3
Show file tree
Hide file tree
Showing 31 changed files with 2,464 additions and 827 deletions.
90 changes: 90 additions & 0 deletions api-spec/openapi/swagger/ark/v1/admin.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,58 @@
"application/json"
],
"paths": {
"/v1/admin/market-hour": {
"get": {
"operationId": "AdminService_GetMarketHourConfig",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetMarketHourConfigResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"tags": [
"AdminService"
]
},
"post": {
"operationId": "AdminService_UpdateMarketHourConfig",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1UpdateMarketHourConfigResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1UpdateMarketHourConfigRequest"
}
}
],
"tags": [
"AdminService"
]
}
},
"/v1/admin/note": {
"post": {
"operationId": "AdminService_CreateNote",
Expand Down Expand Up @@ -186,6 +238,14 @@
}
}
},
"v1GetMarketHourConfigResponse": {
"type": "object",
"properties": {
"config": {
"$ref": "#/definitions/v1MarketHourConfig"
}
}
},
"v1GetRoundDetailsResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -263,6 +323,25 @@
}
}
},
"v1MarketHourConfig": {
"type": "object",
"properties": {
"startTime": {
"type": "string",
"format": "date-time"
},
"endTime": {
"type": "string",
"format": "date-time"
},
"period": {
"type": "string"
},
"roundInterval": {
"type": "string"
}
}
},
"v1ScheduledSweep": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -296,6 +375,17 @@
"format": "int64"
}
}
},
"v1UpdateMarketHourConfigRequest": {
"type": "object",
"properties": {
"config": {
"$ref": "#/definitions/v1MarketHourConfig"
}
}
},
"v1UpdateMarketHourConfigResponse": {
"type": "object"
}
}
}
22 changes: 22 additions & 0 deletions api-spec/openapi/swagger/ark/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@
},
"forfeitAddress": {
"type": "string"
},
"marketHour": {
"$ref": "#/definitions/v1MarketHour"
}
}
},
Expand Down Expand Up @@ -776,6 +779,25 @@
}
}
},
"v1MarketHour": {
"type": "object",
"properties": {
"nextStartTime": {
"type": "string",
"format": "date-time"
},
"nextEndTime": {
"type": "string",
"format": "date-time"
},
"period": {
"type": "string"
},
"roundInterval": {
"type": "string"
}
}
},
"v1Node": {
"type": "object",
"properties": {
Expand Down
32 changes: 32 additions & 0 deletions api-spec/protobuf/ark/v1/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ syntax = "proto3";
package ark.v1;

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

service AdminService {
rpc GetScheduledSweep(GetScheduledSweepRequest) returns (GetScheduledSweepResponse) {
Expand All @@ -27,6 +29,17 @@ service AdminService {
body: "*"
};
}
rpc GetMarketHourConfig(GetMarketHourConfigRequest) returns (GetMarketHourConfigResponse) {
option (google.api.http) = {
get: "/v1/admin/market-hour"
};
}
rpc UpdateMarketHourConfig(UpdateMarketHourConfigRequest) returns (UpdateMarketHourConfigResponse) {
option (google.api.http) = {
post: "/v1/admin/market-hour"
body: "*"
};
}
}

message GetScheduledSweepRequest {}
Expand Down Expand Up @@ -79,3 +92,22 @@ message CreateNoteRequest {
message CreateNoteResponse {
repeated string notes = 1;
}

message GetMarketHourConfigRequest {}

message GetMarketHourConfigResponse {
MarketHourConfig config = 1;
}

message UpdateMarketHourConfigRequest {
MarketHourConfig config = 1;
}

message UpdateMarketHourConfigResponse {}

message MarketHourConfig {
google.protobuf.Timestamp start_time = 1;
google.protobuf.Timestamp end_time = 2;
google.protobuf.Duration period = 3;
google.protobuf.Duration round_interval = 4;
}
10 changes: 10 additions & 0 deletions api-spec/protobuf/ark/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ syntax = "proto3";
package ark.v1;

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

service ArkService {
rpc GetInfo(GetInfoRequest) returns (GetInfoResponse) {
Expand Down Expand Up @@ -126,6 +128,7 @@ message GetInfoResponse {
string boarding_descriptor_template = 7;
repeated string vtxo_descriptor_templates = 8;
string forfeit_address = 9;
MarketHour market_hour = 10;
}

message GetBoardingAddressRequest {
Expand Down Expand Up @@ -388,4 +391,11 @@ message DeleteNostrRecipientResponse {}

message Tapscripts {
repeated string scripts = 1;
}

message MarketHour {
google.protobuf.Timestamp next_start_time = 1;
google.protobuf.Timestamp next_end_time = 2;
google.protobuf.Duration period = 3;
google.protobuf.Duration round_interval = 4;
}
Loading

0 comments on commit ae3ccb3

Please sign in to comment.