Skip to content

Add local store #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: v8/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dkg/modules/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def create(
minimum_number_of_node_replications = arguments.get(
"minimum_number_of_node_replications"
)
local_store = arguments.get("local_store")
blockchain_id = self.manager.blockchain_provider.blockchain_id

dataset = {}
Expand Down Expand Up @@ -448,6 +449,15 @@ def create(
frequency,
)

local_store_result = None
if local_store:
retry = 0
while (not (local_store_result or {}).get("status")) and retry < 6:
local_store_result = self.node_service.local_store(
dataset_root, dataset, blockchain_id, ual
)
retry += 1

return json.loads(
Web3.to_json(
{
Expand All @@ -471,6 +481,7 @@ def create(
},
"numberOfConfirmations": finality_status_result,
"requiredConfirmations": minimum_number_of_finalization_confirmations,
**({"localStore": local_store_result} if local_store else {}),
},
}
)
Expand Down
11 changes: 11 additions & 0 deletions dkg/modules/asset/async_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ async def create(
minimum_number_of_node_replications = arguments.get(
"minimum_number_of_node_replications"
)
local_store = arguments.get("local_store")
blockchain_id = self.manager.blockchain_provider.blockchain_id

dataset = {}
Expand Down Expand Up @@ -462,6 +463,15 @@ async def create(
frequency,
)

local_store_result = None
if local_store:
retry = 0
while (not (local_store_result or {}).get("status")) and retry < 6:
local_store_result = await self.node_service.local_store(
dataset_root, dataset, blockchain_id, ual
)
retry += 1

return json.loads(
Web3.to_json(
{
Expand All @@ -483,6 +493,7 @@ async def create(
},
"numberOfConfirmations": finality_status_result,
"requiredConfirmations": minimum_number_of_finalization_confirmations,
**({"localStore": local_store_result} if local_store else {}),
},
}
)
Expand Down
4 changes: 4 additions & 0 deletions dkg/services/input_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_asset_create_arguments(self, options):
"minimum_number_of_node_replications": self.get_minimum_number_of_node_replications(
options
),
"local_store": self.get_local_store(options),
}

def get_query_arguments(self, options):
Expand Down Expand Up @@ -181,3 +182,6 @@ def get_repository(self, options):
or self.config.get("repository")
or DefaultParameters.REPOSITORY.value
)

def get_local_store(self, options):
return options.get("local_store") or False
8 changes: 8 additions & 0 deletions dkg/services/node_services/async_node_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, manager: AsyncRequestManager):
_publish = Method(NodeRequest.publish)
_get = Method(NodeRequest.get)
_query = Method(NodeRequest.query)
_local_store = Method(NodeRequest.local_store)

async def info(self) -> NodeResponseDict:
return await self._info()
Expand Down Expand Up @@ -182,3 +183,10 @@ async def query(
paranet_ual,
):
return await self._query(query, query_type, repository, paranet_ual)

async def local_store(self, dataset_root, dataset, blockchain_id, ual):
try:
result = await self._local_store(dataset_root, dataset, blockchain_id, ual)
return result.get("data")
except Exception as e:
raise Exception(f"Unable to local store: {e}")
8 changes: 8 additions & 0 deletions dkg/services/node_services/node_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, manager: DefaultRequestManager):
_publish = Method(NodeRequest.publish)
_get = Method(NodeRequest.get)
_query = Method(NodeRequest.query)
_local_store = Method(NodeRequest.local_store)

def get_operation_result(
self, operation_id: str, operation: str, max_retries: int, frequency: int
Expand Down Expand Up @@ -165,3 +166,10 @@ def query(
paranet_ual,
):
return self._query(query, query_type, repository, paranet_ual)

def local_store(self, dataset_root, dataset, blockchain_id, ual):
try:
result = self._local_store(dataset_root, dataset, blockchain_id, ual)
return result.get("data")
except Exception as e:
raise Exception(f"Unable to local store: {e}")
11 changes: 11 additions & 0 deletions dkg/utils/node_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ class NodeRequest:
},
)

local_store = NodeCall(
method=HTTPRequestMethod.POST,
path="local-store",
data={
"datasetRoot": str,
"dataset": dict[str, list[str]],
"blockchain": str,
"UAL": UAL,
},
)


class LocalStoreOperationStatus(AutoStrEnumUpperCase):
LOCAL_STORE_INIT_START = auto()
Expand Down
2 changes: 1 addition & 1 deletion examples/async_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def print_json(json_dict: dict):
"epochs_num": 2,
"minimum_number_of_finalization_confirmations": 3,
"minimum_number_of_node_replications": 1,
"token_amount": 100,
"local_store": True,
},
)
print(
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def print_json(json_dict: dict):
"epochs_num": 2,
"minimum_number_of_finalization_confirmations": 3,
"minimum_number_of_node_replications": 1,
"token_amount": 100,
"local_store": True,
},
)
print(
Expand Down