Skip to content

Commit

Permalink
Rebase & squash slashing
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed May 28, 2018
1 parent f36eb22 commit 95c5baf
Showing 33 changed files with 401 additions and 122 deletions.
32 changes: 15 additions & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -52,9 +52,9 @@
name = "github.com/stretchr/testify"
version = "~1.2.1"

[[constraint]]
[[override]]
name = "github.com/tendermint/abci"
version = "~0.10.3"
branch = "cwgoes/timestamp-in-evidence"

[[constraint]]
name = "github.com/tendermint/go-crypto"
@@ -70,11 +70,11 @@

[[constraint]]
name = "github.com/tendermint/iavl"
version = "~0.7.0"
branch = "develop"

[[constraint]]
name = "github.com/tendermint/tendermint"
version = "0.19.5-rc1"
branch = "cwgoes/update-abci"

[[override]]
name = "github.com/tendermint/tmlibs"
@@ -88,4 +88,3 @@
[prune]
go-tests = true
unused-packages = true

18 changes: 11 additions & 7 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
@@ -65,9 +65,10 @@ type BaseApp struct {
// See methods setCheckState and setDeliverState.
// .valUpdates accumulate in DeliverTx and are reset in BeginBlock.
// QUESTION: should we put valUpdates in the deliverState.ctx?
checkState *state // for CheckTx
deliverState *state // for DeliverTx
valUpdates []abci.Validator // cached validator changes from DeliverTx
checkState *state // for CheckTx
deliverState *state // for DeliverTx
valUpdates []abci.Validator // cached validator changes from DeliverTx
absentValidators [][]byte // absent validators from begin block
}

var _ abci.Application = (*BaseApp)(nil)
@@ -234,9 +235,9 @@ func (app *BaseApp) initFromStore(mainKey sdk.StoreKey) error {
// NewContext returns a new Context with the correct store, the given header, and nil txBytes.
func (app *BaseApp) NewContext(isCheckTx bool, header abci.Header) sdk.Context {
if isCheckTx {
return sdk.NewContext(app.checkState.ms, header, true, nil, app.Logger)
return sdk.NewContext(app.checkState.ms, header, true, nil, app.Logger, nil)
}
return sdk.NewContext(app.deliverState.ms, header, false, nil, app.Logger)
return sdk.NewContext(app.deliverState.ms, header, false, nil, app.Logger, nil)
}

type state struct {
@@ -252,15 +253,15 @@ func (app *BaseApp) setCheckState(header abci.Header) {
ms := app.cms.CacheMultiStore()
app.checkState = &state{
ms: ms,
ctx: sdk.NewContext(ms, header, true, nil, app.Logger),
ctx: sdk.NewContext(ms, header, true, nil, app.Logger, nil),
}
}

func (app *BaseApp) setDeliverState(header abci.Header) {
ms := app.cms.CacheMultiStore()
app.deliverState = &state{
ms: ms,
ctx: sdk.NewContext(ms, header, false, nil, app.Logger),
ctx: sdk.NewContext(ms, header, false, nil, app.Logger, nil),
}
}

@@ -384,6 +385,8 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
if app.beginBlocker != nil {
res = app.beginBlocker(app.deliverState.ctx, req)
}
// set the absent validators for addition to context in deliverTx
app.absentValidators = req.AbsentValidators
return
}

@@ -493,6 +496,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
ctx = app.checkState.ctx.WithTxBytes(txBytes)
} else {
ctx = app.deliverState.ctx.WithTxBytes(txBytes)
ctx = ctx.WithAbsentValidators(app.absentValidators)
}

// Simulate a DeliverTx for gas calculation
2 changes: 1 addition & 1 deletion baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ func TestInitChainer(t *testing.T) {

// set initChainer and try again - should see the value
app.SetInitChainer(initChainer)
app.InitChain(abci.RequestInitChain{AppStateBytes: []byte("{}")}) // must have valid JSON genesis file, even if empty
app.InitChain(abci.RequestInitChain{GenesisBytes: []byte("{}")}) // must have valid JSON genesis file, even if empty
app.Commit()
res = app.Query(query)
assert.Equal(t, value, res.Value)
29 changes: 18 additions & 11 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
)

@@ -34,30 +35,33 @@ type GaiaApp struct {
cdc *wire.Codec

// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyIBC *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyIBC *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
keySlashing *sdk.KVStoreKey

// Manage getting and setting accounts
accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper
ibcMapper ibc.Mapper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
}

func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
cdc := MakeCodec()

// create your application object
var app = &GaiaApp{
BaseApp: bam.NewBaseApp(appName, cdc, logger, db),
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"),
keyStake: sdk.NewKVStoreKey("stake"),
BaseApp: bam.NewBaseApp(appName, cdc, logger, db),
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"),
keyStake: sdk.NewKVStoreKey("stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
}

// define the accountMapper
@@ -71,6 +75,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.RegisterCodespace(slashing.DefaultCodespace))

// register message routes
app.Router().
@@ -80,6 +85,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {

// initialize BaseApp
app.SetInitChainer(app.initChainer)
app.SetBeginBlocker(slashing.NewBeginBlocker(app.slashingKeeper))
app.SetEndBlocker(stake.NewEndBlocker(app.stakeKeeper))
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper))
@@ -105,7 +111,8 @@ func MakeCodec() *wire.Codec {

// custom logic for gaia initialization
func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
stateJSON := req.AppStateBytes
stateJSON := req.GenesisBytes
// TODO is this now the whole genesis file?

var genesisState GenesisState
err := app.cdc.UnmarshalJSON(stateJSON, &genesisState)
12 changes: 6 additions & 6 deletions docs/spec/staking/old/spec.md
Original file line number Diff line number Diff line change
@@ -297,12 +297,12 @@ type TxProveLive struct {
## Delegator bond

Atom holders may delegate coins to validators, under this circumstance their
funds are held in a `DelegatorBond`. It is owned by one delegator, and is
funds are held in a `Delegation`. It is owned by one delegator, and is
associated with the shares for one validator. The sender of the transaction is
considered to be the owner of the bond,

``` golang
type DelegatorBond struct {
type Delegation struct {
Candidate crypto.PubKey
Shares rational.Rat
AdjustmentFeePool coin.Coins
@@ -318,19 +318,19 @@ Description:
- AdjustmentRewardPool: Adjustment factor used to passively calculate each
bonds entitled fees from `Candidate.ProposerRewardPool``

Each `DelegatorBond` is individually indexed within the store by delegator
Each `Delegation` is individually indexed within the store by delegator
address and candidate pubkey.

- key: Delegator and Candidate-Pubkey
- value: DelegatorBond
- value: Delegation


### Delegating

Delegator bonds are created using the TxDelegate transaction. Within this
transaction the validator candidate queried with an amount of coins, whereby
given the current exchange rate of candidate's delegator-shares-to-atoms the
candidate will return shares which are assigned in `DelegatorBond.Shares`.
candidate will return shares which are assigned in `Delegation.Shares`.

``` golang
type TxDelegate struct {
@@ -671,5 +671,5 @@ rate, all commission on fees must be simultaneously withdrawn.
`candidate.Adjustment` must be set to the value of `canidate.Count` for the
height which the candidate is added on the validator set.
- The feePool of a new delegator bond will be 0 for the height at which the bond
was added. This is achieved by setting `DelegatorBond.FeeWithdrawalHeight` to
was added. This is achieved by setting `Delegation.FeeWithdrawalHeight` to
the height which the bond was added.
18 changes: 9 additions & 9 deletions docs/spec/staking/old/spec2.md
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ The staking module persists the following to the store:
- `GlobalState`, describing the global pools
- a `Candidate` for each candidate validator, indexed by public key
- a `Candidate` for each candidate validator, indexed by shares in the global pool (ie. ordered)
- a `DelegatorBond` for each delegation to a candidate by a delegator, indexed by delegator and candidate
- a `Delegation` for each delegation to a candidate by a delegator, indexed by delegator and candidate
public keys
- a `Queue` of unbonding delegations (TODO)

@@ -146,15 +146,15 @@ When validators are kicked from the validator set they are removed from this
list.


### DelegatorBond
### Delegation

Atom holders may delegate coins to validators, under this circumstance their
funds are held in a `DelegatorBond`. It is owned by one delegator, and is
funds are held in a `Delegation`. It is owned by one delegator, and is
associated with the shares for one validator. The sender of the transaction is
considered to be the owner of the bond,

``` golang
type DelegatorBond struct {
type Delegation struct {
Candidate crypto.PubKey
Shares rational.Rat
AdjustmentFeePool coin.Coins
@@ -170,11 +170,11 @@ Description:
- AdjustmentRewardPool: Adjustment factor used to passively calculate each
bonds entitled fees from `Candidate.ProposerRewardPool``

Each `DelegatorBond` is individually indexed within the store by delegator
Each `Delegation` is individually indexed within the store by delegator
address and candidate pubkey.

- key: Delegator and Candidate-Pubkey
- value: DelegatorBond
- value: Delegation


### Unbonding Queue
@@ -308,7 +308,7 @@ All bonding, whether self-bonding or delegation, is done via
Delegator bonds are created using the TxDelegate transaction. Within this
transaction the validator candidate queried with an amount of coins, whereby
given the current exchange rate of candidate's delegator-shares-to-atoms the
candidate will return shares which are assigned in `DelegatorBond.Shares`.
candidate will return shares which are assigned in `Delegation.Shares`.

``` golang
type TxDelegate struct {
@@ -616,7 +616,7 @@ synced past the height of the oldest `powerChange`. This trim procedure will
occur on an epoch basis.

```golang
type powerChange struct {
type powerChange struct
height int64 // block height at change
power rational.Rat // total power at change
prevpower rational.Rat // total power at previous height-1
@@ -694,5 +694,5 @@ rate, all commission on fees must be simultaneously withdrawn.
`candidate.Adjustment` must be set to the value of `canidate.Count` for the
height which the candidate is added on the validator set.
- The feePool of a new delegator bond will be 0 for the height at which the bond
was added. This is achieved by setting `DelegatorBond.FeeWithdrawalHeight` to
was added. This is achieved by setting `Delegation.FeeWithdrawalHeight` to
the height which the bond was added.
4 changes: 2 additions & 2 deletions docs/spec/staking/transactions.md
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ unbond(tx TxUnbond):
return

removeShares(candidate Candidate, shares rational.Rat):
globalPoolSharesToRemove = delegatorShareExRate(candidate) * shares
globalPoolSharesToRemove = DelegatorShareExRate(candidate) * shares

if candidate.Status == Bonded
gs.BondedShares -= globalPoolSharesToRemove
@@ -218,7 +218,7 @@ removeShares(candidate Candidate, shares rational.Rat):
candidate.IssuedDelegatorShares -= shares
return returnedCoins

delegatorShareExRate(candidate Candidate):
DelegatorShareExRate(candidate Candidate):
if candidate.IssuedDelegatorShares.IsZero() then return rational.One
return candidate.GlobalStakeShares / candidate.IssuedDelegatorShares

Loading

0 comments on commit 95c5baf

Please sign in to comment.