diff --git a/executor/batch/handler.go b/executor/batch/handler.go index e1b0ce2..2c044a7 100644 --- a/executor/batch/handler.go +++ b/executor/batch/handler.go @@ -181,7 +181,7 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight uint64) Save: true, }) - for offset := int64(0); ; offset += bs.batchCfg.MaxChunkSize { + for offset := int64(0); ; offset += int64(bs.batchCfg.MaxChunkSize) { readLength, err := bs.batchFile.ReadAt(batchBuffer, offset) if err != nil && err != io.EOF { return err @@ -202,7 +202,7 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight uint64) }) checksum := sha256.Sum256(batchBuffer) checksums = append(checksums, checksum[:]) - if int64(readLength) < bs.batchCfg.MaxChunkSize { + if uint64(readLength) < bs.batchCfg.MaxChunkSize { break } } @@ -250,7 +250,7 @@ func (bs *BatchSubmitter) checkBatch(blockHeight uint64, blockTime time.Time) er // then finalize the batch if blockTime.After(bs.lastSubmissionTime.Add(bs.bridgeInfo.BridgeConfig.SubmissionInterval*2/3)) || blockTime.After(bs.lastSubmissionTime.Add(time.Duration(bs.batchCfg.MaxSubmissionTime)*time.Second)) || - fileSize > (bs.batchCfg.MaxChunks-1)*bs.batchCfg.MaxChunkSize { + uint64(fileSize) > (bs.batchCfg.MaxChunks-1)*bs.batchCfg.MaxChunkSize { // finalize the batch bs.batchHeader.End = blockHeight diff --git a/executor/executor.go b/executor/executor.go index b561282..26e1e68 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -209,15 +209,13 @@ func (ex *Executor) getStartHeights(ctx context.Context, bridgeId uint64) (l1Sta // get the last submitted output height before the start height from the host if ex.cfg.L2StartHeight != 0 { - output, err := ex.host.QueryOutputByL2BlockNumber(ctx, bridgeId, uint64(ex.cfg.L2StartHeight)) + output, err := ex.host.QueryOutputByL2BlockNumber(ctx, bridgeId, ex.cfg.L2StartHeight) if err != nil { return 0, 0, 0, 0, err } else if output != nil { l1StartHeight = output.OutputProposal.L1BlockNumber l2StartHeight = output.OutputProposal.L2BlockNumber startOutputIndex = output.OutputIndex + 1 - } else { - startOutputIndex = 1 } } // get the last deposit tx height from the host @@ -232,6 +230,11 @@ func (ex *Executor) getStartHeights(ctx context.Context, bridgeId uint64) (l1Sta if l1StartHeight > depositTxHeight { l1StartHeight = depositTxHeight } - batchStartHeight = uint64(ex.cfg.BatchStartHeight) - 1 + if l2StartHeight == 0 { + startOutputIndex = 1 + } + if ex.cfg.BatchStartHeight > 0 { + batchStartHeight = ex.cfg.BatchStartHeight - 1 + } return l1StartHeight, l2StartHeight, startOutputIndex, batchStartHeight, err } diff --git a/executor/types/config.go b/executor/types/config.go index 41292e7..7b27541 100644 --- a/executor/types/config.go +++ b/executor/types/config.go @@ -60,20 +60,20 @@ type Config struct { RelayOracle bool `json:"relay_oracle"` // MaxChunks is the maximum number of chunks in a batch. - MaxChunks int64 `json:"max_chunks"` + MaxChunks uint64 `json:"max_chunks"` // MaxChunkSize is the maximum size of a chunk in a batch. - MaxChunkSize int64 `json:"max_chunk_size"` + MaxChunkSize uint64 `json:"max_chunk_size"` // MaxSubmissionTime is the maximum time to submit a batch. - MaxSubmissionTime int64 `json:"max_submission_time"` // seconds + MaxSubmissionTime uint64 `json:"max_submission_time"` // seconds // L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height. // If the latest height stored in the db is not 0, this config is ignored. // L2 starts from the last submitted output l2 block number + 1 before L2StartHeight. // L1 starts from the block number of the output tx + 1 - L2StartHeight int64 `json:"l2_start_height"` + L2StartHeight uint64 `json:"l2_start_height"` // BatchStartHeight is the height to start the batch. If it is 0, it will start from the latest height. // If the latest height stored in the db is not 0, this config is ignored. - BatchStartHeight int64 `json:"batch_start_height"` + BatchStartHeight uint64 `json:"batch_start_height"` } func DefaultConfig() *Config { @@ -219,7 +219,7 @@ func (cfg Config) BatchConfig() BatchConfig { } type BatchConfig struct { - MaxChunks int64 `json:"max_chunks"` - MaxChunkSize int64 `json:"max_chunk_size"` - MaxSubmissionTime int64 `json:"max_submission_time"` // seconds + MaxChunks uint64 `json:"max_chunks"` + MaxChunkSize uint64 `json:"max_chunk_size"` + MaxSubmissionTime uint64 `json:"max_submission_time"` // seconds } diff --git a/keys/keyring.go b/keys/keyring.go index 3897b44..b8517a4 100644 --- a/keys/keyring.go +++ b/keys/keyring.go @@ -3,14 +3,20 @@ package keys import ( "io" + "path" + "github.com/cosmos/go-bip39" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" ) +func GetKeyDir(homePath string) string { + return path.Join(homePath, ".keys") +} + func GetKeyBase(chainId string, dir string, cdc codec.Codec, userInput io.Reader) (keyring.Keyring, error) { - return keyring.New(chainId, "os", dir, userInput, cdc) + return keyring.New(chainId, "os", GetKeyDir(dir), userInput, cdc) } // CreateMnemonic generates a new mnemonic. diff --git a/node/process.go b/node/process.go index 2bd4827..04e8f27 100644 --- a/node/process.go +++ b/node/process.go @@ -195,7 +195,7 @@ func (n *Node) handleEvent(ctx context.Context, blockHeight uint64, latestHeight // txChecker checks pending txs and handle events if the tx is included in the block func (n *Node) txChecker(ctx context.Context) error { - if n.broadcaster != nil { + if n.broadcaster == nil { return nil }