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

chore(repo): add blob-catcher to monorepo #16353

Merged
merged 21 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 .github/workflows/validate-pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
main
deps
deps-dev
blob-catcher
branding
bridge-ui
eventindexer
Expand Down
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"packages/blob-catcher": "0.1.0",
"packages/branding": "0.3.0",
"packages/bridge-ui": "3.0.0",
"packages/eventindexer": "0.13.0",
Expand Down
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Make a contribution](#make-a-contribution)
- [Coding standards](#coding-standards)
- [Documentation standards](#documentation-standards)
- [Engineering tasks](#engineering-tasks)

## Make a contribution

Expand Down Expand Up @@ -211,6 +212,7 @@ struct Some {
```

#### For-loop

The variable in the for-loop shall not be initialized with 0, and we enforce using `++var` instead of `var++``.

This is **correct**:
Expand Down Expand Up @@ -349,3 +351,15 @@ For consistency throughout the project, please use **American English**.
If you are interested in creating some content (video, blog post, tweet thread, visuals, etc.), you are absolutely free to do so. It's useful to get a peer review on these, if you need a peer review please reach out to the community / team on the [Taiko Discord](https://discord.gg/taikoxyz).

If you are looking for some more guidance on creating content, you can consult the [Taiko content guide](https://hackmd.io/@taikolabs/BJurgF1bn).

## Engineering tasks

### Adding a new repo to the monorepo

1. Add the repo to `packages/*`
2. Integrate the repo into the monorepos root dependencies (we use a root go modules and pnpm workspace)
3. Add the repo scope to the `validate-pr-title.yml` workflow
4. Add a package.json with an initial version `0.1.0`
5. Add the package to `release-please-config.json` and the initial version to `.release-please-manifest.json`
6. Ensure the repo has a README
7. Add repo to monorepo README project structure
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ taiko-mono/
├── <a href="./LICENSE.md">LICENSE.md</a>
├── <a href="./README.md">README.md</a>
├── <a href="./packages">packages</a>
│ ├── <a href="./packages/branding">blob-storage</a>: Blob storage service.
│ ├── <a href="./packages/branding">branding</a>: Taiko branding materials.
│ ├── <a href="./packages/bridge-ui">bridge-ui</a>: Bridge UI.
│ ├── <a href="./packages/eventindexer">eventindexer</a>: Event indexer.
│ ├── <a href="./packages/fork-diff">fork-diff</a>: Fork diff page.
│ ├── <a href="./packages/guardian-prover-health-check">guardian-prover-health-check</a>: Guardian prover health check service.
│ ├── <a href="./packages/guardian-prover-health-check-ui">guardian-prover-health-check-ui</a>: Guardian prover health check UI.
│ ├── <a href="./packages/protocol">protocol</a>: Taiko protocol and bridge smart contracts.
│ └── <a href="./packages/relayer">relayer</a>: Bridge backend relayer in Go.
│ ├── <a href="./packages/protocol">protocol</a>: Taiko protocol smart contracts.
│ └── <a href="./packages/relayer">relayer</a>: Bridge backend relayer.
...
</pre>

Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/go-git/go-git/v5 v5.11.0
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/joho/godotenv v1.5.1
github.com/labstack/echo-contrib v0.15.0
github.com/labstack/echo/v4 v4.11.4
Expand All @@ -28,6 +29,7 @@ require (
github.com/swaggo/swag v1.16.3
github.com/testcontainers/testcontainers-go v0.28.0
github.com/urfave/cli/v2 v2.27.1
go.mongodb.org/mongo-driver v1.14.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/sync v0.6.0
gopkg.in/go-playground/assert.v1 v1.2.1
Expand Down Expand Up @@ -131,6 +133,7 @@ require (
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/morkid/gocache v1.0.0 // indirect
github.com/neko-neko/echo-logrus/v2 v2.0.1 // indirect
Expand Down Expand Up @@ -161,7 +164,11 @@ require (
github.com/valyala/fasthttp v1.44.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.20.0 // indirect
Expand Down
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down Expand Up @@ -480,6 +482,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/morkid/gocache v1.0.0 h1:hTnU78Dqp2vs9al5vJC2TmmMF+Hm3nDH1AgRBjSXE+0=
Expand Down Expand Up @@ -656,6 +660,12 @@ github.com/vertica/vertica-sql-go v1.3.3 h1:fL+FKEAEy5ONmsvya2WH5T8bhkvY27y/Ik3R
github.com/vertica/vertica-sql-go v1.3.3/go.mod h1:jnn2GFuv+O2Jcjktb7zyc4Utlbu9YVqpHH/lx63+1M4=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand All @@ -671,6 +681,8 @@ github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf h1:ck
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
github.com/ydb-platform/ydb-go-sdk/v3 v3.55.1 h1:Ebo6J5AMXgJ3A438ECYotA0aK7ETqjQx9WoZvVxzKBE=
github.com/ydb-platform/ydb-go-sdk/v3 v3.55.1/go.mod h1:udNPW8eupyH/EZocecFmaSNJacKKYjzQa7cVgX5U2nc=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
Expand All @@ -680,6 +692,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZx8cOF0+Kkazoc7lwUNMGy0LrzEMxTm4BbTxg=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q=
go.opentelemetry.io/otel v1.20.0 h1:vsb/ggIY+hUjD/zCAQHpzTmndPqv/ml2ArbsbfBYTAc=
Expand Down Expand Up @@ -842,6 +856,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
Expand Down
21 changes: 21 additions & 0 deletions packages/blob-storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
61 changes: 61 additions & 0 deletions packages/blob-storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# blob-storage

Repo for BLOB storage (archive and serve data)

## how to run ?

Prerequisite is to have docker engine up and running.

1. Start the mongoDB

```bash
cd local_docker && docker-compose up -d
```

2. Start the `blob-catcher`

```bash
cd cmd/blob_catcher && go run .
```

By default the above command starts the app from the latest block height. If we want to specifiy a previous blockheight, we can run it like:

```bash
cd cmd/blob_catcher && go run . -past_events=true -start_block=117452
```

2. Start the `server` - by default it listens on port `27001` (sets in `config.go`)

```bash
cd cmd/server && go run .
```

It uses the config from `internal/logic/config.go`.

## how to test / use ?

When the `DB`, `blob-catcher` and `server` is running, the `blob-catcher` is outputting the `blobHash` to the terminal (with the `networkName` variable too, tho it is not written into the DB). Use that `blobHash` (including the 0x) in

1. Either in a curl command like this (you can query multiple blobHashes - comma separated - with one go and the result will be a respective array):

```bash
curl -X GET "http://localhost:27001/getBlob?blobHash=0x01a2a1cdc7ad221934061642a79a760776a013d0e6fa1a1c6b642ace009c372a,0xWRONG_HASH"
```

The result will be something like this:

```bash
{"data":[{"blob":"0x123...00","kzg_commitment":"0xabd68b406920aa74b83cf19655f1179d373b5a8cba21b126b2c18baf2096c8eb9ab7116a89b375546a3c30038485939e"}, {"blob":"NOT_FOUND","kzg_commitment":"NOT_FOUND"}]}
```

2. Or to backtest, use the simple python script below, after overwriting the `blob_hash` variable:

```bash
python3 python_query.py
```

## todos

What is still missing is:

- small refinements and DevOps (prod-grade DB with creditentials, proper containerization)
41 changes: 41 additions & 0 deletions packages/blob-storage/cmd/blob_catcher/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"flag"
"log"
"math/big"
"strconv"

"github.com/taikoxyz/taiko-mono/packages/blob-storage/internal/indexer"
"github.com/taikoxyz/taiko-mono/packages/blob-storage/internal/logic"
)

func main() {
// Define command-line flags
pastEvents := flag.Bool("past_events", false, "Enable indexing past events")
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
startBlock := flag.String("start_block", "", "Block number to start indexing from")

// Parse command-line flags
flag.Parse()

// Convert start block number to *big.Int if provided
var startBlockNumber *big.Int
if *startBlock != "" {
n, err := strconv.ParseInt(*startBlock, 10, 64)
if err != nil {
log.Fatalf("Invalid start block number: %v", err)
}
startBlockNumber = big.NewInt(n)
}

// Load configuration
cfg, err := logic.GetConfig()
if err != nil {
log.Fatal("Error loading config:", err)
}

// Initialize indexer with optional parameters
if err := indexer.InitFromConfig(cfg, *pastEvents, startBlockNumber); err != nil {
log.Fatal("Error running indexer:", err)
}
}
19 changes: 19 additions & 0 deletions packages/blob-storage/cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"log"

"github.com/taikoxyz/taiko-mono/packages/blob-storage/internal/logic"
)

func main() {
cfg, err := logic.GetConfig()
if err != nil {
log.Fatal("Error loading config:", err)
}

srv := logic.NewServer(cfg)
if err := srv.Start(); err != nil {
log.Fatal("Error starting server:", err)
}
}
94 changes: 94 additions & 0 deletions packages/blob-storage/internal/indexer/indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package indexer

import (
"context"
"log"
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)

// Indexer struct holds the configuration and state for the Ethereum chain listener.
type Indexer struct {
rpcURL string
beaconURL string
networkName string
contractAddress common.Address
eventHash common.Hash
startHeight *big.Int
eventCallbackFunc func(string, string, string, types.Log)
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
}

// NewIndexer creates a new Indexer instance.
func NewIndexer(rpcURL, beaconURL, networkName, contractAddress string, pastEvents bool, startBlockNumber *big.Int) *Indexer {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
client, err := ethclient.Dial(rpcURL)
if err != nil {
log.Fatal("Failed to connect to the Ethereum client:", err)
}

if pastEvents == false {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
header, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
startBlockNumber = header.Number
}

slog.Info(client.Client())

cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
return &Indexer{
rpcURL: rpcURL,
beaconURL: beaconURL,
networkName: networkName,
contractAddress: common.HexToAddress(contractAddress),
startHeight: startBlockNumber,
}
}

// SubscribeEvent subscribes to the specified event.
func (indexer *Indexer) SubscribeEvent(eventHash string, callbackFunc func(string, string, string, types.Log)) {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
indexer.eventHash = common.HexToHash(eventHash)
indexer.eventCallbackFunc = callbackFunc
}

// Start starts the Ethereum chain listener/indexer.
func (indexer *Indexer) Start() {
client, err := ethclient.Dial(indexer.rpcURL)
if err != nil {
log.Fatal("Failed to connect to the Ethereum client:", err)
}

query := ethereum.FilterQuery{
Addresses: []common.Address{indexer.contractAddress},
FromBlock: indexer.startHeight,
}

logsCh := make(chan types.Log)
sub, err := client.SubscribeFilterLogs(context.Background(), query, logsCh)
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Fatal("Failed to subscribe to logs:", err)
}

log.Println("Indexer for ", indexer.networkName, " started.")
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved

log.Println("Scraping from blockheight: ", indexer.startHeight)

for {
select {
case err := <-sub.Err():
log.Fatal("Subscription error:", err)
case log := <-logsCh:
if log.Topics[0] == indexer.eventHash {
go indexer.HandleEvent(log)
}
}
}
}

// HandleEvent handles the incoming Ethereum event.
func (indexer *Indexer) HandleEvent(log types.Log) {
indexer.eventCallbackFunc(indexer.rpcURL, indexer.beaconURL, indexer.networkName, log)
}
Loading
Loading