Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-kosu: implement validator removal and subcommand #190

Merged
merged 5 commits into from Jul 30, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

go-kosu: please

  • Loading branch information
gchaincl committed Jul 25, 2019
commit cb5b358de587a5169e89d29e55a06b910be725a7
@@ -9,10 +9,11 @@ import (
"go-kosu/store"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
)

func (app *App) checkWitnessTx(tx *types.TransactionWitness) error {
if app.store.LastEvent() >= tx.Block {
if app.store.LastEvent() > tx.Block {
return errors.New("transaction is older than the recorded state")
}

@@ -56,40 +57,28 @@ func (app *App) pushTransactionWitness(tx *types.TransactionWitness, nodeID []by
return err
}

power := app.powerFromTx(nodeID, tx)

app.log.Info("adding confirmations", "+power", power, "current", wTx.Confirmations)
wTx.Confirmations += uint64(power)
app.log.Info("adding confirmations", "+power", v.Power, "current", wTx.Confirmations)
wTx.Confirmations += uint64(v.Power)
app.store.SetWitnessTx(wTx)

app.log.Info("info", "threshold", app.confirmationThreshold, "conf", wTx.Confirmations)
if app.confirmationThreshold > wTx.Confirmations {
return nil
}
app.store.DeleteWitnessTx(tx.Id)

if tx.Amount.Zero() {
switch tx.Subject {
case types.TransactionWitness_POSTER:
app.store.DeletePoster(tx.Address)
case types.TransactionWitness_VALIDATOR:
v.Balance = tx.Amount
v.Power = 0
v.Applied = false
app.store.SetValidator(nodeID, v)
}
return nil
}
// app.store.DeleteWitnessTx(tx.Id)

switch tx.Subject {
case types.TransactionWitness_POSTER:
app.store.SetPoster(tx.Address, types.Poster{
Balance: tx.Amount,
})
if tx.Amount.Zero() {
app.store.DeletePoster(tx.Address)
} else {
app.store.SetPoster(tx.Address, types.Poster{Balance: tx.Amount})
}
case types.TransactionWitness_VALIDATOR:
app.store.SetValidator(nodeID, &types.Validator{
id := tmhash.SumTruncated(tx.PublicKey)
app.store.SetValidator(id, &types.Validator{
Balance: tx.Amount,
Power: power,
Power: scaleBalance(tx.Amount.BigInt()),
PublicKey: tx.PublicKey,
EthAccount: tx.Address,
Applied: false,
@@ -98,20 +87,6 @@ func (app *App) pushTransactionWitness(tx *types.TransactionWitness, nodeID []by
return nil
}

func (app *App) powerFromTx(nodeID []byte, tx *types.TransactionWitness) int64 {
if tx.Subject == types.TransactionWitness_VALIDATOR && tx.Amount.Zero() {
// if tx amount is 0 it means that it's a validator removal
// so we'll calculate the power out of the validator's amount
v := app.store.Validator(nodeID)
if v == nil {
return 0
}
return v.Power
}

return scaleBalance(tx.Amount.BigInt())
}

func scaleBalance(balance *big.Int) int64 {
if balance.Cmp(big.NewInt(0)) == 0 {
return int64(0)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.