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

Release: #33

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f6c03a
feat: add SP module and related event handlers & stop serving feature…
krish-nr Apr 27, 2023
bbfa421
fix: update to cosmos-sdk v0.47.2 (#31)
yutianwu May 10, 2023
31b5b9a
chore: upgrade gf sdk (#34)
May 15, 2023
bfce6bc
chore: remove grpc connection (#35)
May 16, 2023
1d98a95
feat: block syncer add dual db support config (#32)
krish-nr May 25, 2023
061556e
feat:add group extra field (#38)
constwz May 31, 2023
52daa6b
feat:add database interface (#37)
constwz May 31, 2023
30bdfe1
fix: add group item without any accounts (#39)
krish-nr Jun 8, 2023
dd16db4
chore: code clean (#40)
Jun 12, 2023
87b969f
fix:bucket visibility (#43)
constwz Jul 11, 2023
62b307a
feat: add virtual groups module for sp exit feature (#41)
krish-nr Jul 28, 2023
496b8c1
feat:group member expiration time (#53)
constwz Aug 16, 2023
97a4e23
feat:update mod (#54)
constwz Aug 17, 2023
4142709
fix:group unique index (#55)
constwz Sep 6, 2023
3e9021c
fix:payment Refundable status update (#56)
constwz Oct 17, 2023
7cd108f
feat: add update at index to object table (#57)
annielz Oct 23, 2023
82070b5
feat:bucket size (#58)
constwz Oct 27, 2023
ed4855c
feat: add tags support for bucket/object/group (#60)
ruojunm Dec 7, 2023
bb1d535
fix: update greenfield and greenfield-cosmos-sdk to latest version (#61)
ruojunm Dec 7, 2023
5505a27
fix: update event module (#62)
BarryTong65 Dec 12, 2023
8b5ee76
add fields to Object (#63)
alexgao001 Feb 21, 2024
3c67c32
feat: check bucket extra is limited (#65)
BarryTong65 Mar 26, 2024
0039530
feat: db statistics (#66)
constwz Apr 22, 2024
028f2cc
perf-rpcclient (#67)
constwz Jun 4, 2024
f7b840c
feat: update permission table index (#69)
annielz Dec 18, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- ([\#75](https://github.com/forbole/juno/pull/75)) Allow modules to handle MsgExec inner messages
- ([\#76](https://github.com/forbole/juno/pull/76)) Return 0 as height for `GetLastBlockHeight()` method if there are no blocks saved in database
- ([\#79](https://github.com/forbole/juno/pull/79)) Use `sqlx` instead of `sql` while dealing with a PostgreSQL database
- ([\#83](https://github.com/forbole/juno/pull/83)) Bump `github.com/tendermint/tendermint` to `v0.34.22`
- ([\#83](https://github.com/forbole/juno/pull/83)) Bump `github.com/cometbft/cometbft` to `v0.34.22`
- ([\#84](https://github.com/forbole/juno/pull/84)) Replace database configuration params with URI
- ([\#86](https://github.com/forbole/juno/pull/86)) Revert concurrent handling of transactions and messages

Expand Down
2 changes: 1 addition & 1 deletion cmd/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"os"
"path"

"github.com/cometbft/cometbft/libs/cli"
initcmd "github.com/forbole/juno/v4/cmd/init"
migratecmd "github.com/forbole/juno/v4/cmd/migrate"
parsecmd "github.com/forbole/juno/v4/cmd/parse"
startcmd "github.com/forbole/juno/v4/cmd/start"
"github.com/forbole/juno/v4/types"
"github.com/forbole/juno/v4/types/config"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
)

var (
Expand Down
1 change: 0 additions & 1 deletion cmd/migrate/toml/toml_test.go

This file was deleted.

24 changes: 0 additions & 24 deletions cmd/migrate/toml/types.go

This file was deleted.

3 changes: 1 addition & 2 deletions cmd/parse/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

tomlconfig "github.com/forbole/juno/v4/cmd/migrate/toml"
nodeconfig "github.com/forbole/juno/v4/node/config"
"github.com/forbole/juno/v4/node/remote"
"github.com/forbole/juno/v4/types/config"
Expand All @@ -21,7 +20,7 @@ func ReadConfigPreRunE(cfg *Config) types.CobraCmdFunc {
}
}

func NewParseConfigFromToml(tomlConfig *tomlconfig.TomlConfig) config.Config {
func NewParseConfigFromToml(tomlConfig *config.TomlConfig) config.Config {
config := config.Config{}
config.Chain = tomlConfig.Chain
config.Parser = tomlConfig.Parser
Expand Down
5 changes: 2 additions & 3 deletions cmd/parse/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"github.com/bnb-chain/greenfield/app"

tomlconfig "github.com/forbole/juno/v4/cmd/migrate/toml"
"github.com/forbole/juno/v4/database"
"github.com/forbole/juno/v4/database/builder"
"github.com/forbole/juno/v4/modules/registrar"
Expand All @@ -18,7 +17,7 @@ type Config struct {
setupCfg SdkConfigSetup
buildDb database.Builder
fileType string
tomlConfig *tomlconfig.TomlConfig
tomlConfig *config.TomlConfig
}

// NewConfig allows to build a new Config instance
Expand Down Expand Up @@ -53,7 +52,7 @@ func (cfg *Config) WithConfigParser(p config.Parser) *Config {
}

// WithTomlConfig sets the tomlConfig
func (cfg *Config) WithTomlConfig(tomlConfig *tomlconfig.TomlConfig) *Config {
func (cfg *Config) WithTomlConfig(tomlConfig *config.TomlConfig) *Config {
cfg.tomlConfig = tomlConfig
return cfg
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/start/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func Parsing(ctx *parser.Context) error {
// off of the export queue.
for i, w := range workers {
log.Debugw("starting worker...", "number", i+1)
go w.Start()
go w.Start(context.Background())
}

// Listen for and trap any OS signal to gracefully shutdown and exit
Expand Down
45 changes: 45 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package common
import (
"bytes"
"database/sql/driver"
"encoding/csv"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"math/rand"
"reflect"
"strconv"
"strings"

"golang.org/x/crypto/sha3"
Expand Down Expand Up @@ -462,3 +464,46 @@ func (i Big) Value() (driver.Value, error) {
func (i *Big) Raw() *big.Int {
return (*big.Int)(i)
}

type Uint32Array []uint32

func (a *Uint32Array) Scan(value interface{}) error {
if value == nil {
*a = nil
return nil
}
s, ok := value.(string)
if !ok {
return fmt.Errorf("failed to scan Uint32Array value: %v", value)
}
r := csv.NewReader(strings.NewReader(s))
records, err := r.ReadAll()
if err != nil {
return fmt.Errorf("failed to scan Uint32Array value: %v", err)
}
if len(records) != 1 {
return fmt.Errorf("failed to scan Uint32Array value: invalid format")
}
fields := records[0]
result := make([]uint32, len(fields))
for i, field := range fields {
value, err := strconv.ParseUint(field, 10, 32)
if err != nil {
return fmt.Errorf("failed to scan Uint32Array value: %v", err)
}
result[i] = uint32(value)
}
*a = result
return nil
}

func (a Uint32Array) Value() (driver.Value, error) {
if len(a) == 0 {
return nil, nil
}
values := make([]string, len(a))
for i, value := range a {
values[i] = strconv.FormatUint(uint64(value), 10)
}
return strings.Join(values, ","), nil
}
123 changes: 83 additions & 40 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type Database interface {
// PrepareTables create tables
PrepareTables(ctx context.Context, tables []schema.Tabler) error

// RecreateTables recreate tables when given table exists
RecreateTables(ctx context.Context, tables []schema.Tabler) error
// AutoMigrate Automatically migrate your schema, to keep your schema up to date.
AutoMigrate(ctx context.Context, tables []schema.Tabler) error

// HasBlock tells whether the database has already stored the block having the given height.
// An error is returned if the operation fails.
Expand All @@ -52,14 +52,6 @@ type Database interface {
// An error is returned if the operation fails.
SaveTx(ctx context.Context, blockTimestamp uint64, index int, tx *types.Tx) error

// HasValidator returns true if a given validator by consensus address exists.
// An error is returned if the operation fails.
HasValidator(ctx context.Context, address common.Address) (bool, error)

// SaveValidators stores a list of validators if they do not already exist.
// An error is returned if the operation fails.
SaveValidators(ctx context.Context, validators []*models.Validator) error

// SaveCommitSignatures stores a slice of validator commit signatures.
// An error is returned if the operation fails.
SaveCommitSignatures(ctx context.Context, signatures []*types.CommitSig) error
Expand Down Expand Up @@ -116,12 +108,34 @@ type Database interface {
// An error is returned if the operation fails.
DeleteGroup(ctx context.Context, group *models.Group) error

// CreateStorageProvider will be called to save each sp contained inside an event.
// An error is returned if the operation fails.
CreateStorageProvider(ctx context.Context, storageProvider *models.StorageProvider) error

// UpdateStorageProvider will be called to update each sp
// An error is returned if the operation fails.
UpdateStorageProvider(ctx context.Context, storageProvider *models.StorageProvider) error

// MultiSaveStatement will be called to save each statement contained inside a policy.
// An error is returned if the operation fails.
MultiSaveStatement(ctx context.Context, statements []*models.Statements) error

RemoveStatements(ctx context.Context, policyID common.Hash) error

SaveGVG(ctx context.Context, gvg *models.GlobalVirtualGroup) error

UpdateGVG(ctx context.Context, gvg *models.GlobalVirtualGroup) error

SaveLVG(ctx context.Context, lvg *models.LocalVirtualGroup) error

UpdateLVG(ctx context.Context, lvg *models.LocalVirtualGroup) error

SaveVGF(ctx context.Context, vgf *models.GlobalVirtualGroupFamily) error

UpdateVGF(ctx context.Context, vgf *models.GlobalVirtualGroupFamily) error

SaveDBStatistics(ctx context.Context, ds *models.DataStat) error

// Begin begins a transaction with any transaction options opts
Begin(ctx context.Context) *Impl

Expand Down Expand Up @@ -201,25 +215,19 @@ func (db *Impl) PrepareTables(ctx context.Context, tables []schema.Tabler) error
}

if err := q.Table(t.TableName()).AutoMigrate(t); err != nil {
log.Errorw("create table failed", "table", t.TableName(), "err", err)
log.Errorw("migrate table failed", "table", t.TableName(), "err", err)
return err
}
}

return nil
}

func (db *Impl) RecreateTables(ctx context.Context, tables []schema.Tabler) error {
func (db *Impl) AutoMigrate(ctx context.Context, tables []schema.Tabler) error {
m := db.Db.Migrator()
for _, t := range tables {
if m.HasTable(t.TableName()) {
if err := m.DropTable(t.TableName()); err != nil {
log.Errorw("delete table failed", "table", t.TableName(), "err", err)
return err
}
}
if err := m.CreateTable(t); err != nil {
log.Errorw("create table failed", "table", t.TableName(), "err", err)
if err := m.AutoMigrate(t); err != nil {
log.Errorw("migrate table failed", "table", t.TableName(), "err", err)
return err
}
}
Expand Down Expand Up @@ -332,26 +340,6 @@ func (db *Impl) SaveTx(ctx context.Context, blockTimestamp uint64, index int, tx
return err
}

// HasValidator implements database.Database
func (db *Impl) HasValidator(ctx context.Context, addr common.Address) (bool, error) {
var res bool
stmt := `SELECT EXISTS(SELECT 1 FROM validators WHERE consensus_address = ?);`
err := db.Db.Raw(stmt, addr).WithContext(ctx).Take(&res).Error
return res, err
}

// SaveValidators implements database.Database
func (db *Impl) SaveValidators(ctx context.Context, validators []*models.Validator) error {
if len(validators) == 0 {
return nil
}

err := db.Db.Table((&models.Validator{}).TableName()).WithContext(ctx).
Clauses(clause.OnConflict{DoNothing: true}).Save(validators).Error

return err
}

// SaveCommitSignatures implements database.Database
func (db *Impl) SaveCommitSignatures(ctx context.Context, signatures []*types.CommitSig) error {
if len(signatures) == 0 {
Expand Down Expand Up @@ -472,6 +460,18 @@ func (db *Impl) DeleteGroup(ctx context.Context, group *models.Group) error {
return db.Db.WithContext(ctx).Table((&models.Group{}).TableName()).Where("group_id = ?", group.GroupID).Updates(group).Error
}

func (db *Impl) CreateStorageProvider(ctx context.Context, storageProvider *models.StorageProvider) error {
err := db.Db.WithContext(ctx).Table((&models.StorageProvider{}).TableName()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "sp_id"}},
UpdateAll: true,
}).Create(storageProvider).Error
return err
}

func (db *Impl) UpdateStorageProvider(ctx context.Context, storageProvider *models.StorageProvider) error {
return db.Db.WithContext(ctx).Table((&models.StorageProvider{}).TableName()).Where("sp_id = ? ", storageProvider.SpId).Updates(storageProvider).Error
}

func (db *Impl) MultiSaveStatement(ctx context.Context, statements []*models.Statements) error {
return db.Db.WithContext(ctx).Table((&models.Statements{}).TableName()).Create(statements).Error
}
Expand All @@ -480,6 +480,49 @@ func (db *Impl) RemoveStatements(ctx context.Context, policyID common.Hash) erro
return db.Db.WithContext(ctx).Table((&models.Statements{}).TableName()).Where("policy_id = ?", policyID).Update("removed", true).Error
}

func (db *Impl) SaveGVG(ctx context.Context, gvg *models.GlobalVirtualGroup) error {
err := db.Db.WithContext(ctx).Table((&models.GlobalVirtualGroup{}).TableName()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "global_virtual_group_id"}},
UpdateAll: true,
}).Create(gvg).Error
return err
}

func (db *Impl) UpdateGVG(ctx context.Context, gvg *models.GlobalVirtualGroup) error {
err := db.Db.WithContext(ctx).Table((&models.GlobalVirtualGroup{}).TableName()).Where("global_virtual_group_id = ?", gvg.GlobalVirtualGroupId).Updates(gvg).Error
return err
}

func (db *Impl) SaveLVG(ctx context.Context, lvg *models.LocalVirtualGroup) error {
err := db.Db.WithContext(ctx).Table((&models.LocalVirtualGroup{}).TableName()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "local_virtual_group_id"}},
UpdateAll: true,
}).Create(lvg).Error
return err
}

func (db *Impl) UpdateLVG(ctx context.Context, lvg *models.LocalVirtualGroup) error {
err := db.Db.WithContext(ctx).Table((&models.LocalVirtualGroup{}).TableName()).Where("local_virtual_group_id = ? and bucket_id = ?", lvg.LocalVirtualGroupId, lvg.BucketID).Updates(lvg).Error
return err
}

func (db *Impl) SaveVGF(ctx context.Context, vgf *models.GlobalVirtualGroupFamily) error {
err := db.Db.WithContext(ctx).Table((&models.GlobalVirtualGroupFamily{}).TableName()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "global_virtual_group_family_id"}},
UpdateAll: true,
}).Create(vgf).Error
return err
}

func (db *Impl) UpdateVGF(ctx context.Context, vgf *models.GlobalVirtualGroupFamily) error {
err := db.Db.WithContext(ctx).Table((&models.GlobalVirtualGroupFamily{}).TableName()).Where("global_virtual_group_family_id = ?", vgf.GlobalVirtualGroupFamilyId).Updates(vgf).Error
return err
}

func (db *Impl) SaveDBStatistics(ctx context.Context, ds *models.DataStat) error {
return nil
}

func (db *Impl) Begin(ctx context.Context) *Impl {
return &Impl{
Db: db.Db.WithContext(ctx).Begin(),
Expand Down
13 changes: 10 additions & 3 deletions database/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"strings"
"testing"

"github.com/cosmos/cosmos-sdk/simapp"
"github.com/bnb-chain/greenfield/app/params"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/stretchr/testify/suite"

"github.com/forbole/juno/v4/database"
Expand All @@ -28,7 +29,13 @@ type DbTestSuite struct {

func (suite *DbTestSuite) SetupTest() {
// Create the codec
codec := simapp.MakeTestEncodingConfig()
codec := testutil.MakeTestEncodingConfig()
paramsCodec := params.EncodingConfig{
InterfaceRegistry: codec.InterfaceRegistry,
Marshaler: codec.Codec,
TxConfig: codec.TxConfig,
Amino: codec.Amino,
}

// Build the database
dbCfg := databaseconfig.NewDatabaseConfig(
Expand All @@ -38,7 +45,7 @@ func (suite *DbTestSuite) SetupTest() {
100000,
100,
)
db, err := postgres.Builder(database.NewContext(dbCfg, &codec))
db, err := postgres.Builder(database.NewContext(dbCfg, &paramsCodec))
suite.Require().NoError(err)

bigDipperDb, ok := (db).(*postgres.Database)
Expand Down
Loading