Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolved concurrency issue when sending BLS-sig txs #202

Merged
merged 1 commit into from
Nov 15, 2022
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
3 changes: 2 additions & 1 deletion x/checkpointing/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, req abci.RequestBeginBlock)
if err != nil {
panic(err)
}
curValSet := k.GetValidatorSet(ctx, epoch.EpochNumber-1)

go func() {
err := k.SendBlsSig(ctx, epoch.EpochNumber-1, lch)
err := k.SendBlsSig(ctx, epoch.EpochNumber-1, lch, curValSet)
if err != nil {
// failing to send a BLS-sig causes a panicking situation
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions x/checkpointing/keeper/bls_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
epochingtypes "github.com/babylonchain/babylon/x/epoching/types"
"time"

"github.com/babylonchain/babylon/client/tx"
Expand All @@ -18,13 +19,12 @@ type BlsSigner interface {
}

// SendBlsSig prepares a BLS signature message and sends it to Tendermint
func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommitHash) error {
func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommitHash, valSet epochingtypes.ValidatorSet) error {
// get self address
curValSet := k.GetValidatorSet(ctx, epochNum)
addr := k.blsSigner.GetAddress()

// check if itself is the validator
_, _, err := curValSet.FindValidatorWithIndex(addr)
_, _, err := valSet.FindValidatorWithIndex(addr)
if err != nil {
// only send the BLS sig when the node itself is a validator, not being a validator is not an error
return nil
Expand Down
3 changes: 1 addition & 2 deletions x/checkpointing/keeper/bls_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ func TestKeeper_SendBlsSig(t *testing.T) {
signer := mocks.NewMockBlsSigner(ctrl)
ckptkeeper, ctx, _ := testkeeper.CheckpointingKeeper(t, ek, signer, clientCtx)

ek.EXPECT().GetValidatorSet(ctx, gomock.Eq(epochNum)).Return(valSet)
signer.EXPECT().GetAddress().Return(addr1)
signer.EXPECT().SignMsgWithBls(gomock.Eq(signBytes)).Return(bls12381.Sign(blsPrivKey1, signBytes), nil)
err = ckptkeeper.SendBlsSig(ctx, epochNum, lch)
err = ckptkeeper.SendBlsSig(ctx, epochNum, lch, valSet)
require.NoError(t, err)
}