Skip to content

Commit

Permalink
chore: Initial Execution API (#9)
Browse files Browse the repository at this point in the history
* feat: add Execute interface

* chore: add proto

* feat: add grpc proxy and mocks

* fix: go module path

* feat: grpc proxy

* feat: json rpc proxy

* chore: change github org name

* chore: change pkg path in mockery.yaml

* chore: change go_package in execution.proto

* chore: clean up proto

* chore: remove rollkit as a dependency
  • Loading branch information
jim380 authored Nov 4, 2024
1 parent d7ebaa7 commit 4023188
Show file tree
Hide file tree
Showing 27 changed files with 3,837 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
with-expecter: true
packages:
github.com/rollkit/go-execution:
interfaces:
Execute:
config:
dir: mocks
outpkg: mocks
41 changes: 29 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,32 @@ test: vet
@go test -v -race -covermode=atomic -coverprofile=coverage.txt $(pkgs) -run $(run) -count=$(count)
.PHONY: test

### proto-gen: Generate protobuf files. Requires docker.
#proto-gen:
# @echo "--> Generating Protobuf files"
# ./proto/get_deps.sh
# ./proto/gen.sh
#.PHONY: proto-gen
#
### proto-lint: Lint protobuf files. Requires docker.
#proto-lint:
# @echo "--> Linting Protobuf files"
# @$(DOCKER_BUF) lint --error-format=json
#.PHONY: proto-lint
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

## check-proto-deps: Check protobuf deps
check-proto-deps:
ifeq (,$(shell which protoc-gen-gocosmos))
@go install github.com/cosmos/gogoproto/protoc-gen-gocosmos@latest
endif
.PHONY: check-proto-deps

## proto-gen: Generate protobuf files
proto-gen: check-proto-deps
@echo "--> Generating Protobuf files"
@go run github.com/bufbuild/buf/cmd/buf@latest generate --path proto/execution
.PHONY: proto-gen

## proto-lint: Lint protobuf files.
proto-lint: check-proto-deps
@echo "--> Linting Protobuf files"
@go run github.com/bufbuild/buf/cmd/buf@latest lint --error-format=json
.PHONY: proto-lint

## mock-gen: Re-generates DA mock
mock-gen: mocks/Execute.go
.PHONY: mock-gen

mocks/Execute.go: execution.go .mockery.yaml
@mockery
16 changes: 16 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v1beta1

# The plugins to run.
plugins:
# The name of the plugin.
- name:
gocosmos
# The the relative output directory.
out: types/pb
# Any options to provide to the plugin.
opt:
- Mgoogle/protobuf/timestamp.proto=github.com/cosmos/gogoproto/types
- Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration
- Mgoogle/protobuf/wrappers.proto=github.com/cosmos/gogoproto/types
- plugins=grpc
- paths=source_relative
8 changes: 8 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 88ef6483f90f478fb938c37dde52ece3
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
26 changes: 26 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: v1beta1
deps:
- buf.build/cosmos/gogo-proto
build:
roots:
- proto
lint:
use:
- STANDARD
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
- COMMENT_ENUM
- COMMENT_ENUM_VALUE
- COMMENT_MESSAGE
- COMMENT_RPC
- COMMENT_SERVICE
- COMMENT_FIELD
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
- SERVICE_SUFFIX
- UNARY_RPC
ignore:
breaking:
use:
- FILE
41 changes: 41 additions & 0 deletions execution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package execution

import (
"time"

"github.com/rollkit/go-execution/types"
)

// Execute defines a common interface for interacting with the execution client.
type Execute interface {
// InitChain initializes the blockchain with genesis information.
InitChain(
genesisTime time.Time,
initialHeight uint64,
chainID string,
) (
stateRoot types.Hash,
maxBytes uint64,
err error,
)

// GetTxs retrieves all available transactions from the execution client's mempool.
GetTxs() ([]types.Tx, error)

// ExecuteTxs executes a set of transactions to produce a new block header.
ExecuteTxs(
txs []types.Tx,
blockHeight uint64,
timestamp time.Time,
prevStateRoot types.Hash,
) (
updatedStateRoot types.Hash,
maxBytes uint64,
err error,
)

// SetFinal marks a block at the given height as final.
SetFinal(
blockHeight uint64,
) error
}
60 changes: 58 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
module github.com/rollkit/template-da-repo
module github.com/rollkit/go-execution

go 1.21.0
go 1.22

toolchain go1.22.4

require (
github.com/celestiaorg/go-header v0.6.2
github.com/cosmos/gogoproto v1.5.0
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.65.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.35.0 // indirect
github.com/libp2p/go-libp2p-pubsub v0.11.0 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.13.0 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)

// Add other dependencies as needed
Loading

0 comments on commit 4023188

Please sign in to comment.