Skip to content

Commit

Permalink
Merge pull request #630 from oasisprotocol/pro-wh/feature/genesisbatch
Browse files Browse the repository at this point in the history
consensus: use batch for genesis queries
  • Loading branch information
pro-wh authored May 6, 2024
2 parents d67678b + 96eba3f commit b2637a3
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 392 deletions.
1 change: 1 addition & 0 deletions .changelog/630.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
consensus: use batch for genesis queries
20 changes: 11 additions & 9 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,25 @@ func (m *processor) debugDumpGenesisJSON(genesisDoc *genesis.Document, heightOrN
func (m *processor) processGenesis(ctx context.Context, genesisDoc *genesis.Document, nodesOverride []nodeapi.Node) error {
m.logger.Info("processing genesis document")
gen := NewGenesisProcessor(m.logger.With("height", "genesis"))
queries, err := gen.Process(genesisDoc, nodesOverride)
batch, err := gen.Process(genesisDoc, nodesOverride)
if err != nil {
return err
}

// Debug: log the SQL into a file if requested.
debugPath := os.Getenv("NEXUS_DUMP_GENESIS_SQL")
if debugPath != "" {
sql := strings.Join(queries, "\n")
if err := os.WriteFile(debugPath, []byte(sql), 0o600 /* Permissions: rw------- */); err != nil {
gen.logger.Error("failed to write genesis sql to file", "err", err)
queries, err := json.Marshal(batch.Queries())
if err != nil {
return err
}
if err := os.WriteFile(debugPath, queries, 0o600 /* Permissions: rw------- */); err != nil {
gen.logger.Error("failed to write genesis queries to file", "err", err)
} else {
gen.logger.Info("wrote genesis sql to file", "path", debugPath)
gen.logger.Info("wrote genesis queries to file", "path", debugPath)
}
}

batch := &storage.QueryBatch{}
for _, query := range queries {
batch.Queue(query)
}
if err := m.target.SendBatch(ctx, batch); err != nil {
return err
}
Expand Down Expand Up @@ -1070,6 +1069,7 @@ func (m *processor) queueSubmissions(batch *storage.QueryBatch, data *governance
submission.Content.Upgrade.Epoch,
submission.CreatedAt,
submission.ClosesAt,
0,
)
case submission.Content.CancelUpgrade != nil:
batch.Queue(queries.ConsensusProposalSubmissionCancelInsert,
Expand All @@ -1080,6 +1080,7 @@ func (m *processor) queueSubmissions(batch *storage.QueryBatch, data *governance
submission.Content.CancelUpgrade.ProposalID,
submission.CreatedAt,
submission.ClosesAt,
0,
)
case submission.Content.ChangeParameters != nil:
batch.Queue(queries.ConsensusProposalSubmissionChangeParametersInsert,
Expand All @@ -1091,6 +1092,7 @@ func (m *processor) queueSubmissions(batch *storage.QueryBatch, data *governance
[]byte(submission.Content.ChangeParameters.Changes),
submission.CreatedAt,
submission.ClosesAt,
0,
)
default:
m.logger.Warn("unknown proposal content type", "proposal_id", submission.ID, "content", submission.Content)
Expand Down
Loading

0 comments on commit b2637a3

Please sign in to comment.