-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: merge base branch to main #402
base: main
Are you sure you want to change the base?
Conversation
* Add chain register struct * Add chain registry * Add chain registry test * Add chain registry queries * Add chain registry queries tests * Add register chain msg * Add register chain msg routing / impl * Update proto/babylon/zoneconcierge/v1/tx.proto * Flatten chain register proto * Remove authority from register chain msg * Add chain not registered check * Add chain already registered check * Update / fix comment * Add registry related queries to rpc server * Fix indentation * Fix: Add signer field to register chain msg * Fix: Own / unique query param / response for list registry
* Move btcstkconsumer proto files under v1/ for consistency * Move register chain protos from zoneconcierge to btcstkconsumer * Refactor chain registry into btcstkconsumer * Fix: proto / code lints * Pass chain register pointer Co-authored-by: Runchao Han <[email protected]>
* Register zoneconcierge msg codecs * Register btcstkconsumer msg codecs
* Add chain id to finality provider * Add finality provider registry * Update fps per chain id registry * Remove commented line * FP registers only non-canonical chains * Add FP registry test * Add registered chain check * Add registration check to fp registry test * Remove optional from chain id * Add own CZ chains FPs store * Store CZ chains FPs in their own store * Adjust names / tests * Refactor fp consumer registry * Adapt tests * Rename for clarity * Add FP CZ chains registry queries * Add FP consumer query tests * Adapt test * Add chain id to fp query response * Remove useless slash condition check * Improve error msg * Move type builder to types package
* Add chains per FP BTC PubKey store * Ensure CZ chains FP does not already exist * Fix: Return err explicitly instead of nil
* Fix typos * Add register chain cli tx * Add chain id to btcstaking create-finality-provider * Add get finality provider by chain queries * Add registered chains cli queries * Add FZ FP chain id query type * Add get CZ FP chain getter / query * Add grpc query. Adjust grpc query paths * Add CZ FP registered chain cli query cmd * Fix: Add tx flags for register chain cmd * Turn consumer chain id into a flag instead of a param * Fix params module import * Add hook to query consumer fps through btcstaking
* Rename consumer keys for clarity * Rename btc staking consumer methods * Rename consumer delegation private methods * Move consumer delegations to btcstaking * Refactor BTC delegations into one store * Simplify logic * Improve comments
* Add needed (for babylon as Consumer) staking capability * Upgrade contracts from latest babylon-contract * Support Mac arm64 arch in passing for copy local wasm * Fix: FP fields protobuf sequence numbers * Update contracts to latest * Fix: make proto-gen * Trim unused fields from new finality provider IBC msg * Update protobuf gens * Update code refs
@@ -295,6 +294,13 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre | |||
if err := ms.AddBTCDelegation(ctx, newBTCDel); err != nil { |
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.
Here we are adding the BTC delegation normally as it is the same for BTC delegations to Babylon vs Consumers, that means for both cases events EventBTCDelegationStateUpdate
are being added and later processed in ProcessAllPowerDistUpdateEvents
-
func (k Keeper) ProcessAllPowerDistUpdateEvents( |
Since rewards of consumer chains will not be handled by the Babylon chain we should handle and do not store the changes of those finality providers in the incentive store (do not call processRewardTracker
k.processRewardTracker(ctx, fpByBtcPkHex, btcDel, func(fp, del sdk.AccAddress, sats uint64) { |
if !exists { | ||
// If not in map, check if it's a Babylon FP or get its consumer | ||
if _, err := k.GetFinalityProvider(ctx, delegationFPBTCPK); err == nil { | ||
continue // It's a Babylon FP, skip |
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.
we already know if the finality provider fpBTCPK
is from the Babylon when querying HasFinalityProvider
It would reduce one read by FP in the list, can be addressed in a future task
fp, err := k.GetFinalityProvider(ctx, key) | ||
if err != nil { | ||
// Try in the btcstkconsumer module | ||
if k.BscKeeper.HasConsumerFinalityProvider(ctx, fpPK) { |
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.
if we are going to have 2 different stores with FPs we should return the same structure/interface and have a function to query a FP by their fpPK to avoid handling in the error case
@@ -27,4 +27,6 @@ var ( | |||
PowerDistUpdateKey = []byte{0x08} // key prefix for power distribution update events | |||
AllowedStakingTxHashesKey = collections.NewPrefix(9) // key prefix for allowed staking tx hashes | |||
HeightToVersionMapKey = []byte{0x10} // key prefix for height to version map | |||
BTCConsumerDelegatorKey = []byte{0x11} // key prefix for the Consumer BTC delegators | |||
BTCStakingEventKey = []byte{0x12} // key prefix for the BTC staking events |
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.
could we put this inside the x/btcstkconsumer
? @gusin13
|
||
// DefaultGenesis returns the default genesis state | ||
func DefaultGenesis() *GenesisState { | ||
return &GenesisState{ |
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.
We have a lot of keys
var (
PortKey = []byte{0x11} // PortKey defines the key to store the port ID in store
ChainInfoKey = []byte{0x12} // ChainInfoKey defines the key to store the chain info for each CZ in store
CanonicalChainKey = []byte{0x13} // CanonicalChainKey defines the key to store the canonical chain for each CZ in store
ForkKey = []byte{0x14} // ForkKey defines the key to store the forks for each CZ in store
EpochChainInfoKey = []byte{0x15} // EpochChainInfoKey defines the key to store each epoch's latests chain info for each CZ in store
LastSentBTCSegmentKey = []byte{0x16} // LastSentBTCSegmentKey is key holding last btc light client segment sent to other cosmos zones
ParamsKey = []byte{0x17} // key prefix for the parameters
SealedEpochProofKey = []byte{0x18} // key prefix for proof of sealed epochs
)
Every data that needs to be know in case of a chain failure should be inside the GenesisState
, a few of our modules don't have that, but still we should take note and create issues
Args: cobra.RangeArgs(2, 3), | ||
Short: "Registers a CZ consumer", | ||
Long: strings.TrimSpace( | ||
`Registers a CZ consumer.`, |
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.
long is the same as short
} | ||
|
||
// ExportGenesis returns the module's exported genesis. | ||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { |
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.
Same, genesis state should have every data needed to relaunch the chain in case of failure
} | ||
|
||
// IterateFPs iterates over all finality providers for a given chain | ||
func (k Keeper) IterateFPs(ctx context.Context, chainId string, handler func(fp *btcstaking.FinalityProvider) bool) { |
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.
also not used
"github.com/babylonlabs-io/babylon/x/btcstkconsumer/types" | ||
) | ||
|
||
var _ types.QueryServer = Keeper{} |
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.
we already have this in grpc_query
File could be removed
if len(m.ConsumerName) == 0 { | ||
return fmt.Errorf("ConsumerName must be non-empty") | ||
} | ||
if len(m.ConsumerDescription) == 0 { |
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.
why do we allow not specify the description in CLI?
babylon/x/btcstkconsumer/client/cli/tx.go
Line 56 in ce31233
description := "" |
var ( | ||
ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") | ||
ErrConsumerNotRegistered = sdkerrors.Register(ModuleName, 1101, "consumer not registered") | ||
ErrInvalidConsumerRegister = sdkerrors.Register(ModuleName, 1102, "invalid consumer register") |
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.
not used
type AccountKeeper interface { | ||
GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation | ||
// Methods imported from account should be defined here | ||
} | ||
|
||
// BankKeeper defines the expected interface for the Bank module. | ||
type BankKeeper interface { | ||
SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins | ||
// Methods imported from bank should be defined here | ||
} |
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.
not used
accountKeeper types.AccountKeeper | ||
bankKeeper types.BankKeeper | ||
clientKeeper types.ClientKeeper | ||
wasmKeeper types.WasmKeeper |
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.
not being used
accountKeeper types.AccountKeeper | |
bankKeeper types.BankKeeper | |
clientKeeper types.ClientKeeper | |
wasmKeeper types.WasmKeeper | |
clientKeeper types.ClientKeeper | |
wasmKeeper types.WasmKeeper |
package types | ||
|
||
// DefaultIndex is the default global index | ||
const DefaultIndex uint64 = 1 |
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.
remove?
StoreKey = ModuleName | ||
|
||
// MemStoreKey defines the in-memory store key | ||
MemStoreKey = "mem_btcstkconsumer" |
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.
not being used
func KeyPrefix(p string) []byte { | ||
return []byte(p) | ||
} |
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.
not being used
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.
delete?
|
||
func NewUnjailFinalityProviderCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "unjail-finality-provider [fp_btc_pk]", |
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.
why remove it? do we not have the unjail option @gitferry
- **Phase 1 integration:** Babylon receives PoS blockchain headers via standard | ||
`MsgUpdateClient` messages in IBC light client protocol, timestamps them, and | ||
functions as a canonical chain oracle for the PoS blockchain. | ||
[Babylonscan](https://babylonscan.io/) shows PoS blockchains with phase 1 | ||
integration. | ||
- **Phase 2 integration:** In addition to phase 1, phase 2 allows a PoS | ||
blockchain to receive BTC timestamps from Babylon via an IBC channel, such | ||
that the PoS blockchain can use BTC timestamps to detect and resolve forks, as | ||
well as other use cases such as Bitcoin-assisted fast unbonding. |
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.
is this still true?
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
// "github.com/cosmos/cosmos-sdk/client/flags" |
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.
can we remove this file?
|
||
// find the last finalised epoch | ||
lastFinalizedEpoch := k.GetLastFinalizedEpoch(ctx) | ||
for _, ConsumerId := range req.ConsumerIds { |
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.
Thinking if doing all of this to 100 consumers at once wouldn't it be too much?
Maybe we should only allow to query one by one
// chain info does not exist yet, initialise chain info for this chain | ||
chainInfo, err = k.InitChainInfo(ctx, indexedHeader.ConsumerId) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to initialize chain info of %s: %w", indexedHeader.ConsumerId, err)) |
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.
all the panics here only can happens due to a programming error?
} | ||
} | ||
|
||
func (d *IBCHeaderDecorator) getHeaderAndClientState(ctx sdk.Context, m sdk.Msg) (*types.HeaderInfo, *ibctmtypes.ClientState) { |
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.
can we add some documentation on this function on what it does? or maybe only to func (d *IBCHeaderDecorator) PostHandle
connectionKeeper types.ConnectionKeeper | ||
channelKeeper types.ChannelKeeper | ||
portKeeper types.PortKeeper | ||
authKeeper types.AccountKeeper |
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.
authKeeper, bankKeeper not used
accountKeeper types.AccountKeeper | ||
bankKeeper types.BankKeeper |
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.
remove unused keepers
// // TODO (Babylon): Dispatch and process packet | ||
// switch packet := modulePacketData.Packet.(type) { | ||
// default: | ||
// errMsg := fmt.Sprintf("unrecognized %s packet type: %T", types.ModuleName, packet) | ||
// return errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) | ||
// } |
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.
leftover?
switch resp := ack.Response.(type) { | ||
case *channeltypes.Acknowledgement_Result: | ||
im.keeper.Logger(ctx).Info("received an Acknowledgement message", "result", string(resp.Result)) | ||
ctx.EventManager().EmitEvent( |
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.
should we emit typed events?
The Zone Concierge module keeps handling IBC headers of PoS blockchains, and | ||
maintains the following KV stores. | ||
|
||
### Parameters |
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.
structures are out of date with the protos
This PR merges the base branch with phase-3 codebase to
main
.Comparison between base and main: https://babylonlabs.atlassian.net/wiki/spaces/BABYLON/pages/5905879