diff --git a/app/app.go b/app/app.go index d955f868..a4357b01 100644 --- a/app/app.go +++ b/app/app.go @@ -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 @@ -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() @@ -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"), @@ -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, @@ -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, @@ -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(). @@ -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) @@ -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}) @@ -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. diff --git a/app/hooks.go b/app/hooks.go index 233da834..c3f2fee1 100644 --- a/app/hooks.go +++ b/app/hooks.go @@ -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) } diff --git a/app/wire.go b/app/wire.go index da3cdf4c..cb382e1c 100644 --- a/app/wire.go +++ b/app/wire.go @@ -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" @@ -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) @@ -28,4 +30,3 @@ func MakeCodec() *codec.Codec { cdc.Seal() return cdc } - diff --git a/cli/commands/linktx.go b/cli/commands/linktx.go index c2d34d86..5af55aba 100644 --- a/cli/commands/linktx.go +++ b/cli/commands/linktx.go @@ -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) diff --git a/client/http_client.go b/client/http_client.go index 0a1596ad..bf2b9b7c 100644 --- a/client/http_client.go +++ b/client/http_client.go @@ -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" @@ -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, } diff --git a/go.mod b/go.mod index 54482df3..b5f36bea 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 50bce205..13d9d168 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/proxy/core/tx.go b/proxy/core/tx.go index 48a4ca1f..920f9511 100644 --- a/proxy/core/tx.go +++ b/proxy/core/tx.go @@ -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) } diff --git a/x/rank/cuda/test_cpu_gpu_determinism.go b/x/rank/cuda/test_cpu_gpu_determinism.go deleted file mode 100644 index 8a2d5d74..00000000 --- a/x/rank/cuda/test_cpu_gpu_determinism.go +++ /dev/null @@ -1,96 +0,0 @@ -package main - -import ( - "fmt" - . "github.com/cybercongress/cyberd/app/storage" - . "github.com/cybercongress/cyberd/app/types" - cpurank "github.com/cybercongress/cyberd/x/rank" - "github.com/tendermint/tendermint/libs/log" -) - -/* -#cgo CFLAGS: -I/usr/lib/ -#cgo LDFLAGS: -lcbdrank -lcudart -#include "cbdrank.h" -*/ -import "C" - -func main() { - - /* --- Init network ------------------------------- */ - stakes := []uint64{3, 1, 2} - - inLinksCount := []uint32{0, 0, 1, 5, 4, 0, 1, 0} - inLinksStartIndex := []uint64{0, 0, 0, 1, 6, 10, 10, 11} - outLinksCount := []uint32{2, 2, 1, 1, 3, 1, 0, 1} - - inLinksOuts := []uint64{7, 1, 4, 4, 4, 2, 5, 0, 0, 1, 3} - inLinksUsers := []uint64{0, 2, 0, 1, 2, 0, 1, 1, 2, 1, 1} - outLinksUsers := []uint64{1, 2, 1, 2, 0, 1, 0, 1, 2, 1, 0} - - /* --- Convert to C ------------------------------- */ - cStakesSize := C.ulong(len(stakes)) - cCidsSize := C.ulong(len(inLinksStartIndex)) - cLinksSize := C.ulong(len(inLinksOuts)) - - cStakes := (*C.ulong)(&stakes[0]) - - cInLinksCount := (*C.uint)(&inLinksCount[0]) - cOutLinksCount := (*C.uint)(&outLinksCount[0]) - - cInLinksOuts := (*C.ulong)(&inLinksOuts[0]) - cInLinksUsers := (*C.ulong)(&inLinksUsers[0]) - cOutLinksUsers := (*C.ulong)(&outLinksUsers[0]) - - /* --- Init rank ---------------------------------- */ - rank := make([]float64, len(inLinksStartIndex)) - cRank := (*C.double)(&rank[0]) - /* --- Run Computation ---------------------------- */ - fmt.Printf("Invoking cuda library...\n") - C.calculate_rank( - cStakes, cStakesSize, cCidsSize, cLinksSize, - cInLinksCount, cOutLinksCount, - cInLinksOuts, cInLinksUsers, cOutLinksUsers, - cRank, - ) - - fmt.Printf("Rank calculated on raw gpu...\n") - for c, r := range rank { - fmt.Printf("%v -> %v\n", c, r) - } - - m := InMemoryStorage{} - m.Empty() - for i := 0; i < 8; i++ { - m.AddCid(Cid(i), CidNumber(i)) - } - m.UpdateStakeByNumber(AccountNumber(0), 3) - m.UpdateStakeByNumber(AccountNumber(1), 1) - m.UpdateStakeByNumber(AccountNumber(2), 2) - - m.AddLink(NewLink(CidNumber(0), CidNumber(4), AccountNumber(1))) - m.AddLink(NewLink(CidNumber(0), CidNumber(4), AccountNumber(2))) - m.AddLink(NewLink(CidNumber(4), CidNumber(3), AccountNumber(1))) - m.AddLink(NewLink(CidNumber(7), CidNumber(2), AccountNumber(0))) - m.AddLink(NewLink(CidNumber(1), CidNumber(3), AccountNumber(2))) - m.AddLink(NewLink(CidNumber(2), CidNumber(3), AccountNumber(0))) - m.AddLink(NewLink(CidNumber(3), CidNumber(6), AccountNumber(1))) - m.AddLink(NewLink(CidNumber(1), CidNumber(4), AccountNumber(1))) - m.AddLink(NewLink(CidNumber(4), CidNumber(3), AccountNumber(0))) - m.AddLink(NewLink(CidNumber(4), CidNumber(3), AccountNumber(2))) - m.AddLink(NewLink(CidNumber(5), CidNumber(4), AccountNumber(1))) - - rank, _ = cpurank.CalculateRank(&m, cpurank.CPU, log.NewNopLogger()) - - fmt.Printf("Rank calculated on cpu...\n") - for c, r := range rank { - fmt.Printf("%v -> %v\n", c, r) - } - - rank, _ = cpurank.CalculateRank(&m, cpurank.GPU, log.NewNopLogger()) - - fmt.Printf("Rank calculated on gpu via cyberd ...\n") - for c, r := range rank { - fmt.Printf("%v -> %v\n", c, r) - } -}