Skip to content

Commit

Permalink
Merge pull request #14 from regen-network/13-upgrade_module
Browse files Browse the repository at this point in the history
#13 upgrade module
  • Loading branch information
aaronc authored Mar 26, 2019
2 parents 8e5cbef + 6d0ac54 commit 22ba9cc
Show file tree
Hide file tree
Showing 31 changed files with 656 additions and 687 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ install:
go install ./cmd/xrncli

test:
go test ./... -godog.strict
go test ./...

test_cover:
bash -x tests/test_cover.sh
Expand Down
25 changes: 21 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/regen-network/regen-ledger/index/postgresql"
"github.com/regen-network/regen-ledger/x/consortium"
Expand All @@ -11,7 +12,12 @@ import (
"github.com/regen-network/regen-ledger/x/group"
"github.com/regen-network/regen-ledger/x/proposal"
"github.com/regen-network/regen-ledger/x/upgrade"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
"io/ioutil"
"os"
"path/filepath"
//"os"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -117,7 +123,7 @@ func NewXrnApp(logger log.Logger, db dbm.DB, postgresUrl string) *xrnApp {
if len(postgresUrl) != 0 {
pgIndexer, err := postgresql.NewIndexer(postgresUrl, txDecoder)
if err == nil {
pgIndexer.AddMigration(geo.PostgresSchema)
pgIndexer.AddMigrations("geo", geo.PostgresMigrations)
app.pgIndexer = pgIndexer
logger.Info("Started PostgreSQL Indexer")
} else {
Expand Down Expand Up @@ -152,7 +158,8 @@ func NewXrnApp(logger log.Logger, db dbm.DB, postgresUrl string) *xrnApp {

app.espKeeper = esp.NewKeeper(app.espStoreKey, app.agentKeeper, app.geoKeeper, cdc)

app.upgradeKeeper = upgrade.NewKeeper(app.upgradeStoreKey, cdc, 1000)
app.upgradeKeeper = upgrade.NewKeeper(app.upgradeStoreKey, cdc)
app.upgradeKeeper.SetDoShutdowner(app.shutdownOnUpgrade)

app.consortiumKeeper = consortium.NewKeeper(app.consortiumStoreKey, cdc, app.agentKeeper, app.upgradeKeeper)

Expand Down Expand Up @@ -230,8 +237,8 @@ func (app *xrnApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.
app.accountKeeper.SetAccount(ctx, acc)
}

for _, group := range genesisState.Groups {
app.agentKeeper.CreateGroup(ctx, group)
for _, g := range genesisState.Groups {
app.agentKeeper.CreateGroup(ctx, g)
}

app.consortiumKeeper.SetValidators(ctx, req.Validators)
Expand All @@ -242,6 +249,15 @@ func (app *xrnApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.
return abci.ResponseInitChain{}
}

func (app *xrnApp) shutdownOnUpgrade(ctx sdk.Context, plan upgrade.Plan) {
if len(plan.Info) != 0 {
home := viper.GetString(cli.HomeFlag)
_ = ioutil.WriteFile(filepath.Join(home, "data", "upgrade-info"), []byte(plan.Info), 0644)
}
ctx.Logger().Error(fmt.Sprintf("UPGRADE \"%s\" NEEDED needed at height %d: %s", plan.Name, ctx.BlockHeight(), plan.Info))
os.Exit(1)
}

func (app *xrnApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
app.upgradeKeeper.BeginBlocker(ctx, req)
return abci.ResponseBeginBlock{}
Expand Down Expand Up @@ -331,6 +347,7 @@ func MakeCodec() *codec.Codec {
group.RegisterCodec(cdc)
proposal.RegisterCodec(cdc)
consortium.RegisterCodec(cdc)
upgrade.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
return cdc
Expand Down
6 changes: 6 additions & 0 deletions cmd/xrncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
geoclient "github.com/regen-network/regen-ledger/x/geo/client"
agentclient "github.com/regen-network/regen-ledger/x/group/client"
proposalclient "github.com/regen-network/regen-ledger/x/proposal/client"
upgradecli "github.com/regen-network/regen-ledger/x/upgrade/client/cli"
upgraderest "github.com/regen-network/regen-ledger/x/upgrade/client/rest"
cmn "github.com/tendermint/tendermint/libs/common"
)

Expand All @@ -38,6 +40,7 @@ const (
storeData = "data"
storeAgent = "group"
storeProposal = "proposal"
storeUpgrade = "upgrade"
)

var defaultCLIHome = os.ExpandEnv("$HOME/.xrncli")
Expand Down Expand Up @@ -178,6 +181,7 @@ func registerRoutes(rs *lcd.RestServer) {
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeAcc)
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
datarest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeData)
upgraderest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, "upgrade-plan", storeUpgrade)
}

func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
Expand All @@ -200,6 +204,8 @@ func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
queryCmd.AddCommand(m.GetQueryCmd())
}

queryCmd.AddCommand(upgradecli.GetQueryCmd("upgrade-plan", storeUpgrade, cdc))

addNodeFlags(queryCmd)

return queryCmd
Expand Down
15 changes: 3 additions & 12 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
with import <nixpkgs>{};

buildGoPackage rec {
buildGoModule rec {
name = "regen-ledger";

goPackagePath = "github.com/regen-network/regen-ledger";
subPackages = [ "cmd/xrnd" "cmd/xrncli" ];

src = ./.;

# buildInputs = [ makeWrapper ];
# binPath = lib.makeBinPath [ ];

goDeps = ./deps.nix;

#postInstall = ''
# wrapProgram $bin/bin/dep2nix --prefix PATH ':' ${binPath}
#'';

meta = with stdenv.lib; {
description = "Regen Networks's Regen Ledger distributed ledger for planetary regeneration";
# TODO license = licenses.bsd3;
description = "Distributed ledger for planetary regeneration";
license = licenses.asl20;
homepage = https://github.com/regen-network/regen-ledger;
};
}
Loading

0 comments on commit 22ba9cc

Please sign in to comment.