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

Eureka port binding #2123

Open
wants to merge 8 commits into
base: feat/ibc_eureka
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased](https://github.com/CosmWasm/wasmd/tree/HEAD)

Bind eureka port and store it in ContractInfo [\#2122](https://github.com/CosmWasm/wasmd/pull/2122)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.54.0...HEAD)

## [v0.54.0](https://github.com/CosmWasm/wasmd/tree/v0.54.0) (2025-01-08)
Expand Down
1 change: 1 addition & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ ContractInfo stores a WASM contract instance
| `label` | [string](#string) | | Label is optional metadata to be stored with a contract instance. |
| `created` | [AbsoluteTxPosition](#cosmwasm.wasm.v1.AbsoluteTxPosition) | | Created Tx position when the contract was instantiated. |
| `ibc_port_id` | [string](#string) | | |
| `eureka_port_id` | [string](#string) | | |
| `extension` | [google.protobuf.Any](#google.protobuf.Any) | | Extension is an extension point to store custom metadata within the persistence model. |


Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
go 1.23.1

require (
github.com/CosmWasm/wasmvm/v2 v2.2.1
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250212100917-aea2a1cdd849
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.11
github.com/cosmos/gogogateway v1.2.0 // indirect
Expand Down Expand Up @@ -221,13 +221,13 @@ require (

replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/CosmWasm/wasmvm/v2 => github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250212100917-aea2a1cdd849
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// See: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// See: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1

// pin version! 126854af5e6d has issues with the store so that queries fail
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CosmWasm/wasmvm/v2 v2.2.1 h1:cmOnM+TDfUl2VRugeo1eJBw4U/Lw0WLviuQHKSo9DVQ=
github.com/CosmWasm/wasmvm/v2 v2.2.1/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250212100917-aea2a1cdd849 h1:cMULScnfrGMd3W3k15i/8KKgDmz5TuEU9L+w76f+pH8=
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250212100917-aea2a1cdd849/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
3 changes: 2 additions & 1 deletion proto/cosmwasm/wasm/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ message ContractInfo {
// Created Tx position when the contract was instantiated.
AbsoluteTxPosition created = 5;
string ibc_port_id = 6 [ (gogoproto.customname) = "IBCPortID" ];
string eureka_port_id = 7 [ (gogoproto.customname) = "EurekaPortID" ];

// Extension is an extension point to store custom metadata within the
// persistence model.
google.protobuf.Any extension = 7
google.protobuf.Any extension = 8
[ (cosmos_proto.accepts_interface) =
"cosmwasm.wasm.v1.ContractInfoExtension" ];
}
Expand Down
30 changes: 30 additions & 0 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type Keeper struct {
// propagate gov authZ to sub-messages
propagateGovAuthorization map[types.AuthorizationPolicyAction]struct{}

// Binds port for Eureka
customBindEurekaPort func(ctx sdk.Context, contractAddr sdk.AccAddress) (string, error)

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
Expand Down Expand Up @@ -376,6 +379,15 @@ func (k Keeper) instantiate(
}
contractInfo.IBCPortID = ibcPort
}
// Should we bind the port in some special way for Eureka?
if report.HasEurekaEntryPoints {
// register Eureka port
eurekaPort, err := k.bindEurekaPort(sdkCtx, contractAddress)
if err != nil {
return nil, nil, err
}
contractInfo.EurekaPortID = eurekaPort
}

// store contract before dispatch so that contract could be called back
historyEntry := contractInfo.InitialHistory(initMsg)
Expand Down Expand Up @@ -409,6 +421,14 @@ func (k Keeper) instantiate(
return contractAddress, data, nil
}

func (k Keeper) bindEurekaPort(sdkCtx sdk.Context, contractAddress sdk.AccAddress) (string, error) {
if k.customBindEurekaPort != nil {
return k.customBindEurekaPort(sdkCtx, contractAddress)
} else {
return k.ensureIbcPort(sdkCtx, contractAddress)
}
}

// Execute executes the contract instance
func (k Keeper) execute(ctx context.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) {
defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "execute")
Expand Down Expand Up @@ -544,6 +564,16 @@ func (k Keeper) migrate(
}
k.mustStoreContractInfo(ctx, contractAddress, contractInfo)

// Should we bind the port in some special way for Eureka?
Copy link
Collaborator

Choose a reason for hiding this comment

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

My understanding is that we need to call this. And I guess also need to make sure that this is called for all registered ports every time the chain starts? So, we might have to keep track of contract ports in storage unless there already is such a mechanism in ibc-go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess this would work providing we would got the list of contracts.
Let's discuss it offline.

Copy link
Contributor

Choose a reason for hiding this comment

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

We discovered yesterday, that the port binding is not supported anymore in ibc-go

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's a difference here between IBC v1 and Eureka. In v1, we don't need to do port binding anymore because ibc-go detects the "wasm" prefix and routes it to us based on that, but I don't know if the same works for Eureka.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it seems that in Eureka we have to use this method: https://github.com/cosmos/ibc-go/blob/3e6d5f597fc498a949011ca1d9e835ef6c163813/modules/core/api/router.go#L24. We have to change our approach a little bit, because so far wasmd added routes in a NewWasmApp method. With Eureka we have to bind a contract address with a new Eureka IBCModule. I started implementation of this module here: #2124

if report.HasEurekaEntryPoints && contractInfo.EurekaPortID != "" {
// register Eureka port
eurekaPort, err := k.bindEurekaPort(sdkCtx, contractAddress)
if err != nil {
return nil, err
}
contractInfo.EurekaPortID = eurekaPort
}

sdkCtx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeMigrate,
sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(newCodeID, 10)),
Expand Down
11 changes: 6 additions & 5 deletions x/wasm/keeper/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,12 @@ func WasmQuerier(k wasmQueryKeeper) func(ctx sdk.Context, request *wasmvmtypes.W
Wrapf("address %s", contractAddr)
}
res := wasmvmtypes.ContractInfoResponse{
CodeID: info.CodeID,
Creator: info.Creator,
Admin: info.Admin,
Pinned: k.IsPinnedCode(ctx, info.CodeID),
IBCPort: info.IBCPortID,
CodeID: info.CodeID,
Creator: info.Creator,
Admin: info.Admin,
Pinned: k.IsPinnedCode(ctx, info.CodeID),
IBCPort: info.IBCPortID,
EurekaPort: info.EurekaPortID,
}
return json.Marshal(res)
case request.CodeInfo != nil:
Expand Down
Loading
Loading