Skip to content

Commit

Permalink
fix(network): Connection should have negotiated remoteAddress and loc…
Browse files Browse the repository at this point in the history
…alAddress

- refs #9064
  • Loading branch information
0xpatrickdev committed Apr 3, 2024
1 parent 87eb568 commit 2184ea3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
22 changes: 17 additions & 5 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,21 @@ const prepareBinder = (zone, powers) => {
},
},
binderOutboundConnectWatcher: {
onFulfilled({ handler: rchandler }, watchContext) {
const { lastFailure, remoteAddr, localAddr, lchandler, port } =
watchContext;
onFulfilled(
{
handler: rchandler,
remoteAddress: negotiatedRemoteAddress,
localAddress: negotiatedLocalAddress,
},
watchContext,
) {
const {
lastFailure,
lchandler,
localAddr: requestedLocalAddress,
remoteAddr: requestedRemoteAddress,
port,
} = watchContext;

const { currentConnections } = this.state;

Expand All @@ -979,11 +991,11 @@ const prepareBinder = (zone, powers) => {
/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>} */ (
lchandler
),
localAddr,
negotiatedLocalAddress || requestedLocalAddress,
/** @type {import('@agoric/vow').Remote<Required<ConnectionHandler>>} */ (
rchandler
),
remoteAddr,
negotiatedRemoteAddress || requestedRemoteAddress,
makeConnection,
current,
)[0];
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/ibc.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export const prepareIBCProtocol = (zone, powers) => {
// Finish the outbound connection.
const ibcHops = rHops.map(hop => `/ibc-hop/${hop}`).join('/');
const remoteAddress = `${ibcHops}/ibc-port/${rPortID}/${chanInfo.order.toLowerCase()}/${rVersion}/ibc-channel/${rChannelID}`;
const localAddress = `${localAddr}/ibc-channel/${channelID}`;
const localAddress = `${localAddr}/${chanInfo.order.toLowerCase()}/${rVersion}/ibc-channel/${channelID}`;
const rchandler = makeIBCConnectionHandler(
{
protocolUtils: util,
Expand Down
13 changes: 12 additions & 1 deletion packages/vats/test/test-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,22 @@ test('network - ibc', async t => {
portID: 'port-1',
channelID: 'channel-1',
counterparty: { port_id: 'port-98', channel_id: 'channel-22' },
counterpartyVersion: 'bar',
counterpartyVersion: 'bar-negotiated',
connectionHops: ['connection-11'],
});

const c = await when(cP);
const remoteAddress = c.getRemoteAddress();
const localAddress = c.getLocalAddress();
t.is(
remoteAddress,
'/ibc-hop/connection-11/ibc-port/port-98/unordered/bar-negotiated/ibc-channel/channel-22',
);
t.is(
localAddress,
'/ibc-port/port-1/unordered/bar-negotiated/ibc-channel/channel-1',
);

t.log('Sending Data - transfer');
const ack = E(c).send('some-transfer-message');

Expand Down

0 comments on commit 2184ea3

Please sign in to comment.