-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Abstract contract interaction #432
Conversation
|
||
@lru_cache(maxsize=1) | ||
def normalized_cl_reward_per_epoch(self, block_identifier: BlockIdentifier = 'latest') -> int: | ||
response = self.functions.get('NORMALIZED_CL_REWARD_PER_EPOCH').call(block_identifier=block_identifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why other syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one function get that receives value by key.
To correctly work with cache and do not increase it's size, I think it's better to use different functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get it, to be honest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@madlabman function get
is the contract function that returns value by key. NORMALIZED_CL_REWARD_PER_EPOCH
isn't state variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@madlabman function
get
is the contract function that returns value by key.NORMALIZED_CL_REWARD_PER_EPOCH
isn't state variable
Got it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/modules/submodules/consensus.py
Outdated
@@ -301,7 +277,7 @@ def _process_report_hash(self, blockstamp: ReferenceBlockStamp, report_hash: Hex | |||
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): | |||
def _process_report_data(self, blockstamp: ReferenceBlockStamp, report_data: tuple, report_hash: bytes): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't found the related changes in place where it is called. is it safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HexBytes just rewrites a few methods related to a representation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w3.keccak() returns HexBytes, but in annotation indicated bytes.
Returned back
|
||
|
||
class AccountingOracleContract(BaseOracleContract): | ||
abi_path = './assets/AccountingOracle.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with the current, but it will be more obvious if you use cwd
somewhere
|
||
@lru_cache(maxsize=1) | ||
def normalized_cl_reward_per_epoch(self, block_identifier: BlockIdentifier = 'latest') -> int: | ||
response = self.functions.get('NORMALIZED_CL_REWARD_PER_EPOCH').call(block_identifier=block_identifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@madlabman function get
is the contract function that returns value by key. NORMALIZED_CL_REWARD_PER_EPOCH
isn't state variable
|
||
response = Web3.to_int(response) | ||
logger.info({ | ||
'msg': 'Call `NORMALIZED_CL_REWARD_PER_EPOCH()`.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not true. We call get
function with NORMALIZED_CL_REWARD_PER_EPOCH
arg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make _get
function and reuse it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's why I didn't get the get
call :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx!
Fixed
@lru_cache(maxsize=1) | ||
@list_of_dataclasses(StakingModule) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we use @list_of_dataclasses
but not for get_all_node_operator_digests
and get_all_node_operator_digests
func. let's use a common approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is easy to do. To create NodeOperator we have to provide a module that is not in the response. That's why I'm doing parsing inside method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work, I guess (regarding to test_dataclasses_utils
)
@lru_cache(maxsize=1)
@list_of_dataclasses(NodeOperator)
def get_all_node_operator_digests(self, module: StakingModule, block_identifier: BlockIdentifier = 'latest') -> list[NodeOperator]:
"""
Returns node operator digest for each node operator in lido protocol
"""
response = self.functions.getAllNodeOperatorDigests(module.id).call(block_identifier=block_identifier)
response = [{**no, "staking_module": module} for no in response]
logger.info({
'msg': f'Call `getAllNodeOperatorDigests({module.id})`.',
'value': response,
'block_identifier': repr(block_identifier),
})
return response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example, you run twice over all NOs.
- Regenerate all dicts with staking module
- From dicts to dataclasses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it already doesn't matter. I've rewritten this function in next PR
No description provided.