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],
app.GetSubspace(machinemoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
homePath,
)
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper)
@ -576,6 +577,7 @@ func New(
app.AccountKeeper,
app.MachineKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
homePath,
)
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,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
"",
)
// Initialize params

View File

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

View File

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

View File

@ -29,6 +29,7 @@ type (
accountKeeper types.AccountKeeper
machineKeeper types.MachineKeeper
authority string
RootDir string
}
)
@ -46,6 +47,7 @@ func NewKeeper(
accountKeeper types.AccountKeeper,
machineKeeper types.MachineKeeper,
authority string,
rootDir string,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
@ -66,6 +68,7 @@ func NewKeeper(
accountKeeper: accountKeeper,
machineKeeper: machineKeeper,
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())
k.StoreDistributionOrder(ctx, *msg.GetDistribution())
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
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)
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)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if validResult && msg.Initiator == validatorIdentity {
go util.SendMqttPopInitMessagesToServer(ctx, challenge)
}

View File

@ -35,7 +35,7 @@ func (k msgServer) CreateRedeemClaim(goCtx context.Context, msg *types.MsgCreate
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))
txID, err := util.DistributeAsset(msg.Beneficiary, util.UintValueToRDDLTokenString(msg.Amount), params.ReissuanceAsset)
if err != nil {

View File

@ -23,7 +23,7 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
reissuance.LastIncludedPop = msg.GetLastIncludedPop()
k.StoreReissuance(ctx, reissuance)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
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)
return &types.MsgReissueRDDLProposalResponse{}, nil

View File

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

View File

@ -49,7 +49,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
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())
err := k.issueMachineNFT(goCtx, msg.Machine)
if err != nil {