Skip to content

Commit 88cfcbd

Browse files
authored
Merge pull request #560 from lidofinance/develop
Merge master
2 parents 2a0ecd1 + da393bf commit 88cfcbd

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

src/modules/submodules/consensus.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
from src.utils.cache import global_lru_cache as lru_cache
2828
from src.web3py.types import Web3
2929

30-
3130
logger = logging.getLogger(__name__)
3231

33-
3432
# Initial epoch is in the future. Revert signature: '0xcd0883ea'
3533
InitialEpochIsYetToArriveRevert = Web3.keccak(text="InitialEpochIsYetToArrive()")[:4].hex()
3634

@@ -135,25 +133,29 @@ def get_member_info(self, blockstamp: BlockStamp) -> MemberInfo:
135133
current_frame_consensus_report = current_frame_member_report = ZERO_HASH
136134

137135
if variables.ACCOUNT:
138-
(
139-
# Current frame's reference slot.
140-
_, # current_frame_ref_slot
141-
# Consensus report for the current frame, if any. Zero bytes otherwise.
142-
current_frame_consensus_report,
143-
# Whether the provided address is a member of the oracle committee.
144-
is_member,
145-
# Whether the oracle committee member is in the fast line members subset of the current reporting frame.
146-
is_fast_lane,
147-
# Whether the oracle committee member is allowed to submit a report at the moment of the call.
148-
_, # can_report
149-
# The last reference slot for which the member submitted a report.
150-
last_member_report_ref_slot,
151-
# The hash reported by the member for the current frame, if any.
152-
current_frame_member_report,
153-
) = consensus_contract.get_consensus_state_for_member(
154-
variables.ACCOUNT.address,
155-
blockstamp.block_hash,
156-
)
136+
try:
137+
(
138+
# Current frame's reference slot.
139+
_, # current_frame_ref_slot
140+
# Consensus report for the current frame, if any. Zero bytes otherwise.
141+
current_frame_consensus_report,
142+
# Whether the provided address is a member of the oracle committee.
143+
is_member,
144+
# Whether the oracle committee member is in the fast line members subset of the current reporting frame.
145+
is_fast_lane,
146+
# Whether the oracle committee member is allowed to submit a report at the moment of the call.
147+
_, # can_report
148+
# The last reference slot for which the member submitted a report.
149+
last_member_report_ref_slot,
150+
# The hash reported by the member for the current frame, if any.
151+
current_frame_member_report,
152+
) = consensus_contract.get_consensus_state_for_member(
153+
variables.ACCOUNT.address,
154+
blockstamp.block_hash,
155+
)
156+
except ContractCustomError as revert:
157+
if revert.data != InitialEpochIsYetToArriveRevert:
158+
raise revert
157159

158160
is_submit_member = self._is_submit_member(blockstamp)
159161

tests/modules/submodules/consensus/test_consensus.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,41 @@ def test_get_frame_custom_exception(web3, consensus):
143143
consensus.get_initial_or_current_frame(bs)
144144

145145

146+
@pytest.fixture()
147+
def use_account(request):
148+
if request.param:
149+
request.getfixturevalue("set_submit_account")
150+
else:
151+
request.getfixturevalue("set_no_account")
152+
153+
146154
@pytest.mark.unit
147-
def test_first_frame_is_not_yet_started(web3, consensus, caplog, set_no_account):
155+
@pytest.mark.parametrize(
156+
"use_account", [True, False], ids=['with_account', "without_account"], indirect=["use_account"]
157+
)
158+
def test_first_frame_is_not_yet_started(web3, consensus, caplog, use_account):
148159
bs = ReferenceBlockStampFactory.build()
149-
150-
consensus_contract = Mock(get_current_frame=Mock(side_effect=ContractCustomError('0xcd0883ea', '0xcd0883ea')))
160+
err = ContractCustomError('0xcd0883ea', '0xcd0883ea')
161+
consensus_contract = Mock(
162+
get_current_frame=Mock(side_effect=err), get_consensus_state_for_member=Mock(side_effect=err)
163+
)
151164
consensus._get_consensus_contract = Mock(return_value=consensus_contract)
165+
consensus._is_submit_member = Mock(return_value=True)
152166
consensus.get_frame_config = Mock(return_value=FrameConfigFactory.build(initial_epoch=5, epochs_per_frame=10))
153167
consensus.get_chain_config = Mock(return_value=ChainConfigFactory.build())
154168

155169
first_frame = consensus.get_initial_or_current_frame(bs)
170+
member_info = consensus.get_member_info(bs)
156171

157172
assert first_frame.ref_slot == 5 * 32 - 1
158173
assert first_frame.report_processing_deadline_slot == (5 + 10) * 32 - 1
174+
assert member_info.is_submit_member
175+
assert member_info.is_report_member
176+
assert member_info.is_fast_lane
177+
assert member_info.current_frame_consensus_report == ZERO_HASH
178+
assert member_info.current_frame_member_report == ZERO_HASH
179+
assert member_info.current_frame_ref_slot == first_frame.ref_slot
180+
assert member_info.deadline_slot == first_frame.report_processing_deadline_slot
159181

160182

161183
@pytest.mark.unit

0 commit comments

Comments
 (0)