refactor: IsValidatorBlockProposer no longer accepts proposerAddress because already given in ctx

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-10-23 12:50:27 +02:00
parent 0b17e93e9c
commit f1e029eaf9
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
5 changed files with 9 additions and 12 deletions

View File

@ -8,6 +8,8 @@ import (
"path/filepath"
"strings"
"github.com/planetmint/planetmint-go/errormsg"
cometcfg "github.com/cometbft/cometbft/config"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -48,12 +50,13 @@ func GetValidatorCometBFTIdentity(ctx sdk.Context, rootDir string) (validatorIde
return
}
func IsValidatorBlockProposer(ctx sdk.Context, proposerAddress []byte, rootDir string) (result bool) {
func IsValidatorBlockProposer(ctx sdk.Context, rootDir string) (result bool) {
validatorIdentity, err := GetValidatorCometBFTIdentity(ctx, rootDir)
if err != nil {
GetAppLogger().Error(ctx, errormsg.CouldNotGetValidatorIdentity+": "+err.Error())
return
}
hexProposerAddress := hex.EncodeToString(proposerAddress)
hexProposerAddress := hex.EncodeToString(ctx.BlockHeader().ProposerAddress)
result = hexProposerAddress == validatorIdentity
return
}

View File

@ -16,7 +16,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
// Check if node is block proposer
// take the following actions only once, that's why we filter for the Block Proposer
if !util.IsValidatorBlockProposer(ctx, proposerAddress, k.RootDir) {
if !util.IsValidatorBlockProposer(ctx, k.RootDir) {
return
}
currentBlockHeight := req.Header.GetHeight()

View File

@ -4,7 +4,6 @@ import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/errormsg"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types"
)
@ -27,12 +26,7 @@ func (k msgServer) InitPop(goCtx context.Context, msg *types.MsgInitPop) (*types
amount := k.GetValidatorPoPReward(ctx)
k.StoreChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if err != nil {
util.GetAppLogger().Error(ctx, initPopTag+errormsg.CouldNotGetValidatorIdentity+": "+err.Error())
return nil, err
}
if msg.Initiator == validatorIdentity {
if util.IsValidatorBlockProposer(ctx, k.RootDir) {
go util.SendMqttPopInitMessagesToServer(ctx, challenge)
}

View File

@ -39,7 +39,7 @@ func (k msgServer) CreateRedeemClaim(goCtx context.Context, msg *types.MsgCreate
redeemClaim,
)
if util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress, k.RootDir) {
if util.IsValidatorBlockProposer(ctx, k.RootDir) {
go postClaimToService(goCtx, msg.GetBeneficiary(), burnCoins.Amount.Uint64(), id)
}

View File

@ -50,7 +50,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
return nil, types.ErrMachineTypeUndefined
}
params := k.GetParams(ctx)
if util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress, k.rootDir) {
if util.IsValidatorBlockProposer(ctx, k.rootDir) {
util.GetAppLogger().Info(ctx, "Issuing Machine NFT: "+msg.Machine.String())
scheme := params.AssetRegistryScheme
domain := params.AssetRegistryDomain