Skip to content

Commit

Permalink
feat: just ack IBC packets and close
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 1, 2020
1 parent cf2d894 commit 88257f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
41 changes: 31 additions & 10 deletions packages/cosmic-swingset/lib/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ const BEGIN_BLOCK = 'BEGIN_BLOCK';
const DELIVER_INBOUND = 'DELIVER_INBOUND';
const END_BLOCK = 'END_BLOCK';
const COMMIT_BLOCK = 'COMMIT_BLOCK';

export default function makeBlockManager({
deliverInbound,
beginBlock,
saveChainState,
saveOutsideState,
savedActions,
savedHeight,
}) {
const IBC_PACKET = 'IBC_PACKET';
const IBC_TIMEOUT = 'IBC_TIMEOUT';

export default function makeBlockManager(
{
deliverInbound,
beginBlock,
saveChainState,
saveOutsideState,
savedActions,
savedHeight,
},
sendToCosmosPort,
) {
let computedHeight = savedHeight;
let runTime = 0;
async function kernelPerformAction(action) {
Expand All @@ -37,6 +42,22 @@ export default function makeBlockManager({
);
break;

case IBC_PACKET: {
// FIXME: We just ack and disconnect.
sendToCosmosPort(action.channelPort, {
method: 'ack',
data64: Buffer.from(JSON.stringify(action)).toString('base64'),
});
sendToCosmosPort(action.channelPort, {
method: 'close',
});
break;
}

case IBC_TIMEOUT:
console.error(`FIXME: Got IBC timeout; not implemented`, action);
break;

case END_BLOCK:
return true;

Expand All @@ -53,7 +74,7 @@ export default function makeBlockManager({
let decohered;
let saveTime = 0;

async function blockManager(action) {
async function blockManager(action, sendToCosmosPort) {
if (decohered) {
throw decohered;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmic-swingset/lib/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export default async function main(progname, args, { path, env, agcc }) {

if (!blockManager) {
const fns = await launchAndInitializeSwingSet();
blockManager = makeBlockManager(fns);
const sendToCosmosPort = (port, obj) => agcc.send(port, stringify(obj));
blockManager = makeBlockManager(fns, sendToCosmosPort);
}
}

Expand Down

0 comments on commit 88257f8

Please sign in to comment.