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

merge latest node & update go work #8

Merged
merged 1 commit into from
Jan 24, 2024
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
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
.PHONY: update format

update: ## update the dependencies
git submodule update --init --recursive
go work sync
cd $(PWD)/l2geth && go mod tidy
cd $(PWD)/tendermint && go mod tidy

format: ## format the code
go work sync
Expand Down
1 change: 1 addition & 0 deletions bindings/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/morph-l2/go-ethereum v1.10.14-0.20240105030148-da6185c8d1cb h1:Lp02ROE0OnDF36GSaA8lN+kzbQGNK+Nj2cGdZworbuc=
github.com/morph-l2/go-ethereum v1.10.14-0.20240105030148-da6185c8d1cb/go.mod h1:9BGKc4l0m6qXgfXBGzp1aFHPE3dXzm2fi+rDtXpr8HM=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
2 changes: 2 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
go 1.20

replace github.com/scroll-tech/go-ethereum => github.com/morph-l2/go-ethereum v0.2.1-beta

use (
./bindings
./contracts
Expand Down
188 changes: 182 additions & 6 deletions go.work.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/core/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (e *Executor) CalculateCapWithProposalBlock(currentBlockBytes []byte, curre
chunksSizeWithCurBlock := e.batchingCache.chunks.Size() + len(e.batchingCache.currentTxsPayload) + len(e.batchingCache.currentBlockContext)
chunkNum := e.batchingCache.chunks.ChunkNum()
// current block will be filled in a new chunk
if e.batchingCache.chunks.IsChunksAppendedWithAddedRc(e.batchingCache.currentRowConsumption) {
if e.batchingCache.chunks.IsChunksAppendedWithNewBlock(e.batchingCache.currentRowConsumption) {
chunksSizeWithCurBlock += 1
chunkNum += 1
}
Expand Down
2 changes: 1 addition & 1 deletion node/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ require (
replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.20.1-beta
github.com/scroll-tech/go-ethereum => github.com/morph-l2/go-ethereum v1.10.14-0.20240105030148-da6185c8d1cb
github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.0.0-20240109085452-f7cf181d017a
github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.0.0-20240109085452-f7cf181d017a
)
69 changes: 69 additions & 0 deletions node/go.sum

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions node/types/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"github.com/scroll-tech/go-ethereum/crypto"
)

const NormalizedRowLimit = 1_000_000
const (
NormalizedRowLimit = 1_000_000
MaxBlocksPerChunk = 100
)

type Chunk struct {
blockContext []byte
Expand Down Expand Up @@ -166,7 +169,7 @@ func (cks *Chunks) Append(blockContext, txsPayload []byte, txHashes []common.Has
}
lastChunk := cks.data[len(cks.data)-1]
accRc, max := lastChunk.accumulateRowUsages(rc)
if max > NormalizedRowLimit { // add a new chunk
if lastChunk.blockNum+1 > MaxBlocksPerChunk || max > NormalizedRowLimit { // add a new chunk
cks.data = append(cks.data, NewChunk(blockContext, txsPayload, txHashes, rc))
cks.size += 1
return
Expand Down Expand Up @@ -204,11 +207,14 @@ func (cks *Chunks) DataHash() common.Hash {
func (cks *Chunks) BlockNum() int { return cks.blockNum }
func (cks *Chunks) ChunkNum() int { return len(cks.data) }
func (cks *Chunks) Size() int { return cks.size }
func (cks *Chunks) IsChunksAppendedWithAddedRc(rc types.RowConsumption) bool {
func (cks *Chunks) IsChunksAppendedWithNewBlock(blockRc types.RowConsumption) bool {
if len(cks.data) == 0 {
return true
}
lastChunk := cks.data[len(cks.data)-1]
_, max := lastChunk.accumulateRowUsages(rc)
if lastChunk.blockNum+1 > MaxBlocksPerChunk {
return true
}
_, max := lastChunk.accumulateRowUsages(blockRc)
return max > NormalizedRowLimit
}
18 changes: 17 additions & 1 deletion node/types/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestChunks_Append(t *testing.T) {
chunks := NewChunks()
require.True(t, chunks.IsChunksAppendedWithAddedRc(types.RowConsumption{{"a", 1}}))
require.True(t, chunks.IsChunksAppendedWithNewBlock(types.RowConsumption{{"a", 1}}))

blockContext := []byte("123")
txPayloads := []byte("abc")
Expand All @@ -39,6 +39,7 @@ func TestChunks_Append(t *testing.T) {
require.EqualValues(t, 2, chunks.BlockNum())
require.EqualValues(t, 1, chunks.ChunkNum())

// the 2nd chunk
blockContext2 := []byte("789")
txPayloads2 := []byte("ghi")
txHashes2 := []common.Hash{common.BigToHash(big.NewInt(3))}
Expand All @@ -56,6 +57,21 @@ func TestChunks_Append(t *testing.T) {
require.EqualValues(t, 3, chunks.BlockNum())
require.EqualValues(t, 2, chunks.ChunkNum())
require.EqualValues(t, 2+len(blockContext)+len(blockContext1)+len(blockContext2)+len(txPayloads)+len(txPayloads1)+len(txPayloads2), chunks.size)

for i := 0; i < 98; i++ {
chunks.Append([]byte("11"), nil, nil, types.RowConsumption{{"a", 1}})
}
// 99 blocks in 2nd chunk
require.EqualValues(t, 2, chunks.ChunkNum())
require.False(t, chunks.IsChunksAppendedWithNewBlock(types.RowConsumption{{"a", 1}}))
// 100 blocks in 2nd chunk
chunks.Append([]byte("11"), nil, nil, types.RowConsumption{{"a", 1}})
require.EqualValues(t, 2, chunks.ChunkNum())

require.True(t, chunks.IsChunksAppendedWithNewBlock(types.RowConsumption{{"a", 1}}))
// append chunk to 3 chunks totally
chunks.Append([]byte("11"), nil, nil, types.RowConsumption{{"a", 1}})
require.EqualValues(t, 3, chunks.ChunkNum())
}

func TestChunk_accumulateRowUsages(t *testing.T) {
Expand Down