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

CIP-21 Governable "lookbackWindow" parameter #1136

Merged
merged 16 commits into from
Jan 20, 2021

Conversation

andres-dg
Copy link
Contributor

@andres-dg andres-dg commented Aug 13, 2020

Description

Modifies celo-blockchain to obtain lookbackWindow parameter from the BlockchainParameters smart contract. It assumes the smart contract will return the same value during an epoch.

lookbackWindow is used on 3 places:

  1. For metrics; where the parent block signatures are analyzed.
  2. For every block on Blockchain we obtain the loobackWindow asses the "upness" of each validator on that block
  3. On the last block of the epoch, to compute the uptime score

Other changes

Tested

Added unit tests.

Related issues

Backwards compatibility

Hardfork Change. Part of Donut Hardfork

@andres-dg andres-dg marked this pull request as draft August 13, 2020 22:32
@andres-dg andres-dg changed the title Configurable Loopback Window Governable Loopback Window Sep 28, 2020
@andres-dg andres-dg changed the title Governable Loopback Window Governable Lookback Window Sep 29, 2020
mcortesi
mcortesi previously approved these changes Oct 21, 2020
@mcortesi mcortesi changed the title Governable Lookback Window Make lookbackWindow Governable Dec 15, 2020
@mcortesi mcortesi changed the title Make lookbackWindow Governable CIP-21 Governable "lookbackWindow" parameter Jan 6, 2021
@mcortesi mcortesi force-pushed the andres-dg/loopbackwindow-refactor branch from 30237db to 3b341ce Compare January 7, 2021 17:23
@mcortesi mcortesi force-pushed the andres-dg/loopbackwindow-refactor branch 3 times, most recently from 8ea43f1 to 657191b Compare January 8, 2021 23:14
@mcortesi mcortesi requested review from mcortesi, kevjue, oneeman and prestwich and removed request for mcortesi and tkporter January 12, 2021 17:19
@mcortesi mcortesi force-pushed the andres-dg/loopbackwindow-refactor branch from 657191b to adfa925 Compare January 12, 2021 17:21
@mcortesi mcortesi marked this pull request as ready for review January 12, 2021 19:55
@mcortesi mcortesi dismissed their stale review January 12, 2021 22:02

i'm the author now

@mcortesi mcortesi force-pushed the andres-dg/loopbackwindow-refactor branch from 3fcaef2 to cc1f94b Compare January 19, 2021 20:04
value, err := getLookbackWindow()
if err != nil {
value = MinSafeLookbackWindow
if !isDonut {
Copy link
Contributor

Choose a reason for hiding this comment

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

I usually prefer to flip the then/else to have if isDonut { instead, except when there is a reason not to. Having the shorter block first is nice, but not necessarily worth it.

if !isDonut {
return defaultLookbackWindow
}
var returnValue uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

Why returnValue rather than value? Also, we could put in the signature (value uint64)

}
return 0, err
}
return lookbackWindow.Uint64(), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

this will have the side effect of truncating any 256-bit value to a go uint64?

Copy link
Contributor

Choose a reason for hiding this comment

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

basically I'm double-checking that an invalid contract state won't cause a panic or something here

mcortesi and others added 16 commits January 20, 2021 14:54
These flags are actually ignored lated in the code; and generate
confussion.

Hence, this commit deprecrated them and clearle states that they are
ignored.
Governable lookback window
* Move logic to uptime model, for cohesiveness
* Move istanbul config processing to istanbul module
* Verify lookbackWindow is within safe boundaries
* Verify EpochSize is at least MinEpochSize

Nits & clean ups
# Conflicts:
#	consensus/istanbul/backend/engine.go
This commits also changes the behaviour pre-hardfork, but it it
considered safe.
@mcortesi mcortesi force-pushed the andres-dg/loopbackwindow-refactor branch from b1e37d4 to 375f565 Compare January 20, 2021 17:55
mcortesi added a commit to celo-org/celo-monorepo that referenced this pull request Jan 20, 2021
Implementation of CIP-21 smart contract changes.
celo-blockchain related PR: celo-org/celo-blockchain#1136
Adds the uptimeLookbackWindow to the BlockchainParameters contract. This is only ever used on the celo-blockchain client to determine the size of the uptime lookback window which is used to compute the validator uptimeScore

An important invariant, is that UptimeLookbackWindow must remain constant during an epoch. Thus, changes to the parameter only take effect on the next epoch. There's an exception to this rule during migration/deployment of this change; there uptimeLookbackWindow should be initialized to chain's current value for the parameter which is part of the ChainConfig on the genesis block.

To initialize the value:

On a new testnet: As part of the migrations, BlockchainParamets.initialize() will do the initialization
On an existing testnet: After upgrading the contract, first call to setLookbackWindow() will the value for the current epoch.
Since BlockchainParameters won't be reinitialized when this change is deployed, a patch was made to the getUptimteLookbackWindow() contract to return 12 (mainnet, baklava & alfajores value for lookbackWindow) in the case of the value not being initalized. This patch can be removed in the future, since it's only necessary until setLoobackWindow() is called and first epoch since deployment has passed

Co-authored-by: Mariano Cortesi <mariano@clabs.co>
@mcortesi mcortesi merged commit d14b756 into master Jan 20, 2021
@mcortesi mcortesi deleted the andres-dg/loopbackwindow-refactor branch January 20, 2021 19:52
@mcortesi mcortesi restored the andres-dg/loopbackwindow-refactor branch January 20, 2021 19:52
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.

None yet

5 participants