Skip to content

Commit

Permalink
fix: Resolved concurrency issue when sending BLS-sig txs (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry authored Nov 15, 2022
1 parent 2c880d6 commit 25d5167
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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)
}

0 comments on commit 25d5167

Please sign in to comment.