mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-27 15:53:41 +00:00
refactor: IsValidatorBlockProposer no longer accepts proposerAddress because already given in ctx
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
0b17e93e9c
commit
f1e029eaf9
@ -8,6 +8,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/planetmint/planetmint-go/errormsg"
|
||||||
|
|
||||||
cometcfg "github.com/cometbft/cometbft/config"
|
cometcfg "github.com/cometbft/cometbft/config"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
@ -48,12 +50,13 @@ func GetValidatorCometBFTIdentity(ctx sdk.Context, rootDir string) (validatorIde
|
|||||||
return
|
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)
|
validatorIdentity, err := GetValidatorCometBFTIdentity(ctx, rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
GetAppLogger().Error(ctx, errormsg.CouldNotGetValidatorIdentity+": "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hexProposerAddress := hex.EncodeToString(proposerAddress)
|
hexProposerAddress := hex.EncodeToString(ctx.BlockHeader().ProposerAddress)
|
||||||
result = hexProposerAddress == validatorIdentity
|
result = hexProposerAddress == validatorIdentity
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
|
|||||||
|
|
||||||
// Check if node is block proposer
|
// Check if node is block proposer
|
||||||
// take the following actions only once, that's why we filter for the 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
|
return
|
||||||
}
|
}
|
||||||
currentBlockHeight := req.Header.GetHeight()
|
currentBlockHeight := req.Header.GetHeight()
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/planetmint/planetmint-go/errormsg"
|
|
||||||
"github.com/planetmint/planetmint-go/util"
|
"github.com/planetmint/planetmint-go/util"
|
||||||
"github.com/planetmint/planetmint-go/x/dao/types"
|
"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)
|
amount := k.GetValidatorPoPReward(ctx)
|
||||||
k.StoreChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
|
k.StoreChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
|
||||||
|
|
||||||
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
|
if util.IsValidatorBlockProposer(ctx, k.RootDir) {
|
||||||
if err != nil {
|
|
||||||
util.GetAppLogger().Error(ctx, initPopTag+errormsg.CouldNotGetValidatorIdentity+": "+err.Error())
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if msg.Initiator == validatorIdentity {
|
|
||||||
go util.SendMqttPopInitMessagesToServer(ctx, challenge)
|
go util.SendMqttPopInitMessagesToServer(ctx, challenge)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func (k msgServer) CreateRedeemClaim(goCtx context.Context, msg *types.MsgCreate
|
|||||||
redeemClaim,
|
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)
|
go postClaimToService(goCtx, msg.GetBeneficiary(), burnCoins.Amount.Uint64(), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
|||||||
return nil, types.ErrMachineTypeUndefined
|
return nil, types.ErrMachineTypeUndefined
|
||||||
}
|
}
|
||||||
params := k.GetParams(ctx)
|
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())
|
util.GetAppLogger().Info(ctx, "Issuing Machine NFT: "+msg.Machine.String())
|
||||||
scheme := params.AssetRegistryScheme
|
scheme := params.AssetRegistryScheme
|
||||||
domain := params.AssetRegistryDomain
|
domain := params.AssetRegistryDomain
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user