Skip to content

Commit 91eb0da

Browse files
author
Albert
committed
Merge branch 'rss3-dev' into rss3-main
2 parents a3bdea1 + 8995985 commit 91eb0da

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

op-batcher/batcher/driver.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type DriverSetup struct {
5151
EndpointProvider dial.L2EndpointProvider
5252
ChannelConfig ChannelConfig
5353
PlasmaDA *plasma.DAClient
54-
NearDA *opnear.DAClient
54+
NearDA opnear.CLIConfig
5555
}
5656

5757
// BatchSubmitter encapsulates a service responsible for submitting L2 tx
@@ -439,10 +439,24 @@ func (l *BatchSubmitter) blobTxCandidate(data txData) (*txmgr.TxCandidate, error
439439
}, nil
440440
}
441441

442-
func (l *BatchSubmitter) submitBlobToNearDA(data []byte) ([]byte, error) {
442+
func (l *BatchSubmitter) submitBlobToNearDA(data []byte) (frameRef []byte, err error) {
443+
defer func() {
444+
if rErr := recover(); rErr != nil {
445+
err = fmt.Errorf("critical error from submitBlobToNearDA: %v", rErr)
446+
}
447+
}()
448+
449+
// create a Near DA Client before submitting blob
450+
daClient, err := opnear.NewDAClient(l.NearDA.DaAccount, l.NearDA.DaContract, l.NearDA.DaKey, l.NearDA.DaNetwork, l.NearDA.DaNamespaceId)
451+
if err != nil {
452+
l.Log.Error("new near da client", "err", err)
453+
return nil, err
454+
}
455+
defer daClient.FreeDAClient()
456+
443457
l.Log.Debug("submitBlobToNearDA", "data", hex.EncodeToString(data), "size", len(data))
444458
// frameRef is the blob commitment, which is provided as [transaction_id ++ commitment]
445-
frameRef, err := l.NearDA.Submit(data)
459+
frameRef, err = daClient.Submit(data)
446460
if err != nil {
447461
l.Log.Warn("failed to submit blob to near da", "err", err)
448462
return nil, err
@@ -451,7 +465,7 @@ func (l *BatchSubmitter) submitBlobToNearDA(data []byte) ([]byte, error) {
451465
// finality is achieved which is 3 blocks (around 2-3 seconds) its not possible for a reorg to happen
452466
// check the submitted blob after finality
453467
time.Sleep(10 * time.Second)
454-
blobData, err := l.NearDA.Get(frameRef, 0)
468+
blobData, err := daClient.Get(frameRef, 0)
455469
if err != nil {
456470
log.Error("failed to get blob from near da, maybe chain reorg", "id", hex.EncodeToString(data), "err", err)
457471
return nil, err

op-batcher/batcher/service.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type BatcherService struct {
5555
EndpointProvider dial.L2EndpointProvider
5656
TxManager txmgr.TxManager
5757
PlasmaDA *plasma.DAClient
58-
NearDA *opnear.DAClient
58+
NearDA opnear.CLIConfig
5959

6060
BatcherConfig
6161

@@ -332,13 +332,7 @@ func (bs *BatcherService) initPlasmaDA(cfg *CLIConfig) error {
332332
}
333333

334334
func (bs *BatcherService) initNearDA(cfg *CLIConfig) error {
335-
bs.Log.Info("initNearDA", "DaAccount", cfg.NearDA.DaAccount, "DaContract", cfg.NearDA.DaContract, "NamespaceId", cfg.NearDA.DaNamespaceId, "Network", cfg.NearDA.DaNetwork)
336-
client, err := opnear.NewDAClient(cfg.NearDA.DaAccount, cfg.NearDA.DaContract, cfg.NearDA.DaKey, cfg.NearDA.DaNetwork, cfg.NearDA.DaNamespaceId)
337-
if err != nil {
338-
bs.Log.Error("Failed to create near da client", "err", err)
339-
return err
340-
}
341-
bs.NearDA = client
335+
bs.NearDA = cfg.NearDA
342336
return nil
343337
}
344338

@@ -422,11 +416,6 @@ func (bs *BatcherService) Stop(ctx context.Context) error {
422416
bs.Log.Info("Batch Submitter stopped")
423417
}
424418

425-
// free near da client
426-
if bs.NearDA != nil {
427-
bs.driver.Log.Info("Free Near DA Client")
428-
bs.NearDA.FreeDAClient()
429-
}
430419
return result
431420
}
432421

op-near/da_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func NewDAClient(accountN, contractN, keyN, networkN string, nameSpace uint32) (
3535
}
3636

3737
func (c *DAClient) FreeDAClient() {
38+
log.Info("free NEAR client")
3839
c.Client.FreeClient()
3940
}
4041

0 commit comments

Comments
 (0)