fix: update blob compressor lib + update dependencies + use tsup (#976)

* fix: update blob compressor lib + update dependencies + use tsup

* fix: update dict path

* fix: lockfile issue

* fix: bump package json version
This commit is contained in:
Victorien Gauch
2025-06-02 14:43:53 +02:00
committed by GitHub
parent 171f090b78
commit 19735ced28
17 changed files with 821 additions and 189 deletions

View File

@@ -98,7 +98,7 @@ jobs:
push: false
tags: ${{ env.IMAGE_NAME }}:${{ env.COMMIT_TAG }}
build-args: |
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.0.1
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.2.0
- name: Save Docker image as artifact
if: ${{ env.PUSH_IMAGE == 'false' }}
run: |
@@ -126,4 +126,4 @@ jobs:
type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-amd64,mode=max,platform=linux/amd64
type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-arm64,mode=max,platform=linux/arm64
build-args: |
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.0.1
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.2.0

View File

@@ -20,7 +20,7 @@ jobs:
- name: Run tests and generate coverage report
env:
NATIVE_LIBS_RELEASE_TAG: blob-libs-v1.0.1
NATIVE_LIBS_RELEASE_TAG: blob-libs-v1.2.0
run: |
pnpm run -F ./ts-libs/linea-native-libs build;
pnpm run -F ./sdk build;

View File

@@ -183,7 +183,6 @@ services:
hostname: postman
image: consensys/linea-postman:${POSTMAN_TAG:-8a0bcc8}
profiles: [ "l2", "debug" ]
platform: linux/amd64
restart: on-failure
ports:
- "9090:3000"

891
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -112,7 +112,7 @@ Stop the postman docker container manually.
Before the postman can be run and tested locally, we must build the monorepo projects linea-sdk and linea-native-libs
```bash
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.0.1 pnpm run -F linea-native-libs build && pnpm run -F linea-sdk build
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.2.0 pnpm run -F linea-native-libs build && pnpm run -F linea-sdk build
```
From the postman folder run the following commands:

View File

@@ -79,7 +79,7 @@ describe("L2ClaimTransactionSizeCalculator", () => {
maxFeePerGas: DEFAULT_MAX_FEE_PER_GAS,
});
expect(transactionSize).toStrictEqual(77);
expect(transactionSize).toStrictEqual(81);
});
});
});

View File

@@ -1,6 +1,6 @@
# @consensys/linea-native-libs
`@consensys/linea-native-libs` is a Node.js library that provides an interface to native Go libraries using the `ffi-napi` and `ref-napi` packages.
`@consensys/linea-native-libs` is a Node.js library that provides an interface to native Go libraries using the `koffi` package.
It provides the following Go libraries wrapper:
- `GoNativeCompressor`: This class allows you to initialize the transaction compressor, check for errors, and get the worst compressed transaction size for a given RLP-encoded transaction.

View File

@@ -1,29 +1,22 @@
{
"name": "@consensys/linea-native-libs",
"version": "0.1.0",
"version": "1.2.0",
"description": "Linea native libs",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"files": [
"dist"
],
"scripts": {
"postbuild": "bash ./src/scripts/build.sh",
"build": "ts-bridge --project tsconfig.build.json --clean",
"build": "tsup --tsconfig tsconfig.build.json",
"clean": "rimraf dist build coverage node_modules",
"test": "jest --bail --detectOpenHandles --forceExit && jest-it-up",
"lint:ts": "npx eslint '**/*.ts'",
@@ -35,21 +28,18 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@ts-bridge/cli": "^0.1.4",
"@ts-bridge/shims": "^0.1.1",
"@types/ffi-napi": "^4.0.10",
"@types/jest": "^29.5.12",
"@types/ref-napi": "^3.0.12",
"@types/unzipper": "^0.10.9",
"dotenv": "^16.4.5",
"ethers": "^6.13.1",
"jest": "^29.7.0",
"jest-it-up": "^3.1.0",
"ts-jest": "^29.1.5",
"unzipper": "^0.12.1"
"@jest/globals": "29.7.0",
"@types/jest": "29.5.14",
"@types/unzipper": "0.10.11",
"dotenv": "16.5.0",
"jest": "29.7.0",
"jest-it-up": "4.0.1",
"ts-jest": "29.3.2",
"tsup": "8.4.0",
"unzipper": "0.12.3",
"viem": "2.29.1"
},
"dependencies": {
"koffi": "^2.9.0"
"koffi": "2.11.0"
}
}

View File

@@ -2,7 +2,7 @@ import { KoffiFunction, load } from "koffi";
import path from "path";
import { getCompressorLibPath } from "./helpers";
const COMPRESSOR_DICT_PATH = path.join(__dirname, "./lib/compressor_dict.bin");
const COMPRESSOR_DICT_PATH = path.join(__dirname, "./lib/25-04-21.bin");
/**
* Class representing a Go Native Compressor.

View File

@@ -1,5 +1,6 @@
import { describe, it, beforeEach, expect } from "@jest/globals";
import { Transaction, Wallet, ethers } from "ethers";
import { parseEther, serializeTransaction, toBytes, toRlp } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { GoNativeCompressor } from "../GoNativeCompressor";
const TEST_ADDRESS = "0x0000000000000000000000000000000000000001";
@@ -15,12 +16,16 @@ describe("GoNativeCompressor", () => {
describe("getCompressedTxSize", () => {
it("Should throw an error if an error occured during tx compression", () => {
const transaction = Transaction.from({
const transaction = serializeTransaction({
to: TEST_ADDRESS,
value: ethers.parseEther("2"),
value: parseEther("2"),
maxFeePerGas: parseEther("0.5"),
maxPriorityFeePerGas: parseEther("0.45"),
nonce: 1,
chainId: 1,
});
const rlpEncodedTransaction = ethers.encodeRlp(transaction.unsignedSerialized);
const input = ethers.getBytes(rlpEncodedTransaction);
const rlpEncodedTransaction = toRlp(transaction);
const input = toBytes(rlpEncodedTransaction);
expect(() => compressor.getCompressedTxSize(input)).toThrow(
"Error while compressing the transaction: rlp: too few elements for types.DynamicFeeTx",
@@ -28,19 +33,22 @@ describe("GoNativeCompressor", () => {
});
it("Should return compressed tx size", async () => {
const transaction = Transaction.from({
const signer = privateKeyToAccount(TEST_PRIVATE_KEY);
const encodedSignedTx = await signer.signTransaction({
to: TEST_ADDRESS,
value: ethers.parseEther("2"),
value: parseEther("2"),
maxFeePerGas: parseEther("0.5"),
maxPriorityFeePerGas: parseEther("0.45"),
nonce: 1,
chainId: 1,
});
const signer = new Wallet(TEST_PRIVATE_KEY);
const encodedSignedTx = await signer.signTransaction(transaction);
const rlpEncodedTransaction = ethers.encodeRlp(encodedSignedTx);
const input = ethers.getBytes(rlpEncodedTransaction);
const rlpEncodedTransaction = toRlp(encodedSignedTx);
const input = toBytes(rlpEncodedTransaction);
const compressedTxSize = compressor.getCompressedTxSize(input);
expect(compressedTxSize).toStrictEqual(43);
expect(compressedTxSize).toStrictEqual(63);
});
});
});

View File

@@ -2,7 +2,7 @@ import { describe, it, expect } from "@jest/globals";
import os from "os";
import fs, { Dirent } from "fs";
import path from "path";
import { getCompressorLibPath } from "..";
import { getCompressorLibPath } from "../helpers";
describe("Helpers", () => {
afterEach(() => {

View File

@@ -30,7 +30,7 @@ export function getCompressorLibPath(): string {
throw new Error(`Unsupported platform: ${platform}`);
}
const dirPath = path.join(__dirname, "..", "lib", directory);
const dirPath = path.join(__dirname, "lib", directory);
if (!existsSync(dirPath)) {
throw new Error(`Directory does not exist: ${dirPath}`);

View File

@@ -8,8 +8,8 @@ error_handler() {
trap 'error_handler $LINENO' ERR
node ./dist/scripts/build.mjs
cp -R src/compressor/lib/ dist/compressor/lib
npx ts-node ./src/scripts/build.ts
cp -R src/compressor/lib/ dist/lib
rm -rf ./dist/scripts
echo "Build script executed successfully."

View File

@@ -8,7 +8,8 @@
"noEmit": false,
"outDir": "dist",
"rootDir": "src",
"sourceMap": true
"sourceMap": true,
"composite": false,
},
"include": ["./src/**/*.ts"],
"exclude": [

View File

@@ -0,0 +1,13 @@
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
tsconfig: "tsconfig.build.json",
format: ["esm", "cjs"],
target: "esnext",
dts: true,
clean: true,
sourcemap: true,
minify: true,
outDir: "dist",
});