diff --git a/Makefile b/Makefile index a075e25ed2..52aa9588e1 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ install: go install ./cmd/xrncli test: - go test ./... -godog.strict + go test ./... test_cover: bash -x tests/test_cover.sh diff --git a/app.go b/app.go index 9c591622d1..15a6430774 100644 --- a/app.go +++ b/app.go @@ -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" @@ -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" @@ -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 { @@ -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) @@ -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) @@ -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{} @@ -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 diff --git a/cmd/xrncli/main.go b/cmd/xrncli/main.go index 0a95de2148..13e372f94d 100644 --- a/cmd/xrncli/main.go +++ b/cmd/xrncli/main.go @@ -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" ) @@ -38,6 +40,7 @@ const ( storeData = "data" storeAgent = "group" storeProposal = "proposal" + storeUpgrade = "upgrade" ) var defaultCLIHome = os.ExpandEnv("$HOME/.xrncli") @@ -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 { @@ -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 diff --git a/default.nix b/default.nix index fec144a131..7b227bc513 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,6 @@ with import {}; -buildGoPackage rec { +buildGoModule rec { name = "regen-ledger"; goPackagePath = "github.com/regen-network/regen-ledger"; @@ -8,18 +8,9 @@ buildGoPackage rec { 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; }; } \ No newline at end of file diff --git a/deps.nix b/deps.nix deleted file mode 100644 index a691f47dee..0000000000 --- a/deps.nix +++ /dev/null @@ -1,534 +0,0 @@ -# file generated from Gopkg.lock using dep2nix (https://github.com/nixcloud/dep2nix) -[ - { - goPackagePath = "github.com/ZondaX/hid-go"; - fetch = { - type = "git"; - url = "https://github.com/ZondaX/hid-go"; - rev = "48b08affede2cea076a3cf13b2e3f72ed262b743"; - sha256 = "1s3bpxnbcbn67xzivjjb1r5ys15m61wkc98l7kcg45n4wfkqak8a"; - }; - } - { - goPackagePath = "github.com/ZondaX/ledger-go"; - fetch = { - type = "git"; - url = "https://github.com/ZondaX/ledger-go"; - rev = "c3225ab10c2f53397d4aa419a588466493572b22"; - sha256 = "1bis35gyxgywk8xmnpm0zlx5gs6b8jwifdk7ig0d1m7pbjazxrjq"; - }; - } - { - goPackagePath = "github.com/bartekn/go-bip39"; - fetch = { - type = "git"; - url = "https://github.com/bartekn/go-bip39"; - rev = "a05967ea095d81c8fe4833776774cfaff8e5036c"; - sha256 = "01dhv6556d9fiia4901qi18kyvxgrxzv1p9fbhfvpvnmfrw96zli"; - }; - } - { - goPackagePath = "github.com/beorn7/perks"; - fetch = { - type = "git"; - url = "https://github.com/beorn7/perks"; - rev = "3a771d992973f24aa725d07868b467d1ddfceafb"; - sha256 = "1l2lns4f5jabp61201sh88zf3b0q793w4zdgp9nll7mmfcxxjif3"; - }; - } - { - goPackagePath = "github.com/bgentry/speakeasy"; - fetch = { - type = "git"; - url = "https://github.com/bgentry/speakeasy"; - rev = "4aabc24848ce5fd31929f7d1e4ea74d3709c14cd"; - sha256 = "02dfrj0wyphd3db9zn2mixqxwiz1ivnyc5xc7gkz58l5l27nzp8s"; - }; - } - { - goPackagePath = "github.com/btcsuite/btcd"; - fetch = { - type = "git"; - url = "https://github.com/btcsuite/btcd"; - rev = "7d2daa5bfef28c5e282571bc06416516936115ee"; - sha256 = "1ygy6m2mdbir2kln3zh5amb56d1ypiymq3m0pj3f4c071aqsrpr6"; - }; - } - { - goPackagePath = "github.com/btcsuite/btcutil"; - fetch = { - type = "git"; - url = "https://github.com/btcsuite/btcutil"; - rev = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"; - sha256 = "11ipk4g3j3px821pni8r483jyd3zjnvpdn8sr62vkgjjwdfv4ygw"; - }; - } - { - goPackagePath = "github.com/cosmos/cosmos-sdk"; - fetch = { - type = "git"; - url = "https://github.com/regen-network/cosmos-sdk"; - rev = "1a6bed2b19bbdde46b97d228200f8904e4abb261"; - sha256 = "142r6fidmrlyyiwsi5hynvb6dkp6lxz9j0p08pr8zxplbqip0n11"; - }; - } - { - goPackagePath = "github.com/cosmos/go-bip39"; - fetch = { - type = "git"; - url = "https://github.com/cosmos/go-bip39"; - rev = "52158e4697b87de16ed390e1bdaf813e581008fa"; - sha256 = "05a95z4vmij6ijw7fi209hzfvicb86cyh8cvn7ldqq60kiz1mdsg"; - }; - } - { - goPackagePath = "github.com/davecgh/go-spew"; - fetch = { - type = "git"; - url = "https://github.com/davecgh/go-spew"; - rev = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"; - sha256 = "0hka6hmyvp701adzag2g26cxdj47g21x6jz4sc6jjz1mn59d474y"; - }; - } - { - goPackagePath = "github.com/fsnotify/fsnotify"; - fetch = { - type = "git"; - url = "https://github.com/fsnotify/fsnotify"; - rev = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"; - sha256 = "07va9crci0ijlivbb7q57d2rz9h27zgn2fsm60spjsqpdbvyrx4g"; - }; - } - { - goPackagePath = "github.com/go-kit/kit"; - fetch = { - type = "git"; - url = "https://github.com/go-kit/kit"; - rev = "4dc7be5d2d12881735283bcab7352178e190fc71"; - sha256 = "0w2lh1dkhrnd08jk8y0g4wzrg8d43zngh9igg5jpvh5jdblp4cxk"; - }; - } - { - goPackagePath = "github.com/go-logfmt/logfmt"; - fetch = { - type = "git"; - url = "https://github.com/go-logfmt/logfmt"; - rev = "07c9b44f60d7ffdfb7d8efe1ad539965737836dc"; - sha256 = "06smxc112xmixz78nyvk3b2hmc7wasf2sl5vxj1xz62kqcq9lzm9"; - }; - } - { - goPackagePath = "github.com/go-stack/stack"; - fetch = { - type = "git"; - url = "https://github.com/go-stack/stack"; - rev = "2fee6af1a9795aafbe0253a0cfbdf668e1fb8a9a"; - sha256 = "0wk25751ryyvxclyp8jdk5c3ar0cmfr8lrjb66qbg4808x66b96v"; - }; - } - { - goPackagePath = "github.com/gogo/protobuf"; - fetch = { - type = "git"; - url = "https://github.com/gogo/protobuf"; - rev = "636bf0302bc95575d69441b25a2603156ffdddf1"; - sha256 = "1525pq7r6h3s8dncvq8gxi893p2nq8dxpzvq0nfl5b4p6mq0v1c2"; - }; - } - { - goPackagePath = "github.com/golang/protobuf"; - fetch = { - type = "git"; - url = "https://github.com/golang/protobuf"; - rev = "b4deda0973fb4c70b50d226b1af49f3da59f5265"; - sha256 = "0ya4ha7m20bw048m1159ppqzlvda4x0vdprlbk5sdgmy74h3xcdq"; - }; - } - { - goPackagePath = "github.com/golang/snappy"; - fetch = { - type = "git"; - url = "https://github.com/golang/snappy"; - rev = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"; - sha256 = "05w6mpc4qcy0pv8a2bzng8nf4s5rf5phfang4jwy9rgf808q0nxf"; - }; - } - { - goPackagePath = "github.com/gorilla/context"; - fetch = { - type = "git"; - url = "https://github.com/gorilla/context"; - rev = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42"; - sha256 = "03p4hn87vcmfih0p9w663qbx9lpsf7i7j3lc7yl7n84la3yz63m4"; - }; - } - { - goPackagePath = "github.com/gorilla/mux"; - fetch = { - type = "git"; - url = "https://github.com/gorilla/mux"; - rev = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf"; - sha256 = "0pvzm23hklxysspnz52mih6h1q74vfrdhjfm1l3sa9r8hhqmmld2"; - }; - } - { - goPackagePath = "github.com/gorilla/websocket"; - fetch = { - type = "git"; - url = "https://github.com/gorilla/websocket"; - rev = "66b9c49e59c6c48f0ffce28c2d8b8a5678502c6d"; - sha256 = "00i4vb31nsfkzzk7swvx3i75r2d960js3dri1875vypk3v2s0pzk"; - }; - } - { - goPackagePath = "github.com/hashicorp/hcl"; - fetch = { - type = "git"; - url = "https://github.com/hashicorp/hcl"; - rev = "8cb6e5b959231cc1119e43259c4a608f9c51a241"; - sha256 = "0q6ml0qqs0yil76mpn4mdx4lp94id8vbv575qm60jzl1ijcl5i66"; - }; - } - { - goPackagePath = "github.com/inconshreveable/mousetrap"; - fetch = { - type = "git"; - url = "https://github.com/inconshreveable/mousetrap"; - rev = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"; - sha256 = "1mn0kg48xkd74brf48qf5hzp0bc6g8cf5a77w895rl3qnlpfw152"; - }; - } - { - goPackagePath = "github.com/jmhodges/levigo"; - fetch = { - type = "git"; - url = "https://github.com/jmhodges/levigo"; - rev = "c42d9e0ca023e2198120196f842701bb4c55d7b9"; - sha256 = "1pdm8pwjj0dix559657gdbbs2cvrwlnnwhh7qqab4a0psg6ssalg"; - }; - } - { - goPackagePath = "github.com/kr/logfmt"; - fetch = { - type = "git"; - url = "https://github.com/kr/logfmt"; - rev = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"; - sha256 = "02ldzxgznrfdzvghfraslhgp19la1fczcbzh7wm2zdc6lmpd1qq9"; - }; - } - { - goPackagePath = "github.com/magiconair/properties"; - fetch = { - type = "git"; - url = "https://github.com/magiconair/properties"; - rev = "c2353362d570a7bfa228149c62842019201cfb71"; - sha256 = "1a10362wv8a8qwb818wygn2z48lgzch940hvpv81hv8gc747ajxn"; - }; - } - { - goPackagePath = "github.com/mattn/go-isatty"; - fetch = { - type = "git"; - url = "https://github.com/mattn/go-isatty"; - rev = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c"; - sha256 = "0zs92j2cqaw9j8qx1sdxpv3ap0rgbs0vrvi72m40mg8aa36gd39w"; - }; - } - { - goPackagePath = "github.com/matttproud/golang_protobuf_extensions"; - fetch = { - type = "git"; - url = "https://github.com/matttproud/golang_protobuf_extensions"; - rev = "c12348ce28de40eed0136aa2b644d0ee0650e56c"; - sha256 = "1d0c1isd2lk9pnfq2nk0aih356j30k3h1gi2w0ixsivi5csl7jya"; - }; - } - { - goPackagePath = "github.com/mitchellh/mapstructure"; - fetch = { - type = "git"; - url = "https://github.com/mitchellh/mapstructure"; - rev = "3536a929edddb9a5b34bd6861dc4a9647cb459fe"; - sha256 = "03bpv28jz9zhn4947saqwi328ydj7f6g6pf1m2d4m5zdh5jlfkrr"; - }; - } - { - goPackagePath = "github.com/pelletier/go-toml"; - fetch = { - type = "git"; - url = "https://github.com/pelletier/go-toml"; - rev = "c01d1270ff3e442a8a57cddc1c92dc1138598194"; - sha256 = "1fjzpcjng60mc3a4b2ql5a00d5gah84wj740dabv9kq67mpg8fxy"; - }; - } - { - goPackagePath = "github.com/pkg/errors"; - fetch = { - type = "git"; - url = "https://github.com/pkg/errors"; - rev = "645ef00459ed84a119197bfb8d8205042c6df63d"; - sha256 = "001i6n71ghp2l6kdl3qq1v2vmghcz3kicv9a5wgcihrzigm75pp5"; - }; - } - { - goPackagePath = "github.com/pmezard/go-difflib"; - fetch = { - type = "git"; - url = "https://github.com/pmezard/go-difflib"; - rev = "792786c7400a136282c1664665ae0a8db921c6c2"; - sha256 = "0c1cn55m4rypmscgf0rrb88pn58j3ysvc2d0432dp3c6fqg6cnzw"; - }; - } - { - goPackagePath = "github.com/prometheus/client_golang"; - fetch = { - type = "git"; - url = "https://github.com/prometheus/client_golang"; - rev = "abad2d1bd44235a26707c172eab6bca5bf2dbad3"; - sha256 = "01gnylazia30pcp069xcng482gwmm3xcx5zgrlwdkhic1lyb6i9l"; - }; - } - { - goPackagePath = "github.com/prometheus/client_model"; - fetch = { - type = "git"; - url = "https://github.com/prometheus/client_model"; - rev = "5c3871d89910bfb32f5fcab2aa4b9ec68e65a99f"; - sha256 = "04psf81l9fjcwascsys428v03fx4fi894h7fhrj2vvcz723q57k0"; - }; - } - { - goPackagePath = "github.com/prometheus/common"; - fetch = { - type = "git"; - url = "https://github.com/prometheus/common"; - rev = "4724e9255275ce38f7179b2478abeae4e28c904f"; - sha256 = "0pcx8hlnrxx5nnmpk786cn99rsgqk1jrd3c9f6fsx8qd8y5iwjy6"; - }; - } - { - goPackagePath = "github.com/prometheus/procfs"; - fetch = { - type = "git"; - url = "https://github.com/prometheus/procfs"; - rev = "aa55a523dc0a8297edf51bb75e8eec13eb3be45d"; - sha256 = "1s44rwqx67n2w9xjvkcpslz44gghbw73izxavlls503zccr4hhb9"; - }; - } - { - goPackagePath = "github.com/rakyll/statik"; - fetch = { - type = "git"; - url = "https://github.com/rakyll/statik"; - rev = "aa8a7b1baecd0f31a436bf7956fcdcc609a83035"; - sha256 = "00q9akb9m66wv9m895vbm3kywi6a2gidn27kz29h19ada998kz12"; - }; - } - { - goPackagePath = "github.com/rcrowley/go-metrics"; - fetch = { - type = "git"; - url = "https://github.com/rcrowley/go-metrics"; - rev = "e2704e165165ec55d062f5919b4b29494e9fa790"; - sha256 = "1yvvwqyfdnnjgnc3j4y0g1b897ad0wwlgn6x4dx83s20ax2lyz2q"; - }; - } - { - goPackagePath = "github.com/rs/cors"; - fetch = { - type = "git"; - url = "https://github.com/rs/cors"; - rev = "9a47f48565a795472d43519dd49aac781f3034fb"; - sha256 = "12j838rj6xl9y1xqs1mnh9zkc3dkpn94iqkp6jkdkxw631aa94dr"; - }; - } - { - goPackagePath = "github.com/satori/go.uuid"; - fetch = { - type = "git"; - url = "https://github.com/satori/go.uuid"; - rev = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3"; - sha256 = "1j4s5pfg2ldm35y8ls8jah4dya2grfnx2drb4jcbjsyrp4cm5yfb"; - }; - } - { - goPackagePath = "github.com/spf13/afero"; - fetch = { - type = "git"; - url = "https://github.com/spf13/afero"; - rev = "d40851caa0d747393da1ffb28f7f9d8b4eeffebd"; - sha256 = "0miv4faf5ihjfifb1zv6aia6f6ik7h1s4954kcb8n6ixzhx9ck6k"; - }; - } - { - goPackagePath = "github.com/spf13/cast"; - fetch = { - type = "git"; - url = "https://github.com/spf13/cast"; - rev = "8c9545af88b134710ab1cd196795e7f2388358d7"; - sha256 = "0xq1ffqj8y8h7dcnm0m9lfrh0ga7pssnn2c1dnr09chqbpn4bdc5"; - }; - } - { - goPackagePath = "github.com/spf13/cobra"; - fetch = { - type = "git"; - url = "https://github.com/spf13/cobra"; - rev = "ef82de70bb3f60c65fb8eebacbb2d122ef517385"; - sha256 = "1q1nsx05svyv9fv3fy6xv6gs9ffimkyzsfm49flvl3wnvf1ncrkd"; - }; - } - { - goPackagePath = "github.com/spf13/jwalterweatherman"; - fetch = { - type = "git"; - url = "https://github.com/spf13/jwalterweatherman"; - rev = "4a4406e478ca629068e7768fc33f3f044173c0a6"; - sha256 = "093fmmvavv84pv4q84hav7ph3fmrq87bvspjj899q0qsx37yvdr8"; - }; - } - { - goPackagePath = "github.com/spf13/pflag"; - fetch = { - type = "git"; - url = "https://github.com/spf13/pflag"; - rev = "298182f68c66c05229eb03ac171abe6e309ee79a"; - sha256 = "1cj3cjm7d3zk0mf1xdybh0jywkbbw7a6yr3y22x9sis31scprswd"; - }; - } - { - goPackagePath = "github.com/spf13/viper"; - fetch = { - type = "git"; - url = "https://github.com/spf13/viper"; - rev = "a1b837276271029e31f796ae5d03ba9ffb017244"; - sha256 = "0a01ljf1niz86v2il97m31ivbq73zj4kh6wl5cc4kaqr5zryxq2q"; - }; - } - { - goPackagePath = "github.com/stretchr/testify"; - fetch = { - type = "git"; - url = "https://github.com/stretchr/testify"; - rev = "12b6f73e6084dad08a7c6e575284b177ecafbc71"; - sha256 = "01f80s0q64pw5drfgqwwk1wfwwkvd2lhbs56lhhkff4ni83k73fd"; - }; - } - { - goPackagePath = "github.com/syndtr/goleveldb"; - fetch = { - type = "git"; - url = "https://github.com/syndtr/goleveldb"; - rev = "b001fa50d6b27f3f0bb175a87d0cb55426d0a0ae"; - sha256 = "1k7085a5vbdlbw0ymba31smxxaqlx41ji585ncxcrrs7xnnsaz32"; - }; - } - { - goPackagePath = "github.com/tendermint/btcd"; - fetch = { - type = "git"; - url = "https://github.com/tendermint/btcd"; - rev = "e5840949ff4fff0c56f9b6a541e22b63581ea9df"; - sha256 = "14wxgv8pny40vnwb4jad596sxsj7vk66av9yf0f495p458ymi7l4"; - }; - } - { - goPackagePath = "github.com/tendermint/go-amino"; - fetch = { - type = "git"; - url = "https://github.com/tendermint/go-amino"; - rev = "dc14acf9ef15f85828bfbc561ed9dd9d2a284885"; - sha256 = "0mz3h5k5rbkkgajm4rnl5wxkds8qk6nsq5adwg8z5fxvimxxf5bi"; - }; - } - { - goPackagePath = "github.com/tendermint/iavl"; - fetch = { - type = "git"; - url = "https://github.com/tendermint/iavl"; - rev = "de0740903a67b624d887f9055d4c60175dcfa758"; - sha256 = "1ghwxvd0f6iiwqi0m2bgyjllm4nhz72k71ajp5byf4w4zlwy8fzl"; - }; - } - { - goPackagePath = "github.com/tendermint/tendermint"; - fetch = { - type = "git"; - url = "https://github.com/tendermint/tendermint"; - rev = "0138530df202f5b8e8be1edb9c2f705e404a79cb"; - sha256 = "0456a8islcy80n4w8lgyl81qaah3i4xw1lvjaq3basljpqhdxmsj"; - }; - } - { - goPackagePath = "github.com/zondax/ledger-cosmos-go"; - fetch = { - type = "git"; - url = "https://github.com/zondax/ledger-cosmos-go"; - rev = "d4aed6d929a703bb555a2d79fe9c470afe61f648"; - sha256 = "17hvgb42q5k9k96sgx519plb0y1dvxjqnmrk09ldkid6yvc917ih"; - }; - } - { - goPackagePath = "golang.org/x/crypto"; - fetch = { - type = "git"; - url = "https://github.com/tendermint/crypto"; - rev = "3764759f34a542a3aef74d6b02e35be7ab893bba"; - sha256 = "0hpar8rj0xnxnrrxi3g6695lq24ibp5i9k1hif7ki6mrl2xciws2"; - }; - } - { - goPackagePath = "golang.org/x/net"; - fetch = { - type = "git"; - url = "https://go.googlesource.com/net"; - rev = "292b43bbf7cb8d35ddf40f8d5100ef3837cced3f"; - sha256 = "0n3d0hh6ip64g41ha80gdx508r8ycsj3mxcp7h7dqknrk2aqsp6y"; - }; - } - { - goPackagePath = "golang.org/x/sys"; - fetch = { - type = "git"; - url = "https://go.googlesource.com/sys"; - rev = "4ed8d59d0b35e1e29334a206d1b3f38b1e5dfb31"; - sha256 = "0yj125avhqv9d3r0dcndzgd5kgzf1cv9b3z3gv0dlr5fcb18ikbw"; - }; - } - { - goPackagePath = "golang.org/x/text"; - fetch = { - type = "git"; - url = "https://go.googlesource.com/text"; - rev = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"; - sha256 = "0r6x6zjzhr8ksqlpiwm5gdd7s209kwk5p4lw54xjvz10cs3qlq19"; - }; - } - { - goPackagePath = "google.golang.org/genproto"; - fetch = { - type = "git"; - url = "https://github.com/google/go-genproto"; - rev = "bd91e49a0898e27abb88c339b432fa53d7497ac0"; - sha256 = "1f5q04h03q6fksbfkhz13ai5849rkkb8xrmmi7cxs4lzsi6ixkg8"; - }; - } - { - goPackagePath = "google.golang.org/grpc"; - fetch = { - type = "git"; - url = "https://github.com/grpc/grpc-go"; - rev = "2e463a05d100327ca47ac218281906921038fd95"; - sha256 = "0a9xl6c5j7lvsb4q6ry5p892rjm86p47d4f8xrf0r8lxblf79qbg"; - }; - } - { - goPackagePath = "gopkg.in/yaml.v2"; - fetch = { - type = "git"; - url = "https://github.com/go-yaml/yaml"; - rev = "51d6538a90f86fe93ac480b35f37b2be17fef232"; - sha256 = "01wj12jzsdqlnidpyjssmj0r4yavlqy7dwrg7adqd8dicjc4ncsa"; - }; - } -] \ No newline at end of file diff --git a/go.mod b/go.mod index 81aff250bb..f098bfd6ef 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/pflag v1.0.3 // indirect github.com/spf13/viper v1.0.3 + github.com/stretchr/testify v1.2.2 github.com/syndtr/goleveldb v0.0.0-20181128100959-b001fa50d6b2 // indirect github.com/tendermint/btcd v0.0.0-20180816174608-e5840949ff4f // indirect github.com/tendermint/go-amino v0.14.1 diff --git a/index/postgresql/impl.go b/index/postgresql/impl.go index dc2aacc30c..094dd9b2db 100644 --- a/index/postgresql/impl.go +++ b/index/postgresql/impl.go @@ -13,7 +13,7 @@ import ( type indexer struct { conn *sql.DB txDecoder sdk.TxDecoder - migrations []string + migrations map[string][]string curTx *sql.Tx blockHeader abci.Header } @@ -26,11 +26,11 @@ func NewIndexer(connString string, txDecoder sdk.TxDecoder) (Indexer, error) { if err != nil { return nil, err } - return &indexer{conn: conn, txDecoder: txDecoder, migrations: []string{}}, nil + return &indexer{conn: conn, txDecoder: txDecoder, migrations: make(map[string][]string)}, nil } -func (indexer *indexer) AddMigration(ddl string) { - indexer.migrations = append(indexer.migrations, ddl) +func (indexer *indexer) AddMigrations(module string, ddlStatements []string) { + indexer.migrations[module] = ddlStatements } func (indexer *indexer) Exec(query string, args ...interface{}) { @@ -45,12 +45,50 @@ func (indexer *indexer) Exec(query string, args ...interface{}) { } func (indexer *indexer) OnInitChain(abci.RequestInitChain, abci.ResponseInitChain) { - _, err := indexer.conn.Exec(InitialSchema) + indexer.ApplyMigrations() +} + +var baseMigrations = []string{InitialSchema} + +func (indexer *indexer) ApplyMigrations() { + _, err := indexer.conn.Exec(`CREATE TABLE IF NOT EXISTS __migration_state ( + module text PRIMARY KEY, + version int, + other jsonb + );`) if err != nil { panic(err) } - for _, ddl := range indexer.migrations { - _, err := indexer.conn.Exec(ddl) + indexer.applyModuleMigrations("", baseMigrations) + for key, value := range indexer.migrations { + indexer.applyModuleMigrations(key, value) + } +} + +func (indexer *indexer) applyModuleMigrations(module string, ddl []string) { + row := indexer.conn.QueryRow("SELECT version FROM __migration_state WHERE module = $1", module) + version := 0 + haveRow := false + if row != nil { + err := row.Scan(&version) + if err == nil { + haveRow = true + } + } + n := len(ddl) + for i := version; i < n; i++ { + _, err := indexer.conn.Exec(ddl[i]) + if err != nil { + panic(err) + } + } + if !haveRow { + _, err := indexer.conn.Exec("INSERT INTO __migration_state (module, version) VALUES ($1, $2)", module, n) + if err != nil { + panic(err) + } + } else { + _, err := indexer.conn.Exec("UPDATE __migration_state SET version = $1 WHERE module = $2", n, module) if err != nil { panic(err) } diff --git a/index/postgresql/types.go b/index/postgresql/types.go index bbc4bf9a2d..79f03ed5d5 100644 --- a/index/postgresql/types.go +++ b/index/postgresql/types.go @@ -12,7 +12,7 @@ type Indexer interface { // AddMigration adds a migration to the list of migrations to be run during // InitChain or an upgrade. Migrations will be run in the order // they are added - AddMigration(ddl string) + AddMigrations(module string, ddlStatements []string) // Exec executes a PostgreSQL statement against the database. // Can be used in keepers for custom indexing diff --git a/index/types.go b/index/types.go index 8606f0b9fc..9090c63ef8 100644 --- a/index/types.go +++ b/index/types.go @@ -12,6 +12,8 @@ import ( type Indexer interface { // OnInitChain intercepts the InitChain ABCI method OnInitChain(abci.RequestInitChain, abci.ResponseInitChain) + // ApplyMigrations applies any pending migrations + ApplyMigrations() // OnBeginBlock intercepts the BeginBlock ABCI method OnBeginBlock(abci.RequestBeginBlock, abci.ResponseBeginBlock) // BeforeDeliverTx should be called on the ABCI DeliverTx method diff --git a/module.nix b/module.nix index 1e4c6fbb8c..93028dfb44 100644 --- a/module.nix +++ b/module.nix @@ -97,7 +97,7 @@ in }; }) - (mkIf xrndCfg.restServer { + (mkIf (xrndCfg.enable && xrndCfg.restServer) { users.groups.xrn = {}; users.users.xrnrest = { diff --git a/testnets/next/genesis.json b/testnets/next/genesis.json index 4b6024c291..794770e3dc 100644 --- a/testnets/next/genesis.json +++ b/testnets/next/genesis.json @@ -1,6 +1,6 @@ { "genesis_time": "2018-12-19T20:40:06.463846Z", - "chain_id": "xrn-test-2", + "chain_id": "xrn-test-next", "consensus_params": { "block_size": { "max_bytes": "22020096", @@ -60,7 +60,18 @@ "sequence": "0" } ], - "groups": [], + "groups": [ + { + "decision_threshold": "1", + "members": [ + { + "address": "xrn:1xrsmkqh305m09tc5x73v4t3wtcuqmf6cgy2taw", + "weight": "1" + } + ], + "memo": "Regen Consortium" + } + ], "auth": { "collected_fees": null, "params": { diff --git a/util/godog.go b/util/godog.go index 506368a738..4113082581 100644 --- a/util/godog.go +++ b/util/godog.go @@ -11,6 +11,7 @@ import ( var opt = godog.Options{ Output: colors.Colored(os.Stdout), Format: "progress", // can define default values + Strict: true, } func init() { diff --git a/x/consortium/actions.go b/x/consortium/actions.go index ce8e4eb3d2..356c70d84e 100644 --- a/x/consortium/actions.go +++ b/x/consortium/actions.go @@ -8,7 +8,10 @@ import ( ) type ActionScheduleUpgrade struct { - UpgradeInfo upgrade.UpgradeInfo `json:"upgrade_info"` + Plan upgrade.Plan `json:"upgrade_plan"` +} + +type ActionCancelUpgrade struct { } /* @@ -24,16 +27,29 @@ type ActionChangeValidatorSet struct { func (action ActionScheduleUpgrade) Route() string { return "consortium" } -func (action ActionScheduleUpgrade) Type() string { return "upgrade" } +func (action ActionScheduleUpgrade) Type() string { return "consortium.upgrade" } func (action ActionScheduleUpgrade) ValidateBasic() sdk.Error { - if action.UpgradeInfo.Height <= 0 { - return sdk.ErrUnknownRequest("Upgrade height must be greater than 0") + return action.Plan.ValidateBasic() +} + +func (action ActionScheduleUpgrade) GetSignBytes() []byte { + b, err := json.Marshal(action) + if err != nil { + panic(err) } + return sdk.MustSortJSON(b) +} + +func (ActionCancelUpgrade) Route() string { return "consortium" } + +func (ActionCancelUpgrade) Type() string { return "consortium.cancel-upgrade" } + +func (ActionCancelUpgrade) ValidateBasic() sdk.Error { return nil } -func (action ActionScheduleUpgrade) GetSignBytes() []byte { +func (action ActionCancelUpgrade) GetSignBytes() []byte { b, err := json.Marshal(action) if err != nil { panic(err) @@ -43,7 +59,7 @@ func (action ActionScheduleUpgrade) GetSignBytes() []byte { func (action ActionChangeValidatorSet) Route() string { return "consortium" } -func (action ActionChangeValidatorSet) Type() string { return "changeValidatorSet" } +func (action ActionChangeValidatorSet) Type() string { return "consortium.changeValidatorSet" } func (action ActionChangeValidatorSet) ValidateBasic() sdk.Error { panic("implement me") diff --git a/x/consortium/client/cli/tx.go b/x/consortium/client/cli/tx.go index 43c7b5fe38..5dfc9b7254 100644 --- a/x/consortium/client/cli/tx.go +++ b/x/consortium/client/cli/tx.go @@ -1,37 +1,68 @@ package cli import ( + "encoding/json" + "fmt" "github.com/regen-network/regen-ledger/x/consortium" "github.com/regen-network/regen-ledger/x/proposal" proposalcli "github.com/regen-network/regen-ledger/x/proposal/client/cli" "github.com/regen-network/regen-ledger/x/upgrade" "github.com/spf13/cobra" - "strconv" + "time" "github.com/cosmos/cosmos-sdk/codec" ) func GetCmdProposeUpgrade(cdc *codec.Codec) *cobra.Command { - var memo string + var timeStr string + var height int64 + var commit string cmd := proposalcli.GetCmdPropose(cdc, func(cmd *cobra.Command, args []string) (action proposal.ProposalAction, e error) { - blockHeightStr := args[0] - blockHeight, err := strconv.ParseInt(blockHeightStr, 10, 64) - if err != nil { - return nil, err + name := args[0] + + var t time.Time + var err error + if len(timeStr) != 0 { + t, err = time.Parse(time.RFC3339, timeStr) + if err != nil { + return nil, fmt.Errorf("error parsing time: %+v", err) + } + } + + info := make(map[string]interface{}) + if len(commit) != 0 { + info["commit"] = commit } + jsonInfo, err := json.Marshal(info) + return consortium.ActionScheduleUpgrade{ - UpgradeInfo: upgrade.UpgradeInfo{ - Height: blockHeight, - Memo: memo, + Plan: upgrade.Plan{ + Name: name, + Time: t, + Height: height, + Info: string(jsonInfo), }, }, nil }) cmd.Args = cobra.ExactArgs(1) - cmd.Use = "propose-upgrade [--upgrade-memo ]" - cmd.Short = "Propose an ESP version" - cmd.Flags().StringVar(&memo, "upgrade-memo", "", "Any memo to attach to the upgrade plan such as a git commit hash") + cmd.Use = "propose-upgrade [--upgrade-time