Skip to content

Commit

Permalink
[AUD-430] Remove identity endpoint to serve registered content nodes (#…
Browse files Browse the repository at this point in the history
…1305)

* Cache the list of content node services in redis

* Rip out this entire flow

* Lint

* More lint
  • Loading branch information
dmanjunath committed Mar 18, 2021
1 parent bddb9ea commit 9bb3ca2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 62 deletions.
19 changes: 0 additions & 19 deletions discovery-provider/src/tasks/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from urllib.parse import urljoin
import logging
import concurrent.futures
import requests

from src import contract_addresses
from src.models import Block, User, Track, Repost, Follow, Playlist, \
Expand Down Expand Up @@ -546,23 +544,6 @@ def revert_blocks(self, db, revert_blocks_list):
rebuild_user_index = rebuild_user_index or bool(revert_user_entries)
# TODO - if we enable revert, need to set the most_recent_indexed_block_redis_key key in redis

# calls GET identityservice/registered_creator_nodes to retrieve creator nodes currently registered on chain
def fetch_cnode_endpoints_from_chain(task_context):
try:
identity_url = task_context.shared_config['discprov']['identity_service_url']
identity_endpoint = urljoin(identity_url, 'registered_creator_nodes')

r = requests.get(identity_endpoint, timeout=3)
if r.status_code != 200:
raise Exception(f"Query to identity_endpoint failed with status code {r.status_code}")

registered_cnodes = r.json()
logger.info(f"Fetched registered creator nodes from chain via {identity_endpoint}")
return registered_cnodes
except Exception as e:
logger.error(f"Identity fetch failed {e}")
return []

######## CELERY TASKS ########
@celery.task(name="update_discovery_provider", bind=True)
def update_task(self):
Expand Down
35 changes: 1 addition & 34 deletions discovery-provider/src/tasks/index_network_peers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import logging
import concurrent.futures
from urllib.parse import urljoin
import requests
from src.tasks.celery_app import celery
from src import eth_abi_values
from src.utils.helpers import get_ipfs_info_from_cnode_endpoint, is_fqdn
from src.models import User
from src.utils.redis_cache import use_redis_cache, pickle_and_set, get_sp_id_key, get_pickled_key
from src.utils.redis_cache import pickle_and_set, get_sp_id_key, get_pickled_key

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -107,32 +105,6 @@ def retrieve_peers_from_db(self):
cnode_endpoints_set.add(cnode_url)
return cnode_endpoints_set

# calls GET identityservice/registered_creator_nodes to retrieve creator nodes currently registered on chain
def fetch_cnode_endpoints_from_identity(self):
try:
identity_url = update_network_peers.shared_config['discprov']['identity_service_url']
identity_endpoint = urljoin(identity_url, 'registered_creator_nodes')

r = requests.get(identity_endpoint, timeout=3)
if r.status_code != 200:
raise Exception(f"Query to identity_endpoint failed with status code {r.status_code}")

registered_cnodes = r.json()
logger.info(
f"index_network_peers.py | Fetched registered creator nodes from chain via"
f"{identity_endpoint} - {registered_cnodes}"
)
return registered_cnodes
except Exception as e:
logger.error(f"Identity fetch failed {e}")
return []

def refresh_cnodes_from_identity(self):
registered_cnodes = use_redis_cache(
'registered_cnodes_from_identity', 30, lambda: fetch_cnode_endpoints_from_identity(self)
)
return registered_cnodes

# Function submitted to future in threadpool executor
def connect_peer(endpoint, ipfs_client):
logger.info(f"index_network_peers.py | Peering with {endpoint}")
Expand Down Expand Up @@ -180,11 +152,6 @@ def update_network_peers(self):
all_peers = peers_from_ethereum
all_peers.update(peers_from_local)

# Legacy list of cnodes from identity
identity_cnodes_map = refresh_cnodes_from_identity(self)
for node_info in identity_cnodes_map:
all_peers.add(node_info['endpoint'])

# Legacy user metadata node is always added to set of known peers
user_metadata_url = update_network_peers.shared_config["discprov"]["user_metadata_service_url"]
all_peers.add(user_metadata_url)
Expand Down
9 changes: 0 additions & 9 deletions identity-service/src/routes/ethRelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,4 @@ module.exports = function (app) {
let gasInfo = await ethTxRelay.getProdGasInfo(req.app.get('redis'), req.logger)
return successResponse(gasInfo)
}))

/**
* Queries and returns all registered content nodes from chain
*/
app.get('/registered_creator_nodes', handleResponse(async (req, res, next) => {
const audiusLibsInstance = req.app.get('audiusLibs')
const creatorNodes = await audiusLibsInstance.ethContracts.ServiceProviderFactoryClient.getServiceProviderList('content-node')
return successResponse(creatorNodes)
}))
}

0 comments on commit 9bb3ca2

Please sign in to comment.