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
6 changes: 3 additions & 3 deletions bridge/setu/processor/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (cp *CheckpointProcessor) sendCheckpointToHeimdall(headerBlockStr string) (

cp.Logger.Info("Processing new header", "headerNumber", header.Number)
var isProposer bool
if isProposer, err = util.IsProposer(cp.cliCtx); err != nil {
if isProposer, err = util.IsProposerByIndex(cp.cliCtx, 0); err != nil {
cp.Logger.Error("Error checking isProposer in HeaderBlock handler", "error", err)
return err
}
Expand Down Expand Up @@ -386,8 +386,8 @@ func (cp *CheckpointProcessor) handleCheckpointNoAck() {
if isNoAckRequired {
var isProposer bool

if isProposer, err = util.IsInProposerList(cp.cliCtx, count); err != nil {
cp.Logger.Error("Error checking IsInProposerList while proposing Checkpoint No-Ack ", "error", err)
if isProposer, err = util.IsProposerByIndex(cp.cliCtx, count); err != nil {
cp.Logger.Error("Error checking IsProposer while proposing Checkpoint No-Ack ", "error", err)
return
}

Expand Down
16 changes: 12 additions & 4 deletions bridge/setu/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ func Logger() log.Logger {
return logger
}

// IsProposer checks if we are proposer
func IsProposer(cliCtx cliContext.CLIContext) (bool, error) {
// IsProposer checks if we are proposer.
// index starts from 0, and it will return whether it is the current proposer
// if index = 0.
func IsProposerByIndex(cliCtx cliContext.CLIContext, index uint64) (bool, error) {
var proposers []hmtypes.Validator
count := uint64(1)
count := index + 1
result, err := helper.FetchFromAPI(cliCtx,
helper.GetHeimdallServerEndpoint(fmt.Sprintf(ProposersURL, strconv.FormatUint(count, 10))),
)
Expand All @@ -105,7 +107,13 @@ func IsProposer(cliCtx cliContext.CLIContext) (bool, error) {
return false, err
}

if bytes.Equal(proposers[0].Signer.Bytes(), helper.GetAddress()) {
proposerSize := len(proposers)
if proposerSize == 0 {
return false, nil
}
proposerIndex := index % uint64(proposerSize)

if bytes.Equal(proposers[proposerIndex].Signer.Bytes(), helper.GetAddress()) {
return true, nil
}

Expand Down