Skip to content
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

InfractionCollector Contract #267

Merged
merged 31 commits into from
Aug 20, 2024
Merged

Conversation

theref
Copy link
Contributor

@theref theref commented May 15, 2024

Scope is outlined in #266

  • First Draft of Contract
  • Updates to existing contracts
  • Deployment scripts
  • Tests

Related to https://github.com/nucypher/sprints/issues/35

@theref theref requested a review from cygnusv May 15, 2024 12:32
@theref theref self-assigned this May 15, 2024
@theref theref marked this pull request as draft May 15, 2024 12:32
@theref theref requested a review from vzotova May 15, 2024 13:20
@theref theref force-pushed the infraction branch 2 times, most recently from f7c7407 to 7704038 Compare May 20, 2024 13:07
@theref theref changed the title WIP InfractionCollector Contract InfractionCollector Contract May 20, 2024
@theref theref marked this pull request as ready for review May 20, 2024 13:21
@theref theref marked this pull request as draft May 20, 2024 13:22
Copy link
Member

@cygnusv cygnusv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

contracts/contracts/coordination/InfractionCollector.sol Outdated Show resolved Hide resolved
@theref theref marked this pull request as ready for review June 5, 2024 12:02
README.md Outdated Show resolved Hide resolved
contracts/contracts/coordination/InfractionCollector.sol Outdated Show resolved Hide resolved
contracts/contracts/coordination/InfractionCollector.sol Outdated Show resolved Hide resolved
contracts/contracts/coordination/TACoChildApplication.sol Outdated Show resolved Hide resolved
deployment/constructor_params/lynx/child.yml Outdated Show resolved Hide resolved
deployment/constructor_params/lynx/infraction.yml Outdated Show resolved Hide resolved
tests/test_child_application.py Outdated Show resolved Hide resolved
tests/test_infraction.py Outdated Show resolved Hide resolved
tests/test_infraction.py Show resolved Hide resolved
@theref theref force-pushed the infraction branch 2 times, most recently from 8109c9c to 904b811 Compare August 8, 2024 13:41
README.md Outdated Show resolved Hide resolved
contracts/contracts/coordination/InfractionCollector.sol Outdated Show resolved Hide resolved
tests/test_infraction.py Outdated Show resolved Hide resolved
}

// Mapping to keep track of reported infractions
mapping(uint32 => mapping(address => mapping(InfractionType => bool))) public infractions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason why the top-level index here is the ritual ID? I'm not suggesting any changes at this moment but how this data structure is formed has implications on how cost-effective and code-efficient looking up infractions is later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each storage lookup has a relatively high cost, so in general, you'd want to reduce the number of read and writes. In this case, there's some optimizations you can do here:

  • If for each ritual and staker there can only be one infraction (which doesn't seem unlikely), you can remove the last bool since storage slots are falsy by default (i.e., zero bytes). For that you'd only need to add a NONE initial value to InfractionType, so that actual infractions write non-zero bytes.
  • An alternative implementation choice that is often used in smart contracts is to use a hash-based look-up key, instead of a chain of mappings. See e.g., https://github.com/nucypher/nucypher-contracts/blob/main/contracts/contracts/coordination/GlobalAllowList.sol#L38-L44
  • If you prefer to keep the mapping chain, Solidity supports naming the keys and values in the mapping definition, so it'd be something like: mapping(uint32 ritualId => mapping(address stakingProvider => mapping(InfractionType => bool))) public infractions. This is just a readability improvement.

Copy link
Member

@derekpierre derekpierre Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how this data structure is formed has implications on how cost-effective and code-efficient looking up infractions is later.

This is a really interesting consideration.

I don't have clear thoughts on this at the moment, but is it more likely that infractions would be looked up/checked via staking provider address instead of by ritual id? This would be from a dashboard or ...(?).

For example, would we want to know all infractions for a specific staker address as opposed to all infractions from a failed ritual id? Even in the latter case (all infractions from failed ritual id), it is easy to get the list of all staking provider addresses for a ritual id from the coordinator (which this contract also has a reference to), and then check infractions for each staking provider address.

So, keying by staking provider address instead of ritual id could be better.

Comment on lines 56 to 58
infractions[ritualId][stakingProviders[i]][
InfractionType.MISSING_TRANSCRIPT
] = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my above comment - it's worth considering an alternate structure here so that it's easier to lookup all infractions pertaining to a single node. Without any real world usage data, it's hard to know exactly what types of on-chain queries we will need to handle penalties later. Based on prior discussions, we may need to identify multiple subsequent infractions in order to fairly enforce a downtime penalty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taco app is checking subsequent penalties, so we can put it there, otherwise structure will change to mapping and arrays and will consume more gas (not a end of the world though)

@theref theref force-pushed the infraction branch 4 times, most recently from 0687e15 to a03fc2c Compare August 9, 2024 14:22
theref and others added 25 commits August 20, 2024 13:41
Co-authored-by: Derek Pierre <[email protected]>
Co-authored-by: Derek Pierre <[email protected]>
- Move enum
- get tacoChildApplication from Coordinator
- infractions -> infractionsForRitual and value bool -> int256
- tests readability
- replace `if` with `require`
@cygnusv cygnusv merged commit 2211cd3 into nucypher:infractions Aug 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants