From 63ea304af82d868ff0d9a98be3a7fea6b078ba11 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Wed, 17 Jul 2024 09:38:31 +0400 Subject: [PATCH] add initial interface definitions and generator code --- README.md | 7 +++++ buf.gen.yaml | 10 +++++++ buf.yaml | 27 ++++++++++++++++++ go.mod | 2 +- proto/gen.sh | 10 +++++++ proto/protoc.sh | 5 ++++ proto/sequencing/sequencing.proto | 47 +++++++++++++++++++++++++++++++ sequencing.go | 27 ++++++++++++++++++ 8 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 buf.gen.yaml create mode 100644 buf.yaml create mode 100644 proto/gen.sh create mode 100644 proto/protoc.sh create mode 100644 proto/sequencing/sequencing.proto create mode 100644 sequencing.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5b36ed --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# go-sequencing + +go-sequencing defines a generic sequencing interface for modular blockchains + +## Sequencing Interface + +## Implementations \ No newline at end of file diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 0000000..bbf312a --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,10 @@ +version: v1beta1 + +# The plugins to run. +plugins: + # The name of the plugin. + - name: gogofaster + # The the relative output directory. + out: types/pb + # Any options to provide to the plugin. + opt: plugins=grpc,paths=source_relative \ No newline at end of file diff --git a/buf.yaml b/buf.yaml new file mode 100644 index 0000000..a9b0f7d --- /dev/null +++ b/buf.yaml @@ -0,0 +1,27 @@ +version: v1beta1 + +build: + roots: + - proto + - third_party/proto +lint: + use: + - DEFAULT + - 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: + - tendermint +breaking: + use: + - FILE \ No newline at end of file diff --git a/go.mod b/go.mod index 77d492d..e896641 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/rollkit/template-da-repo +module github.com/rollkit/go-sequencing go 1.21.0 diff --git a/proto/gen.sh b/proto/gen.sh new file mode 100644 index 0000000..a34875d --- /dev/null +++ b/proto/gen.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# see: https://stackoverflow.com/a/246128 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"/.. +TARGET_DIR=./types/pb + +cd $SCRIPT_DIR +mkdir -p $TARGET_DIR +rm -rf $TARGET_DIR/* +docker run -u $UID:$(id -g) -e XDG_CACHE_HOME=/tmp/.cache -v $PWD:/workspace --workdir /workspace tendermintdev/docker-build-proto sh ./proto/protoc.sh \ No newline at end of file diff --git a/proto/protoc.sh b/proto/protoc.sh new file mode 100644 index 0000000..60d8606 --- /dev/null +++ b/proto/protoc.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eo pipefail + +buf generate --path="./proto/sequencing" --template="buf.gen.yaml" --config="buf.yaml" \ No newline at end of file diff --git a/proto/sequencing/sequencing.proto b/proto/sequencing/sequencing.proto new file mode 100644 index 0000000..5d5501e --- /dev/null +++ b/proto/sequencing/sequencing.proto @@ -0,0 +1,47 @@ +syntax = "proto3"; +package rollkit; + +// SequencerInput ... +service SequencerInput { + // SubmitRollupTransaction ... + rpc SubmitRollupTransaction(SubmitRollupTransactionRequest) returns (SubmitRollupTransactionResponse) {} +} + +// SubmitRollupTransactionRequest ... +message SubmitRollupTransactionRequest { + // the unhashed rollup id + bytes rollup_id = 1; + // the raw data bytes of the rollup transaction + bytes data = 2; +} + +// SubmitRollupTransactionResponse ... +message SubmitRollupTransactionResponse { +} + +// SequencerOutput ... +service SequencerOutput { + // SubmitRollupTransaction ... + rpc GetNextBatch(BatchRequest) returns (BatchResponse) {} +} + +// BatchRequest provides the last batch while requesting for the next batch +message BatchRequest { + repeated bytes transactions = 1; +} + +// BatchResponse contains the transaction batch that is last sequenced +message BatchResponse { + repeated bytes transactions = 1; +} + +// BatchVerifier +service BatchVerifier { + // VerifyBatch ... + rpc VerifyBatch(BatchRequest) returns VerificationResponse {} +} + +// VerificationResponse +message VerificationResponse { + bool success = 1; +} diff --git a/sequencing.go b/sequencing.go new file mode 100644 index 0000000..db9b915 --- /dev/null +++ b/sequencing.go @@ -0,0 +1,27 @@ +package sequencing + +// SequencerInput provides a method for submitting a transaction from rollup to sequencer +type SequencerInput interface { + // SubmitRollupTransaction submits a transaction from rollup to sequencer + SubmitRollupTransaction(rollupId RollupId, tx Tx) error +} + +// SequencerOutput provides a method for getting the next batch of transactions from sequencer to rollup +type SequencerOutput interface { + // GetNextBatch returns the next batch of transactions from sequencer to rollup + // lastBatch is the last batch of transactions received from the sequencer + // returns the next batch of transactions and an error if any from the sequencer + GetNextBatch(lastBatch []Tx) ([]Tx, error) +} + +// BatchVerifier provides a method for verifying a batch of transactions received from the sequencer +type BatchVerifier interface { + // VerifyBatch verifies a batch of transactions received from the sequencer + VerifyBatch(batch []Tx) (bool, error) +} + +// RollupId is a unique identifier for a rollup chain +type RollupId = []byte + +// Tx is a rollup transaction +type Tx = []byte