Skip to content

Commit

Permalink
Bug/config (#9)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sh-cha authored Aug 16, 2024
1 parent f8acae3 commit 4e209e6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions executor/batch/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
16 changes: 8 additions & 8 deletions executor/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
8 changes: 7 additions & 1 deletion keys/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion node/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4e209e6

Please sign in to comment.