Merge pull request #1011 from cosmos/cwgoes/slashing

Implement slashing (v1)
This commit is contained in:
Rigel
2018-05-31 11:09:44 -07:00
committed by GitHub
30 changed files with 895 additions and 77 deletions
+9
View File
@@ -31,6 +31,7 @@ type Context struct {
// create a new context
func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, txBytes []byte, logger log.Logger) Context {
c := Context{
Context: context.Background(),
pst: newThePast(),
@@ -43,6 +44,7 @@ func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, txBytes []byt
c = c.WithIsCheckTx(isCheckTx)
c = c.WithTxBytes(txBytes)
c = c.WithLogger(logger)
c = c.WithAbsentValidators(nil)
c = c.WithGasMeter(NewInfiniteGasMeter())
return c
}
@@ -128,6 +130,7 @@ const (
contextKeyIsCheckTx
contextKeyTxBytes
contextKeyLogger
contextKeyAbsentValidators
contextKeyGasMeter
)
@@ -157,6 +160,9 @@ func (c Context) TxBytes() []byte {
func (c Context) Logger() log.Logger {
return c.Value(contextKeyLogger).(log.Logger)
}
func (c Context) AbsentValidators() [][]byte {
return c.Value(contextKeyAbsentValidators).([][]byte)
}
func (c Context) GasMeter() GasMeter {
return c.Value(contextKeyGasMeter).(GasMeter)
}
@@ -182,6 +188,9 @@ func (c Context) WithTxBytes(txBytes []byte) Context {
func (c Context) WithLogger(logger log.Logger) Context {
return c.withValue(contextKeyLogger, logger)
}
func (c Context) WithAbsentValidators(AbsentValidators [][]byte) Context {
return c.withValue(contextKeyAbsentValidators, AbsentValidators)
}
func (c Context) WithGasMeter(meter GasMeter) Context {
return c.withValue(contextKeyGasMeter, meter)
}
+5 -2
View File
@@ -56,8 +56,11 @@ type ValidatorSet interface {
IterateValidatorsBonded(Context,
func(index int64, validator Validator) (stop bool))
Validator(Context, Address) Validator // get a particular validator by owner address
TotalPower(Context) Rat // total power of the validator set
Validator(Context, Address) Validator // get a particular validator by owner address
TotalPower(Context) Rat // total power of the validator set
Slash(Context, crypto.PubKey, int64, Rat) // slash the validator and delegators of the validator, specifying offence height & slash fraction
Revoke(Context, crypto.PubKey) // revoke a validator
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
}
//_______________________________________________________________________________
+5
View File
@@ -25,6 +25,11 @@ func (t Tags) AppendTags(a Tags) Tags {
return append(t, a...)
}
// Turn tags into KVPair list
func (t Tags) ToKVPairs() []cmn.KVPair {
return []cmn.KVPair(t)
}
// New variadic tags, must be k string, v []byte repeating
func NewTags(tags ...interface{}) Tags {
var ret Tags