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

check for bookmark entry in data stream file #2670

Merged
merged 2 commits into from
Oct 16, 2023
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
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ require (
github.com/markbates/errx v1.1.0 // indirect
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
Expand Down Expand Up @@ -154,4 +156,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
)

require github.com/prometheus/client_golang v1.16.0
require (
github.com/fatih/color v1.13.0
github.com/prometheus/client_golang v1.16.0
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ github.com/ethereum/go-ethereum v1.13.2 h1:g9mCpfPWqCA1OL4e6C98PeVttb0HadfBRuKTG
github.com/ethereum/go-ethereum v1.13.2/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
Expand Down Expand Up @@ -521,16 +523,20 @@ github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcncea
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
Expand Down Expand Up @@ -1005,6 +1011,7 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
30 changes: 24 additions & 6 deletions sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (s *Sequencer) Start(ctx context.Context) {
}

func (s *Sequencer) updateDataStreamerFile(ctx context.Context, streamServer *datastreamer.StreamServer) {
var skipBookMark, skipL2BlockStart bool
var currentL2Block uint64
var currentTxIndex uint64
var err error
Expand Down Expand Up @@ -252,9 +253,17 @@ func (s *Sequencer) updateDataStreamerFile(ctx context.Context, streamServer *da
log.Infof("Latest entry: %+v", latestEntry)

switch latestEntry.Type {
case state.EntryTypeBookMark:
log.Info("Latest entry type is BookMark")
currentL2Block = binary.LittleEndian.Uint64(latestEntry.Data[1:9])
skipBookMark = true
currentL2Block--
case state.EntryTypeL2BlockStart:
log.Info("Latest entry type is L2BlockStart")
currentL2Block = binary.LittleEndian.Uint64(latestEntry.Data[8:16])
skipBookMark = true
skipL2BlockStart = true
currentL2Block--
case state.EntryTypeL2Tx:
log.Info("Latest entry type is L2Tx")
for latestEntry.Type == state.EntryTypeL2Tx {
Expand All @@ -268,6 +277,7 @@ func (s *Sequencer) updateDataStreamerFile(ctx context.Context, streamServer *da
log.Fatal("Latest entry is not a L2BlockStart")
}
currentL2Block = binary.LittleEndian.Uint64(latestEntry.Data[8:16])
currentL2Block--
case state.EntryTypeL2BlockEnd:
log.Info("Latest entry type is L2BlockEnd")
currentL2Block = binary.LittleEndian.Uint64(latestEntry.Data[0:8])
Expand Down Expand Up @@ -316,9 +326,13 @@ func (s *Sequencer) updateDataStreamerFile(ctx context.Context, streamServer *da
L2BlockNumber: l2block.L2BlockNumber,
}

_, err = streamServer.AddStreamBookmark(bookMark.Encode())
if err != nil {
log.Fatal(err)
if !skipBookMark {
_, err = streamServer.AddStreamBookmark(bookMark.Encode())
if err != nil {
log.Fatal(err)
}
} else {
skipBookMark = false
}

blockStart := state.DSL2BlockStart{
Expand All @@ -330,9 +344,13 @@ func (s *Sequencer) updateDataStreamerFile(ctx context.Context, streamServer *da
ForkID: l2block.ForkID,
}

_, err = streamServer.AddStreamEntry(state.EntryTypeL2BlockStart, blockStart.Encode())
if err != nil {
log.Fatal(err)
if !skipL2BlockStart {
_, err = streamServer.AddStreamEntry(state.EntryTypeL2BlockStart, blockStart.Encode())
if err != nil {
log.Fatal(err)
}
} else {
skipL2BlockStart = false
}

entry, err = streamServer.AddStreamEntry(state.EntryTypeL2Tx, l2Transactions[x].Encode())
Expand Down
18 changes: 10 additions & 8 deletions tools/datastreamer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ generate-file: check-go
validate-file: check-go
rebuild: check-go
decode-entry: check-go
adecode-l2block: check-go
decode-l2block: check-go

arguments := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))

Expand All @@ -21,18 +21,17 @@ generate-file: ## Runs the tool to populate the binary file
validate-file: ## Runs the tool to validate the binary file
go run main.go validate -cfg config/tool.config.toml

.PHONY: decode-l2block
decode-l2block: ## Runs the tool to decode a given l2 block number
go run main.go decode-l2block -cfg config/tool.config.toml -l2block $(arguments)

.PHONY: decode-entry
decode-entry: ## Runs the tool to decode a given entry number
go run main.go decode-entry -cfg config/tool.config.toml -entry $(arguments)

.PHONY: rebuild
rebuild: ## Runs the tool to rebuild state roots from a given block
go run main.go rebuild -cfg config/tool.config.toml -l2block $(arguments)
.PHONY: decode-l2block
decode-l2block: ## Runs the tool to decode a given L2 block
go run main.go decode-l2block -cfg config/tool.config.toml -l2block $(arguments)

# .PHONY: rebuild
# rebuild: ## Runs the tool to rebuild state roots from a given block
# go run main.go rebuild -cfg config/tool.config.toml -l2block $(arguments)

## Help display.
## Pulls comments from beside commands and prints a nicely formatted
Expand All @@ -44,3 +43,6 @@ help: ## Prints this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT:
@echo ""
2 changes: 1 addition & 1 deletion tools/datastreamer/config/tool.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Port = 6901
Filename = "datastream.bin"
[StreamServer.Log]
Environment = "development"
Level = "info"
Level = "error"
Outputs = ["stdout"]

[StateDB]
Expand Down
Loading