-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * Change submit * Next batch * remove duplicated line * Regenerate mocks * Fix relay's tests * Submit data cache add * add postgress + fix issues * change cache struct * Fix service tests * Cleanup * cleanup * next cleanup * Extend proposer duties warn. * Add registration cache flag
- Loading branch information
Showing
33 changed files
with
3,342 additions
and
1,365 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 |
---|---|---|
|
@@ -26,3 +26,5 @@ cmd/scratch/* | |
# profiling | ||
*.prof | ||
*.svg | ||
|
||
.data |
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,16 +1,15 @@ | ||
build: | ||
go build ./cmd/dreamboat | ||
|
||
build-cli: | ||
go build ./cmd/test-cli | ||
build-migration: | ||
go build -o migration-postgres ./cmd/migration/postgres | ||
|
||
# Mock testing | ||
mocks: clean-mocks | ||
# This roundabout call to 'go generate' allows us to: | ||
# - use modules | ||
# - prevent grep missing (totally fine) from causing nonzero exit | ||
# - mirror the pkg/ structure under internal/test/mock | ||
# - prevent grep missing (totally fine) from causing nonzero exit | ||
@find . -name '*.go' | xargs -I{} grep -l '//go:generate' {} | xargs -I{} -P 10 go generate {} | ||
|
||
clean-mocks: | ||
@find . -name 'mock_*.go' | xargs -I{} rm {} | ||
@find . -name 'mocks.go' | xargs -I{} rm {} |
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,92 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"embed" | ||
"errors" | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
migrate "github.com/golang-migrate/migrate/v4" | ||
_ "github.com/golang-migrate/migrate/v4/database/postgres" | ||
|
||
"github.com/golang-migrate/migrate/v4/source/iofs" | ||
) | ||
|
||
//go:embed migrations/* | ||
var content embed.FS | ||
|
||
type flags struct { | ||
databaseURL string | ||
migrationType string | ||
version uint | ||
verbose bool | ||
} | ||
|
||
var cf = flags{} | ||
|
||
func init() { | ||
flag.StringVar(&cf.databaseURL, "db", "", "Database URL") | ||
flag.StringVar(&cf.migrationType, "migrations", "", `Type of migration (available: "validators")`) | ||
flag.BoolVar(&cf.verbose, "verbose", true, "Verbosity of logs during run") | ||
flag.UintVar(&cf.version, "version", 0, "Version parameter sets db changes to specified revision (up or down)") | ||
flag.Parse() | ||
} | ||
|
||
func main() { | ||
log.SetOutput(os.Stdout) | ||
// Initialize configuration | ||
if cf.databaseURL == "" { | ||
log.Fatal(errors.New("database url is not set")) | ||
} | ||
|
||
if err := migrateDB(cf.databaseURL); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func migrateDB(dburl string) error { | ||
db, err := sql.Open("postgres", dburl) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer db.Close() | ||
|
||
if cf.migrationType != "validators" { // it will have more | ||
log.Fatal("migration type (`migrations`) is not properly set") | ||
} | ||
|
||
d, err := iofs.New(content, "migrations/"+cf.migrationType) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
m, err := migrate.NewWithSourceInstance("iofs", d, dburl) | ||
if err != nil { | ||
return err | ||
} | ||
defer m.Close() | ||
|
||
if cf.version > 0 { | ||
if cf.verbose { | ||
log.Println("Migrating to version: ", cf.version) | ||
} | ||
|
||
if err := m.Migrate(cf.version); err != nil { | ||
return err | ||
} | ||
} else { | ||
err = m.Up() | ||
} | ||
|
||
if err != nil { | ||
if err != migrate.ErrNoChange { | ||
return err | ||
} | ||
if cf.verbose { | ||
log.Println("No change") | ||
} | ||
} | ||
return nil | ||
} |
2 changes: 2 additions & 0 deletions
2
cmd/migration/postgres/migrations/validators/000001_initialize_tables.down.sql
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,2 @@ | ||
DROP TABLE IF EXISTS validator_registrations; | ||
|
9 changes: 9 additions & 0 deletions
9
cmd/migration/postgres/migrations/validators/000001_initialize_tables.up.sql
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,9 @@ | ||
CREATE TABLE IF NOT EXISTS validator_registrations ( | ||
pubkey VARCHAR(98) NOT NULL, | ||
fee_recipient VARCHAR(42) NOT NULL, | ||
gas_limit bigint NOT NULL, | ||
reg_time timestamp, | ||
signature VARCHAR NOT NULL, | ||
updated_at timestamp, | ||
UNIQUE(pubkey) | ||
); |
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.