Skip to content

Commit 9d1d8d9

Browse files
committed
add l1 start height in config to avoid to use TxSearch
1 parent 86916b3 commit 9d1d8d9

File tree

6 files changed

+101
-50
lines changed

6 files changed

+101
-50
lines changed

challenger/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Challenger is responsible for
1010

1111
## Config
1212

13-
To configure the Executor, fill in the values in the `~/.opinit/executor.json` file.
13+
To configure the Challenger, fill in the values in the `~/.opinit/challenger.json` file.
1414

1515
```json
1616
{
@@ -28,6 +28,11 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
2828
"bech32_prefix": "init",
2929
"rpc_address": "tcp://localhost:27657",
3030
},
31+
// L1StartHeight is the height to start the l1 node. If it is 0, it will finds the optimal height and sets it automatically.
32+
// However, if you do not want to use this feature, set it to a non-zero value.
33+
// There is no need for modification under normal circumstances, because it
34+
// is automatically determined when you set the l2 start height,
35+
"l1_start_height": 0,
3136
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
3237
// If the latest height stored in the db is not 0, this config is ignored.
3338
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.

challenger/challenger.go

+31-20
Original file line numberDiff line numberDiff line change
@@ -193,43 +193,54 @@ func (c *Challenger) RegisterQuerier() {
193193
}
194194

195195
func (c *Challenger) getProcessedHeights(ctx context.Context, bridgeId uint64) (l1ProcessedHeight int64, l2ProcessedHeight int64, processedOutputIndex uint64, err error) {
196-
// get the bridge start height from the host
197-
l1ProcessedHeight, err = c.host.QueryCreateBridgeHeight(ctx, bridgeId)
198-
if err != nil {
199-
return 0, 0, 0, err
200-
}
201-
196+
var outputL1BlockNumber int64
202197
// get the last submitted output height before the start height from the host
203198
if c.cfg.L2StartHeight != 0 {
204199
output, err := c.host.QueryLastFinalizedOutput(ctx, bridgeId)
205200
if err != nil {
206201
return 0, 0, 0, err
207202
} else if output != nil {
208-
l1ProcessedHeight = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
203+
outputL1BlockNumber = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
209204
l2ProcessedHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
210205
processedOutputIndex = output.OutputIndex
211206
}
212207
}
213-
if l2ProcessedHeight > 0 {
214-
// get the last deposit tx height from the host
215-
l1Sequence, err := c.child.QueryNextL1Sequence(ctx, l2ProcessedHeight-1)
208+
209+
if c.cfg.L1StartHeight == 0 {
210+
// get the bridge start height from the host
211+
l1ProcessedHeight, err = c.host.QueryCreateBridgeHeight(ctx, bridgeId)
216212
if err != nil {
217213
return 0, 0, 0, err
218214
}
219-
// query l1Sequence tx height
220-
depositTxHeight, err := c.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence)
221-
if err != nil {
222-
return 0, 0, 0, err
223-
} else if depositTxHeight == 0 && l1Sequence > 1 {
224-
// query l1Sequence - 1 tx height
225-
depositTxHeight, err = c.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence-1)
215+
216+
if l2ProcessedHeight > 0 {
217+
l1Sequence, err := c.child.QueryNextL1Sequence(ctx, l2ProcessedHeight-1)
226218
if err != nil {
227219
return 0, 0, 0, err
228220
}
221+
// query l1Sequence tx height
222+
depositTxHeight, err := c.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence)
223+
if err != nil {
224+
return 0, 0, 0, err
225+
} else if depositTxHeight == 0 && l1Sequence > 1 {
226+
// query l1Sequence - 1 tx height
227+
depositTxHeight, err = c.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence-1)
228+
if err != nil {
229+
return 0, 0, 0, err
230+
}
231+
}
232+
233+
if depositTxHeight > l1ProcessedHeight {
234+
l1ProcessedHeight = depositTxHeight
235+
}
236+
if outputL1BlockNumber < l1ProcessedHeight {
237+
l1ProcessedHeight = outputL1BlockNumber
238+
}
229239
}
230-
if depositTxHeight >= 1 && depositTxHeight-1 < l1ProcessedHeight {
231-
l1ProcessedHeight = depositTxHeight - 1
232-
}
240+
} else {
241+
l1ProcessedHeight = c.cfg.L1StartHeight
233242
}
243+
l1ProcessedHeight--
244+
234245
return l1ProcessedHeight, l2ProcessedHeight, processedOutputIndex, err
235246
}

challenger/types/config.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ type Config struct {
3737
// L2Node is the configuration for the l2 node.
3838
L2Node NodeConfig `json:"l2_node"`
3939

40+
// L1StartHeight is the height to start the l1 node. If it is 0, it will finds the optimal height and sets it automatically.
41+
// However, if you do not want to use this feature, set it to a non-zero value.
42+
// There is no need for modification under normal circumstances, because it
43+
// is automatically determined when you set the l2 start height,
44+
L1StartHeight int64 `json:"l1_start_height"`
4045
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
4146
// If the latest height stored in the db is not 0, this config is ignored.
4247
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.
4348
// L1 starts from the block number of the output tx + 1
44-
L2StartHeight uint64 `json:"l2_start_height"`
49+
L2StartHeight int64 `json:"l2_start_height"`
4550
}
4651

4752
func DefaultConfig() *Config {
@@ -60,6 +65,7 @@ func DefaultConfig() *Config {
6065
Bech32Prefix: "init",
6166
RPCAddress: "tcp://localhost:27657",
6267
},
68+
L1StartHeight: 0,
6369
L2StartHeight: 0,
6470
}
6571
}
@@ -84,6 +90,14 @@ func (cfg Config) Validate() error {
8490
if err := cfg.L2Node.Validate(); err != nil {
8591
return err
8692
}
93+
94+
if cfg.L1StartHeight < 0 {
95+
return errors.New("l1 start height must be greater than or equal to 0")
96+
}
97+
98+
if cfg.L2StartHeight < 0 {
99+
return errors.New("l2 start height must be greater than or equal to 0")
100+
}
87101
return nil
88102
}
89103

executor/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
5858
"max_chunk_size": 300000,
5959
// MaxSubmissionTime is the maximum time to submit a batch.
6060
"max_submission_time": 3600,
61+
// L1StartHeight is the height to start the l1 node. If it is 0, it will finds the optimal height and sets it automatically.
62+
// However, if you do not want to use this feature, set it to a non-zero value.
63+
// There is no need for modification under normal circumstances, because it
64+
// is automatically determined when you set the l2 start height,
65+
"l1_start_height": 0,
6166
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
6267
// If the latest height stored in the db is not 0, this config is ignored.
6368
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.

executor/executor.go

+34-28
Original file line numberDiff line numberDiff line change
@@ -214,46 +214,52 @@ func (ex *Executor) makeDANode(ctx context.Context, bridgeInfo opchildtypes.Brid
214214
}
215215

216216
func (ex *Executor) getProcessedHeights(ctx context.Context, bridgeId uint64) (l1ProcessedHeight int64, l2ProcessedHeight int64, processedOutputIndex uint64, batchProcessedHeight int64, err error) {
217-
// get the bridge start height from the host
218-
l1ProcessedHeight, err = ex.host.QueryCreateBridgeHeight(ctx, bridgeId)
219-
if err != nil {
220-
return 0, 0, 0, 0, err
217+
var outputL1BlockNumber int64
218+
// get the last submitted output height before the start height from the host
219+
if ex.cfg.L2StartHeight != 0 {
220+
output, err := ex.host.QueryOutputByL2BlockNumber(ctx, bridgeId, ex.cfg.L2StartHeight)
221+
if err != nil {
222+
return 0, 0, 0, 0, err
223+
} else if output != nil {
224+
outputL1BlockNumber = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
225+
l2ProcessedHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
226+
processedOutputIndex = output.OutputIndex
227+
}
221228
}
222229

223-
l1Sequence, err := ex.child.QueryNextL1Sequence(ctx, 0)
224-
if err != nil {
225-
return 0, 0, 0, 0, err
226-
}
230+
if ex.cfg.L1StartHeight == 0 {
231+
// get the bridge start height from the host
232+
l1ProcessedHeight, err = ex.host.QueryCreateBridgeHeight(ctx, bridgeId)
233+
if err != nil {
234+
return 0, 0, 0, 0, err
235+
}
227236

228-
// query l1Sequence tx height
229-
depositTxHeight, err := ex.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence)
230-
if err != nil {
231-
return 0, 0, 0, 0, err
232-
} else if depositTxHeight == 0 && l1Sequence > 1 {
233-
// query l1Sequence - 1 tx height
234-
depositTxHeight, err = ex.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence-1)
237+
l1Sequence, err := ex.child.QueryNextL1Sequence(ctx, 0)
235238
if err != nil {
236239
return 0, 0, 0, 0, err
237240
}
238-
}
239-
if depositTxHeight >= 1 && depositTxHeight-1 > l1ProcessedHeight {
240-
l1ProcessedHeight = depositTxHeight - 1
241-
}
242241

243-
// get the last submitted output height before the start height from the host
244-
if ex.cfg.L2StartHeight != 0 {
245-
output, err := ex.host.QueryOutputByL2BlockNumber(ctx, bridgeId, ex.cfg.L2StartHeight)
242+
// query l1Sequence tx height
243+
depositTxHeight, err := ex.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence)
246244
if err != nil {
247245
return 0, 0, 0, 0, err
248-
} else if output != nil {
249-
l1BlockNumber := types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
250-
if l1BlockNumber < l1ProcessedHeight {
251-
l1ProcessedHeight = l1BlockNumber
246+
} else if depositTxHeight == 0 && l1Sequence > 1 {
247+
// query l1Sequence - 1 tx height
248+
depositTxHeight, err = ex.host.QueryDepositTxHeight(ctx, bridgeId, l1Sequence-1)
249+
if err != nil {
250+
return 0, 0, 0, 0, err
252251
}
253-
l2ProcessedHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
254-
processedOutputIndex = output.OutputIndex
255252
}
253+
if depositTxHeight > l1ProcessedHeight {
254+
l1ProcessedHeight = depositTxHeight
255+
}
256+
if outputL1BlockNumber < l1ProcessedHeight {
257+
l1ProcessedHeight = outputL1BlockNumber
258+
}
259+
} else {
260+
l1ProcessedHeight = ex.cfg.L1StartHeight
256261
}
262+
l1ProcessedHeight--
257263

258264
if ex.cfg.BatchStartHeight > 0 {
259265
batchProcessedHeight = ex.cfg.BatchStartHeight - 1

executor/types/config.go

+10
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ type Config struct {
6767
// MaxSubmissionTime is the maximum time to submit a batch.
6868
MaxSubmissionTime int64 `json:"max_submission_time"` // seconds
6969

70+
// L1StartHeight is the height to start the l1 node. If it is 0, it will finds the optimal height and sets it automatically.
71+
// However, if you do not want to use this feature, set it to a non-zero value.
72+
// There is no need for modification under normal circumstances, because it
73+
// is automatically determined when you set the l2 start height,
74+
L1StartHeight int64 `json:"l1_start_height"`
7075
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
7176
// If the latest height stored in the db is not 0, this config is ignored.
7277
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.
@@ -117,6 +122,7 @@ func DefaultConfig() *Config {
117122
MaxChunkSize: 300000, // 300KB
118123
MaxSubmissionTime: 60 * 60, // 1 hour
119124

125+
L1StartHeight: 0,
120126
L2StartHeight: 0,
121127
BatchStartHeight: 0,
122128
}
@@ -159,6 +165,10 @@ func (cfg Config) Validate() error {
159165
return errors.New("max submission time must be greater than 0")
160166
}
161167

168+
if cfg.L1StartHeight < 0 {
169+
return errors.New("l1 start height must be greater than or equal to 0")
170+
}
171+
162172
if cfg.L2StartHeight < 0 {
163173
return errors.New("l2 start height must be greater than or equal to 0")
164174
}

0 commit comments

Comments
 (0)