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

Feat/delay logout #56

Merged
merged 8 commits into from
Apr 1, 2018
Merged

Feat/delay logout #56

merged 8 commits into from
Apr 1, 2018

Conversation

djrtwo
Copy link
Contributor

@djrtwo djrtwo commented Mar 22, 2018

This PR adds dynasty_logout_delay as a parameter in the casper contract to address #51. We can now set the dynasty delay when deploying the contract rather than having to use the built in 2 dynasties.

This PR:

  • adds _dynasty_logout_delay to contract params and dynasty_logout_delay as a constant in the contract
  • adds dynasty_wei_delta map as variable to the contract as a replacement to next_dynasty_wei_delta and second_next_dynasty_wei_delta. This maps from a dynasty number to the +/- wei to change in total deposits for that dynasty number.
  • adds default_end_dynasty as a constant to the contract because we use the huge number in a conditional as well as the original assignment for a validator
  • add relevant tests
  • increase coverage of basic logout tests

Some things to note:

  • The first person to write to a mapping in dynasty_wei_delta from a 0 pays 20000 gas as opposed to subsequent writings costing 4000. This can make certain operations like logging out cost slightly different gas costs depending on if you are the first one to do something for that end_dynasty.
  • Our previous default of 2 for the logout delay can be used as the param if we happened to decide not to make it a longer delay.
  • After we use a mapping from dynasty_wei_delta to update the current dynasty deposits in increment_dynasty, we could potentially 0 this out if that helps with the state in the EVM. I'm not 100% sure if this actually frees up space. This operation occurs in increment_dynasty within initialize_epoch so it wouldn't cost any user for that write operation.

Note all tests in the corresponding pyethapp repo currently fail. The contract currently fails to deploy over there because of the additional dynasty_logout_delay parameter. I'll add a PR to fix that soon. That said, all tests pass in this local repo and the contract changes are ready for review.

@djrtwo
Copy link
Contributor Author

djrtwo commented Mar 22, 2018

@ChihChengLiang @karlfloersch @vbuterin Parameterizing logout delay is ready for review

@djrtwo djrtwo changed the title [WIP] Feat/delay logout Feat/delay logout Mar 22, 2018
Copy link
Contributor

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

Looks good to me.

self.base_penalty_factor = _base_penalty_factor
self.min_deposit_size = _min_deposit_size

# helper contracts
Copy link
Contributor

Choose a reason for hiding this comment

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

like the reorder of these variables ❤️

self.next_dynasty_wei_delta -= reward
if current_dynasty == end_dynasty - 2:
self.second_next_dynasty_wei_delta -= reward
if end_dynasty < self.default_end_dynasty:
Copy link
Contributor

Choose a reason for hiding this comment

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

This would happen in the logout, right? A comment would be nice to have here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, if the validator is in logout period. I'll make a comment!

(-1),
]
)
def test_dynasty_wei_delta_defaults(casper, dynasty):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure the purpose of this test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was a sanity check when I added the new var early in dev. Will remove

@ChihChengLiang
Copy link
Contributor

ChihChengLiang commented Mar 29, 2018

ahah... sorry this needs to upgrade to new Vyper style too.

@djrtwo
Copy link
Contributor Author

djrtwo commented Mar 29, 2018 via email

@djrtwo
Copy link
Contributor Author

djrtwo commented Mar 29, 2018 via email

@djrtwo
Copy link
Contributor Author

djrtwo commented Mar 30, 2018

@ChihChengLiang That merge was surprisingly not fun. But it's done

@djrtwo
Copy link
Contributor Author

djrtwo commented Mar 30, 2018

Also, I fixed #67 here.

@djrtwo djrtwo requested a review from vbuterin March 30, 2018 03:17
@ChihChengLiang
Copy link
Contributor

ChihChengLiang commented Mar 30, 2018

That merge was surprisingly not fun. But it's done

I'm so sorry for that merge. will wait longer after the review.

@djrtwo djrtwo merged commit ccd2936 into ethereum:master Apr 1, 2018
@djrtwo djrtwo deleted the feat/delay-logout branch April 1, 2018 02:51
This was referenced Apr 1, 2018
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.

2 participants