Skip to content

Commit 4e209e6

Browse files
authored
Bug/config (#9)
* bug fix initializing ouptut index when l2 start height 0 * key dir change * move get key dir func to keys * tx checker does not start when broadcaster is nil
1 parent f8acae3 commit 4e209e6

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

executor/batch/handler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight uint64)
181181
Save: true,
182182
})
183183

184-
for offset := int64(0); ; offset += bs.batchCfg.MaxChunkSize {
184+
for offset := int64(0); ; offset += int64(bs.batchCfg.MaxChunkSize) {
185185
readLength, err := bs.batchFile.ReadAt(batchBuffer, offset)
186186
if err != nil && err != io.EOF {
187187
return err
@@ -202,7 +202,7 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight uint64)
202202
})
203203
checksum := sha256.Sum256(batchBuffer)
204204
checksums = append(checksums, checksum[:])
205-
if int64(readLength) < bs.batchCfg.MaxChunkSize {
205+
if uint64(readLength) < bs.batchCfg.MaxChunkSize {
206206
break
207207
}
208208
}
@@ -250,7 +250,7 @@ func (bs *BatchSubmitter) checkBatch(blockHeight uint64, blockTime time.Time) er
250250
// then finalize the batch
251251
if blockTime.After(bs.lastSubmissionTime.Add(bs.bridgeInfo.BridgeConfig.SubmissionInterval*2/3)) ||
252252
blockTime.After(bs.lastSubmissionTime.Add(time.Duration(bs.batchCfg.MaxSubmissionTime)*time.Second)) ||
253-
fileSize > (bs.batchCfg.MaxChunks-1)*bs.batchCfg.MaxChunkSize {
253+
uint64(fileSize) > (bs.batchCfg.MaxChunks-1)*bs.batchCfg.MaxChunkSize {
254254

255255
// finalize the batch
256256
bs.batchHeader.End = blockHeight

executor/executor.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,13 @@ func (ex *Executor) getStartHeights(ctx context.Context, bridgeId uint64) (l1Sta
209209

210210
// get the last submitted output height before the start height from the host
211211
if ex.cfg.L2StartHeight != 0 {
212-
output, err := ex.host.QueryOutputByL2BlockNumber(ctx, bridgeId, uint64(ex.cfg.L2StartHeight))
212+
output, err := ex.host.QueryOutputByL2BlockNumber(ctx, bridgeId, ex.cfg.L2StartHeight)
213213
if err != nil {
214214
return 0, 0, 0, 0, err
215215
} else if output != nil {
216216
l1StartHeight = output.OutputProposal.L1BlockNumber
217217
l2StartHeight = output.OutputProposal.L2BlockNumber
218218
startOutputIndex = output.OutputIndex + 1
219-
} else {
220-
startOutputIndex = 1
221219
}
222220
}
223221
// get the last deposit tx height from the host
@@ -232,6 +230,11 @@ func (ex *Executor) getStartHeights(ctx context.Context, bridgeId uint64) (l1Sta
232230
if l1StartHeight > depositTxHeight {
233231
l1StartHeight = depositTxHeight
234232
}
235-
batchStartHeight = uint64(ex.cfg.BatchStartHeight) - 1
233+
if l2StartHeight == 0 {
234+
startOutputIndex = 1
235+
}
236+
if ex.cfg.BatchStartHeight > 0 {
237+
batchStartHeight = ex.cfg.BatchStartHeight - 1
238+
}
236239
return l1StartHeight, l2StartHeight, startOutputIndex, batchStartHeight, err
237240
}

executor/types/config.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ type Config struct {
6060
RelayOracle bool `json:"relay_oracle"`
6161

6262
// MaxChunks is the maximum number of chunks in a batch.
63-
MaxChunks int64 `json:"max_chunks"`
63+
MaxChunks uint64 `json:"max_chunks"`
6464
// MaxChunkSize is the maximum size of a chunk in a batch.
65-
MaxChunkSize int64 `json:"max_chunk_size"`
65+
MaxChunkSize uint64 `json:"max_chunk_size"`
6666
// MaxSubmissionTime is the maximum time to submit a batch.
67-
MaxSubmissionTime int64 `json:"max_submission_time"` // seconds
67+
MaxSubmissionTime uint64 `json:"max_submission_time"` // seconds
6868

6969
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
7070
// If the latest height stored in the db is not 0, this config is ignored.
7171
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.
7272
// L1 starts from the block number of the output tx + 1
73-
L2StartHeight int64 `json:"l2_start_height"`
73+
L2StartHeight uint64 `json:"l2_start_height"`
7474
// BatchStartHeight is the height to start the batch. If it is 0, it will start from the latest height.
7575
// If the latest height stored in the db is not 0, this config is ignored.
76-
BatchStartHeight int64 `json:"batch_start_height"`
76+
BatchStartHeight uint64 `json:"batch_start_height"`
7777
}
7878

7979
func DefaultConfig() *Config {
@@ -219,7 +219,7 @@ func (cfg Config) BatchConfig() BatchConfig {
219219
}
220220

221221
type BatchConfig struct {
222-
MaxChunks int64 `json:"max_chunks"`
223-
MaxChunkSize int64 `json:"max_chunk_size"`
224-
MaxSubmissionTime int64 `json:"max_submission_time"` // seconds
222+
MaxChunks uint64 `json:"max_chunks"`
223+
MaxChunkSize uint64 `json:"max_chunk_size"`
224+
MaxSubmissionTime uint64 `json:"max_submission_time"` // seconds
225225
}

keys/keyring.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ package keys
33
import (
44
"io"
55

6+
"path"
7+
68
"github.com/cosmos/go-bip39"
79

810
"github.com/cosmos/cosmos-sdk/codec"
911
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1012
)
1113

14+
func GetKeyDir(homePath string) string {
15+
return path.Join(homePath, ".keys")
16+
}
17+
1218
func GetKeyBase(chainId string, dir string, cdc codec.Codec, userInput io.Reader) (keyring.Keyring, error) {
13-
return keyring.New(chainId, "os", dir, userInput, cdc)
19+
return keyring.New(chainId, "os", GetKeyDir(dir), userInput, cdc)
1420
}
1521

1622
// CreateMnemonic generates a new mnemonic.

node/process.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (n *Node) handleEvent(ctx context.Context, blockHeight uint64, latestHeight
195195

196196
// txChecker checks pending txs and handle events if the tx is included in the block
197197
func (n *Node) txChecker(ctx context.Context) error {
198-
if n.broadcaster != nil {
198+
if n.broadcaster == nil {
199199
return nil
200200
}
201201

0 commit comments

Comments
 (0)