Skip to content

Commit

Permalink
consensus: store finalized roothash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Feb 2, 2024
1 parent 91539b8 commit b79015c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
41 changes: 41 additions & 0 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,14 @@ func (m *processor) queueRegistryEventInserts(batch *storage.QueryBatch, data *r
}

func (m *processor) queueRootHashMessageUpserts(batch *storage.QueryBatch, data *rootHashData) error {
finalized := map[coreCommon.Namespace]uint64{}
for _, event := range data.Events {
switch {
case event.RoothashMisc != nil:
switch event.Type {
case apiTypes.ConsensusEventTypeRoothashFinalized:
finalized[event.RoothashMisc.RuntimeID] = *event.RoothashMisc.Round
}
case event.RoothashExecutorCommitted != nil:
runtime := RuntimeFromID(event.RoothashExecutorCommitted.RuntimeID, m.network)
if runtime == nil {
Expand All @@ -655,6 +661,41 @@ func (m *processor) queueRootHashMessageUpserts(batch *storage.QueryBatch, data
relatedAddresses,
)
}
case event.RoothashMessage != nil:
runtime := RuntimeFromID(event.RoothashMessage.RuntimeID, m.network)
if runtime == nil {
break
}
batch.Queue(queries.ConsensusRoothashMessageFinalizeUpsert,
runtime,
finalized[event.RoothashMessage.RuntimeID],
event.RoothashMessage.Index,
event.RoothashMessage.Module,
event.RoothashMessage.Code,
nil,
)
}
}
for rtid, results := range data.LastRoundResults {
runtime := RuntimeFromID(rtid, m.network)
if runtime == nil {
// We shouldn't even have gathered last round results for unknown
// runtimes. But prevent nil-runtime inserts anyway.
continue
}
round, ok := finalized[rtid]
if !ok {
continue
}
for _, message := range results.Messages {
batch.Queue(queries.ConsensusRoothashMessageFinalizeUpsert,
runtime,
round,
message.Index,
message.Module,
message.Code,
cbor.Marshal(message.Result),
)
}
}

Expand Down
11 changes: 11 additions & 0 deletions analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ var (
body = excluded.body,
related_accounts = excluded.related_accounts`

ConsensusRoothashMessageFinalizeUpsert = `
INSERT INTO chain.roothash_messages
(runtime, round, message_index, error_module, error_code, result)
VALUES
($1, $2, $3, $4, $5, $6)
ON CONFLICT (runtime, round, message_index) DO UPDATE
SET
error_module = excluded.error_module,
error_code = excluded.error_code,
result = excluded.result`

ConsensusAccountRelatedTransactionInsert = `
INSERT INTO chain.accounts_related_transactions (account_address, tx_block, tx_index)
VALUES ($1, $2, $3)`
Expand Down

0 comments on commit b79015c

Please sign in to comment.