Skip to content

Commit d71576b

Browse files
committed
Same signer may not confirm different blocks of the same number
1 parent 72a9943 commit d71576b

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 3.2.12 on 2022-03-19 10:07
2+
3+
import uuid
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('blockchain', '0004_pendingblock'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='BlockConfirmation',
17+
fields=[
18+
('_id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
19+
('number', models.PositiveBigIntegerField()),
20+
('hash', models.CharField(max_length=128)),
21+
('signer', models.CharField(max_length=64)),
22+
('body', models.BinaryField()),
23+
],
24+
options={
25+
'ordering': ('number', 'signer'),
26+
'unique_together': {('number', 'signer')},
27+
},
28+
),
29+
]

node/blockchain/models/block_confirmation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class BlockConfirmation(CustomModel):
1414
body = models.BinaryField()
1515

1616
class Meta:
17-
unique_together = ('number', 'hash', 'signer')
17+
unique_together = ('number', 'signer')
1818
ordering = unique_together
1919

2020
def __str__(self):
21-
return f'block_number={self.number}, hash={self.hash}, signer={self.signer}'
21+
return f'block_number={self.number}, signer={self.signer}, hash={self.hash}'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from celery import shared_task
2+
3+
# from node.blockchain.facade import BlockchainFacade
4+
5+
6+
@shared_task
7+
def process_block_confirmations_task():
8+
# TODO(dmu) CRITICAL: Implement https://thenewboston.atlassian.net/browse/BC-272
9+
# facade = BlockchainFacade.get_instance()
10+
# next_block_number = facade.get_next_block_number()
11+
# get all confirmation for next block number
12+
# if there is no 2/3
13+
raise NotImplementedError
14+
15+
16+
def start_process_block_confirmations_task():
17+
process_block_confirmations_task.delay()

node/blockchain/views/block_confirmation.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ def create(self, request, *args, **kwargs):
2121

2222
ORMBlockConfirmation.objects.update_or_create(
2323
number=block_confirmation.get_number(),
24-
hash=block_confirmation.get_hash(),
2524
signer=block_confirmation.signer,
26-
body=block_confirmation.json(), # TODO(dmu) LOW: Pick request body as is instead
25+
defaults={
26+
'hash': block_confirmation.get_hash(),
27+
'body': block_confirmation.json(), # TODO(dmu) LOW: Pick request body AS IS instead
28+
},
2729
)
2830

31+
# TODO(dmu) CRITICAL: https://thenewboston.atlassian.net/browse/BC-272
32+
# if next block number and we have enough confirmations then run a celery task
33+
# to add the block to the blockchain
34+
2935
return Response(serializer.data, status=status.HTTP_201_CREATED)

0 commit comments

Comments
 (0)