Skip to content

Commit

Permalink
consensus: rename related_runtime and related_runtime_round
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Feb 29, 2024
1 parent a9a5ed8 commit 0934827
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
30 changes: 15 additions & 15 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ const (
type EventType = apiTypes.ConsensusEventType // alias for brevity

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

// OpenSignedTxNoVerify decodes the Transaction inside a Signed transaction
Expand Down Expand Up @@ -485,8 +485,8 @@ func (m *processor) queueTxEventInserts(batch *storage.QueryBatch, data *consens
i,
accounts,
common.StringOrNil(eventData.roothashRuntimeID),
eventData.relatedRuntime,
eventData.relatedRuntimeRound,
eventData.roothashRuntime,
eventData.roothashRuntimeRound,
)
}
uniqueTxAccounts := extractUniqueAddresses(txAccounts)
Expand Down Expand Up @@ -1044,8 +1044,8 @@ func (m *processor) queueSingleEventInserts(batch *storage.QueryBatch, eventData
nil,
accounts,
common.StringOrNil(eventData.roothashRuntimeID),
eventData.relatedRuntime,
eventData.relatedRuntimeRound,
eventData.roothashRuntime,
eventData.roothashRuntimeRound,
)

return nil
Expand Down Expand Up @@ -1081,20 +1081,20 @@ func (m *processor) extractEventData(event nodeapi.Event) parsedEvent {
eventData.relatedAddresses = []staking.Address{event.GovernanceVote.Submitter}
case event.RoothashMisc != nil:
eventData.roothashRuntimeID = &event.RoothashMisc.RuntimeID
eventData.relatedRuntime = RuntimeFromID(event.RoothashMisc.RuntimeID, m.network)
eventData.relatedRuntimeRound = event.RoothashMisc.Round
eventData.roothashRuntime = RuntimeFromID(event.RoothashMisc.RuntimeID, m.network)
eventData.roothashRuntimeRound = 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
eventData.roothashRuntime = RuntimeFromID(event.RoothashExecutorCommitted.RuntimeID, m.network)
eventData.roothashRuntimeRound = &event.RoothashExecutorCommitted.Round
if event.RoothashExecutorCommitted.NodeID != nil {
// TODO: preimage?
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)
eventData.roothashRuntime = RuntimeFromID(event.RoothashMessage.RuntimeID, m.network)
case event.RegistryEntity != nil:
addr := staking.NewAddress(event.RegistryEntity.Entity.ID)
accounts := []staking.Address{addr}
Expand Down
2 changes: 1 addition & 1 deletion analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var (
schedule = excluded.schedule`

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

ConsensusAccountRelatedTransactionInsert = `
Expand Down
4 changes: 2 additions & 2 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1612,13 +1612,13 @@ components:
The ID of the runtime to which the event relates, encoded in hex.
Present only for events of type `roothash.*`.
example: 000000000000000000000000000000000000000000000000e2eaa99fc008f87f
related_runtime:
roothash_runtime:
allOf: [$ref: '#/components/schemas/Runtime']
description: |
The runtime to which the event relates.
Present only for events of type `roothash.*`.
example: emerald
related_runtime_round:
roothash_runtime_round:
type: integer
format: int64
description: |
Expand Down
4 changes: 2 additions & 2 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ func (c *StorageClient) Events(ctx context.Context, p apiTypes.GetConsensusEvent
&e.TxIndex,
&e.TxHash,
&e.RoothashRuntimeId,
&e.RelatedRuntime,
&e.RelatedRuntimeRound,
&e.RoothashRuntime,
&e.RoothashRuntimeRound,
&e.Type,
&e.Body,
); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const (
WHERE tx_hash = $1::text`

Events = `
SELECT tx_block, tx_index, tx_hash, roothash_runtime_id, related_runtime, related_runtime_round, type, body
SELECT tx_block, tx_index, tx_hash, roothash_runtime_id, roothash_runtime, roothash_runtime_round, type, body
FROM chain.events
WHERE ($1::bigint IS NULL OR tx_block = $1::bigint) AND
($2::integer IS NULL OR tx_index = $2::integer) AND
Expand Down
10 changes: 5 additions & 5 deletions storage/migrations/00_consensus.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ CREATE TABLE chain.events
related_accounts TEXT[],
-- added in 10_roothash.up.sql
-- roothash_runtime_id HEX64,
-- related_runtime runtime,
-- related_runtime_round UINT63,
-- roothash_runtime runtime,
-- roothash_runtime_round UINT63,

FOREIGN KEY (tx_block, tx_index) REFERENCES chain.transactions(block, tx_index) DEFERRABLE INITIALLY DEFERRED
);
Expand All @@ -89,10 +89,10 @@ CREATE INDEX ix_events_tx_hash ON chain.events (tx_hash);
CREATE INDEX ix_events_type ON chain.events (type, tx_block); -- tx_block is for sorting the events of a given type by recency
-- added in 10_roothash.up.sql
-- CREATE INDEX ix_events_roothash
-- ON chain.events (related_runtime, related_runtime_round)
-- ON chain.events (roothash_runtime, roothash_runtime_round)
-- WHERE
-- related_runtime IS NOT NULL AND
-- related_runtime_round IS NOT NULL;
-- roothash_runtime IS NOT NULL AND
-- roothash_runtime_round IS NOT NULL;

-- Beacon Backend Data

Expand Down
10 changes: 5 additions & 5 deletions storage/migrations/10_roothash.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ ALTER TABLE chain.events
ADD COLUMN roothash_runtime_id HEX64,
-- This is a nexus runtime name, for example `sapphire`. This is only set
-- for supported runtimes.
ADD COLUMN related_runtime runtime,
ADD COLUMN related_runtime_round UINT63;
ADD COLUMN roothash_runtime runtime,
ADD COLUMN roothash_runtime_round UINT63;

-- ix_events_roothash is the link between runtime blocks and consensus blocks.
-- Given a runtime block (runtime, round), you can look up the roothash events
-- with this index and find the events when the block was proposed (first
-- executor commit), committed to, and finalized.
CREATE INDEX ix_events_roothash
ON chain.events (related_runtime, related_runtime_round)
ON chain.events (roothash_runtime, roothash_runtime_round)
WHERE
related_runtime IS NOT NULL AND
related_runtime_round IS NOT NULL;
roothash_runtime IS NOT NULL AND
roothash_runtime_round IS NOT NULL;

COMMIT;

0 comments on commit 0934827

Please sign in to comment.