diff --git a/docs/architecture/ADR-002-QGB-ValSet.md b/docs/architecture/ADR-002-QGB-ValSet.md index 453bb3b49b..b7a7b9f29a 100644 --- a/docs/architecture/ADR-002-QGB-ValSet.md +++ b/docs/architecture/ADR-002-QGB-ValSet.md @@ -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 ). diff --git a/proto/qgb/query.proto b/proto/qgb/query.proto index f6bdecb914..b5e3b8da15 100644 --- a/proto/qgb/query.proto +++ b/proto/qgb/query.proto @@ -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. diff --git a/x/qgb/abci.go b/x/qgb/abci.go index fab07093b2..6c8a190c20 100644 --- a/x/qgb/abci.go +++ b/x/qgb/abci.go @@ -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) @@ -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 { diff --git a/x/qgb/keeper/keeper_attestation.go b/x/qgb/keeper/keeper_attestation.go index bcf5f2723a..2ca2e49a83 100644 --- a/x/qgb/keeper/keeper_attestation.go +++ b/x/qgb/keeper/keeper_attestation.go @@ -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") } diff --git a/x/qgb/types/keys.go b/x/qgb/types/keys.go index a61f5a71e9..d6397778c4 100644 --- a/x/qgb/types/keys.go +++ b/x/qgb/types/keys.go @@ -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