Skip to content

Commit

Permalink
Partitioning. Operation hash to bytes. Remove mumbainet
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jun 30, 2023
1 parent 7e3f802 commit db85072
Show file tree
Hide file tree
Showing 32 changed files with 282 additions and 114 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand All @@ -25,7 +25,7 @@ jobs:
- name: install Go
uses: actions/setup-go@v2
with:
go-version: 1.19.x
go-version: 1.20.x
- name: checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand All @@ -25,7 +25,7 @@ jobs:
- name: install Go
uses: actions/setup-go@v2
with:
go-version: 1.19.x
go-version: 1.20.x
- name: checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion build/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---------------------------------------------------------------------
# The first stage container, for building the application
# ---------------------------------------------------------------------
FROM golang:1.19-alpine as builder
FROM golang:1.20-alpine as builder

ENV CGO_ENABLED=0
ENV GO111MODULE=on
Expand Down
2 changes: 1 addition & 1 deletion build/indexer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---------------------------------------------------------------------
# The first stage container, for building the application
# ---------------------------------------------------------------------
FROM golang:1.19-alpine as builder
FROM golang:1.20-alpine as builder

ENV CGO_ENABLED=0
ENV GO111MODULE=on
Expand Down
15 changes: 14 additions & 1 deletion cmd/api/handlers/entrypoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/baking-bad/bcdhub/internal/bcd"
"github.com/baking-bad/bcdhub/internal/bcd/ast"
"github.com/baking-bad/bcdhub/internal/bcd/encoding"
"github.com/baking-bad/bcdhub/internal/bcd/formatter"
"github.com/baking-bad/bcdhub/internal/bcd/types"
"github.com/baking-bad/bcdhub/internal/config"
Expand Down Expand Up @@ -151,6 +152,18 @@ func GetEntrypointSchema() gin.HandlerFunc {
return
}

var (
hash []byte
err error
)

if esReq.Hash != "" {
hash, err = encoding.DecodeBase58(esReq.Hash)
if handleError(c, ctx.Storage, err, http.StatusBadRequest) {
return
}
}

symLink, err := getCurrentSymLink(ctx.Blocks)
if handleError(c, ctx.Storage, err, 0) {
return
Expand Down Expand Up @@ -207,7 +220,7 @@ func GetEntrypointSchema() gin.HandlerFunc {
return
}

opg, err := ctx.Operations.GetByHashAndCounter(esReq.Hash, int64(*esReq.Counter))
opg, err := ctx.Operations.GetByHashAndCounter(hash, int64(*esReq.Counter))
if handleError(c, ctx.Storage, err, 0) {
return
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/api/handlers/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"net/http"

"github.com/baking-bad/bcdhub/internal/bcd/encoding"
"github.com/baking-bad/bcdhub/internal/config"
"github.com/baking-bad/bcdhub/internal/models/migration"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -61,10 +62,14 @@ func prepareMigrations(ctx *config.Context, data []migration.Migration) ([]Migra
if err != nil && !ctx.Storage.IsRecordNotFound(err) {
return nil, err
}
var hash string
if len(data[i].Hash) > 0 {
hash = encoding.MustEncodeOperationHash(data[i].Hash)
}
result[i] = Migration{
Level: data[i].Level,
Timestamp: data[i].Timestamp,
Hash: data[i].Hash,
Hash: hash,
Protocol: proto.Hash,
PrevProtocol: prevProto.Hash,
Kind: data[i].Kind.String(),
Expand Down
19 changes: 15 additions & 4 deletions cmd/api/handlers/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/baking-bad/bcdhub/internal/bcd"
"github.com/baking-bad/bcdhub/internal/bcd/ast"
"github.com/baking-bad/bcdhub/internal/bcd/consts"
"github.com/baking-bad/bcdhub/internal/bcd/encoding"
"github.com/baking-bad/bcdhub/internal/bcd/formatter"
formattererror "github.com/baking-bad/bcdhub/internal/bcd/formatter/error"
"github.com/baking-bad/bcdhub/internal/bcd/tezerrors"
Expand Down Expand Up @@ -113,9 +114,14 @@ func GetOperation() gin.HandlerFunc {
operations := make([]operation.Operation, 0)
var foundContext *config.Context

hash, err := encoding.DecodeBase58(req.Hash)
if handleError(c, any.Storage, err, http.StatusBadRequest) {
return
}

network := modelTypes.NewNetwork(queryReq.Network)
if ctx, ok := ctxs[network]; ok {
op, err := ctx.Operations.GetByHash(req.Hash)
op, err := ctx.Operations.GetByHash(hash)
if err != nil {
if !ctx.Storage.IsRecordNotFound(err) {
handleError(c, ctx.Storage, err, 0)
Expand All @@ -127,7 +133,7 @@ func GetOperation() gin.HandlerFunc {
}
} else {
for _, ctx := range ctxs {
op, err := ctx.Operations.GetByHash(req.Hash)
op, err := ctx.Operations.GetByHash(hash)
if err != nil {
if !ctx.Storage.IsRecordNotFound(err) {
handleError(c, ctx.Storage, err, 0)
Expand Down Expand Up @@ -383,19 +389,24 @@ func GetByHashAndCounter() gin.HandlerFunc {
return
}

hash, err := encoding.DecodeBase58(req.Hash)
if handleError(c, ctxs.Any().Storage, err, http.StatusBadRequest) {
return
}

var opg []operation.Operation
var foundContext *config.Context

ctx, err := ctxs.Get(modelTypes.NewNetwork(args.Network))
if err == nil {
opg, err = ctx.Operations.GetByHashAndCounter(req.Hash, req.Counter)
opg, err = ctx.Operations.GetByHashAndCounter(hash, req.Counter)
if handleError(c, ctx.Storage, err, 0) {
return
}
foundContext = ctx
} else {
for _, ctx := range ctxs {
opg, err = ctx.Operations.GetByHashAndCounter(req.Hash, req.Counter)
opg, err = ctx.Operations.GetByHashAndCounter(hash, req.Counter)
if handleError(c, ctx.Storage, err, 0) {
return
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/api/handlers/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/baking-bad/bcdhub/internal/bcd/ast"
"github.com/baking-bad/bcdhub/internal/bcd/encoding"
"github.com/baking-bad/bcdhub/internal/bcd/formatter"
"github.com/baking-bad/bcdhub/internal/bcd/tezerrors"
"github.com/baking-bad/bcdhub/internal/models/account"
Expand Down Expand Up @@ -67,7 +68,9 @@ type Operation struct {
// FromModel -
func (o *Operation) FromModel(operation operation.Operation) {
o.ID = operation.ID
o.Hash = operation.Hash
if len(operation.Hash) > 0 {
o.Hash = encoding.MustEncodeOperationHash(operation.Hash)
}
o.Internal = operation.Internal
o.Timestamp = operation.Timestamp.UTC()

Expand Down Expand Up @@ -97,9 +100,13 @@ func (o *Operation) FromModel(operation operation.Operation) {

// ToModel -
func (o *Operation) ToModel() operation.Operation {
var hash []byte
if o.Hash != "" {
hash = encoding.MustDecodeBase58(o.Hash)
}
return operation.Operation{
ID: o.ID,
Hash: o.Hash,
Hash: hash,
Internal: o.Internal,
Timestamp: o.Timestamp,
Level: o.Level,
Expand Down Expand Up @@ -636,8 +643,13 @@ func NewEvent(o operation.Operation) (*Event, error) {
return nil, nil
}

var hash string
if len(o.Hash) > 0 {
hash = encoding.MustEncodeOperationHash(o.Hash)
}

e := &Event{
Hash: o.Hash,
Hash: hash,
Status: o.Status.String(),
Timestamp: o.Timestamp,
Level: o.Level,
Expand Down
4 changes: 2 additions & 2 deletions cmd/api/handlers/run_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func RunOperation() gin.HandlerFunc {
}
parser := operations.NewGroup(parserParams)

store := postgres.NewStore(ctx.StorageDB.DB)
store := postgres.NewStore(ctx.StorageDB.DB, ctx.Partitions)
if err := parser.Parse(response, store); handleError(c, ctx.Storage, err, 0) {
return
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func parseBigMapDiffs(c *gin.Context, ctx *config.Context, response noderpc.RunC
},
}

store := postgres.NewStore(ctx.StorageDB.DB)
store := postgres.NewStore(ctx.StorageDB.DB, ctx.Partitions)
switch operation.Kind {
case types.OperationKindTransaction.String():
err = specific.StorageParser.ParseTransaction(nodeOperation, &model, store)
Expand Down
5 changes: 4 additions & 1 deletion cmd/api/handlers/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/baking-bad/bcdhub/internal/bcd/ast"
"github.com/baking-bad/bcdhub/internal/bcd/encoding"
"github.com/baking-bad/bcdhub/internal/config"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -72,7 +73,9 @@ func GetContractTicketUpdates() gin.HandlerFunc {
if handleError(c, ctx.Storage, err, 0) {
return
}
update.OperationHash = operation.Hash
if len(operation.Hash) > 0 {
update.OperationHash = encoding.MustEncodeOperationHash(operation.Hash)
}

response = append(response, update)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/indexer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (bi *BlockchainIndexer) handleBlock(ctx context.Context, block *Block) erro
}
}

store := postgres.NewStore(tx)
store := postgres.NewStore(tx, bi.Partitions)
if err := bi.implicitMigration(ctx, block, bi.currentProtocol, store); err != nil {
return err
}
Expand All @@ -263,7 +263,7 @@ func (bi *BlockchainIndexer) handleBlock(ctx context.Context, block *Block) erro
return err
}

if err := store.Save(); err != nil {
if err := store.Save(ctx); err != nil {
return err
}

Expand Down Expand Up @@ -543,7 +543,7 @@ func (bi *BlockchainIndexer) vestingMigration(ctx context.Context, head noderpc.
return err
}

store := postgres.NewStore(tx)
store := postgres.NewStore(tx, bi.Partitions)

for _, address := range addresses {
if !bcd.IsContract(address) {
Expand All @@ -560,7 +560,7 @@ func (bi *BlockchainIndexer) vestingMigration(ctx context.Context, head noderpc.
}
}

return store.Save()
return store.Save(ctx)
}

func (bi *BlockchainIndexer) reinit(ctx context.Context, cfg config.Config, indexerConfig config.IndexerConfig) error {
Expand Down
Loading

0 comments on commit db85072

Please sign in to comment.