Skip to content

Commit

Permalink
QGB nits + docs for the merge 2 (#753)
Browse files Browse the repository at this point in the history
Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
rach-id and rootulp committed Sep 21, 2022
1 parent 69c8d28 commit d94943d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion docs/architecture/ADR-002-QGB-ValSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ significantPowerDiff := false
If the previous valset is not null, then we had a previous set of validators defining a certain power.
We check if the current valset power is significantly different from the previous one. If so, we set the `significantPowerDiff` to true.

The significance of power difference is calculated using a pre-defined constant. Currently, it is `0.05`.
The significance of power difference is calculated using a pre-defined constant. Currently, it is defined as:

```go
// SignificantPowerDifferenceThreshold the threshold of change in the validator set power
// that would need the creation of a new valset request.
const SignificantPowerDifferenceThreshold = 0.05
```

For more information on the normalization of power, check [here](https://github.com/celestiaorg/celestia-app/blob/df46d122da5f1fab1bd99bfb2bfcf9002f5bc154/x/qgb/types/validator.go#L101
).

Expand Down
2 changes: 1 addition & 1 deletion proto/qgb/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ service Query {
option (google.api.http).get = "/qgb/params";
}

// attestations' requests queries
// queries for attestations requests waiting to be signed by an orchestrator

// AttestationRequestByNonce queries attestation request by nonce.
// Returns nil if not found.
Expand Down
6 changes: 5 additions & 1 deletion x/qgb/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// SignificantPowerDifferenceThreshold the threshold of change in the validator set power
// that would need the creation of a new valset request.
const SignificantPowerDifferenceThreshold = 0.05

// EndBlocker is called at the end of every block.
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
handleDataCommitmentRequest(ctx, k)
Expand Down Expand Up @@ -64,7 +68,7 @@ func handleValsetRequest(ctx sdk.Context, k keeper.Keeper) {
panic(sdkerrors.Wrap(err, "invalid latest valset members"))
}

significantPowerDiff = intCurrMembers.PowerDiff(*intLatestMembers) > 0.05
significantPowerDiff = intCurrMembers.PowerDiff(*intLatestMembers) > SignificantPowerDifferenceThreshold
}

if (latestValset == nil) || (lastUnbondingHeight == uint64(ctx.BlockHeight())) || significantPowerDiff {
Expand Down
3 changes: 3 additions & 0 deletions x/qgb/keeper/keeper_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (k Keeper) StoreAttestation(ctx sdk.Context, at types.AttestationRequestI)
// SetLatestAttestationNonce sets the latest attestation request nonce, since it's
// expected that this value will only increase by one and it panics otherwise.
func (k Keeper) SetLatestAttestationNonce(ctx sdk.Context, nonce uint64) {
// in case the latest attestation nonce doesn't exist,
// we proceed to initialize it in the store.
// however, if it already exists, we check if the nonce is correctly incremented.
if k.CheckLatestAttestationNonce(ctx) && k.GetLatestAttestationNonce(ctx)+1 != nonce {
panic("not incrementing latest attestation nonce correctly")
}
Expand Down
2 changes: 1 addition & 1 deletion x/qgb/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
)

const (
// ValsetRequestKey indexes valset requests by nonce
// AttestationRequestKey indexes attestation requests by nonce
AttestationRequestKey = "AttestationRequestKey"

// LastUnBondingBlockHeight indexes the last validator unbonding block height
Expand Down

0 comments on commit d94943d

Please sign in to comment.