mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 15:22:15 +00:00
remove TimeoutTx
This commit is contained in:
parent
7652c5d0de
commit
f4b42cdfab
@ -46,11 +46,6 @@ func TestBlock(t *testing.T) {
|
|||||||
Fee: RandUInt64Exp(),
|
Fee: RandUInt64Exp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
timeoutTx := &TimeoutTx{
|
|
||||||
AccountId: RandUInt64Exp(),
|
|
||||||
Penalty: RandUInt64Exp(),
|
|
||||||
}
|
|
||||||
|
|
||||||
dupeoutTx := &DupeoutTx{
|
dupeoutTx := &DupeoutTx{
|
||||||
VoteA: Vote{
|
VoteA: Vote{
|
||||||
Height: RandUInt32Exp(),
|
Height: RandUInt32Exp(),
|
||||||
|
28
blocks/tx.go
28
blocks/tx.go
@ -14,8 +14,7 @@ Account Txs:
|
|||||||
Validation Txs:
|
Validation Txs:
|
||||||
3. Bond New validator posts a bond
|
3. Bond New validator posts a bond
|
||||||
4. Unbond Validator leaves
|
4. Unbond Validator leaves
|
||||||
5. Timeout Validator times out
|
5. Dupeout Validator dupes out (signs twice)
|
||||||
6. Dupeout Validator dupes out (signs twice)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type Tx interface {
|
type Tx interface {
|
||||||
@ -31,8 +30,7 @@ const (
|
|||||||
// Validation transactions
|
// Validation transactions
|
||||||
TxTypeBond = byte(0x11)
|
TxTypeBond = byte(0x11)
|
||||||
TxTypeUnbond = byte(0x12)
|
TxTypeUnbond = byte(0x12)
|
||||||
TxTypeTimeout = byte(0x13)
|
TxTypeDupeout = byte(0x13)
|
||||||
TxTypeDupeout = byte(0x14)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadTx(r io.Reader, n *int64, err *error) Tx {
|
func ReadTx(r io.Reader, n *int64, err *error) Tx {
|
||||||
@ -62,12 +60,6 @@ func ReadTx(r io.Reader, n *int64, err *error) Tx {
|
|||||||
BaseTx: ReadBaseTx(r, n, err),
|
BaseTx: ReadBaseTx(r, n, err),
|
||||||
Fee: ReadUInt64(r, n, err),
|
Fee: ReadUInt64(r, n, err),
|
||||||
}
|
}
|
||||||
case TxTypeTimeout:
|
|
||||||
return &TimeoutTx{
|
|
||||||
BaseTx: ReadBaseTx(r, n, err),
|
|
||||||
AccountId: ReadUInt64(r, n, err),
|
|
||||||
Penalty: ReadUInt64(r, n, err),
|
|
||||||
}
|
|
||||||
case TxTypeDupeout:
|
case TxTypeDupeout:
|
||||||
return &DupeoutTx{
|
return &DupeoutTx{
|
||||||
BaseTx: ReadBaseTx(r, n, err),
|
BaseTx: ReadBaseTx(r, n, err),
|
||||||
@ -180,22 +172,6 @@ func (tx *UnbondTx) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
type TimeoutTx struct {
|
|
||||||
BaseTx
|
|
||||||
AccountId uint64
|
|
||||||
Penalty uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *TimeoutTx) WriteTo(w io.Writer) (n int64, err error) {
|
|
||||||
WriteByte(w, TxTypeTimeout, &n, &err)
|
|
||||||
WriteBinary(w, tx.BaseTx, &n, &err)
|
|
||||||
WriteUInt64(w, tx.AccountId, &n, &err)
|
|
||||||
WriteUInt64(w, tx.Penalty, &n, &err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
type DupeoutTx struct {
|
type DupeoutTx struct {
|
||||||
BaseTx
|
BaseTx
|
||||||
VoteA Vote
|
VoteA Vote
|
||||||
|
@ -34,7 +34,8 @@ type State struct {
|
|||||||
BlockHash []byte // Last known block hash
|
BlockHash []byte // Last known block hash
|
||||||
CommitTime time.Time
|
CommitTime time.Time
|
||||||
AccountDetails merkle.Tree
|
AccountDetails merkle.Tree
|
||||||
Validators *ValidatorSet
|
BondedValidators *ValidatorSet
|
||||||
|
UnbondedValidators *ValidatorSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenesisState(db DB, genesisTime time.Time, accDets []*AccountDetail) *State {
|
func GenesisState(db DB, genesisTime time.Time, accDets []*AccountDetail) *State {
|
||||||
@ -58,7 +59,6 @@ func GenesisState(db DB, genesisTime time.Time, accDets []*AccountDetail) *State
|
|||||||
if len(validators) == 0 {
|
if len(validators) == 0 {
|
||||||
panic("Must have some validators")
|
panic("Must have some validators")
|
||||||
}
|
}
|
||||||
validatorSet := NewValidatorSet(validators)
|
|
||||||
|
|
||||||
return &State{
|
return &State{
|
||||||
DB: db,
|
DB: db,
|
||||||
@ -66,7 +66,8 @@ func GenesisState(db DB, genesisTime time.Time, accDets []*AccountDetail) *State
|
|||||||
BlockHash: nil,
|
BlockHash: nil,
|
||||||
CommitTime: genesisTime,
|
CommitTime: genesisTime,
|
||||||
AccountDetails: accountDetails,
|
AccountDetails: accountDetails,
|
||||||
Validators: validatorSet,
|
BondedValidators: NewValidatorSet(validators),
|
||||||
|
UnbondedValidators: NewValidatorSet(nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +86,8 @@ func LoadState(db DB) *State {
|
|||||||
accountDetailsHash := ReadByteSlice(reader, &n, &err)
|
accountDetailsHash := ReadByteSlice(reader, &n, &err)
|
||||||
s.AccountDetails = merkle.NewIAVLTree(BasicCodec, AccountDetailCodec, defaultAccountDetailsCacheCapacity, db)
|
s.AccountDetails = merkle.NewIAVLTree(BasicCodec, AccountDetailCodec, defaultAccountDetailsCacheCapacity, db)
|
||||||
s.AccountDetails.Load(accountDetailsHash)
|
s.AccountDetails.Load(accountDetailsHash)
|
||||||
s.Validators = ReadValidatorSet(reader, &n, &err)
|
s.BondedValidators = ReadValidatorSet(reader, &n, &err)
|
||||||
|
s.UnbondedValidators = ReadValidatorSet(reader, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -107,7 +109,8 @@ func (s *State) Save(commitTime time.Time) {
|
|||||||
WriteTime(&buf, commitTime, &n, &err)
|
WriteTime(&buf, commitTime, &n, &err)
|
||||||
WriteByteSlice(&buf, s.BlockHash, &n, &err)
|
WriteByteSlice(&buf, s.BlockHash, &n, &err)
|
||||||
WriteByteSlice(&buf, s.AccountDetails.Hash(), &n, &err)
|
WriteByteSlice(&buf, s.AccountDetails.Hash(), &n, &err)
|
||||||
WriteBinary(&buf, s.Validators, &n, &err)
|
WriteBinary(&buf, s.BondedValidators, &n, &err)
|
||||||
|
WriteBinary(&buf, s.UnbondedValidators, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -121,7 +124,8 @@ func (s *State) Copy() *State {
|
|||||||
CommitTime: s.CommitTime,
|
CommitTime: s.CommitTime,
|
||||||
BlockHash: s.BlockHash,
|
BlockHash: s.BlockHash,
|
||||||
AccountDetails: s.AccountDetails.Copy(),
|
AccountDetails: s.AccountDetails.Copy(),
|
||||||
Validators: s.Validators.Copy(),
|
BondedValidators: s.BondedValidators.Copy(),
|
||||||
|
UnbondedValidators: s.UnbondedValidators.Copy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +185,35 @@ func (s *State) ExecTx(tx Tx) error {
|
|||||||
accDet.Balance -= btx.Fee // remaining balance are bonded coins.
|
accDet.Balance -= btx.Fee // remaining balance are bonded coins.
|
||||||
accDet.Status = AccountDetailStatusBonded
|
accDet.Status = AccountDetailStatusBonded
|
||||||
s.SetAccountDetail(accDet)
|
s.SetAccountDetail(accDet)
|
||||||
// XXX add validator
|
added := s.BondednValidators.Add(&Validator{
|
||||||
|
Account: accDet.Account,
|
||||||
|
BondHeight: s.Height,
|
||||||
|
VotingPower: accDet.Balance,
|
||||||
|
Accum: 0,
|
||||||
|
})
|
||||||
|
if !added {
|
||||||
|
panic("Failed to add validator")
|
||||||
|
}
|
||||||
case *UnbondTx:
|
case *UnbondTx:
|
||||||
case *TimeoutTx:
|
utx := tx.(*UnbondTx)
|
||||||
|
// Account must be bonded.
|
||||||
|
if accDet.Status != AccountDetailStatusBonded {
|
||||||
|
return ErrStateInvalidAccountState
|
||||||
|
}
|
||||||
|
// Good!
|
||||||
|
accDet.Status = AccountDetailStatusUnbonding
|
||||||
|
s.SetAccountDetail(accDet)
|
||||||
|
val, removed := s.BondedValidators.Remove(accDet.Id)
|
||||||
|
if !removed {
|
||||||
|
panic("Failed to remove validator")
|
||||||
|
}
|
||||||
|
val.UnbondHeight = s.Height
|
||||||
|
added := s.UnbondedValidators.Add(val)
|
||||||
|
if !added {
|
||||||
|
panic("Failed to add validator")
|
||||||
|
}
|
||||||
case *DupeoutTx:
|
case *DupeoutTx:
|
||||||
|
// XXX
|
||||||
}
|
}
|
||||||
panic("Implement ExecTx()")
|
panic("Implement ExecTx()")
|
||||||
return nil
|
return nil
|
||||||
@ -207,11 +236,17 @@ func (s *State) AppendBlock(b *Block) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If any unbonding periods are over,
|
||||||
|
// reward account with bonded coins.
|
||||||
|
|
||||||
|
// If any validators haven't signed in a while,
|
||||||
|
// unbond them, they have timed out.
|
||||||
|
|
||||||
// Increment validator AccumPowers
|
// Increment validator AccumPowers
|
||||||
s.Validators.IncrementAccum()
|
s.BondedValidators.IncrementAccum()
|
||||||
|
|
||||||
// State hashes should match
|
// State hashes should match
|
||||||
if !bytes.Equal(s.Validators.Hash(), b.ValidationStateHash) {
|
if !bytes.Equal(s.BondedValidators.Hash(), b.ValidationStateHash) {
|
||||||
return ErrStateInvalidValidationStateHash
|
return ErrStateInvalidValidationStateHash
|
||||||
}
|
}
|
||||||
if !bytes.Equal(s.AccountDetails.Hash(), b.AccountStateHash) {
|
if !bytes.Equal(s.AccountDetails.Hash(), b.AccountStateHash) {
|
||||||
|
@ -11,7 +11,9 @@ import (
|
|||||||
// TODO consider moving this to another common types package.
|
// TODO consider moving this to another common types package.
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
Account
|
Account
|
||||||
BondHeight uint32 // TODO: is this needed?
|
BondHeight uint32
|
||||||
|
UnbondHeight uint32
|
||||||
|
LastCommitHeight uint32
|
||||||
VotingPower uint64
|
VotingPower uint64
|
||||||
Accum int64
|
Accum int64
|
||||||
}
|
}
|
||||||
@ -21,6 +23,8 @@ func ReadValidator(r io.Reader, n *int64, err *error) *Validator {
|
|||||||
return &Validator{
|
return &Validator{
|
||||||
Account: ReadAccount(r, n, err),
|
Account: ReadAccount(r, n, err),
|
||||||
BondHeight: ReadUInt32(r, n, err),
|
BondHeight: ReadUInt32(r, n, err),
|
||||||
|
UnbondHeight: ReadUInt32(r, n, err),
|
||||||
|
LastCommitHeight: ReadUInt32(r, n, err),
|
||||||
VotingPower: ReadUInt64(r, n, err),
|
VotingPower: ReadUInt64(r, n, err),
|
||||||
Accum: ReadInt64(r, n, err),
|
Accum: ReadInt64(r, n, err),
|
||||||
}
|
}
|
||||||
@ -31,6 +35,8 @@ func (v *Validator) Copy() *Validator {
|
|||||||
return &Validator{
|
return &Validator{
|
||||||
Account: v.Account,
|
Account: v.Account,
|
||||||
BondHeight: v.BondHeight,
|
BondHeight: v.BondHeight,
|
||||||
|
UnbondHeight: v.UnbondHeight,
|
||||||
|
LastCommitHeight: v.LastCommitHeight,
|
||||||
VotingPower: v.VotingPower,
|
VotingPower: v.VotingPower,
|
||||||
Accum: v.Accum,
|
Accum: v.Accum,
|
||||||
}
|
}
|
||||||
@ -40,6 +46,8 @@ func (v *Validator) Copy() *Validator {
|
|||||||
func (v *Validator) WriteTo(w io.Writer) (n int64, err error) {
|
func (v *Validator) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
WriteBinary(w, v.Account, &n, &err)
|
WriteBinary(w, v.Account, &n, &err)
|
||||||
WriteUInt32(w, v.BondHeight, &n, &err)
|
WriteUInt32(w, v.BondHeight, &n, &err)
|
||||||
|
WriteUInt32(w, v.UnbondHeight, &n, &err)
|
||||||
|
WriteUInt32(w, v.LastCommitHeight, &n, &err)
|
||||||
WriteUInt64(w, v.VotingPower, &n, &err)
|
WriteUInt64(w, v.VotingPower, &n, &err)
|
||||||
WriteInt64(w, v.Accum, &n, &err)
|
WriteInt64(w, v.Accum, &n, &err)
|
||||||
return
|
return
|
||||||
|
@ -100,7 +100,7 @@ func (vset *ValidatorSet) Hash() []byte {
|
|||||||
return vset.validators.Hash()
|
return vset.validators.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vset *ValidatorSet) AddValidator(val *Validator) (added bool) {
|
func (vset *ValidatorSet) Add(val *Validator) (added bool) {
|
||||||
if val.Accum != 0 {
|
if val.Accum != 0 {
|
||||||
panic("AddValidator only accepts validators with zero accumpower")
|
panic("AddValidator only accepts validators with zero accumpower")
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func (vset *ValidatorSet) AddValidator(val *Validator) (added bool) {
|
|||||||
return !updated
|
return !updated
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vset *ValidatorSet) RemoveValidator(validatorId uint64) (removed bool) {
|
func (vset *ValidatorSet) Remove(validatorId uint64) (val *Validator, removed bool) {
|
||||||
_, removed = vset.validators.Remove(validatorId)
|
val, removed = vset.validators.Remove(validatorId)
|
||||||
return removed
|
return val.(*Validator), removed
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user