diff --git a/app/cmd/cli/root.go b/app/cmd/cli/root.go index 9168db4ec..5306dd735 100644 --- a/app/cmd/cli/root.go +++ b/app/cmd/cli/root.go @@ -22,6 +22,7 @@ var ( keybase bool mainnet bool testnet bool + altruism bool ) var CLIVersion = app.AppVersion @@ -56,6 +57,7 @@ func init() { startCmd.Flags().BoolVar(&keybase, "keybase", true, "run with keybase, if disabled allows you to stake for the current validator only. providing a keybase is still neccesary for staking for apps & sending transactions") startCmd.Flags().BoolVar(&mainnet, "mainnet", false, "run with mainnet genesis") startCmd.Flags().BoolVar(&testnet, "testnet", false, "run with testnet genesis") + startCmd.Flags().BoolVar(&altruism, "altruism", false, "run with no relay validation") rootCmd.AddCommand(startCmd) rootCmd.AddCommand(resetCmd) rootCmd.AddCommand(version) @@ -78,7 +80,7 @@ var startCmd = &cobra.Command{ if testnet { genesisType = app.TestnetGenesisType } - tmNode := app.InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL, keybase, genesisType) + tmNode := app.InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL, keybase, genesisType, altruism) go rpc.StartRPC(app.GlobalConfig.PocketConfig.RPCPort, simulateRelay) // trap kill signals (2,3,15,9) signalChannel := make(chan os.Signal, 1) diff --git a/app/config.go b/app/config.go index 3491ee517..e4ff1a141 100644 --- a/app/config.go +++ b/app/config.go @@ -178,13 +178,13 @@ func DefaultConfig(dataDir string) Config { return c } -func InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL string, keybase bool, genesisType GenesisType) *node.Node { +func InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL string, keybase bool, genesisType GenesisType, altruism bool) *node.Node { // init config InitConfig(datadir, tmNode, persistentPeers, seeds, remoteCLIURL) // init the keyfiles InitKeyfiles() // init cache - InitPocketCoreConfig() + InitPocketCoreConfig(altruism) // init genesis InitGenesis(genesisType) // init the tendermint node @@ -370,8 +370,8 @@ func InitKeyfiles() { } } -func InitPocketCoreConfig() { - types.InitConfig(GlobalConfig.PocketConfig.UserAgent, GlobalConfig.PocketConfig.DataDir, GlobalConfig.PocketConfig.DataDir, GlobalConfig.PocketConfig.SessionDBType, GlobalConfig.PocketConfig.EvidenceDBType, GlobalConfig.PocketConfig.MaxEvidenceCacheEntires, GlobalConfig.PocketConfig.MaxSessionCacheEntries, GlobalConfig.PocketConfig.EvidenceDBName, GlobalConfig.PocketConfig.SessionDBName) +func InitPocketCoreConfig(altruism bool) { + types.InitConfig(GlobalConfig.PocketConfig.UserAgent, GlobalConfig.PocketConfig.DataDir, GlobalConfig.PocketConfig.DataDir, GlobalConfig.PocketConfig.SessionDBType, GlobalConfig.PocketConfig.EvidenceDBType, GlobalConfig.PocketConfig.MaxEvidenceCacheEntires, GlobalConfig.PocketConfig.MaxSessionCacheEntries, GlobalConfig.PocketConfig.EvidenceDBName, GlobalConfig.PocketConfig.SessionDBName, altruism) types.InitClientBlockAllowance(GlobalConfig.PocketConfig.ClientBlockSyncAllowance) types.InitJSONSorting(GlobalConfig.PocketConfig.JSONSortRelayResponses) nodesTypes.InitConfig(GlobalConfig.PocketConfig.ValidatorCacheSize) diff --git a/x/pocketcore/keeper/service.go b/x/pocketcore/keeper/service.go index cb0b3d616..22cde9e2f 100644 --- a/x/pocketcore/keeper/service.go +++ b/x/pocketcore/keeper/service.go @@ -10,34 +10,36 @@ import ( // "HandleRelay" - Handles an api (read/write) request to a non-native (external) blockchain func (k Keeper) HandleRelay(ctx sdk.Ctx, relay pc.Relay) (*pc.RelayResponse, sdk.Error) { - // get the latest session block height because this relay will correspond with the latest session - sessionBlockHeight := k.GetLatestSessionBlockHeight(ctx) - // get self node (your validator) from the current state - selfNode, err := k.GetSelfNode(ctx) - if err != nil { - return nil, err - } // retrieve the nonNative blockchains your node is hosting hostedBlockchains := k.GetHostedBlockchains() - // get the application that staked on behalf of the client - app, found := k.GetAppFromPublicKey(ctx, relay.Proof.Token.ApplicationPublicKey) - if !found { - return nil, pc.NewAppNotFoundError(pc.ModuleName) - } - // get the session context - sessionCtx, er := ctx.PrevCtx(sessionBlockHeight) - if er != nil { - return nil, sdk.ErrInternal(er.Error()) - } - sessionNodeCount := k.SessionNodeCount(sessionCtx) - // ensure the validity of the relay - maxPossibleRelays, err := relay.Validate(ctx, k.posKeeper, selfNode, hostedBlockchains, sessionBlockHeight, int(sessionNodeCount), app) - if err != nil { - ctx.Logger().Error(fmt.Errorf("could not validate relay for %v, %v, %v %v, %v", selfNode, hostedBlockchains, sessionBlockHeight, int(k.SessionNodeCount(sessionCtx)), app).Error()) - return nil, err + if pc.GlobalAltruism == false { + // get the latest session block height because this relay will correspond with the latest session + sessionBlockHeight := k.GetLatestSessionBlockHeight(ctx) + // get self node (your validator) from the current state + selfNode, err := k.GetSelfNode(ctx) + if err != nil { + return nil, err + } + // get the application that staked on behalf of the client + app, found := k.GetAppFromPublicKey(ctx, relay.Proof.Token.ApplicationPublicKey) + if !found { + return nil, pc.NewAppNotFoundError(pc.ModuleName) + } + // get the session context + sessionCtx, er := ctx.PrevCtx(sessionBlockHeight) + if er != nil { + return nil, sdk.ErrInternal(er.Error()) + } + sessionNodeCount := k.SessionNodeCount(sessionCtx) + // ensure the validity of the relay + maxPossibleRelays, err := relay.Validate(ctx, k.posKeeper, selfNode, hostedBlockchains, sessionBlockHeight, int(sessionNodeCount), app) + if err != nil { + ctx.Logger().Error(fmt.Errorf("could not validate relay for %v, %v, %v %v, %v", selfNode, hostedBlockchains, sessionBlockHeight, int(k.SessionNodeCount(sessionCtx)), app).Error()) + return nil, err + } + // store the proof before execution, because the proof corresponds to the previous relay + relay.Proof.Store(maxPossibleRelays) } - // store the proof before execution, because the proof corresponds to the previous relay - relay.Proof.Store(maxPossibleRelays) // attempt to execute respPayload, err := relay.Execute(hostedBlockchains) if err != nil { @@ -51,13 +53,13 @@ func (k Keeper) HandleRelay(ctx sdk.Ctx, relay pc.Relay) (*pc.RelayResponse, sdk // get the private key from the private validator file pk, er := k.GetPKFromFile(ctx) if er != nil { - ctx.Logger().Error(fmt.Errorf("could not get PK to Sign response for address: %v with hash: %v", selfNode.GetAddress().String(), resp.Hash()).Error()) + ctx.Logger().Error(fmt.Errorf("could not get PK to Sign response for address: %v with hash: %v", "XXX", resp.Hash()).Error()) return nil, pc.NewKeybaseError(pc.ModuleName, er) } // sign the response sig, er := pk.Sign(resp.Hash()) if er != nil { - ctx.Logger().Error(fmt.Errorf("could not sign response for address: %v with hash: %v", selfNode.GetAddress().String(), resp.Hash()).Error()) + ctx.Logger().Error(fmt.Errorf("could not sign response for address: XXX with hash: %v", resp.Hash()).Error()) return nil, pc.NewKeybaseError(pc.ModuleName, er) } // attach the signature in hex to the response diff --git a/x/pocketcore/types/config.go b/x/pocketcore/types/config.go index 12e601068..d5f25b815 100644 --- a/x/pocketcore/types/config.go +++ b/x/pocketcore/types/config.go @@ -7,10 +7,11 @@ import ( var ( globalUserAgent string + GlobalAltruism bool ) // "InitConfig" - Initializes the cache for sessions and evidence -func InitConfig(userAgent, evidenceDir, sessionDir string, sessionDBType, evidenceDBType db.DBBackendType, maxEvidenceEntries, maxSessionEntries int, evidenceDBName, sessionDBName string) { +func InitConfig(userAgent, evidenceDir, sessionDir string, sessionDBType, evidenceDBType db.DBBackendType, maxEvidenceEntries, maxSessionEntries int, evidenceDBName, sessionDBName string, altruism bool) { cacheOnce.Do(func() { globalEvidenceCache = new(CacheStorage) globalSessionCache = new(CacheStorage) @@ -18,6 +19,7 @@ func InitConfig(userAgent, evidenceDir, sessionDir string, sessionDBType, eviden globalSessionCache.Init(sessionDir, sessionDBName, sessionDBType, maxSessionEntries) }) globalUserAgent = userAgent + GlobalAltruism = altruism } func FlushCache() {