Skip to content

Commit

Permalink
consensus: index roothash related runtime and round
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Feb 2, 2024
1 parent c19e42a commit 7f3307e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
34 changes: 28 additions & 6 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
sdkConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"

"github.com/oasisprotocol/nexus/common"
"github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api/transaction"
genesis "github.com/oasisprotocol/nexus/coreapi/v22.2.11/genesis/api"
staking "github.com/oasisprotocol/nexus/coreapi/v22.2.11/staking/api"
Expand All @@ -37,9 +38,12 @@ const (
type EventType = apiTypes.ConsensusEventType // alias for brevity

type parsedEvent struct {
ty EventType
rawBody json.RawMessage
relatedAddresses []staking.Address
ty EventType
rawBody json.RawMessage
roothashRuntimeID *coreCommon.Namespace
relatedAddresses []staking.Address
relatedRuntime *common.Runtime
relatedRuntimeRound *uint64
}

// OpenSignedTxNoVerify decodes the Transaction inside a Signed transaction
Expand Down Expand Up @@ -479,6 +483,9 @@ func (m *processor) queueTxEventInserts(batch *storage.QueryBatch, data *consens
txr.Transaction.Hash().Hex(),
i,
accounts,
common.StringOrNil(eventData.roothashRuntimeID),
eventData.relatedRuntime,
eventData.relatedRuntimeRound,
)
}
uniqueTxAccounts := extractUniqueAddresses(txAccounts)
Expand Down Expand Up @@ -1035,6 +1042,9 @@ func (m *processor) queueSingleEventInserts(batch *storage.QueryBatch, eventData
nil,
nil,
accounts,
common.StringOrNil(eventData.roothashRuntimeID),
eventData.relatedRuntime,
eventData.relatedRuntimeRound,
)

return nil
Expand Down Expand Up @@ -1068,9 +1078,21 @@ func (m *processor) extractEventData(event nodeapi.Event) parsedEvent {
eventData.relatedAddresses = []staking.Address{event.GovernanceProposalSubmitted.Submitter}
case event.GovernanceVote != nil:
eventData.relatedAddresses = []staking.Address{event.GovernanceVote.Submitter}
case event.RoothashExecutorCommitted != nil && event.RoothashExecutorCommitted.NodeID != nil:
nodeAddr := staking.NewAddress(*event.RoothashExecutorCommitted.NodeID)
eventData.relatedAddresses = []staking.Address{nodeAddr}
case event.RoothashMisc != nil:
eventData.roothashRuntimeID = &event.RoothashMisc.RuntimeID
eventData.relatedRuntime = RuntimeFromID(event.RoothashMisc.RuntimeID, m.network)
eventData.relatedRuntimeRound = event.RoothashMisc.Round
case event.RoothashExecutorCommitted != nil:
eventData.roothashRuntimeID = &event.RoothashExecutorCommitted.RuntimeID
eventData.relatedRuntime = RuntimeFromID(event.RoothashExecutorCommitted.RuntimeID, m.network)
eventData.relatedRuntimeRound = &event.RoothashExecutorCommitted.Round
if event.RoothashExecutorCommitted.NodeID != nil {
nodeAddr := staking.NewAddress(*event.RoothashExecutorCommitted.NodeID)
eventData.relatedAddresses = []staking.Address{nodeAddr}
}
case event.RoothashMessage != nil:
eventData.roothashRuntimeID = &event.RoothashMessage.RuntimeID
eventData.relatedRuntime = RuntimeFromID(event.RoothashMessage.RuntimeID, m.network)
case event.RegistryEntity != nil:
addr := staking.NewAddress(event.RegistryEntity.Entity.ID)
accounts := []staking.Address{addr}
Expand Down
4 changes: 2 additions & 2 deletions analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ var (
schedule = excluded.schedule`

ConsensusEventInsert = `
INSERT INTO chain.events (type, body, tx_block, tx_hash, tx_index, related_accounts)
VALUES ($1, $2, $3, $4, $5, $6)`
INSERT INTO chain.events (type, body, tx_block, tx_hash, tx_index, related_accounts, roothash_runtime_id, related_runtime, related_runtime_round)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`

ConsensusAccountRelatedTransactionInsert = `
INSERT INTO chain.accounts_related_transactions (account_address, tx_block, tx_index)
Expand Down

0 comments on commit 7f3307e

Please sign in to comment.