Skip to content

Commit d5b41c8

Browse files
committed
feat: Implement ZSTD compression for DA blobs, integrate it into the DA client, and update related dependencies.
1 parent a5ef771 commit d5b41c8

17 files changed

Lines changed: 277 additions & 25 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ go test -race ./package/...
109109
- Wrap errors with context using `fmt.Errorf`
110110
- Return errors early
111111
- Use custom error types for domain-specific errors
112+
- Never start an error message with "failed to"
112113

113114
### Logging
114115

apps/evm/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/ipld/go-ipld-prime v0.21.0 // indirect
9494
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
9595
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
96-
github.com/klauspost/compress v1.18.0 // indirect
96+
github.com/klauspost/compress v1.18.4 // indirect
9797
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
9898
github.com/koron/go-ssdp v0.0.6 // indirect
9999
github.com/libp2p/go-buffer-pool v0.1.0 // indirect

apps/evm/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
714714
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
715715
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
716716
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
717-
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
718-
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
717+
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
718+
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
719719
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
720720
github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
721721
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=

apps/grpc/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ require (
7373
github.com/ipld/go-ipld-prime v0.21.0 // indirect
7474
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
7575
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
76-
github.com/klauspost/compress v1.18.0 // indirect
76+
github.com/klauspost/compress v1.18.4 // indirect
7777
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
7878
github.com/koron/go-ssdp v0.0.6 // indirect
7979
github.com/libp2p/go-buffer-pool v0.1.0 // indirect

apps/grpc/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
646646
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
647647
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
648648
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
649-
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
650-
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
649+
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
650+
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
651651
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
652652
github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
653653
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=

apps/testapp/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ require (
7272
github.com/ipld/go-ipld-prime v0.21.0 // indirect
7373
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
7474
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
75-
github.com/klauspost/compress v1.18.0 // indirect
75+
github.com/klauspost/compress v1.18.4 // indirect
7676
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
7777
github.com/koron/go-ssdp v0.0.6 // indirect
7878
github.com/libp2p/go-buffer-pool v0.1.0 // indirect

apps/testapp/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
646646
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
647647
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
648648
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
649-
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
650-
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
649+
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
650+
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
651651
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
652652
github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
653653
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=

block/internal/da/client.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/celestiaorg/go-square/v3/share"
12+
"github.com/evstack/ev-node/pkg/da"
1213
"github.com/rs/zerolog"
1314

1415
"github.com/evstack/ev-node/block/internal/common"
@@ -89,15 +90,31 @@ func (c *client) Submit(ctx context.Context, data [][]byte, _ float64, namespace
8990

9091
blobs := make([]*blobrpc.Blob, len(data))
9192
for i, raw := range data {
92-
if uint64(len(raw)) > common.DefaultMaxBlobSize {
93+
// Compress blob data before submission to reduce bandwidth and storage costs
94+
compressed, compErr := da.Compress(raw)
95+
if compErr != nil {
96+
return datypes.ResultSubmit{
97+
BaseResult: datypes.BaseResult{
98+
Code: datypes.StatusError,
99+
Message: fmt.Sprintf("compress blob %d: %v", i, compErr),
100+
},
101+
}
102+
}
103+
c.logger.Debug().
104+
Int("original_size", len(raw)).
105+
Int("compressed_size", len(compressed)).
106+
Float64("ratio", float64(len(compressed))/float64(len(raw))).
107+
Msg("compressed blob for DA submission")
108+
109+
if uint64(len(compressed)) > common.DefaultMaxBlobSize {
93110
return datypes.ResultSubmit{
94111
BaseResult: datypes.BaseResult{
95112
Code: datypes.StatusTooBig,
96113
Message: datypes.ErrBlobSizeOverLimit.Error(),
97114
},
98115
}
99116
}
100-
blobs[i], err = blobrpc.NewBlobV0(ns, raw)
117+
blobs[i], err = blobrpc.NewBlobV0(ns, compressed)
101118
if err != nil {
102119
return datypes.ResultSubmit{
103120
BaseResult: datypes.BaseResult{
@@ -278,12 +295,22 @@ func (c *client) Retrieve(ctx context.Context, height uint64, namespace []byte)
278295
}
279296
}
280297

281-
// Extract IDs and data from the blobs.
298+
// Extract IDs and data from the blobs, decompressing if needed.
282299
ids := make([]datypes.ID, len(blobs))
283300
data := make([]datypes.Blob, len(blobs))
284301
for i, b := range blobs {
285302
ids[i] = blobrpc.MakeID(height, b.Commitment)
286-
data[i] = b.Data()
303+
decompressed, decompErr := da.Decompress(b.Data())
304+
if decompErr != nil {
305+
return datypes.ResultRetrieve{
306+
BaseResult: datypes.BaseResult{
307+
Code: datypes.StatusError,
308+
Message: fmt.Sprintf("decompress blob %d at height %d: %v", i, height, decompErr),
309+
Height: height,
310+
},
311+
}
312+
}
313+
data[i] = decompressed
287314
}
288315

289316
c.logger.Debug().Int("num_blobs", len(blobs)).Msg("retrieved blobs")
@@ -361,7 +388,11 @@ func (c *client) Get(ctx context.Context, ids []datypes.ID, namespace []byte) ([
361388
if b == nil {
362389
continue
363390
}
364-
res = append(res, b.Data())
391+
decompressed, decompErr := da.Decompress(b.Data())
392+
if decompErr != nil {
393+
return nil, fmt.Errorf("decompress blob: %w", decompErr)
394+
}
395+
res = append(res, decompressed)
365396
}
366397

367398
return res, nil

execution/evm/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd
186186
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
187187
github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk=
188188
github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk=
189-
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
190-
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
189+
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
190+
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
191191
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
192192
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
193193
github.com/koron/go-ssdp v0.0.6 h1:Jb0h04599eq/CY7rB5YEqPS83HmRfHP2azkxMN2rFtU=

execution/evm/test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ require (
109109
github.com/inconshreveable/mousetrap v1.1.0 // indirect
110110
github.com/ipfs/go-cid v0.6.0 // indirect
111111
github.com/jmhodges/levigo v1.0.0 // indirect
112-
github.com/klauspost/compress v1.18.0 // indirect
112+
github.com/klauspost/compress v1.18.4 // indirect
113113
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
114114
github.com/kr/pretty v0.3.1 // indirect
115115
github.com/kr/text v0.2.0 // indirect

0 commit comments

Comments
 (0)