Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Do not attempt to commit the already committed block
Browse files Browse the repository at this point in the history
Fork resolution decides if a newly arrived block
should be chosen over current chain. However
if duplicate block is received from the validator
the consensus engine shall ignore the block and not
try to commit again.

Signed-off-by: S m, Aruna <aruna.s.m@intel.com>
  • Loading branch information
arsulegai authored and dcmiddle committed Jul 12, 2019
1 parent 60295cf commit 754766d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
10 changes: 9 additions & 1 deletion core/sawtooth_poet/poet_consensus/poet_fork_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ def compare_forks(self, cur_fork_head, new_fork_head):
cur_fork_head.header_signature[:8],
new_fork_head.header_signature[:8])
chosen_fork_head = cur_fork_head
else:
elif new_fork_head.header_signature > \
cur_fork_head.header_signature:
LOGGER.info(
'Choose new fork %s over current fork %s: '
'New fork header signature (%s) greater than current fork '
Expand All @@ -243,6 +244,13 @@ def compare_forks(self, cur_fork_head, new_fork_head):
new_fork_head.header_signature[:8],
cur_fork_head.header_signature[:8])
chosen_fork_head = new_fork_head
else:
LOGGER.info(
'Choose current fork %s over new fork %s: '
'Current fork header signature is same as new fork '
'header signature',
cur_fork_head.header_signature[:8],
new_fork_head.header_signature[:8])

# Now that we have chosen a fork for the chain head, if we chose the
# new fork and it is a PoET block (i.e., it has a wait certificate),
Expand Down
33 changes: 29 additions & 4 deletions core/tests/test_consensus/test_poet_fork_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,36 @@ def test_both_valid_poet_blocks(
in message)

# Subtest 3: when new & current fork heads have
# the same wait duration
# the same wait duration and same header signature.
# If block header signature is same, it should be same block received
# second time.

# change new_fork_mock_wait_certificate duration to a smaller value
new_fork_mock_wait_certificate.duration = 1.0

# set mock_utils.deserialize_wait_certificate
# to return a specific value for each fork_head
# with cur_fork_head being deserialized first
mock_utils.deserialize_wait_certificate.side_effect = \
[mock_wait_certificate,
new_fork_mock_wait_certificate]

# check test
with mock.patch('sawtooth_poet.poet_consensus.poet_fork_resolver.'
'LOGGER') as mock_logger:
self.assertFalse(fork_resolver.compare_forks(
cur_fork_head=mock_cur_fork_header,
new_fork_head=mock_new_fork_header))

# Subtest 4: when new & current fork heads have
# the same wait duration and different header signature

# Change the mock_new_fork_head.header_signature to something else.
# New fork head's header signature is greater than current fork
# head's header signature
mock_new_fork_header.header_signature = \
'00112233445566778899aabbccddefff'

# set mock_utils.deserialize_wait_certificate
# to return a specific value for each fork_head
# with cur_fork_head being deserialized first
Expand Down Expand Up @@ -445,13 +470,13 @@ def test_different_previous_block_id(
previous_block_id='2',
header_signature='00112233445566778899aabbccddeeff')

# create mock_new_fork_head
# create mock_new_fork_head, with different header signature
mock_new_fork_header = \
mock.Mock(
identifier='0123456789abcdefedcba9876543211',
signer_public_key='90834587139405781349807435098745',
previous_block_id='3',
header_signature='00112233445566778899aabbccddeeff')
header_signature='00112233445566778899aabbccddefff')

fork_resolver = \
poet_fork_resolver.PoetForkResolver(
Expand Down Expand Up @@ -515,7 +540,7 @@ def test_different_previous_block_id(
mock_cur_fork_consensus_state.aggregate_local_mean = 1.0
mock_new_fork_consensus_state.aggregate_local_mean = 1.0

# check test
# check test, return true indicates that new fork won
self.assertTrue(fork_resolver.compare_forks(
cur_fork_head=mock_cur_fork_header,
new_fork_head=mock_new_fork_header))
Expand Down

0 comments on commit 754766d

Please sign in to comment.