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

feat: utilities for instantiating Babylon contracts #66

Merged
merged 7 commits into from
Dec 9, 2024

Conversation

SebastianElvis
Copy link
Member

@SebastianElvis SebastianElvis commented Dec 3, 2024

This PR provides a message MsgInstantiateBabylonContracts for instantiating all Babylon contracts. This simplifies the Cosmos integration: one can first store code of 3 contracts, and then submit this message for instantiating everything.

With this message as baseline, we can then change the handler logic to improve the instantiation flow, e.g., instantiate 3 contracts one by one in this handler, rather than allowing contracts instantiating each other. This will be done in a subsequent PR.

The PR contains the following:

  • function/message for instantiating Babylon contracts
  • CLIs for the messages
  • fuzz tests
  • e2e tests

@SebastianElvis SebastianElvis changed the title refactor: utilities for instantiating Babylon contracts feat: utilities for instantiating Babylon contracts Dec 4, 2024
@SebastianElvis SebastianElvis marked this pull request as ready for review December 4, 2024 04:41
Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Publishing these comments already, as they are generic enough.

Will continue reviewing the rest next.

@@ -17,6 +17,8 @@
- [Query](#babylonlabs.babylon.v1beta1.Query)

- [babylonlabs/babylon/v1beta1/tx.proto](#babylonlabs/babylon/v1beta1/tx.proto)
- [MsgInstantiateBabylonContracts](#babylonlabs.babylon.v1beta1.MsgInstantiateBabylonContracts)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think providing a message for instantiation is not without merit, but why not just instantiate the contracts during bootstrapping?

Since the contracts are fundamental for the SDK operation, I don't see the need to gate their instantiation through a specific protobuf endpoint.

Copy link
Member Author

Choose a reason for hiding this comment

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

why not just instantiate the contracts during bootstrapping?

I was thinking about this as well, but decided to not do this (at least for this PR):

  • This makes it mandatory to have these wasm binaries in hand when executiong babylond to start the chain. Otherwise we would need to somehow wire the wasm binaries into the babylond binary, which is not ideal.
  • It's possible that one wants to invoke MsgInstantiateBabylonContracts after the chain has been running for a while, e.g.,
    • the chain has just passed a gov prop for integrating with Babylon;
    • the chain does not want the old babylon contracts anymore, and wants to deploy a new set of babylon contracts, e.g., due to corrupted DB state
  • Even if we want to instantiate all contracts upon starting the chain, this could be done in a separate PR. This separate PR basically executes the same logic of MsgInstantiateBabylonContracts handler upon starting the chain. Other things are not affected.

Wdyt?

Copy link
Contributor

@maurolacy maurolacy Dec 9, 2024

Choose a reason for hiding this comment

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

OK. But please notice that regarding

This makes it mandatory to have these wasm binaries in hand when executiong babylond to start the chain.

these contracts are on the Consumer side, and so, they are not mandatory for Babylon.

Moreover, there's a way to embed the contracts inside the binary, which makes it pretty much stand-alone. See

https://github.com/confio/tgrade/blob/1bc8463f3760bf9549389a02a9e48eda482a59fe/x/poe/bootstrap.go#L19-L40

for reference / as an example.

proto/babylonlabs/babylon/v1beta1/tx.proto Show resolved Hide resolved
proto/babylonlabs/babylon/v1beta1/tx.proto Show resolved Hide resolved
Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Looks good, but I have some concerns with the overall architecture.

This also seems to be in conflict with the changes in (draft) babylonlabs-io/babylon-contract#94.

Let's discuss offline.

}
if len(config.BTCFinality) == 0 {
return "", "", "", errorsmod.Wrap(types.ErrInvalid, "failed to instantiate BTC finality contract")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand it, you're still delegating the instantiation of the staking and finality contracts to the babylon contract here.

I would very much "flatten" this. Making this function to instantiate all the contracts explicitly, and passing their addresses along, as detailed in #45.

"btc_confirmation_depth": btcConfirmationDepth,
"checkpoint_finalization_timeout": checkpointFinalizationTimeout,
"notify_cosmos_zone": notifyCosmosZone,
"btc_staking_code_id": btcStakingCodeId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing the code ids and relying on the internal instantiation logic, let's just flatten this for the SDK to instantiate everything explicitly.

WDYT? Let's discuss offline in any case.

Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

LGTM.

After offline discussions, we agreed that flattening of instantiation will be done in a follow-up PR. Will create the issue and reference it here.

Update: #67.

@SebastianElvis SebastianElvis merged commit b6bbc02 into main Dec 9, 2024
8 checks passed
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.

2 participants