mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 14:35:47 +00:00
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:
parent
65134b4a0b
commit
27a94d485f
@ -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)
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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())
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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()
|
||||||
|
|||||||
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user