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 upstream v0.2.7 #8

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v3
- name: Lint
Expand Down
32 changes: 31 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
test:
strategy:
matrix:
go-version: [ 1.19.x ]
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand All @@ -27,3 +27,33 @@
- name: Test
run: make test
working-directory: ./


- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage.out

# sonar-cloud:
# needs: test
# name: SonarCloud
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Code
# uses: actions/checkout@v3
# with:
# submodules: recursive
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
#
# - name: Download code coverage results
# uses: actions/download-artifact@v3
# with:
# name: code-coverage-report
#
# - name: SonarCloud analysis
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
73 changes: 65 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,79 @@ run:

linters:
enable:
- whitespace
- gosec
- gci
- misspell
- gomnd
- gofmt
- goimports
- revive
- gci # Gci controls Go package import order and makes it always deterministic.
- mnd # An analyzer to detect magic numbers.
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- whitespace # Tool for detection of leading and trailing whitespace
- wastedassign # Finds wasted assignment statements
- unconvert # Unnecessary type conversions
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
- thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- stylecheck # Stylecheck is a replacement for golint
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- nolintlint # Ill-formed or insufficient nolint directives
- misspell # Misspelled English words in comments
- makezero # Finds slice declarations with non-zero initial length
- lll # Long lines
- importas # Enforces consistent import aliases
- gosec # Security problems
- gofmt # Whether the code was gofmt-ed
- goimports # Unused imports
- goconst # Repeated strings that could be replaced by a constant
- forcetypeassert # Finds forced type assertions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dupl # Code clone detection
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- gocritic # Highly extensible Go source code linter providing checks currently missing from other linters.
- errcheck # Errcheck is a go lint rule for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- godox # Godox is a linter for TODOs and FIXMEs left in the code

linters-settings:
dupl:
threshold: 300
revive:
rules:
- name: exported
arguments:
- disableStutteringCheck

gocritic:
# The checks that should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic ./build/bin/golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- ruleguard

disabled-checks:
- regexpMust
- appendAssign
- rangeValCopy
- exitAfterDefer
- elseif
- dupBranchBody
- assignOp
- singleCaseSwitch
- unlambda
- captLocal
- commentFormatting
- ifElseChain
- importShadow
- paramTypeCombine
- builtinShadow
- typeUnparen

# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags:
- performance
- diagnostic
- opinionated
disabled-tags:
- experimental

issues:
include:
- EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ FROM golang:1.21 AS build
# INSTALL DEPENDENCIES
RUN go install github.com/gobuffalo/packr/v2/[email protected]
COPY go.mod go.sum /src/
RUN cd /src && go mod download
WORKDIR /src
RUN go mod download

# BUILD BINARY
COPY relay /src/relay
COPY datastreamer /src/datastreamer
COPY log /src/log
COPY Makefile version.go config/environments/testnet/config.toml /src/
RUN cd /src && make build-dsrelay

RUN make build-dsrelay

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.19.0
Expand All @@ -21,10 +21,10 @@ COPY --from=build /src/dist/dsrelay /app/dsrelay
COPY --from=build /src/config.toml /app/sample.config.toml

ARG USER=dsrelay
ENV HOME /home/$USER
ENV HOME=/home/$USER
RUN adduser -D $USER
USER $USER
WORKDIR $HOME

EXPOSE 7900
CMD ["/bin/sh", "-c", "/app/dsrelay"]
CMD ["/bin/sh", "-c", "/app/dsrelay"]
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ check-docker:
@which docker > /dev/null || (echo "Error: docker is not installed" && exit 1)

# Targets that require the checks
run-server: check-go
build-dsapp: check-go
build-dsrelay: check-go
build-docker: check-docker
build-docker-nc: check-docker

.PHONY: install-linter
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.52.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.59.1

.PHONY: lint
lint: ## Runs the linter
Expand All @@ -45,7 +44,7 @@ build-docker-nc: ## Builds a docker image with datastream relay binary but witho

.PHONY: test
test:
go test -count=1 -short -race -p 1 -timeout 60s ./...
go test -coverprofile coverage.out -count=1 -short -race -p 1 -timeout 60s ./...

## Help display.
## Pulls comments from beside commands and prints a nicely formatted
Expand All @@ -57,3 +56,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}'

generate-code-from-proto: ## Generates code from proto files
cd proto/datastream/v1 && protoc --proto_path=. --proto_path=../../include --go_out=../../../datastream --go-grpc_out=../../../datastream --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative datastream.proto
118 changes: 78 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,43 +294,81 @@ Sequencer data stream service to stream L2 blocks and L2 txs

List of events (entry types):

### Start L2 Block
- Entry type = 1
- Entry data:
>u64 batchNum
>u64 blockL2Num
>u64 timestamp
>u32 deltaTimestamp
>u32 L1InfoTreeIndex
>u8[32] l1BlockHash
>u8[32] globalExitRoot
>u8[20] coinbase
>u16 forkID
>u32 chainID

### L2 TX
- Entry type = 2
- Entry data:
>u8 gasPricePercentage
>u8 isValid // Intrinsic
>u8[32] stateRoot
>u32 encodedTXLength
>u8[] encodedTX

### End L2 Block
- Entry type = 3
- Entry data:
>u64 blockL2Num
>u8[32] l2BlockHash
>u8[32] stateRoot

### Update GER
- Entry type = 4
- Entry data:
>u64 batchNum
>u64 timestamp
>u8[32] globalExitRoot
>u8[20] coinbase
>u16 forkID
>u32 chainID
>u8[32] stateRoot
### BatchStart:
uint64 number
BatchType type
uint64 fork_id
uint64 chain_id
Debug debug

### BatchEnd:
uint64 number
bytes local_exit_root
bytes state_root
Debug debug

### L2Block:
uint64 number
uint64 batch_number
uint64 timestamp
uint32 delta_timestamp
uint64 min_timestamp
bytes l1_blockhash
uint32 l1_infotree_index
bytes hash
bytes state_root
bytes global_exit_root
bytes coinbase
uint64 block_gas_limit
bytes block_info_root
Debug debug

### L2BlockEnd:
uint64 number

### Transaction:
uint64 l2block_number
uint64 index
bool is_valid
bytes encoded
uint32 effective_gas_price_percentage
bytes im_state_root
Debug debug

### UpdateGER:
uint64 batch_number
uint64 timestamp
bytes global_exit_root
bytes coinbase
uint64 fork_id
uint64 chain_id
bytes state_root
Debug debug

### BookMark:
BookmarkType type
uint64 value

### Debug:
string message

### BookmarkType:
BOOKMARK_TYPE_UNSPECIFIED = 0;
BOOKMARK_TYPE_BATCH = 1;
BOOKMARK_TYPE_L2_BLOCK = 2;

### EntryType:
ENTRY_TYPE_UNSPECIFIED = 0;
ENTRY_TYPE_BATCH_START = 1;
ENTRY_TYPE_L2_BLOCK = 2;
ENTRY_TYPE_TRANSACTION = 3;
ENTRY_TYPE_BATCH_END = 4;
ENTRY_TYPE_UPDATE_GER = 5;
ENTRY_TYPE_L2_BLOCK_END = 6;

### BatchType:
BATCH_TYPE_UNSPECIFIED = 0;
BATCH_TYPE_REGULAR = 1;
BATCH_TYPE_FORCED = 2;
BATCH_TYPE_INJECTED = 3;
BATCH_TYPE_INVALID = 4;
Loading
Loading