Skip to content

Commit

Permalink
fix(cosmic-swingset): slog begin/end-block and input events
Browse files Browse the repository at this point in the history
Changes cosmic-swingset to add the following events to the slogfile:

* `type: 'cosmic-swingset-deliver-inbound'`: an inbound message was given to
  the mailbox device
* `type: 'cosmic-swingset-bridge-inbound'`: a message was given to the bridge
  device
* `type: 'cosmic-swingset-begin-block'`: the cosmos-side SwingSet module was
  given a BEGIN_BLOCK event
* `type: 'cosmic-swingset-end-block-start'`: the cosmos-side SwingSet module
  was given an END_BLOCK event, and SwingSet's `controller.run()` is about to
  be called
* `type: 'cosmic-swingset-end-block-finish'`: the cosmos-side SwingSet module
  was given an END_BLOCK event, and SwingSet's `controller.run()` has just
  finished running

The begin/end block events include the block's height and time, both of which
are part of the consensus state. The deliver/bridge events include some
information about the messages being delivered.

This enables slogfile post-processing tools to correlate cranks with the
blocks whose transactions provoked them.
  • Loading branch information
warner committed May 25, 2021
1 parent 851fa61 commit cc77234
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export async function launch(
}

let bootstrapBlock;
async function endBlock(_blockHeight, _blockTime) {
async function endBlock(blockHeight, blockTime) {
controller.writeSlogObject({
type: 'cosmic-swingset-end-block-start',
blockHeight,
blockTime,
});
let numCranks = FIXME_MAX_CRANKS_PER_BLOCK;
if (bootstrapBlock) {
// This is the initial block, we need to finish processing the entire
Expand All @@ -170,6 +175,11 @@ export async function launch(
bootstrapBlock = false;
}
await crankScheduler(numCranks);
controller.writeSlogObject({
type: 'cosmic-swingset-end-block-finish',
blockHeight,
blockTime,
});
}

async function saveChainState() {
Expand All @@ -187,20 +197,34 @@ export async function launch(

async function deliverInbound(sender, messages, ack) {
assert(Array.isArray(messages), X`inbound given non-Array: ${messages}`);
controller.writeSlogObject({
type: 'cosmic-swingset-deliver-inbound',
sender,
count: messages.length,
});
if (!mb.deliverInbound(sender, messages, ack)) {
return;
}
console.debug(`mboxDeliver: ADDED messages`);
}

async function doBridgeInbound(source, body) {
controller.writeSlogObject({
type: 'cosmic-swingset-bridge-inbound',
source,
});
// console.log(`doBridgeInbound`);
// the inbound bridge will push messages onto the kernel run-queue for
// delivery+dispatch to some handler vat
bridgeInbound(source, body);
}

async function beginBlock(blockHeight, blockTime) {
controller.writeSlogObject({
type: 'cosmic-swingset-begin-block',
blockHeight,
blockTime,
});
const addedToQueue = timer.poll(blockTime);
console.debug(
`polled; blockTime:${blockTime}, h:${blockHeight}; ADDED =`,
Expand Down

0 comments on commit cc77234

Please sign in to comment.