-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from cybercongress/v2-dev
V2
- Loading branch information
Showing
52 changed files
with
1,829 additions
and
1,101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
CHAIN_PREFIX=bostrom | ||
POSTGRES_DB_FOLDER=$HOME/.cyberindex/postgres | ||
POSTGRES_DB_HOST=localhost | ||
POSTGRES_DB_PORT=5432 | ||
POSTGRES_DB_NAME=cyberindex | ||
POSTGRES_USER_NAME=cyber | ||
POSTGRES_DB_PASSWORD=1cyberindex1 | ||
POSTGRES_SSL_MODE=disable | ||
POSTGRES_FOLDER=$HOME/.cyberindex/postgres | ||
POSTGRES_HOST=localhost | ||
POSTGRES_PORT=5432 | ||
POSTGRES_USER=cyber | ||
POSTGRES_PASSWORD=1cyberindex1 | ||
POSTGRES_SSL=false | ||
HASURA_PORT=8090 | ||
HASURA_ADMIN_SECRET=1hasura1 | ||
JUNO_WORKERS=1 | ||
INDEX_WORKERS=1 | ||
RPC_URL=http://localhost:26657 | ||
GRPC_URL=http://localhost:9090 | ||
START_HEIGHT=1 |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
FROM ubuntu:20.04 | ||
FROM ubuntu:22.04 as builder | ||
|
||
ENV GO_VERSION '1.18.10' | ||
ENV GO_VERSION '1.22.2' | ||
ENV GO_ARCH 'linux-amd64' | ||
ENV GO_BIN_SHA '5e05400e4c79ef5394424c0eff5b9141cb782da25f64f79d54c98af0a37f8d49' | ||
ENV GO_BIN_SHA '5901c52b7a78002aeff14a21f93e0f064f74ce1360fce51c6ee68cd471216a17' | ||
|
||
WORKDIR /app | ||
|
||
|
@@ -19,10 +19,24 @@ ENV PATH="/usr/local/go/bin:$PATH" | |
|
||
COPY . . | ||
|
||
RUN make build | ||
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.5.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a | ||
|
||
RUN cp ./build/cyberindex /usr/local/bin/ | ||
RUN go mod download | ||
|
||
ENTRYPOINT ["./entrypoint.sh"] | ||
RUN LINK_STATICALLY=true BUILD_TAGS="muslc" make build | ||
|
||
CMD ["./start_script.sh"] | ||
FROM ubuntu:22.04 | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends build-essential ca-certificates | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/build/cyberindex /usr/bin/cyberindex | ||
|
||
#COPY --from=builder /root/go/pkg/mod/github.com/!cosm!wasm/[email protected]/internal/api/libwasmvm.x86_64.so /root/go/pkg/mod/github.com/!cosm!wasm/[email protected]/internal/api/libwasmvm.x86_64.so | ||
|
||
COPY ./entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
CMD ["cyberindex", "start"] |
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,190 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/forbole/callisto/v4/types" | ||
|
||
dbtypes "github.com/forbole/callisto/v4/database/types" | ||
) | ||
|
||
// GetLastBlock returns the last block stored inside the database based on the heights | ||
func (db *CyberDb) GetLastBlock() (*dbtypes.BlockRow, error) { | ||
stmt := `SELECT * FROM block ORDER BY height DESC LIMIT 1` | ||
|
||
var blocks []dbtypes.BlockRow | ||
if err := db.Sqlx.Select(&blocks, stmt); err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(blocks) == 0 { | ||
return nil, fmt.Errorf("cannot get block, no blocks saved") | ||
} | ||
|
||
return &blocks[0], nil | ||
} | ||
|
||
// GetLastBlockHeight returns the last block height and timestamp stored inside the database | ||
func (db *CyberDb) GetLastBlockHeightAndTimestamp() (dbtypes.BlockHeightAndTimestamp, error) { | ||
stmt := `SELECT height, timestamp FROM block ORDER BY height DESC LIMIT 1` | ||
|
||
var blockHeightAndTimestamp []dbtypes.BlockHeightAndTimestamp | ||
if err := db.Sqlx.Select(&blockHeightAndTimestamp, stmt); err != nil { | ||
return dbtypes.BlockHeightAndTimestamp{}, fmt.Errorf("cannot get last block height and timestamp from db: %s", err) | ||
} | ||
|
||
if len(blockHeightAndTimestamp) == 0 { | ||
return dbtypes.BlockHeightAndTimestamp{}, nil | ||
} | ||
|
||
return blockHeightAndTimestamp[0], nil | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------------- | ||
|
||
// getBlockHeightTime retrieves the block at the specific time | ||
func (db *CyberDb) getBlockHeightTime(pastTime time.Time) (dbtypes.BlockRow, error) { | ||
stmt := `SELECT * FROM block WHERE block.timestamp <= $1 ORDER BY block.timestamp DESC LIMIT 1;` | ||
|
||
var val []dbtypes.BlockRow | ||
if err := db.Sqlx.Select(&val, stmt, pastTime); err != nil { | ||
return dbtypes.BlockRow{}, err | ||
} | ||
|
||
if len(val) == 0 { | ||
return dbtypes.BlockRow{}, fmt.Errorf("cannot get block time, no blocks saved") | ||
} | ||
|
||
return val[0], nil | ||
} | ||
|
||
// GetBlockHeightTimeMinuteAgo return block height and time that a block proposals | ||
// about a minute ago from input date | ||
func (db *CyberDb) GetBlockHeightTimeMinuteAgo(now time.Time) (dbtypes.BlockRow, error) { | ||
pastTime := now.Add(time.Minute * -1) | ||
return db.getBlockHeightTime(pastTime) | ||
} | ||
|
||
// GetBlockHeightTimeHourAgo return block height and time that a block proposals | ||
// about a hour ago from input date | ||
func (db *CyberDb) GetBlockHeightTimeHourAgo(now time.Time) (dbtypes.BlockRow, error) { | ||
pastTime := now.Add(time.Hour * -1) | ||
return db.getBlockHeightTime(pastTime) | ||
} | ||
|
||
// GetBlockHeightTimeDayAgo return block height and time that a block proposals | ||
// about a day (24hour) ago from input date | ||
func (db *CyberDb) GetBlockHeightTimeDayAgo(now time.Time) (dbtypes.BlockRow, error) { | ||
pastTime := now.Add(time.Hour * -24) | ||
return db.getBlockHeightTime(pastTime) | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------------- | ||
|
||
// SaveAverageBlockTimePerMin save the average block time in average_block_time_per_minute table | ||
func (db *CyberDb) SaveAverageBlockTimePerMin(averageTime float64, height int64) error { | ||
stmt := ` | ||
INSERT INTO average_block_time_per_minute(average_time, height) | ||
VALUES ($1, $2) | ||
ON CONFLICT (one_row_id) DO UPDATE | ||
SET average_time = excluded.average_time, | ||
height = excluded.height | ||
WHERE average_block_time_per_minute.height <= excluded.height` | ||
|
||
_, err := db.Sqlx.Exec(stmt, averageTime, height) | ||
if err != nil { | ||
return fmt.Errorf("error while storing average block time per minute: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SaveAverageBlockTimePerHour save the average block time in average_block_time_per_hour table | ||
func (db *CyberDb) SaveAverageBlockTimePerHour(averageTime float64, height int64) error { | ||
stmt := ` | ||
INSERT INTO average_block_time_per_hour(average_time, height) | ||
VALUES ($1, $2) | ||
ON CONFLICT (one_row_id) DO UPDATE | ||
SET average_time = excluded.average_time, | ||
height = excluded.height | ||
WHERE average_block_time_per_hour.height <= excluded.height` | ||
|
||
_, err := db.Sqlx.Exec(stmt, averageTime, height) | ||
if err != nil { | ||
return fmt.Errorf("error while storing average block time per hour: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SaveAverageBlockTimePerDay save the average block time in average_block_time_per_day table | ||
func (db *CyberDb) SaveAverageBlockTimePerDay(averageTime float64, height int64) error { | ||
stmt := ` | ||
INSERT INTO average_block_time_per_day(average_time, height) | ||
VALUES ($1, $2) | ||
ON CONFLICT (one_row_id) DO UPDATE | ||
SET average_time = excluded.average_time, | ||
height = excluded.height | ||
WHERE average_block_time_per_day.height <= excluded.height` | ||
|
||
_, err := db.Sqlx.Exec(stmt, averageTime, height) | ||
if err != nil { | ||
return fmt.Errorf("error while storing average block time per day: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SaveAverageBlockTimeGenesis save the average block time in average_block_time_from_genesis table | ||
func (db *CyberDb) SaveAverageBlockTimeGenesis(averageTime float64, height int64) error { | ||
stmt := ` | ||
INSERT INTO average_block_time_from_genesis(average_time ,height) | ||
VALUES ($1, $2) | ||
ON CONFLICT (one_row_id) DO UPDATE | ||
SET average_time = excluded.average_time, | ||
height = excluded.height | ||
WHERE average_block_time_from_genesis.height <= excluded.height` | ||
|
||
_, err := db.Sqlx.Exec(stmt, averageTime, height) | ||
if err != nil { | ||
return fmt.Errorf("error while storing average block time since genesis: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------------- | ||
|
||
// SaveGenesis save the given genesis data | ||
func (db *CyberDb) SaveGenesis(genesis *types.Genesis) error { | ||
stmt := ` | ||
INSERT INTO genesis(time, chain_id, initial_height) | ||
VALUES ($1, $2, $3) ON CONFLICT (one_row_id) DO UPDATE | ||
SET time = excluded.time, | ||
initial_height = excluded.initial_height, | ||
chain_id = excluded.chain_id` | ||
|
||
_, err := db.Sqlx.Exec(stmt, genesis.Time, genesis.ChainID, genesis.InitialHeight) | ||
if err != nil { | ||
return fmt.Errorf("error while storing genesis: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetGenesis returns the genesis information stored inside the database | ||
func (db *CyberDb) GetGenesis() (*types.Genesis, error) { | ||
var rows []*dbtypes.GenesisRow | ||
err := db.Sqlx.Select(&rows, `SELECT * FROM genesis;`) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(rows) == 0 { | ||
return nil, fmt.Errorf("no rows inside the genesis table") | ||
} | ||
|
||
row := rows[0] | ||
return types.NewGenesis(row.ChainID, row.Time, row.InitialHeight), nil | ||
} |
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.