Skip to content

Commit

Permalink
seal object validate if secondary SP in_service
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Jan 15, 2024
1 parent fa17b52 commit 4470045
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (k Keeper) SealObject(
}
// validate seal object bls aggregated sig from secondary sps
secondarySpsSealObjectBlsSignHash := types.NewSecondarySpSealObjectSignDoc(ctx.ChainID(), gvg.Id, objectInfo.Id, types.GenerateHash(objectInfo.Checksums[:])).GetBlsSignHash()
err := k.VerifyGVGSecondarySPsBlsSignature(ctx, gvg, secondarySpsSealObjectBlsSignHash, opts.SecondarySpBlsSignatures)
err := k.VerifyGVGSecondarySPsBlsSignatureAndStatus(ctx, gvg, secondarySpsSealObjectBlsSignHash, opts.SecondarySpBlsSignatures)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func (k Keeper) verifyGVGSignatures(ctx sdk.Context, bucketID math.Uint, dstSP *
}
// validate the aggregated bls signature
migrationBucketSignDocBlsSignHash := storagetypes.NewSecondarySpMigrationBucketSignDoc(ctx.ChainID(), bucketID, dstSP.Id, newLvg2gvg.SrcGlobalVirtualGroupId, dstGVG.Id).GetBlsSignHash()
err := k.VerifyGVGSecondarySPsBlsSignature(ctx, dstGVG, migrationBucketSignDocBlsSignHash, newLvg2gvg.SecondarySpBlsSignature)
err := k.VerifyGVGSecondarySPsBlsSignatureAndStatus(ctx, dstGVG, migrationBucketSignDocBlsSignHash, newLvg2gvg.SecondarySpBlsSignature)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion x/storage/keeper/virtualgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package keeper
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/prysmaticlabs/prysm/crypto/bls"

gnfdtypes "github.com/bnb-chain/greenfield/types"
sptypes "github.com/bnb-chain/greenfield/x/sp/types"
"github.com/bnb-chain/greenfield/x/storage/types"
vgtypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"
)
Expand Down Expand Up @@ -115,13 +117,18 @@ func (k Keeper) RebindingVirtualGroup(ctx sdk.Context, bucketInfo *types.BucketI
return nil
}

func (k Keeper) VerifyGVGSecondarySPsBlsSignature(ctx sdk.Context, gvg *vgtypes.GlobalVirtualGroup, signHash [32]byte, signature []byte) error {
func (k Keeper) VerifyGVGSecondarySPsBlsSignatureAndStatus(ctx sdk.Context, gvg *vgtypes.GlobalVirtualGroup, signHash [32]byte, signature []byte) error {
secondarySpBlsPubKeys := make([]bls.PublicKey, 0, len(gvg.SecondarySpIds))
for _, spId := range gvg.GetSecondarySpIds() {
secondarySp, found := k.spKeeper.GetStorageProvider(ctx, spId)
if !found {
panic("should not happen")
}
if ctx.IsUpgraded(upgradetypes.HulunbeierPatch) {
if secondarySp.Status != sptypes.STATUS_IN_SERVICE {
return sptypes.ErrStorageProviderNotInService
}
}
spBlsPubKey, err := bls.PublicKeyFromBytes(secondarySp.BlsKey)
if err != nil {
return types.ErrInvalidBlsPubKey.Wrapf("BLS public key converts failed: %v", err)
Expand Down

0 comments on commit 4470045

Please sign in to comment.