Skip to content

Commit

Permalink
da: upgrade to go-da v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed May 23, 2024
1 parent 389c434 commit 07c3301
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 93 deletions.
20 changes: 10 additions & 10 deletions bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,21 @@ def devnet_deploy(paths):
else:
docker_env['L2OO_ADDRESS'] = l2_output_oracle

if DEVNET_PLASMA:
docker_env['PLASMA_ENABLED'] = 'true'
docker_env['PLASMA_DA_SERVICE'] = 'false'
else:
docker_env['PLASMA_ENABLED'] = 'false'
docker_env['PLASMA_DA_SERVICE'] = 'false'
log.info('Bringing up DA')
run_command(['docker', 'compose', 'up', '-d', 'da'], cwd=paths.ops_bedrock_dir, env=docker_env)
wait_up(26658)
time.sleep(15)
celestia_node_auth_token = run_command([
'docker', 'compose', 'exec', '--no-TTY', 'da', 'celestia', 'bridge', 'auth', 'admin', '--node.store', '/home/celestia/bridge'
], cwd=paths.ops_bedrock_dir, env=docker_env, capture_output=True).stdout.decode().strip()
docker_env['CELESTIA_NODE_AUTH_TOKEN'] = celestia_node_auth_token
print('CELESTIA_NODE_AUTH_TOKEN: ', celestia_node_auth_token)


# Bring up the rest of the services.
log.info('Bringing up `op-node`, `op-proposer` and `op-batcher`.')
run_command(['docker', 'compose', 'up', '-d', 'op-node', 'op-proposer', 'op-batcher', 'artifact-server'], cwd=paths.ops_bedrock_dir, env=docker_env)

log.info('Bringing up DA')
run_command(['docker', 'compose', 'up', '-d', 'da'], cwd=paths.ops_bedrock_dir, env=docker_env)
wait_up(26650)

# Optionally bring up op-challenger.
if DEVNET_FPAC:
log.info('Bringing up `op-challenger`.')
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ require (
golang.org/x/sync v0.6.0
golang.org/x/term v0.20.0
golang.org/x/time v0.5.0
google.golang.org/grpc v1.60.1
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.10
)
Expand Down Expand Up @@ -227,6 +226,7 @@ require (
golang.org/x/tools v0.17.0 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func (l *BatchSubmitter) blobTxCandidate(data txData) (*txmgr.TxCandidate, error
func (l *BatchSubmitter) calldataTxCandidate(data []byte) *txmgr.TxCandidate {
l.Log.Info("building Calldata transaction candidate", "size", len(data))
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Duration(l.RollupConfig.BlockTime)*time.Second)
ids, _, err := l.DAClient.Client.Submit(ctx, [][]byte{data}, -1)
ids, err := l.DAClient.Client.Submit(ctx, [][]byte{data}, -1, l.DAClient.Namespace)
cancel()
if err == nil && len(ids) == 1 {
l.Log.Info("celestia: blob successfully submitted", "id", hex.EncodeToString(ids[0]))
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (bs *BatcherService) initPlasmaDA(cfg *CLIConfig) error {
}

func (bs *BatcherService) initDA(cfg *CLIConfig) error {
client, err := celestia.NewDAClient(cfg.DaConfig.DaRpc)
client, err := celestia.NewDAClient(cfg.DaConfig.Rpc, cfg.DaConfig.AuthToken, cfg.DaConfig.Namespace)
if err != nil {
return err
}
Expand Down
91 changes: 32 additions & 59 deletions op-celestia/cli.go
Original file line number Diff line number Diff line change
@@ -1,94 +1,67 @@
package celestia

import (
"errors"
"fmt"
"net"

"github.com/urfave/cli/v2"

opservice "github.com/ethereum-optimism/optimism/op-service"
)

const (
DaRpcFlagName = "da.rpc"
)

var (
defaultDaRpc = "localhost:26650"

ErrInvalidPort = errors.New("invalid port")
// RPCFlagName defines the flag for the rpc url
RPCFlagName = "da.rpc"
// AuthTokenFlagName defines the flag for the auth token
AuthTokenFlagName = "da.auth_token"
// NamespaceFlagName defines the flag for the namespace
NamespaceFlagName = "da.namespace"

// NamespaceSize is the size of the hex encoded namespace string
NamespaceSize = 58

// defaultRPC is the default rpc dial address
defaultRPC = "grpc://localhost:26650"
)

func Check(address string) error {
_, port, err := net.SplitHostPort(address)
if err != nil {
return err
}

if port == "" {
return ErrInvalidPort
}

_, err = net.LookupPort("tcp", port)
if err != nil {
return err
}

return nil
}

func CLIFlags(envPrefix string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: DaRpcFlagName,
Usage: "dial address of data availability grpc client",
Value: defaultDaRpc,
Name: RPCFlagName,
Usage: "dial address of the data availability rpc client; supports grpc, http, https",
Value: defaultRPC,
EnvVars: opservice.PrefixEnvVar(envPrefix, "DA_RPC"),
},
&cli.StringFlag{
Name: AuthTokenFlagName,
Usage: "authentication token of the data availability client",
EnvVars: opservice.PrefixEnvVar(envPrefix, "DA_AUTH_TOKEN"),
},
&cli.StringFlag{
Name: NamespaceFlagName,
Usage: "namespace of the data availability client",
EnvVars: opservice.PrefixEnvVar(envPrefix, "DA_NAMESPACE"),
},
}
}

type Config struct {
DaRpc string
}

func (c Config) Check() error {
if c.DaRpc == "" {
c.DaRpc = defaultDaRpc
}

if err := Check(c.DaRpc); err != nil {
return fmt.Errorf("invalid da rpc: %w", err)
}

return nil
}

type CLIConfig struct {
DaRpc string
Rpc string
AuthToken string
Namespace string
}

func (c CLIConfig) Check() error {
if c.DaRpc == "" {
c.DaRpc = defaultDaRpc
}

if err := Check(c.DaRpc); err != nil {
return fmt.Errorf("invalid da rpc: %w", err)
}

return nil
}

func NewCLIConfig() CLIConfig {
return CLIConfig{
DaRpc: defaultDaRpc,
Rpc: defaultRPC,
}
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
return CLIConfig{
DaRpc: ctx.String(DaRpcFlagName),
Rpc: ctx.String(RPCFlagName),
AuthToken: ctx.String(AuthTokenFlagName),
Namespace: ctx.String(NamespaceFlagName),
}
}
17 changes: 11 additions & 6 deletions op-celestia/da_client.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package celestia

import (
"encoding/hex"
"time"

"github.com/rollkit/go-da"
"github.com/rollkit/go-da/proxy"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

type DAClient struct {
Client *proxy.Client
Client da.DA
GetTimeout time.Duration
Namespace da.Namespace
}

func NewDAClient(rpc string) (*DAClient, error) {
client := proxy.NewClient()
err := client.Start(rpc, grpc.WithTransportCredentials(insecure.NewCredentials()))
func NewDAClient(rpc, token, namespace string) (*DAClient, error) {
client, err := proxy.NewClient(rpc, token)
if err != nil {
return nil, err
}
ns, err := hex.DecodeString(namespace)
if err != nil {
return nil, err
}
return &DAClient{
Client: client,
GetTimeout: time.Minute,
Namespace: ns,
}, nil
}
4 changes: 2 additions & 2 deletions op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func DefaultSystemConfig(t testing.TB) SystemConfig {
RuntimeConfigReloadInterval: time.Minute * 10,
ConfigPersistence: &rollupNode.DisabledConfigPersistence{},
Sync: sync.Config{SyncMode: sync.CLSync},
DaConfig: celestia.Config{DaRpc: "localhost:26650"},
DaConfig: celestia.CLIConfig{Rpc: "grpc://localhost:26650"},
},
"verifier": {
Driver: driver.Config{
Expand All @@ -145,7 +145,7 @@ func DefaultSystemConfig(t testing.TB) SystemConfig {
RuntimeConfigReloadInterval: time.Minute * 10,
ConfigPersistence: &rollupNode.DisabledConfigPersistence{},
Sync: sync.Config{SyncMode: sync.CLSync},
DaConfig: celestia.Config{DaRpc: "localhost:26650"},
DaConfig: celestia.CLIConfig{Rpc: "grpc://localhost:26650"},
},
},
Loggers: map[string]log.Logger{
Expand Down
2 changes: 1 addition & 1 deletion op-node/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Config struct {
// Plasma DA config
Plasma plasma.CLIConfig

DaConfig celestia.Config
DaConfig celestia.CLIConfig
}

type RPCConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/derive/calldata_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func DataFromEVMTransactions(dsCfg DataSourceConfig, batcherAddr common.Address,
case celestia.DerivationVersionCelestia:
log.Info("celestia: blob request", "id", hex.EncodeToString(tx.Data()))
ctx, cancel := context.WithTimeout(context.Background(), daClient.GetTimeout)
blobs, err := daClient.Client.Get(ctx, [][]byte{data[1:]})
blobs, err := daClient.Client.Get(ctx, [][]byte{data[1:]}, daClient.Namespace)
cancel()
if err != nil {
return nil, NewResetError(fmt.Errorf("celestia: failed to resolve frame: %w", err))
Expand Down
4 changes: 2 additions & 2 deletions op-node/rollup/driver/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
)

func SetDAClient(cfg celestia.Config) error {
client, err := celestia.NewDAClient(cfg.DaRpc)
func SetDAClient(cfg celestia.CLIConfig) error {
client, err := celestia.NewDAClient(cfg.Rpc, cfg.AuthToken, cfg.Namespace)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion op-node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
ConductorRpcTimeout: ctx.Duration(flags.ConductorRpcTimeoutFlag.Name),

Plasma: plasma.ReadCLIConfig(ctx),
DaConfig: celestia.Config(celestia.ReadCLIConfig(ctx)),
DaConfig: celestia.ReadCLIConfig(ctx),
}

if err := cfg.LoadPersisted(log); err != nil {
Expand Down
17 changes: 9 additions & 8 deletions ops-bedrock/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ volumes:

services:
da:
image: ghcr.io/rollkit/local-celestia-devnet:v0.12.7
image: ghcr.io/rollkit/local-celestia-devnet:v0.13.1
ports:
- "26650:26650"
environment:
CELESTIA_NAMESPACE: 000008e5f679bf7116cb
- "26658:26658"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:26659/header/1"]
interval: 10s
Expand Down Expand Up @@ -96,7 +94,9 @@ services:
--pprof.enabled
--rpc.enable-admin
environment:
OP_NODE_DA_RPC: "da:26650"
OP_NODE_DA_RPC: "http://da:26658"
OP_NODE_DA_AUTH_TOKEN: "${CELESTIA_NODE_AUTH_TOKEN}"
OP_NODE_DA_NAMESPACE: "00000000000000000000000000000000000000000008e5f679bf7116cb"
ports:
- "7545:8545"
- "9003:9003"
Expand Down Expand Up @@ -145,8 +145,7 @@ services:
- l1
- l2
- op-node
da:
condition: service_healthy
- da
build:
context: ../
dockerfile: ops/docker/op-stack-go/Dockerfile
Expand All @@ -171,7 +170,9 @@ services:
OP_BATCHER_METRICS_ENABLED: "true"
OP_BATCHER_RPC_ENABLE_ADMIN: "true"
OP_BATCHER_BATCH_TYPE: 0
OP_BATCHER_DA_RPC: "da:26650"
OP_BATCHER_DA_RPC: "http://da:26658"
OP_BATCHER_DA_AUTH_TOKEN: "${CELESTIA_NODE_AUTH_TOKEN}"
OP_BATCHER_DA_NAMESPACE: "00000000000000000000000000000000000000000008e5f679bf7116cb"

op-challenger:
depends_on:
Expand Down

0 comments on commit 07c3301

Please sign in to comment.