Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bridge/setu/listener/tron.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (tl *TronListener) queryAndBroadcastEvents(chainManagerParams *chainmanager
// topup has to be processed first before validator join. so adding delay.
delay := util.TaskDelayBetweenEachVal
tl.sendTaskWithDelay("sendValidatorJoinToHeimdall", selectedEvent.Name, logBytes, delay)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(tl.cliCtx); isCurrentValidator {
} else if isCurrentValidator, delay := util.CalculateTaskDelayWithOffset(tl.cliCtx,1); isCurrentValidator {
// topup has to be processed first before validator join. so adding delay.
delay = delay + util.TaskDelayBetweenEachVal
tl.sendTaskWithDelay("sendValidatorJoinToHeimdall", selectedEvent.Name, logBytes, delay)
Expand All @@ -237,7 +237,7 @@ func (tl *TronListener) queryAndBroadcastEvents(chainManagerParams *chainmanager
}
if bytes.Equal(event.SignerPubkey, pubkeyBytes) {
tl.sendTaskWithDelay("sendSignerChangeToHeimdall", selectedEvent.Name, logBytes, 0)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(tl.cliCtx); isCurrentValidator {
} else if isCurrentValidator, delay := util.CalculateTaskDelayWithOffset(tl.cliCtx,1); isCurrentValidator {
tl.sendTaskWithDelay("sendSignerChangeToHeimdall", selectedEvent.Name, logBytes, delay)
}

Expand All @@ -248,7 +248,7 @@ func (tl *TronListener) queryAndBroadcastEvents(chainManagerParams *chainmanager
}
if util.IsEventSender(tl.cliCtx, event.ValidatorId.Uint64()) {
tl.sendTaskWithDelay("sendUnstakeInitToHeimdall", selectedEvent.Name, logBytes, 0)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(tl.cliCtx); isCurrentValidator {
} else if isCurrentValidator, delay := util.CalculateTaskDelayWithOffset(tl.cliCtx,1); isCurrentValidator {
tl.sendTaskWithDelay("sendUnstakeInitToHeimdall", selectedEvent.Name, logBytes, delay)
}

Expand All @@ -264,7 +264,7 @@ func (tl *TronListener) queryAndBroadcastEvents(chainManagerParams *chainmanager
}
if bytes.Equal(event.User.Bytes(), helper.GetAddress()) {
tl.sendTaskWithDelay("sendTopUpFeeToHeimdall", selectedEvent.Name, logBytes, 0)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(tl.cliCtx); isCurrentValidator {
} else if isCurrentValidator, delay := util.CalculateTaskDelayWithOffset(tl.cliCtx,1); isCurrentValidator {
tl.sendTaskWithDelay("sendTopUpFeeToHeimdall", selectedEvent.Name, logBytes, delay)
}

Expand All @@ -280,7 +280,7 @@ func (tl *TronListener) queryAndBroadcastEvents(chainManagerParams *chainmanager
}
if util.IsEventSender(tl.cliCtx, event.ValidatorId.Uint64()) {
tl.sendTaskWithDelay("sendUnjailToHeimdall", selectedEvent.Name, logBytes, 0)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(tl.cliCtx); isCurrentValidator {
} else if isCurrentValidator, delay := util.CalculateTaskDelayWithOffset(tl.cliCtx,1); isCurrentValidator {
tl.sendTaskWithDelay("sendUnjailToHeimdall", selectedEvent.Name, logBytes, delay)
}

Expand Down
10 changes: 8 additions & 2 deletions bridge/setu/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,15 @@ func IsInProposerList(cliCtx cliContext.CLIContext, count uint64) (bool, error)
return false, nil
}

//default offset 0
func CalculateTaskDelay(cliCtx cliContext.CLIContext) (bool, time.Duration){
return CalculateTaskDelayWithOffset(cliCtx,0)
}

// CalculateTaskDelay calculates delay required for current validator to propose the tx
// It solves for multiple validators sending same transaction.
func CalculateTaskDelay(cliCtx cliContext.CLIContext) (bool, time.Duration) {
// with offset
func CalculateTaskDelayWithOffset(cliCtx cliContext.CLIContext, offset int) (bool, time.Duration) {
// calculate validator position
valPosition := 0
isCurrentValidator := false
Expand All @@ -162,7 +168,7 @@ func CalculateTaskDelay(cliCtx cliContext.CLIContext) (bool, time.Duration) {
logger.Info("Fetched current validatorset list", "currentValidatorcount", len(validatorSet.Validators))
for i, validator := range validatorSet.Validators {
if bytes.Equal(validator.Signer.Bytes(), helper.GetAddress()) {
valPosition = i + 1
valPosition = i + offset
isCurrentValidator = true
break
}
Expand Down
5 changes: 2 additions & 3 deletions helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ type Configuration struct {
BttcRPCUrl string `mapstructure:"bttc_rpc_url"` // RPC endpoint for bttc chain
TendermintRPCUrl string `mapstructure:"tendermint_rpc_url"` // tendemint node url

TronGridURL string `mapstructure:"tron_grid_url"` // tron grid url
TronGridUrl string `mapstructure:"tron_grid_url"` // tron grid url
AmqpURL string `mapstructure:"amqp_url"` // amqp url
DeliveryServerURL string `mapstructure:"delivery_rest_server"` // delivery server url

// tron
TronGridUrl string `mapstructure:"tron_grid_url"` // tron server url
TronGridApiKey string `mapstructure:"tron_grid_api_key"` // tron api key

MainchainGasLimit uint64 `mapstructure:"main_chain_gas_limit"` // gas limit to mainchain transaction. eg....submit checkpoint.
Expand Down Expand Up @@ -266,7 +265,7 @@ func GetDefaultHeimdallConfig() Configuration {
BscRPCUrl: DefaultBscRPCUrl,
TendermintRPCUrl: DefaultTendermintNodeURL,

TronGridURL: DefaultTronGridUrl,
TronGridUrl: DefaultTronGridUrl,
AmqpURL: DefaultAmqpURL,
DeliveryServerURL: DefaultDeliveryServerURL,

Expand Down
2 changes: 1 addition & 1 deletion helper/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func GetHeimdallServerEndpoint(endpoint string) string {

// GetTronGridEndpoint returns tron server endpoint
func GetTronGridEndpoint(endpoint string) string {
u, _ := url.Parse(GetConfig().TronGridURL)
u, _ := url.Parse(GetConfig().TronGridUrl)
u.Path = path.Join(u.Path, endpoint)
return u.String()
}
Expand Down