Skip to content

Commit

Permalink
#126 Update to cosmos 29
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau committed Dec 21, 2018
1 parent ad905c1 commit c28dadb
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 128 deletions.
42 changes: 26 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type CyberdAppDbKeys struct {
stake *sdk.KVStoreKey
tStake *sdk.TransientStoreKey
fees *sdk.KVStoreKey
keyDistr *sdk.KVStoreKey
distr *sdk.KVStoreKey
slashing *sdk.KVStoreKey
params *sdk.KVStoreKey
tParams *sdk.TransientStoreKey
Expand Down Expand Up @@ -119,6 +119,7 @@ type CyberdApp struct {
func NewCyberdApp(
logger log.Logger, db dbm.DB, computeUnit rank.ComputeUnit, baseAppOptions ...func(*baseapp.BaseApp),
) *CyberdApp {

// create and register app-level codec for TXs and accounts
cdc := MakeCodec()

Expand All @@ -132,7 +133,7 @@ func NewCyberdApp(
stake: sdk.NewKVStoreKey("stake"),
fees: sdk.NewKVStoreKey("fee"),
tStake: sdk.NewTransientStoreKey("transient_stake"),
keyDistr: sdk.NewKVStoreKey("distr"),
distr: sdk.NewKVStoreKey("distr"),
slashing: sdk.NewKVStoreKey("slashing"),
params: sdk.NewKVStoreKey("params"),
tParams: sdk.NewTransientStoreKey("transient_params"),
Expand Down Expand Up @@ -174,7 +175,7 @@ func NewCyberdApp(
slashing.DefaultCodespace,
)
app.distrKeeper = distr.NewKeeper(
app.cdc, dbKeys.keyDistr,
app.cdc, dbKeys.distr,
app.paramsKeeper.Subspace(distr.DefaultParamspace),
app.bankKeeper, stakeKeeper, app.feeCollectionKeeper,
distr.DefaultCodespace,
Expand All @@ -190,7 +191,9 @@ func NewCyberdApp(
// register the staking hooks
// NOTE: stakeKeeper above are passed by reference,
// so that it can be modified like below:
app.stakeKeeper = *stakeKeeper.SetHooks(NewHooks(app.slashingKeeper.Hooks()))
app.stakeKeeper = *stakeKeeper.SetHooks(
NewStakeHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()),
)

app.bandwidthMeter = bandwidth.NewBaseMeter(
app.accountKeeper, app.bankKeeper, app.accBandwidthKeeper, bandwidth.MsgBandwidthCosts,
Expand All @@ -201,6 +204,7 @@ func NewCyberdApp(
AddRoute("bank", sdkbank.NewHandler(app.bankKeeper)).
AddRoute("link", link.NewLinksHandler(app.cidNumKeeper, &app.linkIndexedKeeper, app.accountKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper)).
AddRoute("distr", distr.NewHandler(app.distrKeeper)).
AddRoute("slashing", slashing.NewHandler(app.slashingKeeper))

app.QueryRouter().
Expand All @@ -215,7 +219,7 @@ func NewCyberdApp(
// mount the multistore and load the latest state
app.MountStores(
dbKeys.main, dbKeys.acc, dbKeys.cidNum, dbKeys.cidNumReverse, dbKeys.links, dbKeys.rank, dbKeys.stake,
dbKeys.slashing, dbKeys.params, dbKeys.keyDistr, dbKeys.fees, dbKeys.accBandwidth,
dbKeys.slashing, dbKeys.params, dbKeys.distr, dbKeys.fees, dbKeys.accBandwidth,
)
app.MountStoresTransient(dbKeys.tParams, dbKeys.tStake)
err := app.LoadLatestVersion(dbKeys.main)
Expand Down Expand Up @@ -319,17 +323,6 @@ func (app *CyberdApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) ab
}
}

// BeginBlocker reflects logic to run before any TXs application are processed
// by the application.
func (app *CyberdApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
mint.BeginBlocker(ctx, app.minter)
tags := slashing.BeginBlocker(ctx, req, app.slashingKeeper)

return abci.ResponseBeginBlock{
Tags: tags.ToKVPairs(),
}
}

func (app *CyberdApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {

ctx := app.NewContext(true, abci.Header{Height: app.latestBlockHeight})
Expand Down Expand Up @@ -447,6 +440,23 @@ func getSignersTags(tx sdk.Tx) sdk.Tags {
return tags
}

func (app *CyberdApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {

// mint new tokens for the previous block
mint.BeginBlocker(ctx, app.minter)
// distribute rewards for the previous block
distr.BeginBlocker(ctx, req, app.distrKeeper)

// slash anyone who double signed.
// NOTE: This should happen after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool,
// so as to keep the CanWithdrawInvariant invariant.
tags := slashing.BeginBlocker(ctx, req, app.slashingKeeper)
return abci.ResponseBeginBlock{
Tags: tags.ToKVPairs(),
}
}

// Calculates cyber.Rank for block N, and returns Hash of result as app state.
// Calculated app state will be included in N+1 block header, thus influence on block hash.
// App state is consensus driven state.
Expand Down
20 changes: 16 additions & 4 deletions app/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,57 @@ package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/slashing"
)

//types check
var _ sdk.StakingHooks = Hooks{}

// Combined Staking Hooks
type Hooks struct {
sh slashing.Hooks
dh distr.Hooks
}

func NewHooks(sh slashing.Hooks) Hooks {
return Hooks{sh}
func NewStakeHooks(dh distr.Hooks, sh slashing.Hooks) Hooks {
return Hooks{dh: dh, sh: sh}
}

var _ sdk.StakingHooks = Hooks{}

// nolint
func (h Hooks) OnValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {
h.sh.OnValidatorCreated(ctx, valAddr)
h.dh.OnValidatorCreated(ctx, valAddr)
}
func (h Hooks) OnValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) {
h.sh.OnValidatorModified(ctx, valAddr)
h.dh.OnValidatorModified(ctx, valAddr)
}
func (h Hooks) OnValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) {
h.sh.OnValidatorRemoved(ctx, consAddr, valAddr)
h.dh.OnValidatorRemoved(ctx, consAddr, valAddr)
}
func (h Hooks) OnValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) {
h.sh.OnValidatorBonded(ctx, consAddr, valAddr)
h.dh.OnValidatorBonded(ctx, consAddr, valAddr)
}
func (h Hooks) OnValidatorPowerDidChange(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) {
h.sh.OnValidatorPowerDidChange(ctx, consAddr, valAddr)
h.dh.OnValidatorPowerDidChange(ctx, consAddr, valAddr)
}
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) {
h.sh.OnValidatorBeginUnbonding(ctx, consAddr, valAddr)
h.dh.OnValidatorBeginUnbonding(ctx, consAddr, valAddr)
}
func (h Hooks) OnDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
h.sh.OnDelegationCreated(ctx, delAddr, valAddr)
h.dh.OnDelegationCreated(ctx, delAddr, valAddr)
}
func (h Hooks) OnDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
h.sh.OnDelegationSharesModified(ctx, delAddr, valAddr)
h.dh.OnDelegationSharesModified(ctx, delAddr, valAddr)
}
func (h Hooks) OnDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
h.sh.OnDelegationRemoved(ctx, delAddr, valAddr)
h.dh.OnDelegationRemoved(ctx, delAddr, valAddr)
}
3 changes: 2 additions & 1 deletion app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
Expand All @@ -20,6 +21,7 @@ func MakeCodec() *codec.Codec {
sdk.RegisterCodec(cdc)
bank.RegisterCodec(cdc)
ibc.RegisterCodec(cdc)
distr.RegisterCodec(cdc)
auth.RegisterCodec(cdc)
stake.RegisterCodec(cdc)
slashing.RegisterCodec(cdc)
Expand All @@ -28,4 +30,3 @@ func MakeCodec() *codec.Codec {
cdc.Seal()
return cdc
}

2 changes: 1 addition & 1 deletion cli/commands/linktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func LinkTxCmd(cdc *codec.Codec) *cobra.Command {
Short: "Create and sign a link tx",
RunE: func(cmd *cobra.Command, args []string) error {

txCtx := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txCtx := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
Expand Down
3 changes: 2 additions & 1 deletion client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
cli "github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/utils"
cskeys "github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
Expand Down Expand Up @@ -70,7 +71,7 @@ func NewHttpCyberdClient(nodeUrl string, passphrase string, singAddr string) Cyb
Gas: 1000000,
ChainID: status.NodeInfo.Network,
AccountNumber: accountNumber,
Codec: cdc,
TxEncoder: utils.GetTxEncoder(cdc),
Sequence: seq,
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/btcsuite/btcd v0.0.0-20180903232927-cff30e1d23fc // indirect
github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a // indirect
github.com/cosmos/cosmos-sdk v0.27.0
github.com/cosmos/cosmos-sdk v0.29.0
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8 // indirect
github.com/fortytw2/leaktest v1.2.0 // indirect
github.com/go-kit/kit v0.7.0 // indirect
Expand Down Expand Up @@ -60,7 +60,7 @@ require (
github.com/tendermint/btcd v0.0.0-20180816174608-e5840949ff4f // indirect
github.com/tendermint/go-amino v0.14.1
github.com/tendermint/iavl v0.12.0 // indirect
github.com/tendermint/tendermint v0.27.0
github.com/tendermint/tendermint v0.27.3
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
github.com/zondax/ledger-goclient v0.1.0 // indirect
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/btcsuite/btcd v0.0.0-20180903232927-cff30e1d23fc/go.mod h1:Dmm/EzmjnC
github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a h1:RQMUrEILyYJEoAT34XS/kLu40vC0+po/UfxrBBA4qZE=
github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cosmos/cosmos-sdk v0.27.0 h1:EKMsS3SoEL+MN1WH1VwiUUbUjmmmHyseQA49QzgJ/Lw=
github.com/cosmos/cosmos-sdk v0.27.0/go.mod h1:JrX/JpJunJQXBI5PEX2zELHMFzQr/159jDjIhesOh2c=
github.com/cosmos/cosmos-sdk v0.29.0 h1:0tClCHjWsFLxRPoThH5gwzqjvVfBpP708CCLjP3Hz58=
github.com/cosmos/cosmos-sdk v0.29.0/go.mod h1:JrX/JpJunJQXBI5PEX2zELHMFzQr/159jDjIhesOh2c=
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8 h1:Iwin12wRQtyZhH6FV3ykFcdGNlYEzoeR0jN8Vn+JWsI=
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -134,8 +134,8 @@ github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6o
github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso=
github.com/tendermint/iavl v0.12.0 h1:xcaFAr+ycqCj7WN1RzL2EfcBioRDOHcU1oWcg83K028=
github.com/tendermint/iavl v0.12.0/go.mod h1:EoKMMv++tDOL5qKKVnoIqtVPshRrEPeJ0WsgDOLAauM=
github.com/tendermint/tendermint v0.27.0 h1:PeH/nkYqzG7hEdKmG5aJZFCOi6aSr9nIUjC0Echtzjc=
github.com/tendermint/tendermint v0.27.0/go.mod h1:ymcPyWblXCplCPQjbOYbrF1fWnpslATMVqiGgWbZrlc=
github.com/tendermint/tendermint v0.27.3 h1:yJQhTEjFiNtTqO2OQTPnIYmy1Gj3EBqBik3c5wCY7nU=
github.com/tendermint/tendermint v0.27.3/go.mod h1:ymcPyWblXCplCPQjbOYbrF1fWnpslATMVqiGgWbZrlc=
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboadS0DvysUuJXZ4lWVv5Bh5i7+tbIyi+ck4=
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM=
github.com/zondax/ledger-goclient v0.1.0 h1:9JZVE1s565asON/yvxvpDB6k+xfel1BGuvlNflLCu+o=
Expand Down
4 changes: 1 addition & 3 deletions proxy/core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ func TxHandlerFn(ctx ProxyContext, unmarshal UnmarshalTxRequest) func(http.Respo
// BUILDING COSMOS SDK TX
signatures := make([]auth.StdSignature, 0, len(txReq.GetSignatures()))
for _, sig := range txReq.GetSignatures() {
stdSig := auth.StdSignature{
PubKey: sig.PubKey, Signature: sig.Signature, AccountNumber: sig.AccountNumber, Sequence: sig.Sequence,
}
stdSig := auth.StdSignature{PubKey: sig.PubKey, Signature: sig.Signature}
signatures = append(signatures, stdSig)
}

Expand Down
96 changes: 0 additions & 96 deletions x/rank/cuda/test_cpu_gpu_determinism.go

This file was deleted.

0 comments on commit c28dadb

Please sign in to comment.