Skip to content

Commit

Permalink
Bugs/fix ve allocate (#912)
Browse files Browse the repository at this point in the history
* make sure nftAddress is checksumed

* improve performance

* safety checks

* Bump version: 4.5.2 → 4.5.3
  • Loading branch information
alexcos20 authored Oct 6, 2022
1 parent a044bfb commit cfb3975
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.5.2
current_version = 4.5.3
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion aquarius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
__author__ = """OceanProtocol"""
# fmt: off
# bumpversion needs single quotes
__version__ = '4.5.2'
__version__ = '4.5.3'
# fmt: on
8 changes: 4 additions & 4 deletions aquarius/events/events_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ def __init__(self, web3, config_file):
VeAllocate(self._es_instance) if (os.getenv("VEALLOCATE_URL")) else None
)
allocate_message = (
"Enabling veAllocate" if self.purgatory else "veAllocate is disabled"
"VeAllocate enabled" if self.ve_allocate else "VeAllocate disabled"
)
logger.info("PURGATORY: " + allocate_message)
logger.info(allocate_message)
self.retry_mechanism = RetryMechanism(
config_file, self._es_instance, self._retries_db_index, self.purgatory
)

purgatory_message = (
"Enabling purgatory" if self.purgatory else "Purgatory is disabled"
"Purgatory enabled" if self.purgatory else "Purgatory disabled"
)
logger.info("PURGATORY: " + purgatory_message)
logger.info(purgatory_message)

@property
def block_envvar(self):
Expand Down
36 changes: 22 additions & 14 deletions aquarius/events/ve_allocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import elasticsearch
import requests
from web3 import Web3

from aquarius.events.util import make_did

Expand All @@ -28,9 +29,6 @@ def retrieve_new_list(self, env_var):
response = requests.post(os.getenv(env_var))

if response.status_code == requests.codes.ok:
logger.info(
f"veAllocate: Successfully retrieved list from {env_var} env var."
)
return {
(a["nft_addr"], a["ve_allocated"], a["chainID"])
for a in response.json()
Expand All @@ -46,16 +44,24 @@ def update_asset(self, asset, veAllocated):
"""
did = asset["id"]
if "stats" not in asset:
asset["stats"] = {}

asset["stats"]["allocated"] = veAllocated
logger.info(
f"veAllocate: updating asset {did} with state.allocated={veAllocated}."
)
try:
self._es_instance.update(json.dumps(asset), did)
except Exception as e:
logger.warning(f"updating ddo {did} stats.allocated attribute failed: {e}")
asset["stats"] = {"allocated": 0}
if "allocated" not in asset["stats"]:
asset["stats"]["allocated"] = 0
if asset["stats"]["allocated"] != veAllocated:
asset["stats"]["allocated"] = veAllocated
logger.info(
f"veAllocate: updating asset {did} with state.allocated={veAllocated}."
)
try:
self._es_instance.update(json.dumps(asset), did)
except Exception as e:
logger.warning(
f"updating ddo {did} stats.allocated attribute failed: {e}"
)
else:
logger.debug(
f"veAllocate: asset {did} has unchanged state.allocated ({veAllocated})."
)

def update_lists(self):
"""
Expand All @@ -72,11 +78,13 @@ def update_lists(self):
self.update_time = now

ve_list = self.retrieve_new_list("VEALLOCATE_URL")
logger.info(f"veAllocate: Retrieved list of {len(ve_list)} assets to update")

for nft, ve_allocated, chain_id in ve_list:
did = make_did(Web3.toChecksumAddress(nft), chain_id)
try:
did = make_did(nft, chain_id)
asset = self._es_instance.read(did)
self.update_asset(asset, ve_allocated)
except elasticsearch.exceptions.NotFoundError:
logger.debug(f"Cannot find asset {did} for veAllocate update")
continue
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
url="https://github.com/oceanprotocol/aquarius",
# fmt: off
# bumpversion needs single quotes
version='4.5.2',
version='4.5.3',
# fmt: on
zip_safe=False,
)

0 comments on commit cfb3975

Please sign in to comment.