Skip to content
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
1 change: 1 addition & 0 deletions yarn-project/foundation/src/buffer/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './buffer32.js';
export * from './buffer16.js';
export * from './utils.js';
35 changes: 35 additions & 0 deletions yarn-project/foundation/src/buffer/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { trimmedBytesLength } from './utils.js';

describe('trimmedBytesLength', () => {
it('returns 0 for an empty buffer', () => {
expect(trimmedBytesLength(new Uint8Array([]))).toBe(0);
});

it('returns 0 for an all-zeros buffer', () => {
expect(trimmedBytesLength(new Uint8Array([0, 0, 0, 0]))).toBe(0);
});

it('returns full length when there are no trailing zeros', () => {
expect(trimmedBytesLength(new Uint8Array([1, 2, 3]))).toBe(3);
});

it('excludes trailing zeros', () => {
expect(trimmedBytesLength(new Uint8Array([1, 2, 0, 0]))).toBe(2);
});

it('preserves leading zeros', () => {
expect(trimmedBytesLength(new Uint8Array([0, 0, 1, 0, 0]))).toBe(3);
});

it('preserves interior zeros', () => {
expect(trimmedBytesLength(new Uint8Array([1, 0, 0, 2, 0]))).toBe(4);
});

it('handles a single non-zero byte', () => {
expect(trimmedBytesLength(new Uint8Array([0, 0, 5]))).toBe(3);
});

it('handles a single zero byte', () => {
expect(trimmedBytesLength(new Uint8Array([0]))).toBe(0);
});
});
8 changes: 8 additions & 0 deletions yarn-project/foundation/src/buffer/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** Returns the number of bytes in the buffer, excluding any trailing zero bytes. */
export function trimmedBytesLength(buf: Uint8Array): number {
let end = buf.length;
while (end > 0 && buf[end - 1] === 0) {
end--;
}
return end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from
import { sumBigint } from '@aztec/foundation/bigint';
import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
import { trimmedBytesLength } from '@aztec/foundation/buffer';
import { pick } from '@aztec/foundation/collection';
import type { Fr } from '@aztec/foundation/curves/bn254';
import { TimeoutError } from '@aztec/foundation/error';
Expand Down Expand Up @@ -547,7 +548,16 @@ export class SequencerPublisher {
});
return { failedActions: requests.map(r => r.action) };
} else {
this.log.verbose(`Published bundled transactions (${actionsListStr})`, { result, requests });
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
result,
requests: requests.map(r => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be a method on a type?

...r,
// Avoid logging large blob data
blobConfig: r.blobConfig
? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) }
: undefined,
})),
});
const successfulActions: Action[] = [];
const failedActions: Action[] = [];
for (const request of requests) {
Expand Down
Loading