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

fix: remove tombstone from validator_status (already exists in validator_singing_info) #443

Merged
merged 5 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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