assertMessageCanAccommodateSize

function assertMessageCanAccommodateSize(__namedParameters): void;

Asserts that a transaction message can grow from currentSize to nextSize bytes without exceeding sizeLimit.

Use it in a custom MessagePacker after appending the next instruction(s) to the message so the transaction planner knows to pack them into another transaction message. It works on sizes rather than messages so that callers who already computed them do not pay for it twice.

Parameters

ParameterTypeDescription
__namedParameters{ currentSize: number; nextSize: number; sizeLimit: number; }-
__namedParameters.currentSizenumberThe size of the transaction message before packing the next instruction(s), in bytes.
__namedParameters.nextSizenumberThe size of the transaction message after packing the next instruction(s), in bytes.
__namedParameters.sizeLimitnumberThe maximum size of the transaction message, in bytes.

Returns

void

Example

const nextMessage = appendTransactionMessageInstruction(nextInstruction, message);
assertMessageCanAccommodateSize({
  currentSize: getTransactionMessageSize(message),
  nextSize: getTransactionMessageSize(nextMessage),
  sizeLimit: getTransactionMessageSizeLimit(nextMessage),
});
return nextMessage;

Throws

Throws a SolanaError with code SOLANA_ERROR__INSTRUCTION_PLANS__MESSAGE_CANNOT_ACCOMMODATE_PLAN if nextSize exceeds sizeLimit. The error reports how many bytes were required and how many were free.

See

isMessagePackerErrorThatRequiresNewCandidate

On this page