Skip to content

Commit

Permalink
Fixed rounding error in generating UTXOs
Browse files Browse the repository at this point in the history
Other changes:
- Switched to RPC as celery result backend
- Removed celery worker and periodic schedule for non-existent task
  • Loading branch information
joemarct committed Jun 17, 2021
1 parent 72a7d54 commit a78678d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
4 changes: 0 additions & 4 deletions main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,11 @@ class TransactionAdmin(DynamicRawIDMixin, admin.ModelAdmin):
'spend_block_height'
]



def get_actions(self, request):
actions = super().get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
return actions


def resend_unacknowledged_transactions(self, request, queryset):
for tr in queryset:
Expand All @@ -106,7 +103,6 @@ def resend_unacknowledged_transactions(self, request, queryset):
message = platform[1]
chat_id = platform[2]
send_telegram_message(message, chat_id)


# def get_queryset(self, request):
# # For Django < 1.6, override queryset instead of get_queryset
Expand Down
5 changes: 5 additions & 0 deletions main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
app = Celery('configs')


@shared_task()
def add(x, y):
return x + y


# NOTIFICATIONS
@shared_task(rate_limit='20/s', queue='send_telegram_message')
def send_telegram_message(message, chat_id):
Expand Down
10 changes: 8 additions & 2 deletions main/views/view_utxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
from main.models import Transaction
from rest_framework.response import Response
from rest_framework import status
from django.db.models import Q, F
from django.db.models import Q, F, Func


class Round(Func):
function = "ROUND"
template = "%(function)s(%(expressions)s::numeric, 0)"


class UTXO(APIView):

Expand All @@ -23,7 +29,7 @@ def get(self, request, *args, **kwargs):
query = Q(address=data['address']) & Q(spent=False) & Q(amount__gt=dust)
qs = Transaction.objects.filter(query)
utxos_values = qs.annotate(
value=F('amount') * (10 ** 8),
value=Round(F('amount') * (10 ** 8)),
vout=F('index'),
block=F('blockheight__number'),
).values(
Expand Down
9 changes: 0 additions & 9 deletions supervisor/blockscan.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ stderr_logfile_maxbytes=0
stopasgroup = true


[program:celery_problematic_transactions]
command = celery -A watchtower worker -l INFO -c 1 -Ofair -Q problematic_transactions --max-tasks-per-child=1
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopasgroup = true


[program:celery_review_block]
command= celery -A watchtower worker -l INFO -c 1 -Ofair -Q review_block --max-tasks-per-child=10
stdout_logfile=/dev/stdout
Expand Down
9 changes: 0 additions & 9 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ stderr_logfile_maxbytes=0
stopasgroup = true


[program:celery_problematic_transactions]
command = celery -A watchtower worker -n worker10 -l INFO -c 1 -Ofair -Q problematic_transactions --max-tasks-per-child=1
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopasgroup = true


[program:celery_review_block]
command= celery -A watchtower worker -n worker11 -l INFO -c 1 -Ofair -Q review_block --max-tasks-per-child=10
stdout_logfile=/dev/stdout
Expand Down
9 changes: 3 additions & 6 deletions watchtower/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ def decipher(value):
CELERY_IMPORTS = ('main.tasks',)

CELERY_BROKER_URL = 'pyamqp://rabbitmq:5672'
CELERY_RESULT_BACKEND = 'rpc://'

if REDIS_PASSWORD:
# CELERY_BROKER_URL = 'redis://user:%s@%s:%s/%s' % (REDIS_PASSWORD, REDIS_HOST, REDIS_PORT, DB_NUM[0])
CELERY_RESULT_BACKEND = 'redis://user:%s@%s:%s/%s' % (REDIS_PASSWORD, REDIS_HOST, REDIS_PORT, DB_NUM[1])
# CELERY_RESULT_BACKEND = 'redis://user:%s@%s:%s/%s' % (REDIS_PASSWORD, REDIS_HOST, REDIS_PORT, DB_NUM[1])
REDISKV = redis.StrictRedis(
host=REDIS_HOST,
password=REDIS_PASSWORD,
Expand All @@ -172,7 +173,7 @@ def decipher(value):
)
else:
# CELERY_BROKER_URL = 'redis://%s:%s/%s' % (REDIS_HOST, REDIS_PORT, DB_NUM[0])
CELERY_RESULT_BACKEND = 'redis://%s:%s/%s' % (REDIS_HOST, REDIS_PORT, DB_NUM[1])
# CELERY_RESULT_BACKEND = 'redis://%s:%s/%s' % (REDIS_HOST, REDIS_PORT, DB_NUM[1])
REDISKV = redis.StrictRedis(
host=REDIS_HOST,
port=6379,
Expand Down Expand Up @@ -200,10 +201,6 @@ def decipher(value):
'manage_block_transactions': {
'task': 'main.tasks.manage_block_transactions',
'schedule': 7
},
'problematic_transactions': {
'task': 'main.tasks.problematic_transactions',
'schedule': 3
}
}

Expand Down

0 comments on commit a78678d

Please sign in to comment.