From 7b59677012f85d417df1ce1b0b84b65241386fa2 Mon Sep 17 00:00:00 2001 From: VargaElod23 Date: Tue, 1 Aug 2023 13:03:15 +0300 Subject: [PATCH 1/3] removes author and pbftHash from response --- api/api_handler.go | 2 +- internal/storage/types.go | 2 +- models/responseTypes.go | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 models/responseTypes.go diff --git a/api/api_handler.go b/api/api_handler.go index ed2b9ca..bc891cd 100644 --- a/api/api_handler.go +++ b/api/api_handler.go @@ -79,7 +79,7 @@ func (a *ApiHandler) GetAddressDags(ctx echo.Context, address AddressFilter, par // GetAddressPbfts returns all PBFT blocks produced by the selected address func (a *ApiHandler) GetAddressPbfts(ctx echo.Context, address AddressFilter, params GetAddressPbftsParams) error { - return ctx.JSON(http.StatusOK, GetAddressDataPage[Pbft](a, address, ¶ms.Pagination)) + return ctx.JSON(http.StatusOK, GetAddressDataPage[PbftResponse](a, address, ¶ms.Pagination)) } // GetAddressTransactions returns all transactions from and to the selected address diff --git a/internal/storage/types.go b/internal/storage/types.go index 784e0b6..adf061f 100644 --- a/internal/storage/types.go +++ b/internal/storage/types.go @@ -14,7 +14,7 @@ import ( type TotalSupply = big.Int type Paginated interface { - models.Transaction | models.Dag | models.Pbft + models.Transaction | models.Dag | models.PbftResponse } type Yields interface { diff --git a/models/responseTypes.go b/models/responseTypes.go new file mode 100644 index 0000000..bce0d33 --- /dev/null +++ b/models/responseTypes.go @@ -0,0 +1,8 @@ +package models + +type PbftResponse struct { + Hash Hash `json:"hash"` + Number Counter `json:"number"` + Timestamp Timestamp `json:"timestamp"` + TransactionCount Counter `json:"transactionCount"` +} From 1d6eec160498816e7d338de34bfa16ad1f31952b Mon Sep 17 00:00:00 2001 From: VargaElod23 Date: Thu, 3 Aug 2023 13:43:34 +0300 Subject: [PATCH 2/3] adds migration to remove pbfthash --- api/api_handler.go | 2 +- api/openapi.yaml | 3 - api/server.gen.go | 86 +++++++++---------- internal/indexer/block_context.go | 2 - .../migrations/2_pbft_remove_pbfthash.go | 70 +++++++++++++++ internal/storage/pebble/migrations/manager.go | 1 + internal/storage/types.go | 2 +- models/models.gen.go | 1 - models/responseTypes.go | 8 -- 9 files changed, 116 insertions(+), 59 deletions(-) create mode 100644 internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go delete mode 100644 models/responseTypes.go diff --git a/api/api_handler.go b/api/api_handler.go index bc891cd..ed2b9ca 100644 --- a/api/api_handler.go +++ b/api/api_handler.go @@ -79,7 +79,7 @@ func (a *ApiHandler) GetAddressDags(ctx echo.Context, address AddressFilter, par // GetAddressPbfts returns all PBFT blocks produced by the selected address func (a *ApiHandler) GetAddressPbfts(ctx echo.Context, address AddressFilter, params GetAddressPbftsParams) error { - return ctx.JSON(http.StatusOK, GetAddressDataPage[PbftResponse](a, address, ¶ms.Pagination)) + return ctx.JSON(http.StatusOK, GetAddressDataPage[Pbft](a, address, ¶ms.Pagination)) } // GetAddressTransactions returns all transactions from and to the selected address diff --git a/api/openapi.yaml b/api/openapi.yaml index ff64201..7aa5472 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -550,7 +550,6 @@ components: required: - author - hash - - pbftHash - number - transactionCount - timestamp @@ -559,8 +558,6 @@ components: $ref: "#/components/schemas/Address" hash: $ref: "#/components/schemas/Hash" - pbftHash: - $ref: "#/components/schemas/Hash" number: $ref: "#/components/schemas/Counter" transactionCount: diff --git a/api/server.gen.go b/api/server.gen.go index 885f3c6..1d07aa6 100644 --- a/api/server.gen.go +++ b/api/server.gen.go @@ -395,49 +395,49 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xbbXPbNhL+KxjcfWhmaEu286pP58Ztk5s09STqdTI5TwciVxRqEGABULEmo/9+AxAk", - "wTeJlOWcr3P5JJPAYrHPsy9YMF9xKJJUcOBa4dlXnBJJEtAg7V8kiiQodW0emr8jUKGkqa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", + "/un0KaLLvYRXRCEubFvwmHmgw+p+tCdq1YuqSX1kOOYSVOysl99ieRj4ur4gfPwo3Pnd431uNvdQ7lFg", + "1cl/MKiYGNg0Ngs7bnEHxax3IlZ/qbhVG0kPAIstYPshA2vQHLFYjNDoUbBiA2Nlyn1BaF2ORwdBpFre", + "vtp/AbgtSt2eJpRewabsRHVjqJrXjoZP9V+3Hm/7Zdc4ehfqcriJpWeBY/ZQ1r7WC5h4pmiCZVJ+lnxo", + "l7dqSFJex9A+XMzdR80Hg+MhG7j1/3N1xAbucUveThYDTV+20Paan/KlQGQhMm1PV9Lojh177P7g/bNv", + "hBDvg4996LBpwlNiqcDjFRbdBupFgqECcl1YoM72Z0I5B4046C9C3rZm5TQfhJ8m+bpT/zuBJq05KD2E", + "ls7X7aR1BeshpCK7zKd0s/1fAAAA//9oaSfXjj4AAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/internal/indexer/block_context.go b/internal/indexer/block_context.go index e725cf4..47bd111 100644 --- a/internal/indexer/block_context.go +++ b/internal/indexer/block_context.go @@ -160,8 +160,6 @@ func (bc *blockContext) processDagsOld() (err error) { if err != nil { return } - bc.block.PbftHash = block_with_dags.BlockHash - tp := common.MakeThreadPool() for i, dag_hash := range block_with_dags.Schedule.DagBlocksOrder { tp.Go(common.MakeTaskWithResult(bc.processDag, dag_hash, &bc.dags[i], &err).Run) diff --git a/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go b/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go new file mode 100644 index 0000000..84ba30a --- /dev/null +++ b/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go @@ -0,0 +1,70 @@ +package migration + +import ( + "github.com/Taraxa-project/taraxa-indexer/internal/storage/pebble" + "github.com/Taraxa-project/taraxa-indexer/models" + "github.com/ethereum/go-ethereum/rlp" + log "github.com/sirupsen/logrus" +) + +type OldPbft struct { + Author models.Address `json:"author"` + Hash models.Hash `json:"hash"` + Number models.Counter `json:"number"` + PbftHash models.Hash `json:"pbftHash"` + Timestamp models.Timestamp `json:"timestamp"` + TransactionCount models.Counter `json:"transactionCount"` +} + +// RemoveSenderMigration is a migration that removes the Sender attribute from the Dag struct. +type RemovePbftHashMigration struct { + id string +} + +func (m *RemovePbftHashMigration) GetId() string { + return m.id +} + +// Apply is the implementation of the Migration interface for the RemoveSenderMigration. +func (m *RemovePbftHashMigration) Apply(s *pebble.Storage) error { + const PBFT_BATCH_THRESHOLD = 1000 + batch := s.NewBatch() + var last_key []byte + + for { + var o OldPbft + count := 0 + s.ForEachFromKey([]byte("d"), last_key, func(key, res []byte) (stop bool) { + err := rlp.DecodeBytes(res, &o) + if err != nil { + if err.Error() == "rlp: too few elements for migration.OldPbft" { + return false + } + log.WithFields(log.Fields{"migration": m.id, "error": err}).Fatal("Error decoding Pbft") + } + pbft := models.Pbft{ + Author: o.Author, + Hash: o.Hash, + Number: o.Number, + Timestamp: o.Timestamp, + TransactionCount: o.TransactionCount, + } + err = batch.AddToBatchFullKey(&pbft, key) + + if err != nil { + log.WithFields(log.Fields{"migration": m.id, "error": err}).Fatal("Error adding Pbft to batch") + } + + last_key = key + count++ + return count == PBFT_BATCH_THRESHOLD + }) + batch.CommitBatch() + batch = s.NewBatch() + if count < PBFT_BATCH_THRESHOLD { + break + } + } + + return nil +} diff --git a/internal/storage/pebble/migrations/manager.go b/internal/storage/pebble/migrations/manager.go index 79c949b..0848b7f 100644 --- a/internal/storage/pebble/migrations/manager.go +++ b/internal/storage/pebble/migrations/manager.go @@ -22,6 +22,7 @@ func NewManager(s *pebble.Storage) *Manager { storage: s, } m.RegisterMigration(&RemoveSenderMigration{id: "0_dag_removeSender"}) + m.RegisterMigration(&RemovePbftHashMigration{id: "2_pbft_removePbftHash"}) return &m } diff --git a/internal/storage/types.go b/internal/storage/types.go index adf061f..784e0b6 100644 --- a/internal/storage/types.go +++ b/internal/storage/types.go @@ -14,7 +14,7 @@ import ( type TotalSupply = big.Int type Paginated interface { - models.Transaction | models.Dag | models.PbftResponse + models.Transaction | models.Dag | models.Pbft } type Yields interface { diff --git a/models/models.gen.go b/models/models.gen.go index c830153..986b4e4 100644 --- a/models/models.gen.go +++ b/models/models.gen.go @@ -96,7 +96,6 @@ type Pbft struct { Author Address `json:"author"` Hash Hash `json:"hash"` Number Counter `json:"number"` - PbftHash Hash `json:"pbftHash"` Timestamp Timestamp `json:"timestamp"` TransactionCount Counter `json:"transactionCount"` } diff --git a/models/responseTypes.go b/models/responseTypes.go deleted file mode 100644 index bce0d33..0000000 --- a/models/responseTypes.go +++ /dev/null @@ -1,8 +0,0 @@ -package models - -type PbftResponse struct { - Hash Hash `json:"hash"` - Number Counter `json:"number"` - Timestamp Timestamp `json:"timestamp"` - TransactionCount Counter `json:"transactionCount"` -} From 25c092158eff7de6ae6096feab733aafc8d55c5d Mon Sep 17 00:00:00 2001 From: Dmytro Kostenko Date: Thu, 3 Aug 2023 13:17:35 +0200 Subject: [PATCH 3/3] fix: wrong prefix --- .../pebble/migrations/0_dag_removeSender.go | 2 +- .../migrations/2_pbft_remove_pbfthash.go | 2 +- internal/storage/pebble/storage.go | 43 +++++++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/internal/storage/pebble/migrations/0_dag_removeSender.go b/internal/storage/pebble/migrations/0_dag_removeSender.go index 0b3ba0d..a7529f3 100644 --- a/internal/storage/pebble/migrations/0_dag_removeSender.go +++ b/internal/storage/pebble/migrations/0_dag_removeSender.go @@ -33,7 +33,7 @@ func (m *RemoveSenderMigration) Apply(s *pebble.Storage) error { for { var o OldDag count := 0 - s.ForEachFromKey([]byte("d"), last_key, func(key, res []byte) (stop bool) { + s.ForEachFromKey([]byte(pebble.DagsPrefix), last_key, func(key, res []byte) (stop bool) { err := rlp.DecodeBytes(res, &o) if err != nil { if err.Error() == "rlp: too few elements for migration.OldDag" { diff --git a/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go b/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go index 84ba30a..9dd4fdc 100644 --- a/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go +++ b/internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go @@ -34,7 +34,7 @@ func (m *RemovePbftHashMigration) Apply(s *pebble.Storage) error { for { var o OldPbft count := 0 - s.ForEachFromKey([]byte("d"), last_key, func(key, res []byte) (stop bool) { + s.ForEachFromKey([]byte(pebble.PbftPrefix), last_key, func(key, res []byte) (stop bool) { err := rlp.DecodeBytes(res, &o) if err != nil { if err.Error() == "rlp: too few elements for migration.OldPbft" { diff --git a/internal/storage/pebble/storage.go b/internal/storage/pebble/storage.go index 670de13..8df63a1 100644 --- a/internal/storage/pebble/storage.go +++ b/internal/storage/pebble/storage.go @@ -17,6 +17,21 @@ import ( log "github.com/sirupsen/logrus" ) +const AccountPrefix = "b" +const LogsPrefix = "e" +const TransactionPrefix = "t" +const PbftPrefix = "p" +const DagsPrefix = "d" +const StatsPrefix = "s" +const FinalizationDataPrefix = "f" +const GenesisHashPrefix = "g" +const WeekStatsPrefix = "w" +const TotalSupplyPrefix = "ts" +const InternalTransactionsPrefix = "i" +const YieldPrefix = "y" +const ValidatorsYieldPrefix = "vy" +const MultipliedYieldPrefix = "my" + type Storage struct { db *pebble.DB path string @@ -81,33 +96,33 @@ func (s *Storage) get(key []byte) ([]byte, io.Closer, error) { func getPrefix(o interface{}) (ret string) { switch tt := o.(type) { case *[]storage.Account, []storage.Account: - ret = "b" + ret = AccountPrefix case *models.TransactionLogsResponse, models.TransactionLogsResponse: - ret = "e" + ret = LogsPrefix case *models.Transaction, models.Transaction: - ret = "t" + ret = TransactionPrefix case *models.Pbft, models.Pbft: - ret = "p" + ret = PbftPrefix case *models.Dag, models.Dag: - ret = "d" + ret = DagsPrefix case *storage.AddressStats, storage.AddressStats: - ret = "s" + ret = StatsPrefix case *storage.FinalizationData, storage.FinalizationData: - ret = "f" + ret = FinalizationDataPrefix case *storage.GenesisHash, storage.GenesisHash: - ret = "g" + ret = GenesisHashPrefix case *storage.WeekStats, storage.WeekStats: - ret = "w" + ret = WeekStatsPrefix case *storage.TotalSupply, storage.TotalSupply: - ret = "ts" + ret = TotalSupplyPrefix case *models.InternalTransactionsResponse, models.InternalTransactionsResponse: - ret = "i" + ret = InternalTransactionsPrefix case *storage.Yield, storage.Yield: - ret = "y" + ret = YieldPrefix case *storage.ValidatorsYield, storage.ValidatorsYield: - ret = "vy" + ret = ValidatorsYieldPrefix case *storage.MultipliedYield, storage.MultipliedYield: - ret = "my" + ret = MultipliedYieldPrefix // hack if we aren't passing original type directly to this function, but passing interface{} from other function case *interface{}: ret = getPrefix(*o.(*interface{}))