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

removes author and pbftHash from response #117

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ components:
required:
- author
- hash
- pbftHash
- number
- transactionCount
- timestamp
Expand All @@ -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:
Expand Down
86 changes: 43 additions & 43 deletions api/server.gen.go

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

2 changes: 0 additions & 2 deletions internal/indexer/block_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/pebble/migrations/0_dag_removeSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
70 changes: 70 additions & 0 deletions internal/storage/pebble/migrations/2_pbft_remove_pbfthash.go
Original file line number Diff line number Diff line change
@@ -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(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" {
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
}
1 change: 1 addition & 0 deletions internal/storage/pebble/migrations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
43 changes: 29 additions & 14 deletions internal/storage/pebble/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}))
Expand Down
1 change: 0 additions & 1 deletion models/models.gen.go

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