Skip to content

Commit

Permalink
feat: compute separate mempool limit for allowed inbound
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman authored and mergify[bot] committed Oct 5, 2022
1 parent 20dc36b commit ebfc852
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions golang/cosmos/ante/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func (ia inboundAnte) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next
// was lower (e.g. 50%).
if inboundsAllowed == -1 {
state := ia.sk.GetState(ctx)
allowed, found := swingtypes.QueueSizeEntry(state.QueueAllowed, "inbound")
entry := swingtypes.QueueInbound
if simulate {
entry = swingtypes.QueueInboundMempool
}
allowed, found := swingtypes.QueueSizeEntry(state.QueueAllowed, entry)
if found {
actions, err := ia.sk.ActionQueueLength(ctx)
if err != nil {
Expand All @@ -64,7 +68,7 @@ func (ia inboundAnte) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next
inboundsAllowed = 0
}
} else {
// no inbound allowed size from swingset
// if number of allowed entries not given, fail closed
inboundsAllowed = 0
}
}
Expand Down
5 changes: 4 additions & 1 deletion golang/cosmos/x/swingset/types/default-params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const (
BeansPerVatCreation = "vatCreation"
BeansPerXsnapComputron = "xsnapComputron"

QueueInbound = "inbound"
// QueueSize keys.
// Keep up-to-date with updateQueueAllowed() in packanges/cosmic-swingset/src/launch-chain.js
QueueInbound = "inbound"
QueueInboundMempool = "inbound_mempool"
)

var (
Expand Down
14 changes: 12 additions & 2 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,25 @@ export async function launch({

function updateQueueAllowed(_blockHeight, _blockTime, params) {
assert(params.queueMax);

assert(QueueInbound in params.queueMax);

const inboundQueueMax = params.queueMax[QueueInbound];
const inboundMempoolQueueMax = Math.floor(inboundQueueMax / 2);

const inboundQueueSize = inboundQueue.size();

const inboundQueueAllowed = Math.max(0, inboundQueueMax - inboundQueueSize);
const inboundMempoolQueueAllowed = Math.max(
0,
inboundMempoolQueueMax - inboundQueueSize,
);

savedQueueAllowed = { [QueueInbound]: inboundQueueAllowed };
savedQueueAllowed = {
// Keep up-to-date with queue size keys defined in
// golang/cosmos/x/swingset/types/default-params.go
inbound: inboundQueueAllowed,
inbound_mempool: inboundMempoolQueueAllowed,
};
}

async function saveChainState() {
Expand Down

0 comments on commit ebfc852

Please sign in to comment.