diff --git a/.github/auto_request_review.yml b/.github/auto_request_review.yml new file mode 100644 index 0000000..bc48a57 --- /dev/null +++ b/.github/auto_request_review.yml @@ -0,0 +1,15 @@ +reviewers: + defaults: + - rollkit + groups: + rollkit: + - team:core +files: + ".github/**": + - MSevey + - rollkit +options: + ignore_draft: true + ignored_keywords: + - WIP + number_of_reviewers: 3 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..17cbb6c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,41 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + labels: + - T:dependencies + # Group all patch updates into a single PR + groups: + patch-updates: + applies-to: version-updates + update-types: + - "patch" + - package-ecosystem: gomod + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + labels: + - T:dependencies + # Group all patch updates into a single PR + groups: + patch-updates: + applies-to: version-updates + update-types: + - "patch" + - package-ecosystem: docker + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + labels: + - T:dependencies + # Group all patch updates into a single PR + groups: + patch-updates: + applies-to: version-updates + update-types: + - "patch" diff --git a/.github/workflows/ci_release.yml b/.github/workflows/ci_release.yml new file mode 100644 index 0000000..3dda0de --- /dev/null +++ b/.github/workflows/ci_release.yml @@ -0,0 +1,44 @@ +name: CI and Release +on: + push: + branches: + - main + # Trigger on version tags + tags: + - 'v*' + pull_request: + merge_group: + workflow_dispatch: + # Inputs the workflow accepts. + inputs: + version: + # Friendly description to be shown in the UI instead of 'name' + description: "Semver type of new version (major / minor / patch)" + # Input has to be provided for the workflow to run + required: true + type: choice + options: + - patch + - minor + - major + +jobs: + lint: + uses: ./.github/workflows/lint.yml + + test: + uses: ./.github/workflows/test.yml + + # Make a release if this is a manually trigger job, i.e. workflow_dispatch + release: + needs: [lint, test] + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' }} + permissions: "write-all" + steps: + - uses: actions/checkout@v4 + - name: Version Release + uses: rollkit/.github/.github/actions/version-release@v0.4.1 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + version-bump: ${{inputs.version}} diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml new file mode 100644 index 0000000..76eb843 --- /dev/null +++ b/.github/workflows/housekeeping.yml @@ -0,0 +1,85 @@ +name: Housekeeping + +on: + issues: + types: [opened] + pull_request_target: + types: [opened, ready_for_review] + +jobs: + issue-management: + if: ${{ github.event.issue }} + name: Add issues to project and add triage label + uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.4.1 + secrets: inherit + permissions: + issues: write + pull-requests: write + with: + run-labels: true + labels-to-add: "needs-triage" + run-projects: true + project-url: https://github.com/orgs/rollkit/projects/7 + + add-pr-to-project: + # ignore dependabot PRs + if: ${{ github.event.pull_request && github.actor != 'dependabot[bot]' }} + name: Add PRs to project + uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.4.1 + secrets: inherit + permissions: + issues: write + pull-requests: write + with: + run-projects: true + project-url: https://github.com/orgs/rollkit/projects/7 + + auto-add-reviewer: + name: Auto add reviewer to PR + if: github.event.pull_request + uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.4.1 + secrets: inherit + permissions: + issues: write + pull-requests: write + with: + run-auto-request-review: true + + auto-add-assignee-pr: + # ignore dependabot PRs + if: ${{ github.event.pull_request && github.actor != 'dependabot[bot]' }} + name: Assign PR to creator + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Set pull_request url and creator login + # yamllint disable rule:line-length + run: | + echo "PR=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV + echo "CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV + # yamllint enable rule:line-length + - name: Assign PR to creator + run: gh pr edit ${{ env.PR }} --add-assignee ${{ env.CREATOR }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + auto-add-assignee-label: + if: ${{ github.event.issue }} + name: Assign issue to creator + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + - name: Set issue number and creator login + run: | + echo "ISSUE=${{ github.event.issue.number }}" >> $GITHUB_ENV + echo "CREATOR=${{ github.event.issue.user.login }}" >> $GITHUB_ENV + - name: Assign issue to creator + run: gh issue edit ${{ env.ISSUE }} --add-assignee ${{ env.CREATOR }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..19a98ca --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,50 @@ +# lint runs all linters in this repository +# This workflow is triggered by ci_release.yml workflow +name: lint +on: + workflow_call: + +jobs: + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: ./go.mod + # This steps sets the GIT_DIFF environment variable to true + # if files defined in PATTERS changed + - uses: technote-space/get-diff-action@v6.1.2 + with: + # This job will pass without running if go.mod, go.sum, and *.go + # wasn't modified. + PATTERNS: | + **/**.go + go.mod + go.sum + - uses: golangci/golangci-lint-action@v6.1.0 + with: + version: latest + args: --timeout 10m + github-token: ${{ secrets.github_token }} + if: env.GIT_DIFF + + # hadolint lints the Dockerfile +# hadolint: +# uses: rollkit/.github/.github/workflows/reusable_dockerfile_lint.yml@v0.4.1 # yamllint disable-line rule:line-length +# with: +# dockerfile: Dockerfile +# failure-threshold: error + + yamllint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rollkit/.github/.github/actions/yamllint@v0.4.1 + + markdown-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rollkit/.github/.github/actions/markdown-lint@v0.4.1 diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml new file mode 100644 index 0000000..e11fe30 --- /dev/null +++ b/.github/workflows/semantic-pull-request.yml @@ -0,0 +1,20 @@ +name: Semantic Pull Request + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + main: + name: conventional-commit-pr-title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/semantic_release.yml b/.github/workflows/semantic_release.yml new file mode 100644 index 0000000..c5f1d5d --- /dev/null +++ b/.github/workflows/semantic_release.yml @@ -0,0 +1,24 @@ +name: Semantic Release + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Configure Semantic Release + # Work around for non npm project + # REF: https://github.com/cycjimmy/semantic-release-action/issues/115#issuecomment-1817264419 + run: echo '{"branches":[],"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator","@semantic-release/github"]}' > .releaserc.json + - name: Create Release + uses: cycjimmy/semantic-release-action@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + branches: | + ["main"] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..655450c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +# Tests / Code Coverage workflow +# This workflow is triggered by ci_release.yml workflow +name: Tests / Code Coverage +on: + workflow_call: + +jobs: + go_mod_tidy_check: + name: Go Mod Tidy Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: ./go.mod + - run: go mod tidy + - name: check for diff + run: git diff --exit-code + + unit_test: + name: Run Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: set up go + uses: actions/setup-go@v5 + with: + go-version-file: ./go.mod + - name: Run unit test + run: make test + - name: upload coverage report + uses: codecov/codecov-action@v4.5.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + + integration_test: + name: Run Integration Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: set up go + uses: actions/setup-go@v5 + with: + go-version-file: ./go.mod + - name: Integration Tests + run: echo "No integration tests yet" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d85cb58 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,49 @@ +run: + timeout: 5m + modules-download-mode: readonly + +linters: + enable: + - errorlint + - errcheck + - gofmt + - goimports + - gosec + - gosimple + - govet + - ineffassign + - misspell + - revive + - staticcheck + - typecheck + - unconvert + - unused + +issues: + exclude-use-default: false + # mempool and indexer code is borrowed from Tendermint + exclude-dirs: + - mempool + - state/indexer + - state/txindex + - third_party + include: + - EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments + - EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments + +linters-settings: + gosec: + excludes: + - G115 + revive: + rules: + - name: package-comments + disabled: true + - name: duplicated-imports + severity: warning + - name: exported + arguments: + - disableStutteringCheck + + goimports: + local-prefixes: github.com/rollkit diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..6369b8d --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,6 @@ +default: true +MD010: + code_blocks: false +MD013: false +MD024: + allow_different_nesting: true diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..cd2a9e8 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,9 @@ +--- +# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html +extends: default + +rules: + # 120 chars should be enough, but don't fail if a line is longer + line-length: + max: 120 + level: warning diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..226e09a --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +# Define pkgs, run, and cover vairables for test so that we can override them in +# the terminal more easily. +pkgs := $(shell go list ./...) +run := . +count := 1 + +## help: Show this help message +help: Makefile + @echo " Choose a command run in "$(PROJECTNAME)":" + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' +.PHONY: help + +## clean: clean testcache +clean: + @echo "--> Clearing testcache" + @go clean --testcache +.PHONY: clean + +## cover: generate to code coverage report. +cover: + @echo "--> Generating Code Coverage" + @go install github.com/ory/go-acc@latest + @go-acc -o coverage.txt $(pkgs) +.PHONY: cover + +## deps: Install dependencies +deps: + @echo "--> Installing dependencies" + @go mod download +# @make proto-gen + @go mod tidy +.PHONY: deps + +## lint: Run linters golangci-lint and markdownlint. +lint: vet + @echo "--> Running golangci-lint" + @golangci-lint run + @echo "--> Running markdownlint" + @markdownlint --config .markdownlint.yaml '**/*.md' + @echo "--> Running yamllint" + @yamllint --no-warnings . -c .yamllint.yml + +.PHONY: lint + +## fmt: Run fixes for linters. Currently only markdownlint. +fmt: + @echo "--> Formatting markdownlint" + @markdownlint --config .markdownlint.yaml '**/*.md' -f + @echo "--> Formatting go" + @golangci-lint run --fix +.PHONY: fmt + +## vet: Run go vet +vet: + @echo "--> Running go vet" + @go vet $(pkgs) +.PHONY: vet + +## test: Running unit tests +test: vet + @echo "--> Running unit tests" + @go test -v -race -covermode=atomic -coverprofile=coverage.txt $(pkgs) -run $(run) -count=$(count) +.PHONY: test diff --git a/README.md b/README.md index 7358c7c..464cba8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # based-sequencer + Based sequencer that implements go-sequencing interface diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c68b54d --- /dev/null +++ b/go.mod @@ -0,0 +1,19 @@ +module github.com/rollkit/based-sequencer + +go 1.23.1 + +require ( + github.com/rollkit/go-da v0.7.0 + github.com/rollkit/go-sequencing v0.0.0-20240924073851-5e3b8522a072 +) + +require ( + github.com/cosmos/gogoproto v1.7.0 // indirect + github.com/google/go-cmp v0.6.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect + google.golang.org/grpc v1.67.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..533d742 --- /dev/null +++ b/go.sum @@ -0,0 +1,30 @@ +github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro= +github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rollkit/go-da v0.7.0 h1:b4o5dWCCqwH0fbbhfNOoLraAsCHjN5PV1Z2rNkUB+pU= +github.com/rollkit/go-da v0.7.0/go.mod h1:9YCbEhUkF/QHbbKPBe5uvu93Co/mgPRtYjlwj6GPuhI= +github.com/rollkit/go-sequencing v0.0.0-20240924073851-5e3b8522a072 h1:ryzQ53hpEZ/tzsweDkEFUP3ovFcmi0IBye4JhCNIs+8= +github.com/rollkit/go-sequencing v0.0.0-20240924073851-5e3b8522a072/go.mod h1:s/3XzHYeY+bximgM8PDdQmoe9aWBSOa4NDQmBxpMJ4A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= +google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sequencer.go b/sequencer.go new file mode 100644 index 0000000..89db3ab --- /dev/null +++ b/sequencer.go @@ -0,0 +1,42 @@ +package based_sequencer + +import ( + "context" + "time" + + "github.com/rollkit/go-da" + "github.com/rollkit/go-sequencing" +) + +// BasedSequencer implements go-sequencing API with based sequencing logic. +// +// All transactions are passed directly to DA to be saved in a namespace. Each transaction is submitted as separate blob. +// When batch is requested DA blocks are scanned to read all blobs from given namespace at given height. +type BasedSequencer struct { + da da.DA +} + +// NewSequencer initializes a BasedSequencer with the provided DA implementation. +func NewSequencer(da da.DA) *BasedSequencer { + return &BasedSequencer{da: da} +} + +var _ sequencing.Sequencer = (*BasedSequencer)(nil) + +// SubmitRollupTransaction submits a transaction directly to DA, as a single blob. +func (b *BasedSequencer) SubmitRollupTransaction(ctx context.Context, rollupId sequencing.RollupId, tx sequencing.Tx) error { + //TODO implement me + panic("implement me") +} + +// GetNextBatch reads data from namespace in DA and builds transactions batches. +func (b *BasedSequencer) GetNextBatch(ctx context.Context, lastBatchHash sequencing.Hash) (*sequencing.Batch, time.Time, error) { + //TODO implement me + panic("implement me") +} + +// VerifyBatch ensures data-availability of a batch in DA. +func (b *BasedSequencer) VerifyBatch(ctx context.Context, batchHash sequencing.Hash) (bool, error) { + //TODO implement me + panic("implement me") +}