livepeer / protocol

Livepeer protocol
MIT License
154 stars 45 forks source link

bonding: Implement active stake checkpointing #614

Closed victorges closed 1 year ago

victorges commented 1 year ago

What does this pull request do? Explain your changes. (required) This is to introduce a checkpointing logic in bonding manager so that we can lookup historical information about any point in time. We need this in order to support an on-chain governance system with support for OpenZeppelin Governor abstractions. That is why it also implements the IERC5808 interface to plug into OZ Governor framework.

It is implemented as "external" to BondingManager as possible in a separate BondingVotes contract, but there were a couple places where BondingManager needed changes to start checkpointing its state.

Specific updates (required)

How did you test each of these updates (required)

Does this pull request close any open issues? Implements PRO-28

Checklist:

victorges commented 1 year ago

@yondonfu @0xcadams Ok I think NOW this one is ready to go! :)

victorges commented 1 year ago

Ran the gas report on confluence branch (current) compared to this (checkpoints). Here are the reports, it seems to have increased around 200k gas on the bond/unbond functions due to the checkpoints that have been made. The checkpoint initialization itself also costs around 170k gas, which should still be relatively cheap on Arbitrum, but I haven't found a way to reliably calculate how it would cost considering the calldata cost on L1.

gas-report-checkpoints.txt gas-report-current.txt

victorges commented 1 year ago

OK @yondonfu @0xcadams I've addressed the feedback on your comments and this is ready for another review round. I have included some other changes as well that seemed necessary after the rounds of testing with the testnet and some discussions.

I recommend reviewing commit by commit, I avoided making a force push here not to lose history, and also isolated the less trivial changes in their own commits. As an overview of each: