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: use debugName to differentiate sim-chain instances #1446

Merged
merged 2 commits into from
Aug 12, 2020
Merged
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
18 changes: 11 additions & 7 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ function makeConsole(tag) {
}
const console = makeConsole('SwingSet:controller');

// FIXME: Put this somewhere better.
process.on('unhandledRejection', e =>
console.error('UnhandledPromiseRejectionWarning:', e),
);

const ADMIN_DEVICE_PATH = require.resolve('./kernel/vatAdmin/vatAdmin-src');
const ADMIN_VAT_PATH = require.resolve('./kernel/vatAdmin/vatAdminWrapper');
const KERNEL_SOURCE_PATH = require.resolve('./kernel/kernel.js');
Expand Down Expand Up @@ -135,10 +130,19 @@ export async function buildVatController(
argv = [],
runtimeOptions = {},
) {
const { debugPrefix = '' } = runtimeOptions;
if (typeof Compartment === 'undefined') {
throw Error('SES must be installed before calling buildVatController');
}

// eslint-disable-next-line no-shadow
const console = makeConsole(`${debugPrefix}SwingSet:controller`);

// FIXME: Put this somewhere better.
process.on('unhandledRejection', e =>
console.error('UnhandledPromiseRejectionWarning:', e),
);

// https://github.com/Agoric/SES-shim/issues/292
harden(Object.getPrototypeOf(console));
harden(console);
Expand Down Expand Up @@ -168,7 +172,7 @@ export async function buildVatController(
const kernelNS = await importBundle(kernelSource, {
filePrefix: 'kernel',
endowments: {
console: makeConsole('SwingSet:kernel'),
console: makeConsole(`${debugPrefix}SwingSet:kernel`),
require: kernelRequire,
HandledPromise,
},
Expand Down Expand Up @@ -203,7 +207,7 @@ export async function buildVatController(

function makeVatEndowments(consoleTag) {
return harden({
console: makeConsole(`SwingSet:${consoleTag}`),
console: makeConsole(`${debugPrefix}SwingSet:${consoleTag}`),
HandledPromise,
// re2 is a RegExp work-a-like that disables backtracking expressions for
// safer memory consumption
Expand Down
20 changes: 18 additions & 2 deletions packages/cosmic-swingset/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -418,6 +419,13 @@ func NewAgoricApp(
return app
}

type cosmosInitAction struct {
Type string `json:"type"`
IBCPort int `json:"ibcPort"`
StoragePort int `json:"storagePort"`
ChainID string `json:"chainID"`
}

// Name returns the name of the App
func (app *AgoricApp) Name() string { return app.BaseApp.Name() }

Expand All @@ -428,8 +436,16 @@ func (app *AgoricApp) MustInitController(ctx sdk.Context) {
app.controllerInited = true

// Begin initializing the controller here.
msg := fmt.Sprintf(`{"type":"AG_COSMOS_INIT","ibcPort":%d,"storagePort":%d}`, app.IBCPort, swingset.GetPort("storage"))
_, err := app.swingSetKeeper.CallToController(ctx, msg)
action := &cosmosInitAction{
Type: "AG_COSMOS_INIT",
IBCPort: app.IBCPort,
StoragePort: swingset.GetPort("storage"),
ChainID: ctx.ChainID(),
}
bz, err := json.Marshal(action)
if err == nil {
_, err = app.swingSetKeeper.CallToController(ctx, string(bz))
}
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot initialize Controller", err)
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions packages/cosmic-swingset/lib/ag-solo/fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function connectToFakeChain(basedir, GCI, role, delay, inbound) {
flushChainSends,
vatsdir,
argv,
GCI, // debugName
);

const blockManager = makeBlockManager(s);
Expand Down
5 changes: 5 additions & 0 deletions packages/cosmic-swingset/lib/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async function buildSwingset(
storage,
vatsDir,
argv,
debugName = undefined,
) {
const debugPrefix = debugName === undefined ? '' : `${debugName}:`;
const config = {};
const mbs = buildMailboxStateMap();
mbs.populateFromData(mailboxState);
Expand Down Expand Up @@ -50,6 +52,7 @@ async function buildSwingset(

const controller = await buildVatController(config, argv, {
hostStorage: storage,
debugPrefix,
});
await controller.run();

Expand All @@ -64,6 +67,7 @@ export async function launch(
flushChainSends,
vatsDir,
argv,
debugName = undefined,
) {
log.info('Launching SwingSet kernel');

Expand All @@ -87,6 +91,7 @@ export async function launch(
storage,
vatsDir,
argv,
debugName,
);

function saveChainState() {
Expand Down
2 changes: 2 additions & 0 deletions packages/cosmic-swingset/x/swingset/blockers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type beginBlockAction struct {
StoragePort int `json:"storagePort"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
ChainID string `json:"chainID"`
}

type endBlockAction struct {
Expand All @@ -34,6 +35,7 @@ func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) erro
StoragePort: GetPort("storage"),
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
ChainID: ctx.ChainID(),
}
b, err := json.Marshal(action)
if err != nil {
Expand Down