Skip to content

Commit

Permalink
feat: sqlite aggregator (#189)
Browse files Browse the repository at this point in the history
* feat: sqlite aggregator
  • Loading branch information
ToniRamirezM authored Nov 22, 2024
1 parent d2cf7cc commit 46a6789
Show file tree
Hide file tree
Showing 33 changed files with 1,080 additions and 1,396 deletions.
138 changes: 55 additions & 83 deletions aggregator/aggregator.go

Large diffs are not rendered by default.

367 changes: 184 additions & 183 deletions aggregator/aggregator_test.go

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions aggregator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math/big"

"github.com/0xPolygon/cdk/aggregator/db"
"github.com/0xPolygon/cdk/config/types"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/zkevm-ethtx-manager/ethtxmanager"
Expand Down Expand Up @@ -62,14 +61,6 @@ type Config struct {
// ProofStatePollingInterval is the interval time to polling the prover about the generation state of a proof
ProofStatePollingInterval types.Duration `mapstructure:"ProofStatePollingInterval"`

// TxProfitabilityCheckerType type for checking is it profitable for aggregator to validate batch
// possible values: base/acceptall
TxProfitabilityCheckerType TxProfitabilityCheckerType `mapstructure:"TxProfitabilityCheckerType"`

// TxProfitabilityMinReward min reward for base tx profitability checker when aggregator will validate batch
// this parameter is used for the base tx profitability checker
TxProfitabilityMinReward TokenAmountWithDecimals `mapstructure:"TxProfitabilityMinReward"`

// IntervalAfterWhichBatchConsolidateAnyway is the interval duration for the main sequencer to check
// if there are no transactions. If there are no transactions in this interval, the sequencer will
// consolidate the batch anyway.
Expand Down Expand Up @@ -117,8 +108,8 @@ type Config struct {
// UseFullWitness is a flag to enable the use of full witness in the aggregator
UseFullWitness bool `mapstructure:"UseFullWitness"`

// DB is the database configuration
DB db.Config `mapstructure:"DB"`
// DBPath is the path to the database
DBPath string `mapstructure:"DBPath"`

// EthTxManager is the config for the ethtxmanager
EthTxManager ethtxmanager.Config `mapstructure:"EthTxManager"`
Expand Down
25 changes: 0 additions & 25 deletions aggregator/db/config.go

This file was deleted.

31 changes: 0 additions & 31 deletions aggregator/db/db.go

This file was deleted.

35 changes: 35 additions & 0 deletions aggregator/db/dbstorage/dbstorage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dbstorage

import (
"context"
"database/sql"

"github.com/0xPolygon/cdk/db"
)

// DBStorage implements the Storage interface
type DBStorage struct {
DB *sql.DB
}

// NewDBStorage creates a new DBStorage instance
func NewDBStorage(dbPath string) (*DBStorage, error) {
db, err := db.NewSQLiteDB(dbPath)
if err != nil {
return nil, err
}

return &DBStorage{DB: db}, nil
}

func (d *DBStorage) BeginTx(ctx context.Context, options *sql.TxOptions) (db.Txer, error) {
return db.NewTx(ctx, d.DB)
}

func (d *DBStorage) getExecQuerier(dbTx db.Txer) db.Querier {
if dbTx == nil {
return d.DB
}

return dbTx
}
Loading

0 comments on commit 46a6789

Please sign in to comment.