Skip to content

Commit

Permalink
Merge branch 'main' into check-gasleft
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Apr 4, 2024
2 parents d982b7b + 08034a1 commit 6833bb8
Show file tree
Hide file tree
Showing 41 changed files with 473 additions and 354 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/bridge-ui-preview-internal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_BRIDGE_UI_INTERNAL }}

on:
push:
branches-ignore:
- main
- release-please-*
paths:
- "packages/bridge-ui/**"

jobs:
Deploy-Preview:
runs-on: [taiko-runner]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install pnpm dependencies
uses: ./.github/actions/install-pnpm-dependencies

- name: Install Vercel CLI
run: pnpm add --global vercel@latest

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
37 changes: 16 additions & 21 deletions .github/workflows/bridge-ui-preview.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Vercel Preview Deployment

env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_BRIDGE_UI }}

on:
push:
Expand All @@ -14,25 +13,21 @@ on:
jobs:
Deploy-Preview:
runs-on: [taiko-runner]
strategy:
matrix:
org: ["Public", "Internal"]
include:
- org: "Public"
org_id_secret: "VERCEL_ORG_ID"
project_id_secret: "VERCEL_PROJECT_ID_BRIDGE_UI"
- org: "Internal"
org_id_secret: "VERCEL_ORG_ID"
project_id_secret: "VERCEL_PROJECT_ID_BRIDGE_UI_INTERNAL"
steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v4

- name: Install pnpm dependencies
uses: ./.github/actions/install-pnpm-dependencies

- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Setup Vercel Environment for ${{ matrix.org }}
run: |
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} --scope=${{ secrets[matrix.org_id_secret] }} --project-id=${{ secrets[matrix.project_id_secret] }}
vercel link --token=${{ secrets.VERCEL_TOKEN }} --confirm --name=${{ matrix.org }} --scope=${{ secrets[matrix.org_id_secret] }}
- name: Build Project Artifacts for ${{ matrix.org }}
run: pnpm add --global vercel@latest

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel for ${{ matrix.org }}

- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.21
require (
github.com/buildkite/terminal-to-html/v3 v3.8.0
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/cyberhorsey/errors v0.0.0-20220929234051-087d6d8bb841
github.com/cyberhorsey/webutils v0.0.0-20230314183728-56890c6ddbe7
github.com/davecgh/go-spew v1.1.1
github.com/ethereum-optimism/optimism v1.7.0
github.com/ethereum-optimism/optimism v1.7.2
github.com/ethereum/go-ethereum v1.13.14
github.com/go-git/go-git/v5 v5.11.0
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
Expand All @@ -35,7 +35,7 @@ require (
gopkg.in/yaml.v3 v3.0.1
gorm.io/datatypes v1.2.0
gorm.io/driver/mysql v1.5.6
gorm.io/gorm v1.25.8
gorm.io/gorm v1.25.9
gotest.tools v2.2.0+incompatible
)

Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ github.com/buildkite/terminal-to-html/v3 v3.8.0/go.mod h1:j3XxsnYElte/Bo7Pft+U5e
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
Expand Down Expand Up @@ -175,8 +175,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z8veEq5ZO3DfIhZ7xgRP9WTc=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs=
github.com/ethereum-optimism/optimism v1.7.0 h1:tDzT+46hkJyUTqyB3VuE+zsb+pw4RmQN48NLICHsWpo=
github.com/ethereum-optimism/optimism v1.7.0/go.mod h1:CT8RgUDaJuySsnQ/6XTiBYmwVuIys587cE8zMPwflZ8=
github.com/ethereum-optimism/optimism v1.7.2 h1:9S1Qi9Ns4eGuFtfpIG4OnX/CDzA0dx4mHGIv5oaYeEw=
github.com/ethereum-optimism/optimism v1.7.2/go.mod h1:ZwYKTK1oLHPnVsNvGbVXCn2FNwdacfizPAAEDHVh6Ck=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
Expand Down Expand Up @@ -844,8 +844,8 @@ gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco=
gorm.io/datatypes v1.2.0/go.mod h1:o1dh0ZvjIjhH/bngTpypG6lVRJ5chTBxE09FH/71k04=
gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8=
gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.6 h1:ydr9xEd5YAM0vxVDY0X139dyzNz10spDiDlC7+ibLeU=
gorm.io/driver/postgres v1.5.6/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
Expand All @@ -854,8 +854,8 @@ gorm.io/driver/sqlserver v1.4.1/go.mod h1:DJ4P+MeZbc5rvY58PnmN1Lnyvb5gw5NPzGshHD
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.3/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.8 h1:WAGEZ/aEcznN4D03laj8DKnehe1e9gYQAjW8xyPRdeo=
gorm.io/gorm v1.25.8/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8=
gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
Expand Down
2 changes: 1 addition & 1 deletion packages/blobstorage/.default.indexer.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RPC_URL=wss://l1ws.internal.taiko.xyz
BEACON_URL=https://l1beacon.internal.taiko.xyz/eth/v1/beacon/blob_sidecars/
BEACON_URL=https://l1beacon.internal.taiko.xyz
TAIKO_L1_CONTRACT_ADDRESS=0xC069c3d2a9f2479F559AD34485698ad5199C555f
DATABASE_HOST=localhost
DATABASE_PORT=3306
Expand Down
135 changes: 135 additions & 0 deletions packages/blobstorage/indexer/beaconclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package indexer

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"time"
)

var (
blobURL = "eth/v1/beacon/blob_sidecars"
genesisURL = "eth/v1/beacon/genesis"
configURL = "eth/v1/config/spec"
)

type GetSpecResponse struct {
Data map[string]string `json:"data"`
}

type GenesisResponse struct {
Data struct {
GenesisTime string `json:"genesis_time"`
} `json:"data"`
}

type BeaconClient struct {
*http.Client
beaconURL string
genesisTime uint64
secondsPerSlot uint64
}

type BlobsResponse struct {
Data []struct {
Index string `json:"index"`
Blob string `json:"blob"`
KzgCommitment string `json:"kzg_commitment"`
KzgCommitmentHex []byte `json:"-"`
} `json:"data"`
}

func NewBeaconClient(cfg *Config, timeout time.Duration) (*BeaconClient, error) {
httpClient := &http.Client{Timeout: timeout}

// Get the genesis time.
url := fmt.Sprintf("%s/%s", cfg.BeaconURL, genesisURL)
genesisTime, err := getGenesisTime(url, httpClient)
if err != nil {
return nil, fmt.Errorf("failed to get genesis time: %v", err)
}

url = fmt.Sprintf("%s/%s", cfg.BeaconURL, configURL)
// Get the seconds per slot.
secondsPerSlot, err := getConfigValue(url, "SECONDS_PER_SLOT", httpClient)
if err != nil {
return nil, fmt.Errorf("failed to get SECONDS_PER_SLOT: %v", err)
}

secondsPerSlotUint64, err := strconv.ParseUint(secondsPerSlot, 10, 64)
if err != nil {
return nil, err
}

return &BeaconClient{
beaconURL: cfg.BeaconURL,
genesisTime: genesisTime,
secondsPerSlot: secondsPerSlotUint64,
}, nil
}

func getGenesisTime(endpoint string, client *http.Client) (uint64, error) {
res, err := client.Get(endpoint)
if err != nil {
return 0, err
}
defer res.Body.Close()

var genesisDetail GenesisResponse
if err := json.NewDecoder(res.Body).Decode(&genesisDetail); err != nil {
return 0, err
}

return strconv.ParseUint(genesisDetail.Data.GenesisTime, 10, 64)
}

func getConfigValue(endpoint, key string, client *http.Client) (string, error) {
res, err := client.Get(endpoint)
if err != nil {
return "", err
}
defer res.Body.Close()

var spec GetSpecResponse
if err := json.NewDecoder(res.Body).Decode(&spec); err != nil {
return "", err
}

value, ok := spec.Data[key]
if !ok {
return "", fmt.Errorf("key %s not found in config spec", key)
}

return value, nil
}

func (c *BeaconClient) getBlobs(ctx context.Context, blockID uint64) (*BlobsResponse, error) {
url := fmt.Sprintf("%s/%s/%v", c.beaconURL, blobURL, blockID)
response, err := http.Get(url)
if err != nil {
return nil, err
}
defer response.Body.Close()

body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}

var responseData BlobsResponse
if err := json.Unmarshal(body, &responseData); err != nil {
return nil, err
}

return &responseData, nil
}

func (c *BeaconClient) timeToSlot(timestamp uint64) (uint64, error) {
if timestamp < c.genesisTime {
return 0, fmt.Errorf("provided timestamp (%v) precedes genesis time (%v)", timestamp, c.genesisTime)
}
return (timestamp - c.genesisTime) / c.secondsPerSlot, nil
}
47 changes: 16 additions & 31 deletions packages/blobstorage/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package indexer
import (
"context"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"io"
"math/big"
"net/http"
"sync"
"time"

Expand All @@ -27,18 +23,8 @@ import (
"github.com/taikoxyz/taiko-mono/packages/blobstorage/pkg/utils"
)

type Response struct {
Data []struct {
Index string `json:"index"`
Blob string `json:"blob"`
KzgCommitment string `json:"kzg_commitment"`
KzgCommitmentHex []byte `json:"-"`
} `json:"data"`
}

// Indexer struct holds the configuration and state for the Ethereum chain listener.
type Indexer struct {
beaconURL string
ethClient *ethclient.Client
startHeight *uint64
taikoL1 *taikol1.TaikoL1
Expand All @@ -48,6 +34,7 @@ type Indexer struct {
wg *sync.WaitGroup
ctx context.Context
latestIndexedBlockNumber uint64
beaconClient *BeaconClient
}

func (i *Indexer) InitFromCli(ctx context.Context, c *cli.Context) error {
Expand Down Expand Up @@ -81,16 +68,22 @@ func InitFromConfig(ctx context.Context, i *Indexer, cfg *Config) (err error) {
return err
}

l1BeaconClient, err := NewBeaconClient(cfg, utils.DefaultTimeout)
if err != nil {
return err
}

i.blobHashRepo = blobHashRepo
i.ethClient = client
i.beaconURL = cfg.BeaconURL
i.taikoL1 = taikoL1
i.startHeight = cfg.StartingBlockID
i.db = db
i.wg = &sync.WaitGroup{}
i.ctx = ctx
i.cfg = cfg

i.beaconClient = l1BeaconClient

return nil
}

Expand Down Expand Up @@ -291,31 +284,23 @@ func (i *Indexer) checkReorg(ctx context.Context, event *taikol1.TaikoL1BlockPro
}

func (i *Indexer) storeBlob(ctx context.Context, event *taikol1.TaikoL1BlockProposed) error {
slog.Info("blockProposed event found", "blockID", event.Meta.L1Height+1, "emittedIn", event.Raw.BlockNumber, "blobUsed", event.Meta.BlobUsed)

if !event.Meta.BlobUsed {
return nil
}

blockID := event.Meta.L1Height + 1
url := fmt.Sprintf("%s/%v", i.beaconURL, blockID)
response, err := http.Get(url)
blockID, err := i.beaconClient.timeToSlot(event.Meta.Timestamp)
if err != nil {
return err
}
defer response.Body.Close()

body, err := io.ReadAll(response.Body)
if err != nil {
return err
slog.Info("blockProposed event found", "blockID", blockID, "emittedIn", event.Raw.BlockNumber, "blobUsed", event.Meta.BlobUsed)

if !event.Meta.BlobUsed {
return nil
}

var responseData Response
if err := json.Unmarshal(body, &responseData); err != nil {
blobsResponse, err := i.beaconClient.getBlobs(ctx, blockID)
if err != nil {
return err
}

for _, data := range responseData.Data {
for _, data := range blobsResponse.Data {
data.KzgCommitmentHex = common.FromHex(data.KzgCommitment)

metaBlobHash := common.BytesToHash(event.Meta.BlobHash[:])
Expand Down
Loading

0 comments on commit 6833bb8

Please sign in to comment.