Skip to content

Commit

Permalink
enter batch model if fall behind
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyangLiu committed Aug 25, 2020
1 parent 915364e commit dd893a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type BBCConfig struct {
Mnemonic string `json:"mnemonic"`
SleepMillisecondForWaitBlock int64 `json:"sleep_millisecond_for_wait_block"`
BlockIntervalForCleanUpUndeliveredPackages uint64 `json:"block_interval_for_clean_up_undelivered_packages"`
BehindBlockThreshold uint64 `json:"behind_block_threshold"`
}

func (cfg *BBCConfig) Validate() {
Expand All @@ -78,6 +79,9 @@ func (cfg *BBCConfig) Validate() {
if cfg.BlockIntervalForCleanUpUndeliveredPackages == 0 {
panic("block interval for cleanup undelivered packages must not be zero")
}
if cfg.BehindBlockThreshold == 0 {
panic("behind block threshold should be be positive")
}
}

type BSCConfig struct {
Expand Down
3 changes: 2 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"aws_secret_name": "",
"mnemonic": "",
"sleep_millisecond_for_wait_block": 500,
"block_interval_for_clean_up_undelivered_packages": 5500
"block_interval_for_clean_up_undelivered_packages": 5500,
"behind_block_threshold": 100
},
"bsc_config": {
"key_type": "local_private_key",
Expand Down
19 changes: 19 additions & 0 deletions relayer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@ const (
WaitSecondForTrackTx = 10
)

func (r *Relayer) getLatestHeight() uint64 {
abciInfo, err := r.bbcExecutor.RpcClient.ABCIInfo()
if err != nil {
common.Logger.Errorf("Query latest height error: %s", err.Error())
return 0
}
return uint64(abciInfo.Response.LastBlockHeight)
}

func (r *Relayer) relayerDaemon(startHeight uint64, curValidatorsHash cmn.HexBytes) {
var tashSet *common.TaskSet
var err error
height := startHeight
common.Logger.Info("Start relayer daemon")
for {
latestHeight := r.getLatestHeight() - 1
if latestHeight > height+r.bbcExecutor.Config.BBCConfig.BehindBlockThreshold {
err := r.cleanPreviousPackages(latestHeight)
if err != nil {
common.Logger.Error(err.Error())
}
height = latestHeight
continue // packages have been delivered on cleanup
}

tashSet, curValidatorsHash, err = r.bbcExecutor.MonitorCrossChainPackage(int64(height), curValidatorsHash)
if err != nil {
sleepTime := time.Duration(r.bbcExecutor.Config.BBCConfig.SleepMillisecondForWaitBlock * int64(time.Millisecond))
Expand Down

0 comments on commit dd893a3

Please sign in to comment.