-
Notifications
You must be signed in to change notification settings - Fork 267
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
Record validator set during EndBlock
for QGB orchestrator
#232
Changes from all commits
edb33c5
d1bffe3
290722b
5b3a329
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
syntax = "proto3"; | ||
package qgb; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "qgb/types.proto"; | ||
import "qgb/msgs.proto"; | ||
|
||
option go_package = "github.com/celestiaorg/celestia-app/x/qgb/types"; | ||
|
||
// GenesisState defines the capability module's genesis state. | ||
message GenesisState {} | ||
// Params represent the Quantum Gravity Bridge genesis and store parameters. | ||
message Params { | ||
option (gogoproto.stringer) = false; | ||
|
||
uint64 data_commitment_window = 1; | ||
} | ||
|
||
// GenesisState struct, containing all persistant data required by the Gravity module | ||
message GenesisState { | ||
Params params = 1; | ||
} | ||
|
||
// GravityCounters contains the many noces and counters required to maintain the bridge state in the genesis | ||
message GravityNonces { | ||
// the nonce of the last generated validator set | ||
uint64 latest_valset_nonce = 1; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a new line here ? that's how it is in Github :D |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
syntax = "proto3"; | ||
package qgb; | ||
import "gogoproto/gogo.proto"; | ||
option go_package = "github.com/celestiaorg/celestia-app/x/qgb/types"; | ||
|
||
// BridgeValidator represents a validator's ETH address and its power | ||
message BridgeValidator { | ||
uint64 power = 1; | ||
string ethereum_address = 2; | ||
} | ||
|
||
// Valset is the Ethereum Bridge Multsig Set, each gravity validator also | ||
// maintains an ETH key to sign messages, these are used to check signatures on | ||
// ETH because of the significant gas savings | ||
message Valset { | ||
uint64 nonce = 1; | ||
repeated BridgeValidator members = 2 [(gogoproto.nullable) = false]; | ||
uint64 height = 3; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, new line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package qgb | ||
|
||
import ( | ||
"github.com/celestiaorg/celestia-app/x/qgb/keeper" | ||
"github.com/celestiaorg/celestia-app/x/qgb/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// EndBlocker is called at the end of every block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we be sending the data root of every block ? not a commitment over a set of data roots? |
||
func EndBlocker(ctx sdk.Context, k keeper.Keeper) { | ||
// get the last valsets to compare against | ||
latestValset := k.GetLatestValset(ctx) | ||
lastUnbondingHeight := k.GetLastUnBondingBlockHeight(ctx) | ||
|
||
significantPowerDiff := false | ||
if latestValset != nil { | ||
vs, err := k.GetCurrentValset(ctx) | ||
if err != nil { | ||
// this condition should only occur in the simulator | ||
// ref : https://github.com/Gravity-Bridge/Gravity-Bridge/issues/35 | ||
if err == types.ErrNoValidators { | ||
ctx.Logger().Error("no bonded validators", | ||
"cause", err.Error(), | ||
) | ||
return | ||
} | ||
panic(err) | ||
} | ||
intCurrMembers, err := types.BridgeValidators(vs.Members).ToInternal() | ||
if err != nil { | ||
panic(sdkerrors.Wrap(err, "invalid current valset members")) | ||
} | ||
intLatestMembers, err := types.BridgeValidators(latestValset.Members).ToInternal() | ||
if err != nil { | ||
panic(sdkerrors.Wrap(err, "invalid latest valset members")) | ||
} | ||
|
||
significantPowerDiff = intCurrMembers.PowerDiff(*intLatestMembers) > 0.05 | ||
} | ||
|
||
if (latestValset == nil) || (lastUnbondingHeight == uint64(ctx.BlockHeight())) || significantPowerDiff { | ||
// if the conditions are true, put in a new validator set request to be signed and submitted to Ethereum | ||
k.SetValsetRequest(ctx) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// Wrapper struct | ||
type Hooks struct { | ||
k Keeper | ||
} | ||
|
||
// Create new gravity hooks | ||
func (k Keeper) Hooks() Hooks { | ||
// if startup is mis-ordered in app.go this hook will halt | ||
// the chain when called. Keep this check to make such a mistake | ||
// obvious | ||
if k.storeKey == nil { | ||
panic("Hooks initialized before GravityKeeper!") | ||
} | ||
return Hooks{k} | ||
} | ||
|
||
func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) { | ||
|
||
// When Validator starts Unbonding, Persist the block height in the store | ||
// Later in endblocker, check if there is at least one validator who started unbonding and create a valset request. | ||
// The reason for creating valset requests in endblock is to create only one valset request per block, | ||
// if multiple validators starts unbonding at same block. | ||
|
||
// this hook IS called for jailing or unbonding triggered by users but it IS NOT called for jailing triggered | ||
// in the endblocker therefore we call the keeper function ourselves there. | ||
|
||
h.k.SetLastUnBondingBlockHeight(ctx, uint64(ctx.BlockHeight())) | ||
|
||
} | ||
|
||
func (h Hooks) BeforeDelegationCreated(_ sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { | ||
} | ||
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {} | ||
func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) {} | ||
func (h Hooks) AfterValidatorBonded(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {} | ||
|
||
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {} | ||
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) {} | ||
func (h Hooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) {} | ||
func (h Hooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { | ||
} | ||
func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, but can you format the alignment for this file, and add a newline at the end?