Skip to content

Commit

Permalink
Timescale
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 26, 2023
1 parent ffce081 commit 6d3a813
Show file tree
Hide file tree
Showing 36 changed files with 155 additions and 465 deletions.
2 changes: 1 addition & 1 deletion cmd/indexer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (bi *BlockchainIndexer) handleBlock(ctx context.Context, block *Block) erro
}

func (bi *BlockchainIndexer) parseAndSaveBlock(ctx context.Context, block *Block) error {
store := postgres.NewStore(bi.Partitions, bi.StorageDB.DB)
store := postgres.NewStore(bi.StorageDB.DB)
if err := bi.parseImplicitOperations(ctx, block, bi.currentProtocol, store); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.flextesa.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.6"
services:
db:
image: postgres:14
image: timescale/timescaledb:latest-pg15
shm_size: 1g
restart: always
environment:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.6"
services:
db:
image: postgres:14
image: timescale/timescaledb:latest-pg15
shm_size: 1g
user: postgres
restart: always
Expand Down
2 changes: 0 additions & 2 deletions internal/config/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/baking-bad/bcdhub/internal/models/ticket"
"github.com/baking-bad/bcdhub/internal/models/types"
"github.com/baking-bad/bcdhub/internal/noderpc"
"github.com/baking-bad/bcdhub/internal/postgres"
"github.com/baking-bad/bcdhub/internal/postgres/core"
"github.com/baking-bad/bcdhub/internal/services/mempool"
"github.com/pkg/errors"
Expand Down Expand Up @@ -48,7 +47,6 @@ type Context struct {
Domains domains.Repository
Scripts contract.ScriptRepository
SmartRollups smartrollup.Repository
Partitions *postgres.PartitionManager

Cache *cache.Cache
}
Expand Down
2 changes: 0 additions & 2 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/baking-bad/bcdhub/internal/bcd/tezerrors"
"github.com/baking-bad/bcdhub/internal/postgres"
"github.com/baking-bad/bcdhub/internal/postgres/account"
"github.com/baking-bad/bcdhub/internal/postgres/bigmapdiff"
"github.com/baking-bad/bcdhub/internal/postgres/contract"
Expand Down Expand Up @@ -103,7 +102,6 @@ func WithStorage(cfg StorageConfig, appName string, maxPageSize int64) ContextOp
ctx.TicketUpdates = ticket.NewStorage(conn)
ctx.Scripts = contractStorage
ctx.SmartRollups = smartrollup.NewStorage(conn)
ctx.Partitions = postgres.NewPartitionManager(conn)
}
}

Expand Down
7 changes: 1 addition & 6 deletions internal/models/account/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ func (a *Account) GetID() int64 {
return a.ID
}

// GetIndex -
func (a *Account) GetIndex() string {
func (Account) TableName() string {
return "accounts"
}

// IsEmpty -
func (a *Account) IsEmpty() bool {
return a.Address == "" || a.Type == types.AccountTypeUnknown
}

func (Account) PartitionBy() string {
return ""
}
11 changes: 3 additions & 8 deletions internal/models/bigmapaction/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@ type BigMapAction struct {
bun.BaseModel `bun:"big_map_actions"`

ID int64 `bun:"id,pk,notnull,autoincrement"`
Action types.BigMapAction `bun:",type:SMALLINT"`
Action types.BigMapAction `bun:"action,type:SMALLINT"`
SourcePtr *int64
DestinationPtr *int64
OperationID int64
Level int64
Address string
Timestamp time.Time
Timestamp time.Time `bun:"timestamp,pk,notnull"`
}

// GetID -
func (b *BigMapAction) GetID() int64 {
return b.ID
}

// GetIndex -
func (b *BigMapAction) GetIndex() string {
func (b *BigMapAction) TableName() string {
return "big_map_actions"
}

func (BigMapAction) PartitionBy() string {
return ""
}
7 changes: 1 addition & 6 deletions internal/models/bigmapdiff/bigmapstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func (b *BigMapState) GetID() int64 {
return b.ID
}

// GetIndex -
func (b *BigMapState) GetIndex() string {
func (BigMapState) TableName() string {
return "big_map_states"
}

Expand Down Expand Up @@ -62,7 +61,3 @@ func (b *BigMapState) ToDiff() BigMapDiff {

return bmd
}

func (BigMapState) PartitionBy() string {
return ""
}
15 changes: 5 additions & 10 deletions internal/models/bigmapdiff/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,22 @@ type BigMapDiff struct {

ID int64 `bun:"id,pk,notnull,autoincrement"`
Ptr int64 `bun:"ptr"`
Key types.Bytes `bun:",notnull,type:bytea"`
Key types.Bytes `bun:"key,notnull,type:bytea"`
KeyHash string
Value types.Bytes `bun:",type:bytea"`
Value types.Bytes `bun:"value,type:bytea"`
Level int64
Contract string
Timestamp time.Time `bun:",pk"`
ProtocolID int64 `bun:",type:SMALLINT"`
Timestamp time.Time `bun:"timestamp,pk,notnull"`
ProtocolID int64 `bun:"protocol_id,type:SMALLINT"`
OperationID int64
}

func (BigMapDiff) PartitionBy() string {
return "RANGE(timestamp)"
}

// GetID -
func (b *BigMapDiff) GetID() int64 {
return b.ID
}

// GetIndex -
func (b *BigMapDiff) GetIndex() string {
func (BigMapDiff) TableName() string {
return "big_map_diffs"
}

Expand Down
17 changes: 6 additions & 11 deletions internal/models/block/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
type Block struct {
bun.BaseModel `bun:"blocks"`

ID int64 `bun:"id,pk,notnull,autoincrement"`
Hash string
Timestamp time.Time
Level int64
ProtocolID int64 `bun:",type:SMALLINT"`
ID int64 `bun:"id,pk,notnull,autoincrement"`
Hash string `bun:"hash"`
Timestamp time.Time `bun:"timestamp,pk,notnull"`
Level int64 `bun:"level"`
ProtocolID int64 `bun:",type:SMALLINT"`

Protocol protocol.Protocol `bun:",rel:belongs-to"`
}
Expand All @@ -25,11 +25,6 @@ func (b *Block) GetID() int64 {
return b.ID
}

// GetIndex -
func (b *Block) GetIndex() string {
func (Block) TableName() string {
return "blocks"
}

func (Block) PartitionBy() string {
return ""
}
3 changes: 1 addition & 2 deletions internal/models/contract/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func (m *GlobalConstant) GetID() int64 {
return m.ID
}

// GetIndex -
func (m *GlobalConstant) GetIndex() string {
func (GlobalConstant) TableName() string {
return "global_constants"
}

Expand Down
13 changes: 4 additions & 9 deletions internal/models/contract/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
type Contract struct {
bun.BaseModel `bun:"contracts"`

ID int64 `bun:"id,pk,notnull,autoincrement"`
Level int64
Timestamp time.Time
ID int64 `bun:"id,pk,notnull,autoincrement"`
Level int64 `bun:"level"`
Timestamp time.Time `bun:"timestamp,pk,notnull"`

AccountID int64
Account account.Account `bun:"rel:belongs-to"`
Expand All @@ -41,8 +41,7 @@ func (c *Contract) GetID() int64 {
return c.ID
}

// GetIndex -
func (c *Contract) GetIndex() string {
func (Contract) TableName() string {
return "contracts"
}

Expand All @@ -54,10 +53,6 @@ func (c *Contract) LogFields() map[string]interface{} {
}
}

func (Contract) PartitionBy() string {
return ""
}

// CurrentScript -
func (c *Contract) CurrentScript() *Script {
switch {
Expand Down
7 changes: 1 addition & 6 deletions internal/models/contract/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ type Script struct {
Constants []GlobalConstant `bun:"m2m:script_constants,join:Script=GlobalConstant"`
}

func (Script) PartitionBy() string {
return ""
}

// GetID -
func (s *Script) GetID() int64 {
return s.ID
}

// GetIndex -
func (s *Script) GetIndex() string {
func (Script) TableName() string {
return "scripts"
}

Expand Down
7 changes: 1 addition & 6 deletions internal/models/contract/script_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ func (ScriptConstants) GetID() int64 {
return 0
}

// GetIndex -
func (ScriptConstants) GetIndex() string {
func (ScriptConstants) TableName() string {
return "script_constants"
}

// Save -
func (ScriptConstants) Save(ctx context.Context, tx bun.IDB) error {
return nil
}

func (ScriptConstants) PartitionBy() string {
return ""
}
16 changes: 6 additions & 10 deletions internal/models/migration/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ type Migration struct {
bun.BaseModel `bun:"migrations"`

ID int64 `bun:"id,pk,notnull,autoincrement"`
ProtocolID int64 `bun:",type:SMALLINT"`
ProtocolID int64 `bun:"protocol_id,type:SMALLINT"`
PrevProtocolID int64
Hash []byte
Timestamp time.Time
Timestamp time.Time `bun:"timestamp,pk,notnull"`
Level int64
Kind types.MigrationKind `bun:",type:SMALLINT"`
Kind types.MigrationKind `bun:"kind,type:SMALLINT"`
ContractID int64
Contract *contract.Contract `bun:",rel:belongs-to"`
Contract *contract.Contract `bun:"rel:belongs-to"`
}

// GetID -
func (m *Migration) GetID() int64 {
return m.ID
}

// GetIndex -
func (m *Migration) GetIndex() string {
// TableName -
func (Migration) TableName() string {
return "migrations"
}

Expand All @@ -41,7 +41,3 @@ func (m *Migration) LogFields() map[string]interface{} {
"kind": m.Kind,
}
}

func (Migration) PartitionBy() string {
return ""
}
62 changes: 12 additions & 50 deletions internal/models/mock/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d3a813

Please sign in to comment.