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

mock: init #5

Merged
merged 9 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-da
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versioningPath).lastCommit=$(shell git rev-parse HEAD)' -X '$(versioningPath).semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'"
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf

Expand All @@ -7,6 +8,12 @@ pkgs := $(shell go list ./...)
run := .
count := 1

## build: Build mock-da binary.
build:
@echo "--> Building mock-da"
@go build -o build/ ${LDFLAGS} ./...
.PHONY: build

## help: Show this help message
help: Makefile
@echo " Choose a command run in "$(PROJECTNAME)":"
Expand Down Expand Up @@ -54,7 +61,7 @@ fmt:
.PHONY: fmt

## vet: Run go vet
vet:
vet:
@echo "--> Running go vet"
@go vet $(pkgs)
.PHONY: vet
Expand Down
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Mock DA

Mock DA implements the [go-da][go-da] interface over a mock Data Availability service.

It is intended to be used for testing DA layers without having to setup the actual services.
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

## Usage

```sh
make build
./mock-da
```

should output

```sh
2024/04/11 12:23:34 Listening on: localhost:7980
```

Which exposes the [go-da] interface over JSONRPC and can be accessed with a http client like [xh][xh]:
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

### MaxBlobSize

```sh
xh http://127.0.0.1:7980 id=1 method=da.MaxBlobSize | jq
```

output:

```sh
{
"jsonrpc": "2.0",
"result": 1974272,
"id": "1"
}
```

#### Submit

```sh
xh http://127.0.0.1:7980 id=1 method=da.Submit 'params[][]=SGVsbG8gd28ybGQh' 'params[]:=-2' 'params[]=AAAAAAAAAAAAAAAAAAAAAAAAAAECAwQFBgcICRA=' | jq
```

output:

```sh
{
"jsonrpc": "2.0",
"result": [
"AQAAAAAAAADfgz5/IP20UeF81iRRzDBu/qC8eXr9DUyplrfXod3VOA=="
],
"id": "1"
}
```

#### Get

```sh
xh http://127.0.0.1:7980 id=1 method=da.Get 'params[][]=AQAAAAAAAADfgz5/IP20UeF81iRRzDBu/qC8eXr9DUyplrfXod3VOA==' 'params[]=AAAAAAAAAAAAAAAAAAAAAAAAAAECAwQFBgcICRA='
```

output:

```sh
{
"jsonrpc": "2.0",
"result": [
"SGVsbG8gd28ybGQh"
],
"id": "1"
}
```

## References

[1] [go-da][go-da]
[1] [xh][xh]
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

[go-da]: https://github.com/rollkit/go-da
[xh]: https://github.com/ducaale/xh
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions cmd/mock-da/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"context"
"flag"
"fmt"
"log"
"net/url"
"os"
"os/signal"
"syscall"

proxy "github.com/rollkit/go-da/proxy/jsonrpc"
goDATest "github.com/rollkit/go-da/test"
)

const (
// MockDAAddress is the mock address for the gRPC server
MockDAAddress = "grpc://localhost:7980"
)

func main() {
var (
host string
port string
)
addr, _ := url.Parse(MockDAAddress)
flag.StringVar(&port, "port", addr.Port(), "listening port")
flag.StringVar(&host, "host", addr.Hostname(), "listening address")
flag.Parse()
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

srv := proxy.NewServer(host, port, goDATest.NewDummyDA())
log.Printf("Listening on: %s:%s", host, port)
if err := srv.Start(context.Background()); err != nil {
log.Fatal("error while serving:", err)
}
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGINT)
<-interrupt
fmt.Println("\nCtrl+C pressed. Exiting...")
os.Exit(0)
}
98 changes: 98 additions & 0 deletions docs/celestia/errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Celestia Node/Core/App Errors

Exhaustive list of errors returned by celestia node/core/app when trying to submit a PFB transaction. There might be a few duplicates because some errors like `sdkerrors` are wrapped in celestia-app.

## celestia-node

- `SubmitPayForBlob` - `state: no blobs provided`
- `SubmitPayForBlob` - `parsing insufficient min gas price error`
- `SubmitPayForBlob` - `sdkErrors.ABCIError`
- `SubmitPayForBlob` - `failed to submit blobs after %d attempts: %w`

## celestia-app

- `AnteHandle` - `errors.Wrap(sdkerrors.ErrInsufficientFee, "not enough gas to pay for blobs")`
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
- `checkTxFeeWithValidatorMinGasPrices` - `errors.Wrap(sdkerror.ErrTxDecode, "Tx must be a FeeTx")`
- `ValidateBasic` - `ErrNoNamespaces`
- `ValidateBasic` - `ErrNoShareVersions`
- `ValidateBasic` - `ErrNoBlobSizes`
- `ValidateBasic` - `ErrNoShareCommitments`
- `ValidateBasic` - `ErrInvalidNamespace`
- `ValidateBasic` - `ErrUnsupportedShareVersion`
- `ValidateBasic` - `ErrInvalidShareCommitment`
- `ValidateBasic` - `ErrMismatchedNumberOfPFBComponent.Wrapf("namespaces %d blob sizes %d share versions %d share commitments %d)`
- `ValidateBlobNamespace` - `ErrReservedNamespace`
- `ValidateBlobNamespace` - `ErrInvalidNamespaceVersion`
- `ValidateBlobs` - `namespace version %d is too large`
- `ValidateBlobs` - `ErrNoBlobs`
- `ValidateBlobs` - `ErrZeroBlobSize`
- `ValidateBlobs` - `ErrUnsupportedShareVersion`
- `ParseInsufficientMinGasPrice` - `parsing insufficient min gas price error`
- `ParseInsufficientMinGasPrice` - `unexpected case: required gas price is zer`
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

## celestia-core

- `BroadcastTxCommit` - `ErrTimedOutWaitingForTx` - `timed out waiting for tx to be included in a block`
- `BroadcastTxCommit` - `max_subscription_clients %d reached`
- `BroadcastTxCommit` - `max_subscriptions_per_client %d reached`
- `BroadcastTxCommit` - `failed to subscribe to tx: %w`
- `BroadcastTxCommit` - `error on broadcastTxCommit: %v`
- `BroadcastTxCommit` - `deliverTxSub was cancelled (reason: %s)`
- `PreCheck` - `tx size is too big`
- `CheckTx` - `ErrTxTooLarge` - `Tx too large. Max size is %d, but got %d`
- `CheckTx` - `ErrPreCheck` - cosmos-sdk errors, see below
- `CheckTx` - `ErrTxInCache` - `tx already exists in cache`
- `CheckTx` - `ErrMempoolIsFull` - `mempool is full: number of txs %d (max: %d), total txs bytes %d (max: %d)`
- `CheckTx` - `mem.proxyAppConn.Error()` - `proxyAppConn may error if tx buffer is full`
- `PostCheck` - `gas wanted %d is negative`
- `PostCheck` - `gas wanted %d is greater than max gas`
- `TryAddNewTx` - `ErrTxInMempool` - `tx already exists in mempool`
- `TryAddNewTx` - `ErrTxAlreadyRejected` - `tx was previously rejected`
- `TryAddNewTx` - `ErrPreCheck`
- `TryAddNewTx` - `mem.proxyAppConn.Error()`
- `TryAddNewTx` - `application rejected transaction with code %d (Log: %s)`
- `TryAddNewTx` - `rejected bad transaction after post check: %w`

## cosmos-sdk

`ErrTxDecode` - `tx parse error`
`ErrInvalidSequence` - `invalid sequence`
`ErrUnauthorized` - `unauthorized`
`ErrInsufficientFunds` - `insufficient funds`
`ErrUnknownRequest` - `unknown request`
`ErrInvalidAddress` - `invalid address`
`ErrInvalidPubKey` - `invalid pubkey`
`ErrUnknownAddress` - `unknown address`
`ErrInvalidCoins` - `invalid coins`
`ErrOutOfGas` - `out of gas`
`ErrMemoTooLarge` - `memo too large`
`ErrInsufficientFee` - `insufficient fee`
`ErrTooManySignatures` - `maximum number of signatures exceeded`
`ErrNoSignatures` - `no signatures supplied`
`ErrJSONMarshal` - `failed to marshal JSON bytes`
`ErrJSONUnmarshal` - `failed to unmarshal JSON bytes`
`ErrInvalidRequest` - `invalid request`
`ErrTxInMempoolCache` - `tx already in mempool`
`ErrMempoolIsFull` - `mempool is full`
`ErrTxTooLarge` - `tx too large`
`ErrKeyNotFound` - `key not found`
`ErrWrongPassword` - `invalid account password`
`ErrorInvalidSigner` - `tx intended signer does not match the given signer`
`ErrorInvalidGasAdjustment` - `invalid gas adjustment`
`ErrInvalidHeight` - `invalid height`
`ErrInvalidVersion` - `invalid version`
`ErrInvalidChainID` - `invalid chain-id`
`ErrInvalidType` - `invalid type`
`ErrTxTimeoutHeight` - `tx timeout height`
`ErrUnknownExtensionOptions` - `unknown extension options`
`ErrWrongSequence` - `incorrect account sequence`
`ErrPackAny` - `failed packing protobuf message to Any`
`ErrUnpackAny` - `failed unpacking protobuf message from Any`
`ErrLogic` - `internal logic error`
`ErrConflict` - `conflict`
`ErrNotSupported` - `feature not supported`
`ErrNotFound` - `not found`
`ErrIO` - `Internal IO error`
`ErrAppConfig` - `error in app.toml`
`ErrInvalidGasLimit` - `invalid gas limit`
`ErrPanic` - errorsmod.ErrPanic
21 changes: 20 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
module github.com/rollkit/template-da-repo

go 1.21.0
go 1.21.1

require github.com/rollkit/go-da v0.5.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/filecoin-project/go-jsonrpc v0.3.1 // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/ipfs/go-log/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
go.opencensus.io v0.22.3 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading