Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codecv2): add zstd compression and increase chunks num per batch post compression #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bee839b
feat: add codecv0 and codecv1
colinlyguo Apr 29, 2024
b8939df
feat: add codecv0 and codecv1
colinlyguo Apr 29, 2024
9ac5267
feat(codecv1): add zstd compression and increase chunks num per batch…
colinlyguo Apr 29, 2024
5fdc0f4
add zstd compression
colinlyguo Apr 30, 2024
9299133
remove .so files
colinlyguo May 2, 2024
6781e4c
add codecv2
colinlyguo May 2, 2024
e767359
fix
colinlyguo May 2, 2024
da2fdb4
fix lint
colinlyguo May 2, 2024
1f0a29c
add .so files
colinlyguo May 2, 2024
7a132fb
add codecv2 type
colinlyguo May 3, 2024
3bc7a1a
tweak
colinlyguo May 3, 2024
4c14871
Apply suggestions from code review
colinlyguo May 6, 2024
6aefc05
remove timezone setting
colinlyguo May 6, 2024
e5d513b
refactor
colinlyguo May 6, 2024
f180ac6
fix
colinlyguo May 6, 2024
f59cf99
Apply suggestions from code review
colinlyguo May 6, 2024
3331873
small fix
colinlyguo May 6, 2024
e9dbcf9
refactor
colinlyguo May 6, 2024
c2a0852
rename rs to libzstd
colinlyguo May 6, 2024
67cc822
use early return
colinlyguo May 6, 2024
d6ff1c1
change DecodeDABlock to receiver form
colinlyguo May 6, 2024
f33369d
use enum as versions, removing constant
colinlyguo May 6, 2024
1f826c0
remove init() and log.Crit()
colinlyguo May 7, 2024
0d68db7
Merge branch 'main' into feat-codecv1-add-zstd-compression-and-increa…
colinlyguo May 7, 2024
ae120d0
Merge branch 'main' into feat-codecv1-add-zstd-compression-and-increa…
colinlyguo May 7, 2024
1e4f404
add gas estimation
colinlyguo May 7, 2024
665489b
tweak
colinlyguo May 7, 2024
db68c80
build .so files on-the-fly
colinlyguo May 7, 2024
313e40b
fix CI
colinlyguo May 7, 2024
90c40f2
use default path to compile and link
colinlyguo May 7, 2024
eced2d8
remove libzstd/rs_zstd.h and fix CI
colinlyguo May 7, 2024
51a2ea7
rename
colinlyguo May 8, 2024
03564e1
rename
colinlyguo May 8, 2024
fac550e
rename
colinlyguo May 8, 2024
c4d0a70
revert
colinlyguo May 8, 2024
f1562af
add -L/lib/ -Wl,-rpath=/lib
colinlyguo May 9, 2024
063c447
temp try
colinlyguo May 9, 2024
edcaf71
try
colinlyguo May 9, 2024
c53bf3a
add CGO_LDFLAGS
colinlyguo May 9, 2024
b138b33
fix
colinlyguo May 9, 2024
31b6d84
try fix
colinlyguo May 9, 2024
6b7de14
revert
colinlyguo May 9, 2024
4eeab8d
remove cp to /usr/local/lib
colinlyguo May 9, 2024
682340e
tweak
colinlyguo May 9, 2024
b70c79a
fix
colinlyguo May 9, 2024
5489d45
try deleting LD_LIBRARY_PATH
colinlyguo May 10, 2024
f8b88ce
revert
colinlyguo May 10, 2024
6a578e0
remove Dockerfile
colinlyguo May 13, 2024
729c7fe
tweak
colinlyguo May 15, 2024
1629f39
remove txTypeTest
colinlyguo May 15, 2024
acac056
decrease the 256 bytes extra buffer to 128 bytes
colinlyguo May 15, 2024
2e52866
add a comment
colinlyguo May 15, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/codec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- name: Lint
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- name: Install goimports
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- name: Test codec packages
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.exe
*.exe~
*.dll
*.a
*.so
*.dylib

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: fmt lint test
.PHONY: fmt lint test build run

lint:
GOBIN=$(PWD)/build/bin go run ./build/lint.go
Expand All @@ -9,4 +9,4 @@ fmt:
gofumpt -l -w .

test:
go test -v -race -gcflags="-l" -ldflags="-s=false" -coverprofile=coverage.txt -covermode=atomic ./...
./run_test.sh
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# da-codec
# da-codec

## Running unit tests
```
docker pull scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 --platform linux/amd64
docker run -it --rm -v "$(PWD):/workspace" -w /workspace scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03
cd libzstd
make libzstd
cd ..
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/libzstd
export CGO_LDFLAGS="-L$(pwd)/libzstd -Wl,-rpath,$(pwd)/libzstd"
go test -v -race ./...
```
10 changes: 6 additions & 4 deletions build/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ linters-settings:
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew
rules:
main:
files:
- $all
deny:
- pkg: "github.com/davecgh/go-spew/spew"
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
Expand Down
4 changes: 2 additions & 2 deletions build/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
// GolangCIVersion to be used for linting.
GolangCIVersion = "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2"
GolangCIVersion = "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2"
)

// GOBIN environment variable.
Expand Down Expand Up @@ -51,7 +51,7 @@ func lint() {
}

cmd = exec.Command(filepath.Join(goBin(), "golangci-lint"))
cmd.Args = append(cmd.Args, "run", "--config", "build/.golangci.yml")
cmd.Args = append(cmd.Args, "run", "--config", "build/.golangci.yml", "--timeout", "2m")

if *v {
cmd.Args = append(cmd.Args, "-v")
Expand Down
1 change: 1 addition & 0 deletions encoding/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func ConstructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePo
if tx.Type != types.L1MessageTxType {
continue
}

currentIndex := tx.Nonce

if currentIndex < nextIndex {
Expand Down
38 changes: 14 additions & 24 deletions encoding/codecv0/codecv0.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
"github.com/scroll-tech/da-codec/encoding"
)

// CodecV0Version denotes the version of the codec.
const CodecV0Version = 0

// DABlock represents a Data Availability Block.
type DABlock struct {
BlockNumber uint64
Expand Down Expand Up @@ -91,22 +88,20 @@ func (b *DABlock) Encode() []byte {
return bytes
}

// DecodeDABlock takes a byte slice and decodes it into a DABlock.
func DecodeDABlock(bytes []byte) (*DABlock, error) {
// Decode populates the fields of a DABlock from a byte slice.
func (b *DABlock) Decode(bytes []byte) error {
if len(bytes) != 60 {
return nil, errors.New("block encoding is not 60 bytes long")
return errors.New("block encoding is not 60 bytes long")
}

block := &DABlock{
BlockNumber: binary.BigEndian.Uint64(bytes[0:8]),
Timestamp: binary.BigEndian.Uint64(bytes[8:16]),
BaseFee: new(big.Int).SetUint64(binary.BigEndian.Uint64(bytes[40:48])),
GasLimit: binary.BigEndian.Uint64(bytes[48:56]),
NumTransactions: binary.BigEndian.Uint16(bytes[56:58]),
NumL1Messages: binary.BigEndian.Uint16(bytes[58:60]),
}
b.BlockNumber = binary.BigEndian.Uint64(bytes[0:8])
b.Timestamp = binary.BigEndian.Uint64(bytes[8:16])
b.BaseFee = new(big.Int).SetUint64(binary.BigEndian.Uint64(bytes[40:48]))
b.GasLimit = binary.BigEndian.Uint64(bytes[48:56])
b.NumTransactions = binary.BigEndian.Uint16(bytes[56:58])
b.NumL1Messages = binary.BigEndian.Uint16(bytes[58:60])

return block, nil
return nil
}

// NewDAChunk creates a new DAChunk from the given encoding.Chunk and the total number of L1 messages popped before.
Expand Down Expand Up @@ -160,8 +155,9 @@ func (c *DAChunk) Encode() ([]byte, error) {
if txData.Type == types.L1MessageTxType {
continue
}

var txLen [4]byte
rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(txData)
rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(txData, false /* no mock */)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -248,7 +244,7 @@ func NewDABatch(batch *encoding.Batch) (*DABatch, error) {
}

daBatch := DABatch{
Version: CodecV0Version,
Version: uint8(encoding.CodecV0),
BatchIndex: batch.Index,
L1MessagePopped: totalL1MessagePoppedAfter - batch.TotalL1MessagePoppedBefore,
TotalL1MessagePopped: totalL1MessagePoppedAfter,
Expand Down Expand Up @@ -298,12 +294,6 @@ func (b *DABatch) Hash() common.Hash {
return crypto.Keccak256Hash(bytes)
}

// DecodeFromCalldata attempts to decode a DABatch and an array of DAChunks from the provided calldata byte slice.
func DecodeFromCalldata(data []byte) (*DABatch, []*DAChunk, error) {
// TODO: implement this function.
return nil, nil, nil
}

// CalldataNonZeroByteGas is the gas consumption per non zero byte in calldata.
const CalldataNonZeroByteGas = 16

Expand Down Expand Up @@ -471,7 +461,7 @@ func EstimateBatchL1CommitCalldataSize(b *encoding.Batch) (uint64, error) {
}

func getTxPayloadLength(txData *types.TransactionData) (uint64, error) {
rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(txData)
rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(txData, false /* no mock */)
if err != nil {
return 0, err
}
Expand Down
Loading
Loading