Skip to content

Commit

Permalink
fix: remove tombstone from validator_status (already exists in `val…
Browse files Browse the repository at this point in the history
…idator_singing_info`) (#443)

## Description

Closes: #XXXX

Removing `tombstone status` from `validator_status` because:
- it makes the code cleaner as `tombstone status` is already stored in `validator_singing_info`
- it saves grpc calls for each validator at each block
- the front-end `graphQL` does not query it from `validator_status` table anyways

c.f. #411



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
huichiaotsou authored Aug 8, 2022
1 parent 413ffe6 commit ea65fc9
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 55 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased
### Changes
#### Staking Module
- ([\#443](https://github.com/forbole/bdjuno/pull/443)) Remove tombstone status from staking module(already stored in slashing module)

## Version v3.2.0
### Changes
#### Mint module
Expand Down
2 changes: 1 addition & 1 deletion cmd/parse/gov/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func proposalCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db)
mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db)
slashingModule := slashing.NewModule(sources.SlashingSource, parseCtx.EncodingConfig.Marshaler, db)
stakingModule := staking.NewModule(sources.StakingSource, slashingModule, parseCtx.EncodingConfig.Marshaler, db)
stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db)

// Build the gov module
govModule := gov.NewModule(sources.GovSource, nil, distrModule, mintModule, slashingModule, stakingModule, parseCtx.EncodingConfig.Marshaler, db)
Expand Down
2 changes: 1 addition & 1 deletion cmd/parse/staking/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func validatorsCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
db := database.Cast(parseCtx.Database)

// Build the staking module
stakingModule := staking.NewModule(sources.StakingSource, nil, parseCtx.EncodingConfig.Marshaler, db)
stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db)

// Get latest height
height, err := parseCtx.Node.LatestHeight()
Expand Down
1 change: 0 additions & 1 deletion database/schema/03-staking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ CREATE TABLE validator_status
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
status INT NOT NULL,
jailed BOOLEAN NOT NULL,
tombstoned BOOLEAN NOT NULL DEFAULT FALSE,
height BIGINT NOT NULL
);
CREATE INDEX validator_status_height_index ON validator_status (height);
Expand Down
9 changes: 4 additions & 5 deletions database/staking_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,17 @@ func (db *Db) SaveValidatorsStatuses(statuses []types.ValidatorStatus) error {
validatorStmt := `INSERT INTO validator (consensus_address, consensus_pubkey) VALUES`
var valParams []interface{}

statusStmt := `INSERT INTO validator_status (validator_address, status, jailed, tombstoned, height) VALUES `
statusStmt := `INSERT INTO validator_status (validator_address, status, jailed, height) VALUES `
var statusParams []interface{}

for i, status := range statuses {
vi := i * 2
validatorStmt += fmt.Sprintf("($%d, $%d),", vi+1, vi+2)
valParams = append(valParams, status.ConsensusAddress, status.ConsensusPubKey)

si := i * 5
statusStmt += fmt.Sprintf("($%d,$%d,$%d,$%d,$%d),", si+1, si+2, si+3, si+4, si+5)
statusParams = append(statusParams, status.ConsensusAddress, status.Status, status.Jailed, status.Tombstoned, status.Height)
si := i * 4
statusStmt += fmt.Sprintf("($%d,$%d,$%d,$%d),", si+1, si+2, si+3, si+4)
statusParams = append(statusParams, status.ConsensusAddress, status.Status, status.Jailed, status.Height)
}

validatorStmt = validatorStmt[:len(validatorStmt)-1]
Expand All @@ -432,7 +432,6 @@ func (db *Db) SaveValidatorsStatuses(statuses []types.ValidatorStatus) error {
ON CONFLICT (validator_address) DO UPDATE
SET status = excluded.status,
jailed = excluded.jailed,
tombstoned = excluded.tombstoned,
height = excluded.height
WHERE validator_status.height <= excluded.height`
_, err = db.Sql.Exec(statusStmt, statusParams...)
Expand Down
8 changes: 0 additions & 8 deletions database/staking_validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,13 @@ func (suite *DbTestSuite) TestSaveValidatorStatus() {
validator1.GetConsPubKey(),
1,
false,
false,
10,
),
types.NewValidatorStatus(
validator2.GetConsAddr(),
validator2.GetConsPubKey(),
2,
true,
true,
10,
),
})
Expand All @@ -656,14 +654,12 @@ func (suite *DbTestSuite) TestSaveValidatorStatus() {
dbtypes.NewValidatorStatusRow(
1,
false,
false,
validator1.GetConsAddr(),
10,
),
dbtypes.NewValidatorStatusRow(
2,
true,
true,
validator2.GetConsAddr(),
10,
),
Expand All @@ -680,15 +676,13 @@ func (suite *DbTestSuite) TestSaveValidatorStatus() {
validator1.GetConsPubKey(),
3,
true,
true,
9,
),
types.NewValidatorStatus(
validator2.GetConsAddr(),
validator2.GetConsPubKey(),
3,
true,
true,
11,
),
})
Expand All @@ -703,14 +697,12 @@ func (suite *DbTestSuite) TestSaveValidatorStatus() {
dbtypes.NewValidatorStatusRow(
1,
false,
false,
validator1.GetConsAddr(),
10,
),
dbtypes.NewValidatorStatusRow(
3,
true,
true,
validator2.GetConsAddr(),
11,
),
Expand Down
5 changes: 1 addition & 4 deletions database/types/staking_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,15 @@ func (v ValidatorVotingPowerRow) Equal(w ValidatorVotingPowerRow) bool {
type ValidatorStatusRow struct {
Status int `db:"status"`
Jailed bool `db:"jailed"`
Tombstoned bool `db:"tombstoned"`
ConsAddress string `db:"validator_address"`
Height int64 `db:"height"`
}

// NewValidatorStatusRow builds a new ValidatorStatusRow
func NewValidatorStatusRow(status int, jailed bool, tombstoned bool, consAddess string, height int64) ValidatorStatusRow {
func NewValidatorStatusRow(status int, jailed bool, consAddess string, height int64) ValidatorStatusRow {
return ValidatorStatusRow{
Status: status,
Jailed: jailed,
Tombstoned: tombstoned,
ConsAddress: consAddess,
Height: height,
}
Expand All @@ -259,7 +257,6 @@ func NewValidatorStatusRow(status int, jailed bool, tombstoned bool, consAddess
func (v ValidatorStatusRow) Equal(w ValidatorStatusRow) bool {
return v.Status == w.Status &&
v.Jailed == w.Jailed &&
v.Tombstoned == w.Tombstoned &&
v.ConsAddress == w.ConsAddress &&
v.Height == w.Height
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ select_permissions:
- validator_address
- status
- jailed
- tombstoned
- height
filter: {}
role: anonymous
2 changes: 1 addition & 1 deletion modules/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules {
feegrantModule := feegrant.NewModule(cdc, db)
mintModule := mint.NewModule(sources.MintSource, cdc, db)
slashingModule := slashing.NewModule(sources.SlashingSource, cdc, db)
stakingModule := staking.NewModule(sources.StakingSource, slashingModule, cdc, db)
stakingModule := staking.NewModule(sources.StakingSource, cdc, db)
govModule := gov.NewModule(sources.GovSource, authModule, distrModule, mintModule, slashingModule, stakingModule, cdc, db)

return []jmodules.Module{
Expand Down
11 changes: 0 additions & 11 deletions modules/staking/expected_modules.go

This file was deleted.

17 changes: 7 additions & 10 deletions modules/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ var (

// Module represents the x/staking module
type Module struct {
cdc codec.Codec
db *database.Db
source stakingsource.Source
slashingModule SlashingModule
cdc codec.Codec
db *database.Db
source stakingsource.Source
}

// NewModule returns a new Module instance
func NewModule(
source stakingsource.Source, slashingModule SlashingModule,
cdc codec.Codec, db *database.Db,
source stakingsource.Source, cdc codec.Codec, db *database.Db,
) *Module {
return &Module{
cdc: cdc,
db: db,
source: source,
slashingModule: slashingModule,
cdc: cdc,
db: db,
source: source,
}
}

Expand Down
9 changes: 0 additions & 9 deletions modules/staking/utils_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package staking

import (
"fmt"
"strings"

"google.golang.org/grpc/codes"

juno "github.com/forbole/juno/v3/types"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
Expand Down Expand Up @@ -176,17 +173,11 @@ func (m *Module) GetValidatorsStatuses(height int64, validators []stakingtypes.V
return nil, fmt.Errorf("error while getting validator consensus public key: %s", err)
}

valSigningInfo, err := m.slashingModule.GetSigningInfo(height, consAddr)
if err != nil && !strings.Contains(err.Error(), codes.NotFound.String()) {
return nil, fmt.Errorf("error while getting validator signing info: %s", err)
}

statuses[index] = types.NewValidatorStatus(
consAddr.String(),
consPubKey.String(),
int(validator.GetStatus()),
validator.IsJailed(),
valSigningInfo.Tombstoned,
height,
)
}
Expand Down
4 changes: 1 addition & 3 deletions types/staking_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,16 @@ type ValidatorStatus struct {
ConsensusPubKey string
Status int
Jailed bool
Tombstoned bool
Height int64
}

// NewValidatorStatus creates a new ValidatorVotingPower
func NewValidatorStatus(valConsAddr, pubKey string, status int, jailed bool, tombstoned bool, height int64) ValidatorStatus {
func NewValidatorStatus(valConsAddr, pubKey string, status int, jailed bool, height int64) ValidatorStatus {
return ValidatorStatus{
ConsensusAddress: valConsAddr,
ConsensusPubKey: pubKey,
Status: status,
Jailed: jailed,
Tombstoned: tombstoned,
Height: height,
}
}
Expand Down

0 comments on commit ea65fc9

Please sign in to comment.