-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the storing of the validators uptime data over time (part of #3)
- Loading branch information
Showing
12 changed files
with
240 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking" | ||
) | ||
|
||
// SaveValidators allows the bulk saving of a list of validators | ||
func (db BigDipperDb) SaveValidators(validators []staking.Validator) error { | ||
var insertParams []interface{} | ||
|
||
queryInsert := "INSERT INTO validator (consensus_address, consensus_pubkey) VALUES " | ||
for i, result := range validators { | ||
p1 := i * 2 // starting position for insert params | ||
|
||
queryInsert += fmt.Sprintf("($%d,$%d),", p1+1, p1+2) | ||
|
||
key, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, result.ConsPubKey) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
insertParams = append(insertParams, result.ConsAddress().String(), key) | ||
} | ||
|
||
queryInsert = queryInsert[:len(queryInsert)-1] // remove trailing "," | ||
queryInsert += " ON CONFLICT DO NOTHING" | ||
_, err := db.Sql.Exec(queryInsert, insertParams...) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
CREATE TABLE validator | ||
( | ||
id SERIAL PRIMARY KEY, | ||
consensus_address CHARACTER VARYING(52) NOT NULL UNIQUE, /* Validator consensus address */ | ||
consensus_pubkey CHARACTER VARYING(83) NOT NULL UNIQUE | ||
); | ||
|
||
CREATE TABLE pre_commit | ||
( | ||
id SERIAL PRIMARY KEY, | ||
validator_address CHARACTER VARYING(52) NOT NULL REFERENCES validator (consensus_address), | ||
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
voting_power INTEGER NOT NULL, | ||
proposer_priority INTEGER NOT NULL | ||
); | ||
|
||
CREATE TABLE block | ||
( | ||
id SERIAL PRIMARY KEY, | ||
height INTEGER NOT NULL UNIQUE, | ||
hash CHARACTER VARYING(64) NOT NULL UNIQUE, | ||
num_txs INTEGER DEFAULT 0, | ||
total_gas INTEGER DEFAULT 0, | ||
proposer_address CHARACTER VARYING(52) NOT NULL REFERENCES validator (consensus_address), | ||
pre_commits INTEGER NOT NULL, | ||
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL | ||
); | ||
|
||
CREATE TABLE transaction | ||
( | ||
id SERIAL PRIMARY KEY, | ||
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
gas_wanted INTEGER DEFAULT 0, | ||
gas_used INTEGER DEFAULT 0, | ||
height INTEGER NOT NULL REFERENCES block (height), | ||
txhash CHARACTER VARYING(64) NOT NULL UNIQUE, | ||
messages JSONB NOT NULL DEFAULT '[]'::JSONB, | ||
fee JSONB NOT NULL DEFAULT '{}'::JSONB, | ||
signatures JSONB NOT NULL DEFAULT '[]'::JSONB, | ||
memo CHARACTER VARYING(256) | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE TABLE staking_pool | ||
( | ||
height BIGINT NOT NULL, | ||
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
bonded_tokens BIGINT NOT NULL, | ||
not_bonded_tokens BIGINT NOT NULL | ||
); | ||
|
||
CREATE TABLE validator_uptime | ||
( | ||
height BIGINT NOT NULL, | ||
validator_address CHARACTER VARYING(52) NOT NULL REFERENCES validator (consensus_address), | ||
signed_blocks_window BIGINT NOT NULL, | ||
missed_blocks_counter BIGINT NOT NULL | ||
); | ||
|
||
CREATE TABLE validator_info | ||
( | ||
consensus_address CHARACTER VARYING(52) NOT NULL references validator (consensus_address), | ||
operator_address TEXT NOT NULL | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package staking | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAddress(t *testing.T) { | ||
prefix := "desmos" | ||
|
||
cfg := sdk.GetConfig() | ||
cfg.SetBech32PrefixForAccount( | ||
prefix, | ||
prefix+sdk.PrefixPublic, | ||
) | ||
cfg.SetBech32PrefixForValidator( | ||
prefix+sdk.PrefixValidator+sdk.PrefixOperator, | ||
prefix+sdk.PrefixValidator+sdk.PrefixOperator+sdk.PrefixPublic, | ||
) | ||
cfg.SetBech32PrefixForConsensusNode( | ||
prefix+sdk.PrefixValidator+sdk.PrefixConsensus, | ||
prefix+sdk.PrefixValidator+sdk.PrefixConsensus+sdk.PrefixPublic, | ||
) | ||
|
||
consAddr, err := sdk.ConsAddressFromHex("0549E17DCCE2AA4BAB0640C70A692389FE081351") | ||
require.NoError(t, err) | ||
|
||
fmt.Printf(consAddr.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.