Skip to content

Commit 9d3481b

Browse files
committed
bug fix when merging branch
1 parent 497a332 commit 9d3481b

File tree

12 files changed

+43
-59
lines changed

12 files changed

+43
-59
lines changed

executor/batch/batch.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package batch
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"io"
78
"os"
89
"sync"
@@ -136,8 +137,15 @@ func (bs *BatchSubmitter) Initialize(host hostNode, da executortypes.DANode, bri
136137
return nil
137138
}
138139

139-
func (bs *BatchSubmitter) Start(ctx context.Context) {
140-
bs.node.Start(ctx, nodetypes.PROCESS_TYPE_RAW)
140+
func (bs *BatchSubmitter) Start(ctx context.Context, errCh chan error) {
141+
defer func() {
142+
if r := recover(); r != nil {
143+
bs.logger.Error("batch panic", zap.Any("recover", r))
144+
errCh <- fmt.Errorf("batch panic: %v", r)
145+
}
146+
}()
147+
148+
bs.node.Start(ctx, errCh, nodetypes.PROCESS_TYPE_RAW)
141149
}
142150

143151
func (bs *BatchSubmitter) SetBridgeInfo(bridgeInfo opchildtypes.BridgeInfo) {
@@ -156,8 +164,8 @@ func (bs *BatchSubmitter) LoadSubmissionInfo() error {
156164
return nil
157165
}
158166

159-
func (bs *BatchSubmitter) RawKVSubmissionInfo(timestamp int64) types.KV {
160-
return types.KV{
167+
func (bs *BatchSubmitter) SubmissionInfoToRawKV(timestamp int64) types.RawKV {
168+
return types.RawKV{
161169
Key: bs.db.PrefixedKey(SubmissionKey),
162170
Value: dbtypes.FromInt64(timestamp),
163171
}

executor/batch/handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ func (bs *BatchSubmitter) rawBlockHandler(args nodetypes.RawBlockArgs) error {
4444
return err
4545
}
4646

47-
batchKVs := make([]types.KV, 0)
48-
batchKVs = append(batchKVs, bs.node.RawKVSyncInfo(args.BlockHeight))
49-
batchMsgkvs, err := bs.da.RawKVProcessedData(bs.processedMsgs, false)
47+
batchKVs := make([]types.RawKV, 0)
48+
batchKVs = append(batchKVs, bs.node.SyncInfoToRawKV(args.BlockHeight))
49+
batchMsgkvs, err := bs.da.ProcessedMsgsToRawKV(bs.processedMsgs, false)
5050
if err != nil {
5151
return err
5252
}
5353
batchKVs = append(batchKVs, batchMsgkvs...)
5454
if len(batchMsgkvs) > 0 {
55-
batchKVs = append(batchKVs, bs.RawKVSubmissionInfo(pbb.Header.Time.UnixNano()))
55+
batchKVs = append(batchKVs, bs.SubmissionInfoToRawKV(pbb.Header.Time.UnixNano()))
5656
}
5757
err = bs.db.RawBatchSet(batchKVs...)
5858
if err != nil {

executor/child/child.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (ch *Child) Start(ctx context.Context, errCh chan error) {
115115
}
116116
}()
117117

118-
ch.node.Start(ctx, errCh)
118+
ch.node.Start(ctx, errCh, nodetypes.PROCESS_TYPE_DEFAULT)
119119
}
120120

121121
func (ch *Child) registerHandlers() {

executor/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewExecutor(cfg *executortypes.Config, db types.DB, sv *server.Server, logg
5353
db.WithPrefix([]byte(executortypes.ChildNodeName)),
5454
logger.Named(executortypes.ChildNodeName), cdc, txConfig,
5555
),
56-
batch: batch.NewBatchSubmitter(cfg.Version, cfg.DANodeConfig(), cfg.DANodeConfig(), db.WithPrefix([]byte(executortypes.BatchNodeName)), logger.Named(executortypes.BatchNodeName), cdc, txConfig, homePath),
56+
batch: batch.NewBatchSubmitter(cfg.Version, cfg.DANodeConfig(), cfg.BatchConfig(), db.WithPrefix([]byte(executortypes.BatchNodeName)), logger.Named(executortypes.BatchNodeName), cdc, txConfig, homePath),
5757

5858
cfg: cfg,
5959
db: db,

executor/host/query.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (h Host) QueryBatchInfos() (*ophosttypes.QueryBatchInfosResponse, error) {
5252
req := &ophosttypes.QueryBatchInfosRequest{
5353
BridgeId: uint64(h.bridgeId),
5454
}
55-
ctx := node.GetQueryContext(0)
55+
ctx, cancel := node.GetQueryContext(0)
56+
defer cancel()
5657
return h.ophostQueryClient.BatchInfos(ctx, req)
5758
}

executor/types/batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type DANode interface {
99
GetAddressStr() (string, error)
1010
HasKey() bool
1111
BroadcastMsgs(nodetypes.ProcessedMsgs)
12-
RawKVProcessedData([]nodetypes.ProcessedMsgs, bool) ([]types.KV, error)
12+
ProcessedMsgsToRawKV([]nodetypes.ProcessedMsgs, bool) ([]types.RawKV, error)
1313
}
1414

1515
type BatchHeader struct {

executor/types/config.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type Config struct {
3737
// If you don't want to use the bridge executor feature, you can leave it empty.
3838
BridgeExecutorMnemonic string `json:"bridge_executor_mnemonic"`
3939

40+
// BatchSubmitterMnemonic is the mnemonic phrase for the batch submitter,
41+
// which is used to relay the batch of blocks from l2 to da.
42+
//
43+
// If you don't want to use the batch submitter feature, you can leave it empty.
4044
BatchSubmitterMnemonic string `json:"batch_submitter_mnemonic"`
4145

4246
// RelayOracle is the flag to enable the oracle relay feature.
@@ -59,15 +63,19 @@ func DefaultConfig() *Config {
5963

6064
L1RPCAddress: "tcp://localhost:26657",
6165
L2RPCAddress: "tcp://localhost:27657",
66+
DARPCAddress: "tcp://localhost:28657",
6267

6368
L1GasPrice: "0.15uinit",
6469
L2GasPrice: "",
70+
DAGasPrice: "",
6571

6672
L1ChainID: "testnet-l1-1",
6773
L2ChainID: "testnet-l2-1",
74+
DAChainID: "testnet-l3-1",
6875

6976
OutputSubmitterMnemonic: "",
7077
BridgeExecutorMnemonic: "",
78+
BatchSubmitterMnemonic: "",
7179
}
7280
}
7381

@@ -125,8 +133,15 @@ func (cfg Config) DANodeConfig() nodetypes.NodeConfig {
125133
}
126134
}
127135

136+
func (cfg Config) BatchConfig() BatchConfig {
137+
return BatchConfig{
138+
MaxChunks: cfg.MaxChunks,
139+
MaxChunkSize: cfg.MaxChunkSize,
140+
MaxSubmissionTime: cfg.MaxSubmissionTime,
141+
}
142+
}
143+
128144
type BatchConfig struct {
129-
nodetypes.NodeConfig
130145
MaxChunks int64 `json:"max_chunks"`
131146
MaxChunkSize int64 `json:"max_chunk_size"`
132147
MaxSubmissionTime int64 `json:"max_submission_time"` // seconds

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ require (
4444
github.com/gogo/googleapis v1.4.1 // indirect
4545
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4646
github.com/golang/mock v1.6.0 // indirect
47-
github.com/google/brotli/go/cbrotli v0.0.0-20240715182736-39bcecf4559f // indirect
4847
github.com/google/orderedcode v0.0.1 // indirect
4948
github.com/google/s2a-go v0.1.7 // indirect
5049
github.com/google/uuid v1.6.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
561561
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
562562
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
563563
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
564-
github.com/google/brotli/go/cbrotli v0.0.0-20240715182736-39bcecf4559f h1:gMt4P0lp6wvToXa3UD8JocJxpt0yyXdG8SLfLMxkpKM=
565-
github.com/google/brotli/go/cbrotli v0.0.0-20240715182736-39bcecf4559f/go.mod h1:nOPhAkwVliJdNTkj3gXpljmWhjc4wCaVqbMJcPKWP4s=
566564
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
567565
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
568566
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=

node/db.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,12 @@ import (
77
"go.uber.org/zap"
88
)
99

10-
<<<<<<< HEAD
11-
// should use safely
1210
func (n *Node) SetSyncInfo(height uint64) {
1311
n.lastProcessedBlockHeight = height
1412
}
1513

1614
func (n *Node) SaveSyncInfo(height uint64) error {
1715
return n.db.Set(nodetypes.LastProcessedBlockHeightKey, dbtypes.FromUint64(height))
18-
||||||| 222d087
19-
func (n *Node) SaveSyncInfo() error {
20-
return n.db.Set(nodetypes.LastProcessedBlockHeightKey, dbtypes.FromUint64(n.lastProcessedBlockHeight))
21-
=======
22-
//////////////
23-
// SyncInfo //
24-
//////////////
25-
26-
func (n *Node) SaveSyncInfo() error {
27-
return n.db.Set(nodetypes.LastProcessedBlockHeightKey, dbtypes.FromUint64(n.lastProcessedBlockHeight))
28-
>>>>>>> feat/executor
2916
}
3017

3118
func (n *Node) SyncInfoToRawKV(height uint64) types.RawKV {
@@ -108,19 +95,6 @@ func (n *Node) PendingTxsToRawKV(txInfos []nodetypes.PendingTxInfo, delete bool)
10895
return kvs, nil
10996
}
11097

111-
<<<<<<< HEAD
112-
func (n *Node) RawKVProcessedData(processedData []nodetypes.ProcessedMsgs, delete bool) ([]types.KV, error) {
113-
kvs := make([]types.KV, 0, len(processedData))
114-
for _, processedMsgs := range processedData {
115-
||||||| 222d087
116-
func (n *Node) RawKVProcessedData(processedData []nodetypes.ProcessedMsgs, delete bool) ([]types.KV, error) {
117-
kvs := make([]types.KV, 0, len(processedData))
118-
for _, processedMsgs := range processedData {
119-
if !processedMsgs.Save {
120-
continue
121-
}
122-
123-
=======
12498
///////////////////
12599
// ProcessedMsgs //
126100
///////////////////
@@ -130,24 +104,11 @@ func (n *Node) RawKVProcessedData(processedData []nodetypes.ProcessedMsgs, delet
130104
func (n *Node) ProcessedMsgsToRawKV(ProcessedMsgs []nodetypes.ProcessedMsgs, delete bool) ([]types.RawKV, error) {
131105
kvs := make([]types.RawKV, 0, len(ProcessedMsgs))
132106
for _, processedMsgs := range ProcessedMsgs {
133-
if !processedMsgs.Save {
134-
continue
135-
}
136-
137-
>>>>>>> feat/executor
138107
var data []byte
139108
var err error
140109

141-
<<<<<<< HEAD
142110
if !delete && processedMsgs.Save {
143-
data, err = processedMsgs.Marshal()
144-
||||||| 222d087
145-
if !delete {
146-
data, err = processedMsgs.Marshal()
147-
=======
148-
if !delete {
149111
data, err = processedMsgs.MarshalInterfaceJSON(n.cdc)
150-
>>>>>>> feat/executor
151112
if err != nil {
152113
return nil, err
153114
}

0 commit comments

Comments
 (0)