@@ -37,22 +37,24 @@ func (im IBCModule) OnChanOpenInit(
37
37
counterparty channeltypes.Counterparty ,
38
38
version string ,
39
39
) error {
40
- mwVersion , appVersion := channeltypes .SplitChannelVersion (version )
41
- // Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
42
- // lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
43
- // application.
44
- // If an invalid fee version was passed, we expect the underlying application to fail on its version negotiation.
45
- if mwVersion == types .Version {
46
- im .keeper .SetFeeEnabled (ctx , portID , channelID )
47
- } else {
48
- // middleware version is not the expected version for this midddleware. Pass the full version string along,
49
- // if it not valid version for any other lower middleware, an error will be returned by base application.
50
- appVersion = version
40
+ var versionMetadata types.Metadata
41
+ if err := types .ModuleCdc .UnmarshalJSON ([]byte (version ), & versionMetadata ); err != nil {
42
+ // Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
43
+ // lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
44
+ // application.
45
+ return im .app .OnChanOpenInit (ctx , order , connectionHops , portID , channelID ,
46
+ chanCap , counterparty , version )
51
47
}
52
48
49
+ if versionMetadata .FeeVersion != types .Version {
50
+ return sdkerrors .Wrapf (types .ErrInvalidVersion , "expected %s, got %s" , types .Version , versionMetadata .FeeVersion )
51
+ }
52
+
53
+ im .keeper .SetFeeEnabled (ctx , portID , channelID )
54
+
53
55
// call underlying app's OnChanOpenInit callback with the appVersion
54
56
return im .app .OnChanOpenInit (ctx , order , connectionHops , portID , channelID ,
55
- chanCap , counterparty , appVersion )
57
+ chanCap , counterparty , versionMetadata . AppVersion )
56
58
}
57
59
58
60
// OnChanOpenTry implements the IBCModule interface
@@ -68,31 +70,34 @@ func (im IBCModule) OnChanOpenTry(
68
70
counterparty channeltypes.Counterparty ,
69
71
counterpartyVersion string ,
70
72
) (string , error ) {
71
- cpMwVersion , cpAppVersion := channeltypes .SplitChannelVersion (counterpartyVersion )
73
+ var versionMetadata types.Metadata
74
+ if err := types .ModuleCdc .UnmarshalJSON ([]byte (counterpartyVersion ), & versionMetadata ); err != nil {
75
+ // Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
76
+ // lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
77
+ // application.
78
+ return im .app .OnChanOpenTry (ctx , order , connectionHops , portID , channelID , chanCap , counterparty , counterpartyVersion )
79
+ }
72
80
73
- // Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
74
- // lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
75
- // application.
76
- // If an invalid fee version was passed, we expect the underlying application to fail on its version negotiation.
77
- if cpMwVersion == types .Version {
78
- im .keeper .SetFeeEnabled (ctx , portID , channelID )
79
- } else {
80
- // middleware versions are not the expected version for this midddleware. Pass the full version strings along,
81
- // if it not valid version for any other lower middleware, an error will be returned by base application.
82
- cpAppVersion = counterpartyVersion
81
+ if versionMetadata .FeeVersion != types .Version {
82
+ return "" , sdkerrors .Wrapf (types .ErrInvalidVersion , "expected %s, got %s" , types .Version , versionMetadata .FeeVersion )
83
83
}
84
84
85
+ im .keeper .SetFeeEnabled (ctx , portID , channelID )
86
+
85
87
// call underlying app's OnChanOpenTry callback with the app versions
86
- appVersion , err := im .app .OnChanOpenTry (ctx , order , connectionHops , portID , channelID , chanCap , counterparty , cpAppVersion )
88
+ appVersion , err := im .app .OnChanOpenTry (ctx , order , connectionHops , portID , channelID , chanCap , counterparty , versionMetadata . AppVersion )
87
89
if err != nil {
88
90
return "" , err
89
91
}
90
92
91
- if ! im .keeper .IsFeeEnabled (ctx , portID , channelID ) {
92
- return appVersion , nil
93
+ versionMetadata .AppVersion = appVersion
94
+
95
+ versionBytes , err := types .ModuleCdc .MarshalJSON (& versionMetadata )
96
+ if err != nil {
97
+ return "" , err
93
98
}
94
99
95
- return channeltypes . MergeChannelVersions ( types . Version , appVersion ), nil
100
+ return string ( versionBytes ), nil
96
101
}
97
102
98
103
// OnChanOpenAck implements the IBCModule interface
@@ -104,17 +109,22 @@ func (im IBCModule) OnChanOpenAck(
104
109
) error {
105
110
// If handshake was initialized with fee enabled it must complete with fee enabled.
106
111
// If handshake was initialized with fee disabled it must complete with fee disabled.
107
- cpAppVersion := counterpartyVersion
108
112
if im .keeper .IsFeeEnabled (ctx , portID , channelID ) {
109
- var cpFeeVersion string
110
- cpFeeVersion , cpAppVersion = channeltypes .SplitChannelVersion (counterpartyVersion )
113
+ var versionMetadata types.Metadata
114
+ if err := types .ModuleCdc .UnmarshalJSON ([]byte (counterpartyVersion ), & versionMetadata ); err != nil {
115
+ return sdkerrors .Wrap (types .ErrInvalidVersion , "failed to unmarshal ICS29 counterparty version metadata" )
116
+ }
111
117
112
- if cpFeeVersion != types .Version {
113
- return sdkerrors .Wrapf (types .ErrInvalidVersion , "expected counterparty version: %s, got: %s" , types .Version , cpFeeVersion )
118
+ if versionMetadata . FeeVersion != types .Version {
119
+ return sdkerrors .Wrapf (types .ErrInvalidVersion , "expected counterparty version: %s, got: %s" , types .Version , versionMetadata . FeeVersion )
114
120
}
121
+
122
+ // call underlying app's OnChanOpenAck callback with the counterparty app version.
123
+ return im .app .OnChanOpenAck (ctx , portID , channelID , versionMetadata .AppVersion )
115
124
}
125
+
116
126
// call underlying app's OnChanOpenAck callback with the counterparty app version.
117
- return im .app .OnChanOpenAck (ctx , portID , channelID , cpAppVersion )
127
+ return im .app .OnChanOpenAck (ctx , portID , channelID , counterpartyVersion )
118
128
}
119
129
120
130
// OnChanOpenConfirm implements the IBCModule interface
0 commit comments