Skip to content

Commit

Permalink
Merge pull request #372 from lidofinance/feat/new-send-hash-rules
Browse files Browse the repository at this point in the history
not fast lane skip report - fast lane send report
  • Loading branch information
F4ever authored May 2, 2023
2 parents 8cdfd64 + a7bb234 commit 9402d8f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 61 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends -qq \
gcc=4:10.2.1-1 \
libffi-dev=3.3-6 \
g++=4:10.2.1-1 \
git=1:2.30.2-1 \
curl=7.74.0-1.3+deb11u7 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand Down

This file was deleted.

This file was deleted.

28 changes: 17 additions & 11 deletions src/modules/submodules/consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,35 @@ def process_report(self, blockstamp: ReferenceBlockStamp) -> None:
if not self.is_reporting_allowed(blockstamp):
logger.warning({'msg': 'Reporting checks are not passed. Report will not be sent.'})
return

self._process_report_hash(blockstamp, report_hash)
# Even if report hash transaction was failed we have to check if we can report data for current frame
self._process_report_data(blockstamp, report_data, report_hash)

def _process_report_hash(self, blockstamp: ReferenceBlockStamp, report_hash: HexBytes) -> None:
latest_blockstamp, member_info = self._get_latest_data()

# Check if current slot is newer than (member slot + slots_delay)
if not member_info.is_fast_lane:
if latest_blockstamp.slot_number < member_info.current_frame_ref_slot + member_info.fast_lane_length_slot:
logger.info({'msg': f'Member is not in fast lane, so report will be postponed for [{member_info.fast_lane_length_slot}] slots.'})
return None

if not member_info.is_report_member:
logger.info({'msg': 'Account can`t submit report hash.'})
return None

if HexBytes(member_info.current_frame_member_report) != report_hash:
logger.info({'msg': f'Send report hash. Consensus version: [{self.CONSENSUS_VERSION}]'})
self._send_report_hash(blockstamp, report_hash, self.CONSENSUS_VERSION)
else:
logger.info({'msg': 'Provided hash already submitted.'})
if HexBytes(member_info.current_frame_member_report) == report_hash:
logger.info({'msg': 'Account already submitted provided hash.'})
return None

if not member_info.is_fast_lane:
# Check if current slot is newer than (member slot + slots_delay)
if latest_blockstamp.slot_number < member_info.current_frame_ref_slot + member_info.fast_lane_length_slot:
logger.info({'msg': f'Member is not in fast lane, so report will be postponed '
f'for [{member_info.fast_lane_length_slot}] slots.'})
return None

if HexBytes(member_info.current_frame_consensus_report) == report_hash:
logger.info({'msg': 'Consensus reached with provided hash.'})
return None

logger.info({'msg': f'Send report hash. Consensus version: [{self.CONSENSUS_VERSION}]'})
self._send_report_hash(blockstamp, report_hash, self.CONSENSUS_VERSION)
return None

def _process_report_data(self, blockstamp: ReferenceBlockStamp, report_data: tuple, report_hash: HexBytes):
Expand Down
5 changes: 2 additions & 3 deletions src/providers/http_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from prometheus_client import Histogram
from requests import Session, JSONDecodeError
from requests.adapters import HTTPAdapter
from requests.exceptions import ConnectionError as RequestsConnectionError
from urllib3 import Retry

from src.providers.consistency import ProviderConsistencyModule
Expand Down Expand Up @@ -126,8 +125,8 @@ def _get_without_fallbacks(
params=query_params,
timeout=self.request_timeout,
)
except RequestsConnectionError as error:
logger.debug({'msg': str(error)})
except Exception as error:
logger.error({'msg': str(error)})
t.labels(
endpoint=endpoint,
code=0,
Expand Down
12 changes: 10 additions & 2 deletions tests/modules/submodules/consensus/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def test_report_hash(web3, consensus, tx_utils, set_report_account):
def test_report_hash_member_not_in_fast_lane(web3, consensus, caplog):
blockstamp = ReferenceBlockStampFactory.build()
consensus._get_latest_blockstamp = Mock(return_value=blockstamp)
member_info = MemberInfoFactory.build(is_fast_lane=False, current_frame_ref_slot=blockstamp.slot_number - 1)
member_info = MemberInfoFactory.build(
is_fast_lane=False,
current_frame_ref_slot=blockstamp.slot_number - 1,
is_report_member=True,
)
consensus.get_member_info = Mock(return_value=member_info)

consensus._process_report_hash(blockstamp, HexBytes(int.to_bytes(1, 32)))
Expand Down Expand Up @@ -102,7 +106,7 @@ def test_do_not_report_same_hash(consensus, caplog, mock_latest_data):
consensus.get_member_info = Mock(return_value=member_info)

consensus._process_report_hash(blockstamp, HexBytes(int.to_bytes(1, 32)))
assert "Provided hash already submitted" in caplog.messages[-1]
assert "Account already submitted provided hash." in caplog.messages[-1]


# -------- Process report data ---------
Expand Down Expand Up @@ -140,6 +144,7 @@ def test_process_report_data_main_data_submitted(consensus, caplog, mock_latest_
blockstamp = ReferenceBlockStampFactory.build()
report_data = tuple()
report_hash = int.to_bytes(1, 32)
consensus._get_slot_delay_before_data_submit = Mock(return_value=0)

consensus.is_main_data_submitted = Mock(side_effect=[False, True])

Expand All @@ -164,6 +169,7 @@ def test_process_report_data_main_sleep_until_data_submitted(consensus, caplog,

consensus.is_main_data_submitted = Mock(return_value=False)
consensus._get_slot_delay_before_data_submit = Mock(return_value=100)
consensus._submit_report = Mock()

consensus._process_report_data(blockstamp, report_data, report_hash)
assert "Sleep for 100 slots before sending data." in caplog.text
Expand Down Expand Up @@ -203,6 +209,8 @@ def test_process_report_submit_report(consensus, tx_utils, caplog, mock_latest_d
consensus.is_main_data_submitted = Mock(side_effect=main_data_submitted_base)
consensus._get_slot_delay_before_data_submit = Mock(return_value=0)

consensus._submit_report = Mock()

consensus._process_report_data(blockstamp, report_data, report_hash)
assert "Send report data. Contract version: [1]" in caplog.text

Expand Down

0 comments on commit 9402d8f

Please sign in to comment.