Initializing rootDir of dao and machine keeper with the homePath of the validators key material

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2024-03-01 00:15:02 +01:00
parent 65134b4a0b
commit 27a94d485f
No known key found for this signature in database
12 changed files with 20 additions and 13 deletions

View File

@ -549,6 +549,7 @@ func New(
keys[machinemoduletypes.MemStoreKey], keys[machinemoduletypes.MemStoreKey],
app.GetSubspace(machinemoduletypes.ModuleName), app.GetSubspace(machinemoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
homePath,
) )
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper) machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper)
@ -576,6 +577,7 @@ func New(
app.AccountKeeper, app.AccountKeeper,
app.MachineKeeper, app.MachineKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
homePath,
) )
daoModule := daomodule.NewAppModule(appCodec, app.DaoKeeper, app.AccountKeeper, app.BankKeeper) daoModule := daomodule.NewAppModule(appCodec, app.DaoKeeper, app.AccountKeeper, app.BankKeeper)

View File

@ -72,6 +72,7 @@ func DaoKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil, nil,
nil, nil,
authtypes.NewModuleAddress(govtypes.ModuleName).String(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
"",
) )
// Initialize params // Initialize params

View File

@ -61,6 +61,7 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
memStoreKey, memStoreKey,
paramsSubspace, paramsSubspace,
authtypes.NewModuleAddress(govtypes.ModuleName).String(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
"",
) )
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

View File

@ -10,7 +10,6 @@ import (
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"
"github.com/planetmint/planetmint-go/config"
) )
type Key struct { type Key struct {
@ -24,11 +23,9 @@ type KeyFile struct {
PrivKey Key `json:"priv-key"` PrivKey Key `json:"priv-key"`
} }
func GetValidatorCometBFTIdentity(ctx sdk.Context) (string, bool) { func GetValidatorCometBFTIdentity(ctx sdk.Context, rootDir string) (string, bool) {
conf := config.GetConfig()
cfg := cometcfg.DefaultConfig() cfg := cometcfg.DefaultConfig()
jsonFilePath := filepath.Join(conf.ConfigRootDir, cfg.PrivValidatorKey) jsonFilePath := filepath.Join(rootDir, cfg.PrivValidatorKey)
jsonFile, err := os.Open(jsonFilePath) jsonFile, err := os.Open(jsonFilePath)
if err != nil { if err != nil {
@ -50,8 +47,8 @@ func GetValidatorCometBFTIdentity(ctx sdk.Context) (string, bool) {
return strings.ToLower(keyFile.Address), true return strings.ToLower(keyFile.Address), true
} }
func IsValidatorBlockProposer(ctx sdk.Context, proposerAddress []byte) bool { func IsValidatorBlockProposer(ctx sdk.Context, proposerAddress []byte, rootDir string) bool {
validatorIdentity, validResult := GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := GetValidatorCometBFTIdentity(ctx, rootDir)
if !validResult { if !validResult {
return false return false
} }

View File

@ -15,7 +15,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) { if !util.IsValidatorBlockProposer(ctx, proposerAddress, k.RootDir) {
return return
} }
currentBlockHeight := req.Header.GetHeight() currentBlockHeight := req.Header.GetHeight()

View File

@ -29,6 +29,7 @@ type (
accountKeeper types.AccountKeeper accountKeeper types.AccountKeeper
machineKeeper types.MachineKeeper machineKeeper types.MachineKeeper
authority string authority string
RootDir string
} }
) )
@ -46,6 +47,7 @@ func NewKeeper(
accountKeeper types.AccountKeeper, accountKeeper types.AccountKeeper,
machineKeeper types.MachineKeeper, machineKeeper types.MachineKeeper,
authority string, authority string,
rootDir string,
) *Keeper { ) *Keeper {
// set KeyTable if it has not already been set // set KeyTable if it has not already been set
if !ps.HasKeyTable() { if !ps.HasKeyTable() {
@ -66,6 +68,7 @@ func NewKeeper(
accountKeeper: accountKeeper, accountKeeper: accountKeeper,
machineKeeper: machineKeeper, machineKeeper: machineKeeper,
authority: authority, authority: authority,
RootDir: rootDir,
} }
} }

View File

@ -28,7 +28,7 @@ func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDist
util.GetAppLogger().Info(ctx, distributionRequestTag+"storing distribution: "+msg.GetDistribution().String()) util.GetAppLogger().Info(ctx, distributionRequestTag+"storing distribution: "+msg.GetDistribution().String())
k.StoreDistributionOrder(ctx, *msg.GetDistribution()) k.StoreDistributionOrder(ctx, *msg.GetDistribution())
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if !validResult || msg.Distribution.GetProposer() != validatorIdentity { if !validResult || msg.Distribution.GetProposer() != validatorIdentity {
util.GetAppLogger().Info(ctx, distributionRequestTag+"Not the proposer. valid result: %t proposer: %s validator identity: %s", validResult, msg.Distribution.GetProposer(), validatorIdentity) util.GetAppLogger().Info(ctx, distributionRequestTag+"Not the proposer. valid result: %t proposer: %s validator identity: %s", validResult, msg.Distribution.GetProposer(), validatorIdentity)
return &types.MsgDistributionRequestResponse{}, nil return &types.MsgDistributionRequestResponse{}, nil

View File

@ -19,7 +19,7 @@ func (k msgServer) InitPop(goCtx context.Context, msg *types.MsgInitPop) (*types
k.StoreChallenge(ctx, challenge) k.StoreChallenge(ctx, challenge)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if validResult && msg.Initiator == validatorIdentity { if validResult && msg.Initiator == validatorIdentity {
go util.SendMqttPopInitMessagesToServer(ctx, challenge) go util.SendMqttPopInitMessagesToServer(ctx, challenge)
} }

View File

@ -35,7 +35,7 @@ func (k msgServer) CreateRedeemClaim(goCtx context.Context, msg *types.MsgCreate
redeemClaim, redeemClaim,
) )
if util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) { if util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress, k.RootDir) {
util.GetAppLogger().Info(ctx, fmt.Sprintf("Issuing RDDL claim: %s/%d", msg.Beneficiary, id)) util.GetAppLogger().Info(ctx, fmt.Sprintf("Issuing RDDL claim: %s/%d", msg.Beneficiary, id))
txID, err := util.DistributeAsset(msg.Beneficiary, util.UintValueToRDDLTokenString(msg.Amount), params.ReissuanceAsset) txID, err := util.DistributeAsset(msg.Beneficiary, util.UintValueToRDDLTokenString(msg.Amount), params.ReissuanceAsset)
if err != nil { if err != nil {

View File

@ -23,7 +23,7 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
reissuance.LastIncludedPop = msg.GetLastIncludedPop() reissuance.LastIncludedPop = msg.GetLastIncludedPop()
k.StoreReissuance(ctx, reissuance) k.StoreReissuance(ctx, reissuance)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if !validResult || msg.Proposer != validatorIdentity { if !validResult || msg.Proposer != validatorIdentity {
util.GetAppLogger().Info(ctx, reissueTag+"Not the proposer. valid result: %t proposer: %s validator identity: %s", validResult, msg.Proposer, validatorIdentity) util.GetAppLogger().Info(ctx, reissueTag+"Not the proposer. valid result: %t proposer: %s validator identity: %s", validResult, msg.Proposer, validatorIdentity)
return &types.MsgReissueRDDLProposalResponse{}, nil return &types.MsgReissueRDDLProposalResponse{}, nil

View File

@ -22,6 +22,7 @@ type (
memKey storetypes.StoreKey memKey storetypes.StoreKey
paramstore paramtypes.Subspace paramstore paramtypes.Subspace
authority string authority string
rootDir string
} }
) )
@ -36,6 +37,7 @@ func NewKeeper(
memKey storetypes.StoreKey, memKey storetypes.StoreKey,
ps paramtypes.Subspace, ps paramtypes.Subspace,
authority string, authority string,
rootDir string,
) *Keeper { ) *Keeper {
// set KeyTable if it has not already been set // set KeyTable if it has not already been set
if !ps.HasKeyTable() { if !ps.HasKeyTable() {
@ -53,6 +55,7 @@ func NewKeeper(
memKey: memKey, memKey: memKey,
paramstore: ps, paramstore: ps,
authority: authority, authority: authority,
rootDir: rootDir,
} }
} }

View File

@ -49,7 +49,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
return nil, types.ErrMachineTypeUndefined return nil, types.ErrMachineTypeUndefined
} }
if util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) { if util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress, k.rootDir) {
util.GetAppLogger().Info(ctx, "Issuing Machine NFT: "+msg.Machine.String()) util.GetAppLogger().Info(ctx, "Issuing Machine NFT: "+msg.Machine.String())
err := k.issueMachineNFT(goCtx, msg.Machine) err := k.issueMachineNFT(goCtx, msg.Machine)
if err != nil { if err != nil {