Skip to content

Commit

Permalink
keyspace auto discovery, v25.01.0a7
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Jan 3, 2025
1 parent 07e9f9b commit 60d7d1a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ all: format lint

-include .env

GS_REST_SERVICE_VERSIONM ?= "25.01.0a6"
GS_REST_SERVICE_VERSION ?= "2.0.0a6"
GS_REST_SERVICE_VERSIONM ?= "25.01.0a7"
GS_REST_SERVICE_VERSION ?= "2.0.0a7"
GS_REST_DEV_PORT ?= 9000
NUM_WORKERS ?= 1
NUM_THREADS ?= 1
Expand Down
53 changes: 53 additions & 0 deletions gsrest/db/cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import time
from collections import UserDict, namedtuple
from datetime import datetime
from functools import partial
from itertools import product
from math import ceil, floor
Expand Down Expand Up @@ -47,6 +48,14 @@
SEARCH_PAGE_SIZE = 100


def getDateFromKeyspaceName(x):
datePart = x.split("_")[-1]
try:
return datetime.strptime(datePart, "%Y%m%d")
except ValueError:
return None


class NetworkParameters(UserDict):
def __getitem__(self, network):
if network not in self:
Expand Down Expand Up @@ -379,7 +388,20 @@ def __init__(self, config, logger):
self.prepared_statements = {}
self.connect()
self.parameters = NetworkParameters()

for currency in config["currencies"]:
if config["currencies"][currency] is None:
config["currencies"][currency] = {}

# automatically find latest active keyspace if not configured
if "raw" not in config["currencies"][currency]:
config["currencies"][currency]["raw"] = f"{currency}_raw"

if "transformed" not in config["currencies"][currency]:
config["currencies"][currency]["transformed"] = (
self.find_latest_transformed_keyspace(currency)
)

self.check_keyspace(config["currencies"][currency]["raw"])
self.check_keyspace(config["currencies"][currency]["transformed"])
self.load_parameters(currency)
Expand Down Expand Up @@ -422,6 +444,37 @@ def check_keyspace(self, keyspace):
if one(result) is None:
raise BadConfigError("Keyspace {} does not exist".format(keyspace))

if self.logger:
self.logger.info(f"Using keyspace: {keyspace}")

def find_latest_transformed_keyspace(self, network):
query = "SELECT keyspace_name FROM system_schema.keyspaces"
result = self.session.execute(query)
prefix = f"{network.lower()}_transformed"
candidates = [
getDateFromKeyspaceName(x["keyspace_name"])
for x in result
if x["keyspace_name"].startswith(prefix)
]

for c in reversed(sorted(filter(lambda x: x is not None, candidates))):
ks = f"{prefix}_{c.strftime('%Y%m%d')}"
q = f"SELECT * FROM {ks}.summary_statistics limit 1"
result = self.session.execute(q)

if one(result) is None:
if self.logger:
self.logger.error(
f"{ks} is not online (missing summary_statistics row). skipping"
)
continue
else:
return ks

raise Exception(
f"Automatic detection for transformed keyspace failed for network {network}."
)

@eth
def load_token_configuration(self, currency):
return None
Expand Down
2 changes: 1 addition & 1 deletion openapi_server/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
name: Iknaio Cryptoasset Analytics GmbH
description: GraphSense API provides programmatic access to various ledgers' addresses, entities, blocks, transactions and tags for automated and highly efficient forensics tasks.
title: GraphSense API
version: 2.0.0a6
version: 2.0.0a7
servers:
- url: https://api.ikna.io
paths:
Expand Down
2 changes: 1 addition & 1 deletion openapi_spec/graphsense.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
contact:
name: Iknaio Cryptoasset Analytics GmbH
email: [email protected]
version: "2.0.0a6"
version: "2.0.0a7"
servers:
- url: 'https://api.ikna.io'
paths:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "gsrest"
version = "2.0.0a6"
version = "2.0.0a7"
description = "GraphSense API REST API"
readme = "README.md"
changelog = "CHANGELOG.md"
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60d7d1a

Please sign in to comment.