@@ -12,8 +12,9 @@ import (
12
12
"sync"
13
13
"time"
14
14
15
- node "github.com/celestiaorg/celestia-node/api/rpc /client"
15
+ txclient "github.com/celestiaorg/celestia-node/api/client"
16
16
"github.com/celestiaorg/celestia-node/blob"
17
+ "github.com/celestiaorg/celestia-node/nodebuilder/p2p"
17
18
"github.com/celestiaorg/celestia-node/state"
18
19
libshare "github.com/celestiaorg/go-square/v2/share"
19
20
"github.com/celestiaorg/nitro-das-celestia/celestiagen"
@@ -38,7 +39,15 @@ type DAConfig struct {
38
39
NamespaceId string `koanf:"namespace-id" `
39
40
AuthToken string `koanf:"auth-token" reload:"hot"`
40
41
ReadAuthToken string `koanf:"read-auth-token" reload:"hot"`
42
+ CoreToken string `koanf:"core-token" reload:"hot"`
43
+ CoreURL string `koanf:"core-url" reload:"hot"`
44
+ CoreNetwork string `koanf:"core-network" reload:"hot"`
45
+ KeyName string `koanf:"key-name" reload:"hot"`
46
+ KeyPath string `koanf:"key-path" reload:"hot"`
47
+ BackendName string `koanf:"backend-name" reload:"hot"`
41
48
NoopWriter bool `koanf:"noop-writer" reload:"hot"`
49
+ EnableDATLS bool `koanf:"enable-da-tls" reload:"hot"`
50
+ EnableCoreTLS bool `koanf:"enable-core-tls" reload:"hot"`
42
51
ValidatorConfig ValidatorConfig `koanf:"validator-config" reload:"hot"`
43
52
ReorgOnReadFailure bool `koanf:"dangerous-reorg-on-read-failure"`
44
53
CacheCleanupTime time.Duration `koanf:"cache-time"`
@@ -87,8 +96,8 @@ func IsCelestiaMessageHeaderByte(header byte) bool {
87
96
88
97
type CelestiaDA struct {
89
98
Cfg * DAConfig
90
- Client * node .Client
91
- ReadClient * node .Client
99
+ Client * txclient .Client
100
+ ReadClient * txclient .Client
92
101
93
102
Namespace * libshare.Namespace
94
103
@@ -104,6 +113,14 @@ func CelestiaDAConfigAddOptions(prefix string, f *pflag.FlagSet) {
104
113
f .String (prefix + ".namespace-id" , "" , "Celestia Namespace to post data to" )
105
114
f .String (prefix + ".auth-token" , "" , "Auth token for Celestia Node" )
106
115
f .String (prefix + ".read-auth-token" , "" , "Auth token for Celestia Node" )
116
+ f .String (prefix + ".core-token" , "" , "Auth token for Core Celestia Node Endpoint" )
117
+ f .String (prefix + ".core-url" , "" , "URL to Celestia Core endpoint" )
118
+ f .String (prefix + ".core-network" , "celestia" , "Celestia Network to use" )
119
+ f .String (prefix + ".key-name" , "my_key" , "key name to use" )
120
+ f .String (prefix + ".key-path" , "./keys" , "key path to use" )
121
+ f .String (prefix + ".backend-name" , "test" , "keyring backend to use" )
122
+ f .Bool (prefix + ".enable-da-tls" , false , "enable TLS for DA node" )
123
+ f .Bool (prefix + ".enable-core-tls" , false , "enable TLS for Core node" )
107
124
f .Bool (prefix + ".noop-writer" , false , "Noop writer (disable posting to celestia)" )
108
125
f .String (prefix + ".validator-config" + ".eth-rpc" , "" , "Parent chain connection, only used for validation" )
109
126
f .String (prefix + ".validator-config" + ".blobstream" , "" , "Blobstream address, only used for validation" )
@@ -116,21 +133,62 @@ func NewCelestiaDA(cfg *DAConfig) (*CelestiaDA, error) {
116
133
if cfg == nil {
117
134
return nil , errors .New ("celestia cfg cannot be blank" )
118
135
}
119
- daClient , err := node .NewClient (context .Background (), cfg .Rpc , cfg .AuthToken )
136
+
137
+ // Create a keyring
138
+ _ , err := txclient .KeyringWithNewKey (txclient.KeyringConfig {
139
+ KeyName : cfg .KeyName ,
140
+ BackendName : cfg .BackendName ,
141
+ }, cfg .KeyPath )
120
142
if err != nil {
121
143
return nil , err
122
144
}
123
145
124
- var readClient * node.Client
125
- if cfg .ReadRpc != "" && cfg .ReadAuthToken != "" {
126
- readClient , err = node .NewClient (context .Background (), cfg .ReadRpc , cfg .ReadAuthToken )
127
- if err != nil {
128
- return nil , err
129
- }
130
- } else {
131
- readClient = daClient
146
+ // Configure the client
147
+ clientCfg := txclient.Config {
148
+ ReadConfig : txclient.ReadConfig {
149
+ BridgeDAAddr : cfg .Rpc ,
150
+ DAAuthToken : cfg .AuthToken ,
151
+ EnableDATLS : cfg .EnableDATLS ,
152
+ },
153
+ SubmitConfig : txclient.SubmitConfig {
154
+ DefaultKeyName : cfg .KeyName ,
155
+ Network : p2p .Network (cfg .CoreNetwork ),
156
+ CoreGRPCConfig : txclient.CoreGRPCConfig {
157
+ Addr : cfg .CoreURL ,
158
+ TLSEnabled : cfg .EnableCoreTLS ,
159
+ AuthToken : cfg .CoreToken ,
160
+ },
161
+ },
132
162
}
133
163
164
+ readClient , err := txclient .NewReadClient (context .Background (), clientCfg .ReadConfig )
165
+ if err != nil {
166
+ log .Error ("DEBUG: Failed to create celestia client" , "err" , err , "BridgeDAAddr" , clientCfg .ReadConfig .BridgeDAAddr , "CoreAddr" , clientCfg .SubmitConfig .CoreGRPCConfig .Addr )
167
+ return nil , err
168
+ }
169
+
170
+ celestiaClient := & txclient.Client {
171
+ ReadClient : * readClient ,
172
+ }
173
+ // if cfg.ReadRpc != "" && cfg.ReadAuthToken != "" {
174
+ // log.Info("DEBUG: Configuring read client", "cfg.ReadRpc", cfg.ReadRpc)
175
+ // readClientCfg := txclient.Config{
176
+ // ReadConfig: txclient.ReadConfig{
177
+ // BridgeDAAddr: cfg.ReadRpc,
178
+ // DAAuthToken: cfg.ReadAuthToken,
179
+ // EnableDATLS: cfg.EnableDATLS,
180
+ // },
181
+ // }
182
+ // log.Info("DEBUG: About to create read client", "ReadBridgeDAAddr", readClientCfg.ReadConfig.BridgeDAAddr)
183
+ // readClient, err = txclient.New(context.Background(), readClientCfg, kr)
184
+ // if err != nil {
185
+ // log.Error("DEBUG: Failed to create read client", "err", err, "ReadBridgeDAAddr", readClientCfg.ReadConfig.BridgeDAAddr)
186
+ // return nil, err
187
+ // }
188
+ // } else {
189
+ // readClient = celestiaClient
190
+ // }
191
+
134
192
if cfg .NamespaceId == "" {
135
193
return nil , errors .New ("namespace id cannot be blank" )
136
194
}
@@ -146,8 +204,8 @@ func NewCelestiaDA(cfg *DAConfig) (*CelestiaDA, error) {
146
204
147
205
da := & CelestiaDA {
148
206
Cfg : cfg ,
149
- Client : daClient ,
150
- ReadClient : readClient ,
207
+ Client : celestiaClient ,
208
+ ReadClient : celestiaClient ,
151
209
Namespace : & namespace ,
152
210
}
153
211
0 commit comments