diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc7a3129..448949906 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog +*January 20, 2021* +## v0.8.1 +A version based on the patched release of Cosmos SDK 0.40.1 that includes security fixes in Tendermint 0.40.3. + *January 11, 2021* -## v0.8.0-crossfire +## v0.8.0 A version based on the final release of Cosmos SDK 0.40. ### Improvements * [347](https://github.com/crypto-com/chain-main/pull/347) keyring options help extended diff --git a/app/app.go b/app/app.go index 2f1dac48c..ab05d1bcd 100644 --- a/app/app.go +++ b/app/app.go @@ -429,6 +429,9 @@ func New( app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper + // TODO: crossfire may not be long-running, so the special config + this may need to be removed later + app.UpgradeKeeper.SetUpgradeHandler("crossfire-upgrade-test", func(_ sdk.Context, _ upgradetypes.Plan) {}) + return app } diff --git a/default.nix b/default.nix index 272d7d7dd..cba9ce428 100644 --- a/default.nix +++ b/default.nix @@ -25,7 +25,7 @@ let src = lib.sourceByRegex ./. src_regexes; }; subPackages = [ "cmd/chain-maind" ]; - vendorSha256 = sha256:08f2mv6sxgcw5xkqmy87dhz9b8ibj3p7fssmbmbsf2kmaxicq70y; + vendorSha256 = sha256:1krm1xx1xrwkx9g1lw46dkarjpiz101yyk9z60v56k6r2hhbq7q7; runVend = true; outputs = [ "out" diff --git a/examples/testnet.yaml b/examples/testnet.yaml index 55c7fb494..630356269 100644 --- a/examples/testnet.yaml +++ b/examples/testnet.yaml @@ -7,5 +7,7 @@ testnet-croeseid-1: # consensus_key: # priv: # pub: + # optional, using existing pubkey instead of using priv_validator_key.json, generated by tmkms + # pubkey: tcrocnclconspub1..... genesis_file: "%(here)s/testnet_genesis.json" peers: "66a557b8feef403805eb68e6e3249f3148d1a3f2@54.169.58.229:26656,3246d15d34802ca6ade7f51f5a26785c923fb385@54.179.111.207:26656,69c2fbab6b4f58b6cf1f79f8b1f670c7805e3f43@18.141.107.57:26656" diff --git a/go.mod b/go.mod index bba1cc033..38af27d45 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.15 require ( github.com/confluentinc/bincover v0.1.0 - github.com/cosmos/cosmos-sdk v0.40.0 + github.com/cosmos/cosmos-sdk v0.40.1 github.com/cosmos/ledger-go v0.9.2 // indirect - github.com/gogo/protobuf v1.3.1 + github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.4.3 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -14,14 +14,14 @@ require ( github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.1 - github.com/stretchr/testify v1.6.1 - github.com/tendermint/tendermint v0.34.1 + github.com/stretchr/testify v1.7.0 + github.com/tendermint/tendermint v0.34.3 github.com/tendermint/tm-db v0.6.3 - google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d - google.golang.org/grpc v1.33.2 + google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f + google.golang.org/grpc v1.35.0 ) -replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 +replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 replace github.com/cosmos/ledger-cosmos-go => github.com/crypto-com/ledger-cosmos-go v0.9.10-0.20200929055312-01e1d341de0f diff --git a/go.sum b/go.sum index a7db788bd..f9e7abb05 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-metrics v0.3.5 h1:uq4txK6NAUvLQ60rotN+K+JuTnf3XP4TdQmcs9ma5mk= -github.com/armon/go-metrics v0.3.5/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= +github.com/armon/go-metrics v0.3.6 h1:x/tmtOF9cDBoXH7XoAGOz2qqm1DknFD1590XmD/DUJ8= +github.com/armon/go-metrics v0.3.6/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= @@ -87,6 +87,7 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= @@ -104,8 +105,8 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.40.0 h1:nMPdGr5lly9HOENghgr5IRx2QDieqAncHKCSsCdEJSU= -github.com/cosmos/cosmos-sdk v0.40.0/go.mod h1:MMEVnorMyci71WQopgvFmfz2SrDCdWgq5lBjpVclFrg= +github.com/cosmos/cosmos-sdk v0.40.1 h1:gjrtV3MQj/CMeyXN4+sosHMG6Xwa2uH6HITSjSNL/0E= +github.com/cosmos/cosmos-sdk v0.40.1/go.mod h1:vlgqdPpUGSxgqSbZea6fjszoLkPKwCuiqSBySLlv4ro= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= @@ -159,6 +160,7 @@ github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4s github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -336,7 +338,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= @@ -495,10 +497,10 @@ github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Ung github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVscPl0ga4Eoub0= -github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= -github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= -github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQDLUaq15LjNE83nRzkyrLAMcPewig= +github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg= +github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM= +github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= +github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -562,8 +564,11 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca h1:Ld/zXl5t4+D69SiV4JoN7kkfvJdOWlPpfxrzxpLMoUk= @@ -582,8 +587,8 @@ github.com/tendermint/tendermint v0.34.0-rc6 h1:SVuKGvvE22KxfuK8QUHctUrmOWJsncZS github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= github.com/tendermint/tendermint v0.34.0 h1:eXCfMgoqVSzrjzOj6clI9GAejcHH0LvOlRjpCmMJksU= github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= -github.com/tendermint/tendermint v0.34.1 h1:TsJXY8+1NThc/XIENMv1ENzazriHBJJjeP6hN3kpC8g= -github.com/tendermint/tendermint v0.34.1/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= +github.com/tendermint/tendermint v0.34.3 h1:9yEsf3WO5VAwPVwrmM+RffDMiijmNfWaBwNttHm0q5w= +github.com/tendermint/tendermint v0.34.3/go.mod h1:h57vnXeOlrdvvNFCqPBSaOrpOivl+2swWEtlUAqStYE= github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= github.com/tendermint/tm-db v0.6.3 h1:ZkhQcKnB8/2jr5EaZwGndN4owkPsGezW2fSisS9zGbg= @@ -597,6 +602,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= github.com/zondax/ledger-go v0.12.1 h1:hYRcyznPRJp+5mzF2sazTLP2nGvGjYDD2VzhHhFomLU= @@ -662,6 +669,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -683,6 +692,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= @@ -690,8 +700,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc h1:zK/HqS5bZxDptfPJNq8v7vJfXtkU7r9TLIoSr1bXaP4= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200930145003-4acb6c075d10 h1:YfxMZzv3PjGonQYNUaeU2+DhAdqOxerQ30JFB6WgAXo= -golang.org/x/net v0.0.0-20200930145003-4acb6c075d10/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -702,6 +712,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -741,6 +752,7 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= @@ -756,7 +768,6 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -776,9 +787,11 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -814,8 +827,8 @@ google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 h1:iRN4+t0lvZX/l9gH14ARF9i58tsVa5a97k6aH95rC3Y= google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d h1:HV9Z9qMhQEsdlvxNFELgQ11RkMzO3CMkjEySjCtuLes= -google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f h1:izedQ6yVIc5mZsRuXzmSreCOlzI0lCU1HpG8yEdMiKw= +google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -839,6 +852,8 @@ google.golang.org/grpc v1.33.1 h1:DGeFlSan2f+WEtCERJ4J9GJWk15TxUi8QGagfI87Xyc= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/nix/default.nix b/nix/default.nix index 46df8f5ef..350e22dd2 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -15,7 +15,7 @@ import sources.nixpkgs { name = "relayer"; src = pkgs.sources.relayer; subPackages = [ "." ]; - vendorSha256 = sha256:0422zjarm6fk2ca7jfvzf3yz1n7i4zlk65blk34cmqr3m3dmfqw5; + vendorSha256 = sha256:0sb50nl9nmdy4xlly3cmrb8iiyasdkm2y36s8zr9qw4prjm0ngi0; doCheck = false; }; }) diff --git a/nix/sources.json b/nix/sources.json index f2cbd1425..d22ed32c1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -1,15 +1,16 @@ { "cosmos-sdk": { - "branch": "master", + "branch": "release/v0.40.x", "description": ":chains: A Framework for Building High Value Public Blockchains :sparkles:", "homepage": "https://cosmos.network/", "owner": "cosmos", "repo": "cosmos-sdk", - "rev": "a334a59df02fe1f227fbf2a9a1ae153323eb6f8b", - "sha256": "0cjjm8ghk6illv3mgi1xpfkdcjs8gri8z477rs0dk050qgwdq5vp", + "rev": "7cb7a3ab92cdab3dfb260fef7aca665daea2c558", + "sha256": "063ci81v7jfmi6gparxgq3kk6h8grcgz1s8svrmckbyjb0x9h6dk", "type": "tarball", - "url": "https://github.com/cosmos/cosmos-sdk/archive/a334a59df02fe1f227fbf2a9a1ae153323eb6f8b.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" + "url": "https://github.com/cosmos/cosmos-sdk/archive/7cb7a3ab92cdab3dfb260fef7aca665daea2c558.tar.gz", + "url_template": "https://github.com///archive/.tar.gz", + "version": "v0.40.1" }, "nixpkgs": { "branch": "master", @@ -36,15 +37,15 @@ "url_template": "https://github.com///archive/.tar.gz" }, "relayer": { - "branch": "cryptocom-rc6", + "branch": "master", "description": "An example of a server side IBC relayer to be used for Game of Zones and beyond", "homepage": null, - "owner": "yihuang", + "owner": "cosmos", "repo": "relayer", - "rev": "e13898f22bb1dacdb1b947f6d1c4ade73197629b", - "sha256": "0kj58s48vf0r1dpzn3y9c32mir8hzzm1ydh7fxpmc31injlcdil2", + "rev": "1daec66da1700c9fcd8900dbf06c70f2fd838cdf", + "sha256": "0q1jk35cci8kyi9rbmr0yski4977pmzmmrxbrxzif2kp8ghviila", "type": "tarball", - "url": "https://github.com/yihuang/relayer/archive/e13898f22bb1dacdb1b947f6d1c4ade73197629b.tar.gz", + "url": "https://github.com/cosmos/relayer/archive/1daec66da1700c9fcd8900dbf06c70f2fd838cdf.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/pystarport/pystarport/cluster.py b/pystarport/pystarport/cluster.py index 2f400b159..e19b3848a 100644 --- a/pystarport/pystarport/cluster.py +++ b/pystarport/pystarport/cluster.py @@ -235,8 +235,8 @@ def validate_genesis(self, i=0): def add_genesis_account(self, addr, coins, i=0, **kwargs): return self.cosmos_cli(i).add_genesis_account(addr, coins, **kwargs) - def gentx(self, name, coins, i=0, min_self_delegation=1): - return self.cosmos_cli(i).gentx(name, coins, min_self_delegation) + def gentx(self, name, coins, i=0, min_self_delegation=1, pubkey=None): + return self.cosmos_cli(i).gentx(name, coins, min_self_delegation, pubkey) def collect_gentxs(self, gentx_dir, i=0): return self.cosmos_cli(i).collect_gentxs(gentx_dir) @@ -607,6 +607,7 @@ def create_account(cli, account, use_ledger=False): node["staked"], i=i, min_self_delegation=node.get("min_self_delegation", 1), + pubkey=node.get("pubkey"), ) # create accounts diff --git a/pystarport/pystarport/convert.sh b/pystarport/pystarport/convert.sh index 7924f01c8..ce7c97395 100755 --- a/pystarport/pystarport/convert.sh +++ b/pystarport/pystarport/convert.sh @@ -5,8 +5,8 @@ TENDERMINT=./tendermint TMP=$(whereis grpc_python_plugin) PLUGIN="$(cut -d' ' -f2 <<<"$TMP")" mkdir $OUTPUT -git clone --branch v0.40.0 https://github.com/cosmos/cosmos-sdk.git -git clone --branch v0.34.1 https://github.com/tendermint/tendermint.git +git clone --branch v0.40.1 https://github.com/cosmos/cosmos-sdk.git +git clone --branch v0.34.3 https://github.com/tendermint/tendermint.git cp -Rf $COSMOS/third_party/proto/* $COSMOS/proto/ rm -rf $COSMOS/proto/cosmos/base/tendermint # cosmos diff --git a/pystarport/pystarport/cosmoscli.py b/pystarport/pystarport/cosmoscli.py index 7eb831a90..36d5ba081 100644 --- a/pystarport/pystarport/cosmoscli.py +++ b/pystarport/pystarport/cosmoscli.py @@ -150,7 +150,7 @@ def add_genesis_account(self, addr, coins, **kwargs): **kwargs, ) - def gentx(self, name, coins, min_self_delegation=1): + def gentx(self, name, coins, min_self_delegation=1, pubkey=None): return self.raw( "gentx", name, @@ -159,6 +159,7 @@ def gentx(self, name, coins, min_self_delegation=1): home=self.data_dir, chain_id=self.chain_id, keyring_backend="test", + pubkey=pubkey, ) def collect_gentxs(self, gentx_dir): diff --git a/scripts/chain-utils.nix b/scripts/chain-utils.nix index 83e9ae2c3..7d2c623c4 100644 --- a/scripts/chain-utils.nix +++ b/scripts/chain-utils.nix @@ -1,7 +1,7 @@ { pkgs, network }: let fetch-src = ref: builtins.fetchTarball "https://github.com/crypto-com/chain-main/archive/${ref}.tar.gz"; - chain-maind-testnet = (import (fetch-src "v0.8.0-rc1") { }).chain-maind-testnet; + chain-maind-testnet = (import (fetch-src "v0.8.0-croeseid") { }).chain-maind-testnet; cfg = if network == "testnet" then { diff --git a/x/subscription/spec/01_concepts.md b/x/subscription/spec/01_concepts.md new file mode 100644 index 000000000..95f3afb11 --- /dev/null +++ b/x/subscription/spec/01_concepts.md @@ -0,0 +1,26 @@ + + +# Concepts + +## Subscription + +- Subscription plan owners create/stop plans on Chain, the plan prices are defined for specified token denominations, subscribers should do necessary token conversions in other ways, e.g. exchange. +- Users subscribe/unsubscribe to plan. +- Payments are collected automatically at the start of their specified intervals, the results of collections are written into block events. +- Create plan transaction will consume a gas fee to cover the computational cost of future automatic payment collections. +- If the automatic collection mechanism fails on some subscribers, Chain won't automatically retry later, the corresponding plan owner can either configure their plan to automatically cancel these subscribers or manually retry failed collections later. + +### Intervals + +Intervals are specified using [crontab syntax](https://crontab.guru/), for example: + +- `* * * * *`: At *every minute* +- `0 8 * * *`: At *08**:**00* +- `0 8 1 * *`: At *08**:**00* *on day-of-month 1* +- `0 8 * * 1`: At *08**:**00* *on Monday* + +Convenient shortcuts: + +- `@monthly`: `0 0 * * *` \ No newline at end of file diff --git a/x/subscription/spec/02_state.md b/x/subscription/spec/02_state.md new file mode 100644 index 000000000..d17e66938 --- /dev/null +++ b/x/subscription/spec/02_state.md @@ -0,0 +1,87 @@ + + +# State + +The `x/subscription` stores the plans and subscriptions on chain: + +```golang +type SubscriptionPlan struct { + id int, // auto-increasing unique identifier + title string, + description string, + owner Address, // beneficial owner of the plan + price Coins, // price to pay for each period, Coins contains both amount and denomination + subscription_duration int, // duration of subscriptions + cron_spec CronSpec, // Configure time intervals, parsed from crontab syntax + cron_tz Timezone, // timezone for cron_spec +} + +type Subscription struct { + plan_id int, + subscriber Address, + create_time int, // the block time when subscription was created + // the timestamp of last successful collection, + // default to the current block time round-down against cron spec + // subscribers don't pay for the period it gets created in + last_collected_time int, + payment_failures int, // times of failed payment collection +} + +type GenesisState struct { + subscription_plans [SubscriptionPlan]; + subscriptions [Subscription]; +} + +func (s *Subscription) next_collection_time() int { + var plan = get_plan(s.plan_id) + return round_up_time(s.last_collected_time, plan.cron_spec, plan.cron_tz) +} + +func (s *Subscription) expiration_time() int { + var plan = get_plan(s.plan_id) + return s.create_time + plan.subscription_duration +} + +// Parsed crontab syntax +type CronSpec struct { + minute [CronValue] + hour [CronValue] + day [CronValue] + month [CronValue] + wday [CronValue] +} +CronValue = Any | Range(start, end, step) | Value(v) +``` + +## Round time + +We define two functions to round timestamp to the boundary of periods: + +```python +def round_down_time(timestamp, cron_spec, cron_tx): + # return the largest timestamp which matches cron_spec and less or equal than timestamp + +def round_up_time(timestamp, cron_spec, cron_tx): + # return the smallest timestamp which matches cron_spec and greater than timestamp + +def count_period(begin_time, end_time, cron_spec, cron_tz): + # return the number of periods between two timestamps + count = 0 + while True: + begin_time = round_up_time(begin_time, cron_spec, cron_tz) + if begin_time >= end_time: + break + count += 1 + return count +``` + +To keep payment collection idempotent (no duplicated collection in same collection period), we record the last round-down timestamp of collection: + +```python +period_index = round_down_time(block_time, cron_spec) +if period_index > last_period_index: + # do the collection + last_period_index = period_index +``` diff --git a/x/subscription/spec/03_messages.md b/x/subscription/spec/03_messages.md new file mode 100644 index 000000000..299d0bc5d --- /dev/null +++ b/x/subscription/spec/03_messages.md @@ -0,0 +1,56 @@ + + +# Messages + +## MsgCreateSubscriptionPlan + +Plan owners create plans, the message signer is the plan owner. + +```protobuf +message MsgCreateSubscriptionPlan { + string title; + string description; + Coins price, // amount + denomination, amount + denomination, ... + int32 subscription_duration, + repeated int32 collection_timestamps, +} +``` + +## MsgStopSubscriptionPlan + +Sent by plan owners, also removes all corresponding subscriptions. + +```protobuf +message MsgStopSubscriptionPlan { + int32 plan_id, +} +``` + +## MsgCreateSubscription + +The message signer subscribe to the plan. + +```protobuf +message MsgCreateSubscription { + int32 plan_id, +} +``` + +It'll consume some gases for each collection period: + +```python +ConsumeGas( count_period(create_time, expiration_time, plan.cron_spec, plan.cron_tz) * GasPerCollection ) +``` + +## MsgStopSubscription + +Both the subscriber and the plan owner can stop a subscription. + +```protobuf +message MsgStopSubscription { + int32 plan_id, + Address subscriber, +} +``` diff --git a/x/subscription/spec/04_events.md b/x/subscription/spec/04_events.md new file mode 100644 index 000000000..ed4369463 --- /dev/null +++ b/x/subscription/spec/04_events.md @@ -0,0 +1,33 @@ + + +# Events + +The `x/subscription` module emits the following events: + +## BeginBlocker + +| Type | Attribute Key | Attribute Value | +| ----------------- | ------------- | --------------- | +| collect_payment | subscriber | {Address} | +| collect_payment | amount | {Coins} | +| collect_payment | plan_id | {int} | +| stop_subscription | plan_id | {int} | +| stop_subscription | subscriber | {Address} | + + +## MsgStopSubscription + +| Type | Attribute Key | Attribute Value | +| ----------------- | ------------- | --------------- | +| stop_subscription | plan_id | {int} | +| stop_subscription | subscriber | {Address} | + +## MsgCreateSubscription + +| Type | Attribute Key | Attribute Value | +| ------------------- | ------------- | --------------- | +| create_subscription | plan_id | {int} | +| create_subscription | subscriber | {Address} | + diff --git a/x/subscription/spec/05_params.md b/x/subscription/spec/05_params.md new file mode 100644 index 000000000..02164f869 --- /dev/null +++ b/x/subscription/spec/05_params.md @@ -0,0 +1,13 @@ + + +# Parameters + +The subscription module contains the following parameters: + +| Key | Type | Example | +| ------------------- | ---- | ------- | +| GasPerCollection | int | "10000" | +| SubscriptionEnabled | bool | true | +| FailureTolerance | int | 30 | \ No newline at end of file diff --git a/x/subscription/spec/06_begin_block.md b/x/subscription/spec/06_begin_block.md new file mode 100644 index 000000000..a9d026a99 --- /dev/null +++ b/x/subscription/spec/06_begin_block.md @@ -0,0 +1,47 @@ + + +# BeginBlock + +## Remove expired subscriptions + +```python +for plan_id, subscriber, expiration_time in get_subscriptions_sorted_by_expiration_time(): + if block_time >= expiration_time: + stop_subscription(plan_id, subscriber) + else: + break +``` + +## Collect payments + +`x/subscription` module automatically collect payments from subscribers at begin block, and write collection results into events. + +```python +for subscription in get_subscriptions_sorted_by_next_collection_time(): + plan = get_plan(subscription.plan_id) + if block_time >= subscription.next_collection_time(): + current_period = round_down_time(block_time, plan.cron_spec, plan.cron_tz) + if current_period > subscription.last_collected_time: + if transfer(subscription.subscriber, plan.owner, plan.price): + subscription.payment_failures = 0 + emit Event( + 'collect_payment', + plan_id=plan.id, + subscriber=subscription.subscriber, + amount=amount, + ) + subscription.last_collected_time = current_period + else: + subscription.payment_failures += 1 + if subscription.payment_failures > FailureTolerance: + stop_subscription(plan.id, subscription.subscriber) + emit Event( + 'stop_subscription', + plan_id=plan.id, + subscriber=subscription.subscriber, + ) + else: + break +``` diff --git a/x/subscription/spec/README.md b/x/subscription/spec/README.md new file mode 100644 index 000000000..73e6d57d6 --- /dev/null +++ b/x/subscription/spec/README.md @@ -0,0 +1,24 @@ + + +# `x/subscription` + +## Table of Contents + + + +1. **[Concepts](01_concepts.md)** +2. **[State](02_state.md)** +3. **[Messages](03_messages.md)** +4. **[Events](04_events.md)** +5. **[Params](05_params.md)** +6. **[BeginBlock](06_begin_block.md)** + +## Abstract + +`x/subscription` is an implementation of a Cosmos SDK module that allows for billing customers for goods or services at +regular intervals.