Skip to content

Commit

Permalink
Merge pull request #382 from oasisprotocol/mitjat/raw-event-body-as-json
Browse files Browse the repository at this point in the history
nodeapi: Store raw oasis-core in serialized form
  • Loading branch information
mitjat authored Apr 29, 2023
2 parents dc3834f + 20de4d8 commit 35fd167
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
10 changes: 5 additions & 5 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type EventType = apiTypes.ConsensusEventType // alias for brevity

type parsedEvent struct {
ty EventType
rawBodyJSON json.RawMessage
rawBody json.RawMessage
relatedAddresses []staking.Address
}

Expand Down Expand Up @@ -482,7 +482,7 @@ func (m *Main) queueTxEventInserts(batch *storage.QueryBatch, data *storage.Cons
eventData := m.extractEventData(event)
txAccounts = append(txAccounts, eventData.relatedAddresses...)
accounts := extractUniqueAddresses(eventData.relatedAddresses)
body, err := json.Marshal(eventData.rawBodyJSON)
body, err := json.Marshal(eventData.rawBody)
if err != nil {
return err
}
Expand Down Expand Up @@ -915,7 +915,7 @@ func (m *Main) queueGovernanceEventInserts(batch *storage.QueryBatch, data *stor

func (m *Main) queueSingleEventInserts(batch *storage.QueryBatch, eventData *parsedEvent, height int64) error {
accounts := extractUniqueAddresses(eventData.relatedAddresses)
body, err := json.Marshal(eventData.rawBodyJSON)
body, err := json.Marshal(eventData.rawBody)
if err != nil {
return err
}
Expand Down Expand Up @@ -950,8 +950,8 @@ func extractUniqueAddresses(accounts []staking.Address) []string {
// extractEventData extracts the type, the body (JSON-serialized), and the related accounts of an event.
func (m *Main) extractEventData(event nodeapi.Event) parsedEvent {
eventData := parsedEvent{
ty: event.Type,
rawBodyJSON: event.RawBodyJSON,
ty: event.Type,
rawBody: event.RawBody,
}

// Fill in related accounts.
Expand Down
2 changes: 1 addition & 1 deletion storage/oasis/nodeapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Event struct {
// field will be populated.
// We convert to JSON and effectively erase the type here in order to decouple
// oasis-core types (which vary between versions) from the indexer.
RawBodyJSON json.RawMessage
RawBody json.RawMessage

// Called "Kind" in oasis-core but "Type" in indexer APIs and DBs.
Type apiTypes.ConsensusEventType
Expand Down
48 changes: 24 additions & 24 deletions storage/oasis/nodeapi/cobalt/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,41 +171,41 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
case e.Staking.Transfer != nil:
ret = nodeapi.Event{
StakingTransfer: (*nodeapi.TransferEvent)(e.Staking.Transfer),
RawBodyJSON: common.TryAsJSON(e.Staking.Transfer),
RawBody: common.TryAsJSON(e.Staking.Transfer),
Type: apiTypes.ConsensusEventTypeStakingTransfer,
}
case e.Staking.Burn != nil:
ret = nodeapi.Event{
StakingBurn: (*nodeapi.BurnEvent)(e.Staking.Burn),
RawBodyJSON: common.TryAsJSON(e.Staking.Burn),
RawBody: common.TryAsJSON(e.Staking.Burn),
Type: apiTypes.ConsensusEventTypeStakingBurn,
}
case e.Staking.Escrow != nil:
switch {
case e.Staking.Escrow.Add != nil:
ret = nodeapi.Event{
StakingAddEscrow: (*nodeapi.AddEscrowEvent)(e.Staking.Escrow.Add),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.Add),
RawBody: common.TryAsJSON(e.Staking.Escrow.Add),
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
}
case e.Staking.Escrow.Take != nil:
ret = nodeapi.Event{
StakingTakeEscrow: (*nodeapi.TakeEscrowEvent)(e.Staking.Escrow.Take),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.Take),
RawBody: common.TryAsJSON(e.Staking.Escrow.Take),
Type: apiTypes.ConsensusEventTypeStakingEscrowTake,
}
case e.Staking.Escrow.Reclaim != nil:
ret = nodeapi.Event{
StakingReclaimEscrow: (*nodeapi.ReclaimEscrowEvent)(e.Staking.Escrow.Reclaim),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.Reclaim),
RawBody: common.TryAsJSON(e.Staking.Escrow.Reclaim),
Type: apiTypes.ConsensusEventTypeStakingEscrowReclaim,
}
// NOTE: There is no Staking.Escrow.DebondingStart event in Cobalt.
}
case e.Staking.AllowanceChange != nil:
ret = nodeapi.Event{
StakingAllowanceChange: (*nodeapi.AllowanceChangeEvent)(e.Staking.AllowanceChange),
RawBodyJSON: common.TryAsJSON(e.Staking.AllowanceChange),
RawBody: common.TryAsJSON(e.Staking.AllowanceChange),
Type: apiTypes.ConsensusEventTypeStakingAllowanceChange,
}
}
Expand All @@ -223,13 +223,13 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
KeyManager: e.Registry.RuntimeEvent.Runtime.KeyManager,
TEEHardware: e.Registry.RuntimeEvent.Runtime.TEEHardware.String(),
},
RawBodyJSON: common.TryAsJSON(e.Registry.RuntimeEvent),
Type: apiTypes.ConsensusEventTypeRegistryRuntime,
RawBody: common.TryAsJSON(e.Registry.RuntimeEvent),
Type: apiTypes.ConsensusEventTypeRegistryRuntime,
}
case e.Registry.EntityEvent != nil:
ret = nodeapi.Event{
RegistryEntity: (*nodeapi.EntityEvent)(e.Registry.EntityEvent),
RawBodyJSON: common.TryAsJSON(e.Registry.EntityEvent),
RawBody: common.TryAsJSON(e.Registry.EntityEvent),
Type: apiTypes.ConsensusEventTypeRegistryEntity,
}
case e.Registry.NodeEvent != nil:
Expand Down Expand Up @@ -271,13 +271,13 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
Roles: strings.Split(e.Registry.NodeEvent.Node.Roles.String(), ","),
SoftwareVersion: e.Registry.NodeEvent.Node.SoftwareVersion,
},
RawBodyJSON: common.TryAsJSON(e.Registry.NodeEvent),
Type: apiTypes.ConsensusEventTypeRegistryNode,
RawBody: common.TryAsJSON(e.Registry.NodeEvent),
Type: apiTypes.ConsensusEventTypeRegistryNode,
}
case e.Registry.NodeUnfrozenEvent != nil:
ret = nodeapi.Event{
RegistryNodeUnfrozen: (*nodeapi.NodeUnfrozenEvent)(e.Registry.NodeUnfrozenEvent),
RawBodyJSON: common.TryAsJSON(e.Registry.NodeUnfrozenEvent),
RawBody: common.TryAsJSON(e.Registry.NodeUnfrozenEvent),
Type: apiTypes.ConsensusEventTypeRegistryNodeUnfrozen,
}
}
Expand All @@ -291,18 +291,18 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
RoothashExecutorCommitted: &nodeapi.ExecutorCommittedEvent{
NodeID: nil, // Not available in Cobalt.
},
RawBodyJSON: common.TryAsJSON(e.RootHash.ExecutorCommitted),
Type: apiTypes.ConsensusEventTypeRoothashExecutorCommitted,
RawBody: common.TryAsJSON(e.RootHash.ExecutorCommitted),
Type: apiTypes.ConsensusEventTypeRoothashExecutorCommitted,
}
case e.RootHash.ExecutionDiscrepancyDetected != nil:
ret = nodeapi.Event{
RawBodyJSON: common.TryAsJSON(e.RootHash.ExecutionDiscrepancyDetected),
Type: apiTypes.ConsensusEventTypeRoothashExecutionDiscrepancy,
RawBody: common.TryAsJSON(e.RootHash.ExecutionDiscrepancyDetected),
Type: apiTypes.ConsensusEventTypeRoothashExecutionDiscrepancy,
}
case e.RootHash.Finalized != nil:
ret = nodeapi.Event{
RawBodyJSON: common.TryAsJSON(e.RootHash.Finalized),
Type: apiTypes.ConsensusEventTypeRoothashFinalized,
RawBody: common.TryAsJSON(e.RootHash.Finalized),
Type: apiTypes.ConsensusEventTypeRoothashFinalized,
}
}
ret.Height = e.RootHash.Height
Expand All @@ -313,13 +313,13 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
case e.Governance.ProposalSubmitted != nil:
ret = nodeapi.Event{
GovernanceProposalSubmitted: (*nodeapi.ProposalSubmittedEvent)(e.Governance.ProposalSubmitted),
RawBodyJSON: common.TryAsJSON(e.Governance.ProposalSubmitted),
RawBody: common.TryAsJSON(e.Governance.ProposalSubmitted),
Type: apiTypes.ConsensusEventTypeGovernanceProposalSubmitted,
}
case e.Governance.ProposalExecuted != nil:
ret = nodeapi.Event{
GovernanceProposalExecuted: (*nodeapi.ProposalExecutedEvent)(e.Governance.ProposalExecuted),
RawBodyJSON: common.TryAsJSON(e.Governance.ProposalExecuted),
RawBody: common.TryAsJSON(e.Governance.ProposalExecuted),
Type: apiTypes.ConsensusEventTypeGovernanceProposalExecuted,
}
case e.Governance.ProposalFinalized != nil:
Expand All @@ -329,8 +329,8 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
// This assumes that the ProposalState enum is backwards-compatible
State: governance.ProposalState(e.Governance.ProposalFinalized.State),
},
RawBodyJSON: common.TryAsJSON(e.Governance.ProposalFinalized),
Type: apiTypes.ConsensusEventTypeGovernanceProposalFinalized,
RawBody: common.TryAsJSON(e.Governance.ProposalFinalized),
Type: apiTypes.ConsensusEventTypeGovernanceProposalFinalized,
}
case e.Governance.Vote != nil:
ret = nodeapi.Event{
Expand All @@ -339,8 +339,8 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
Submitter: e.Governance.Vote.Submitter,
Vote: e.Governance.Vote.Vote.String(),
},
RawBodyJSON: common.TryAsJSON(e.Governance.Vote),
Type: apiTypes.ConsensusEventTypeGovernanceVote,
RawBody: common.TryAsJSON(e.Governance.Vote),
Type: apiTypes.ConsensusEventTypeGovernanceVote,
}
}
ret.Height = e.Governance.Height
Expand Down
48 changes: 24 additions & 24 deletions storage/oasis/nodeapi/damask/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,46 @@ func convertEvent(e txResultsDamask.Event) nodeapi.Event {
case e.Staking.Transfer != nil:
ret = nodeapi.Event{
StakingTransfer: (*nodeapi.TransferEvent)(e.Staking.Transfer),
RawBodyJSON: common.TryAsJSON(e.Staking.Transfer),
RawBody: common.TryAsJSON(e.Staking.Transfer),
Type: apiTypes.ConsensusEventTypeStakingTransfer,
}
case e.Staking.Burn != nil:
ret = nodeapi.Event{
StakingBurn: (*nodeapi.BurnEvent)(e.Staking.Burn),
RawBodyJSON: common.TryAsJSON(e.Staking.Burn),
RawBody: common.TryAsJSON(e.Staking.Burn),
Type: apiTypes.ConsensusEventTypeStakingBurn,
}
case e.Staking.Escrow != nil:
switch {
case e.Staking.Escrow.Add != nil:
ret = nodeapi.Event{
StakingAddEscrow: (*nodeapi.AddEscrowEvent)(e.Staking.Escrow.Add),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.Add),
RawBody: common.TryAsJSON(e.Staking.Escrow.Add),
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
}
case e.Staking.Escrow.Take != nil:
ret = nodeapi.Event{
StakingTakeEscrow: (*nodeapi.TakeEscrowEvent)(e.Staking.Escrow.Take),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.Take),
RawBody: common.TryAsJSON(e.Staking.Escrow.Take),
Type: apiTypes.ConsensusEventTypeStakingEscrowTake,
}
case e.Staking.Escrow.Reclaim != nil:
ret = nodeapi.Event{
StakingReclaimEscrow: (*nodeapi.ReclaimEscrowEvent)(e.Staking.Escrow.Reclaim),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.Reclaim),
RawBody: common.TryAsJSON(e.Staking.Escrow.Reclaim),
Type: apiTypes.ConsensusEventTypeStakingEscrowReclaim,
}
case e.Staking.Escrow.DebondingStart != nil:
ret = nodeapi.Event{
StakingDebondingStart: (*nodeapi.DebondingStartEscrowEvent)(e.Staking.Escrow.DebondingStart),
RawBodyJSON: common.TryAsJSON(e.Staking.Escrow.DebondingStart),
RawBody: common.TryAsJSON(e.Staking.Escrow.DebondingStart),
Type: apiTypes.ConsensusEventTypeStakingEscrowDebondingStart,
}
}
case e.Staking.AllowanceChange != nil:
ret = nodeapi.Event{
StakingAllowanceChange: (*nodeapi.AllowanceChangeEvent)(e.Staking.AllowanceChange),
RawBodyJSON: common.TryAsJSON(e.Staking.AllowanceChange),
RawBody: common.TryAsJSON(e.Staking.AllowanceChange),
Type: apiTypes.ConsensusEventTypeStakingAllowanceChange,
}
}
Expand All @@ -79,13 +79,13 @@ func convertEvent(e txResultsDamask.Event) nodeapi.Event {
KeyManager: e.Registry.RuntimeEvent.Runtime.KeyManager,
TEEHardware: e.Registry.RuntimeEvent.Runtime.TEEHardware.String(),
},
RawBodyJSON: common.TryAsJSON(e.Registry.RuntimeEvent),
Type: apiTypes.ConsensusEventTypeRegistryRuntime,
RawBody: common.TryAsJSON(e.Registry.RuntimeEvent),
Type: apiTypes.ConsensusEventTypeRegistryRuntime,
}
case e.Registry.EntityEvent != nil:
ret = nodeapi.Event{
RegistryEntity: (*nodeapi.EntityEvent)(e.Registry.EntityEvent),
RawBodyJSON: common.TryAsJSON(e.Registry.EntityEvent),
RawBody: common.TryAsJSON(e.Registry.EntityEvent),
Type: apiTypes.ConsensusEventTypeRegistryEntity,
}
case e.Registry.NodeEvent != nil:
Expand Down Expand Up @@ -127,13 +127,13 @@ func convertEvent(e txResultsDamask.Event) nodeapi.Event {
Roles: strings.Split(e.Registry.NodeEvent.Node.Roles.String(), ","),
SoftwareVersion: e.Registry.NodeEvent.Node.SoftwareVersion,
},
RawBodyJSON: common.TryAsJSON(e.Registry.NodeEvent),
Type: apiTypes.ConsensusEventTypeRegistryNode,
RawBody: common.TryAsJSON(e.Registry.NodeEvent),
Type: apiTypes.ConsensusEventTypeRegistryNode,
}
case e.Registry.NodeUnfrozenEvent != nil:
ret = nodeapi.Event{
RegistryNodeUnfrozen: (*nodeapi.NodeUnfrozenEvent)(e.Registry.NodeUnfrozenEvent),
RawBodyJSON: common.TryAsJSON(e.Registry.NodeUnfrozenEvent),
RawBody: common.TryAsJSON(e.Registry.NodeUnfrozenEvent),
Type: apiTypes.ConsensusEventTypeRegistryNodeUnfrozen,
}
}
Expand All @@ -147,18 +147,18 @@ func convertEvent(e txResultsDamask.Event) nodeapi.Event {
RoothashExecutorCommitted: &nodeapi.ExecutorCommittedEvent{
NodeID: &e.RootHash.ExecutorCommitted.Commit.NodeID,
},
RawBodyJSON: common.TryAsJSON(e.RootHash.ExecutorCommitted),
Type: apiTypes.ConsensusEventTypeRoothashExecutorCommitted,
RawBody: common.TryAsJSON(e.RootHash.ExecutorCommitted),
Type: apiTypes.ConsensusEventTypeRoothashExecutorCommitted,
}
case e.RootHash.ExecutionDiscrepancyDetected != nil:
ret = nodeapi.Event{
RawBodyJSON: common.TryAsJSON(e.RootHash.ExecutionDiscrepancyDetected),
Type: apiTypes.ConsensusEventTypeRoothashExecutionDiscrepancy,
RawBody: common.TryAsJSON(e.RootHash.ExecutionDiscrepancyDetected),
Type: apiTypes.ConsensusEventTypeRoothashExecutionDiscrepancy,
}
case e.RootHash.Finalized != nil:
ret = nodeapi.Event{
RawBodyJSON: common.TryAsJSON(e.RootHash.Finalized),
Type: apiTypes.ConsensusEventTypeRoothashFinalized,
RawBody: common.TryAsJSON(e.RootHash.Finalized),
Type: apiTypes.ConsensusEventTypeRoothashFinalized,
}
}
ret.Height = e.RootHash.Height
Expand All @@ -169,19 +169,19 @@ func convertEvent(e txResultsDamask.Event) nodeapi.Event {
case e.Governance.ProposalSubmitted != nil:
ret = nodeapi.Event{
GovernanceProposalSubmitted: (*nodeapi.ProposalSubmittedEvent)(e.Governance.ProposalSubmitted),
RawBodyJSON: common.TryAsJSON(e.Governance.ProposalSubmitted),
RawBody: common.TryAsJSON(e.Governance.ProposalSubmitted),
Type: apiTypes.ConsensusEventTypeGovernanceProposalSubmitted,
}
case e.Governance.ProposalExecuted != nil:
ret = nodeapi.Event{
GovernanceProposalExecuted: (*nodeapi.ProposalExecutedEvent)(e.Governance.ProposalExecuted),
RawBodyJSON: common.TryAsJSON(e.Governance.ProposalExecuted),
RawBody: common.TryAsJSON(e.Governance.ProposalExecuted),
Type: apiTypes.ConsensusEventTypeGovernanceProposalExecuted,
}
case e.Governance.ProposalFinalized != nil:
ret = nodeapi.Event{
GovernanceProposalFinalized: (*nodeapi.ProposalFinalizedEvent)(e.Governance.ProposalFinalized),
RawBodyJSON: common.TryAsJSON(e.Governance.ProposalFinalized),
RawBody: common.TryAsJSON(e.Governance.ProposalFinalized),
Type: apiTypes.ConsensusEventTypeGovernanceProposalFinalized,
}
case e.Governance.Vote != nil:
Expand All @@ -191,8 +191,8 @@ func convertEvent(e txResultsDamask.Event) nodeapi.Event {
Submitter: e.Governance.Vote.Submitter,
Vote: e.Governance.Vote.Vote.String(),
},
RawBodyJSON: common.TryAsJSON(e.Governance.Vote),
Type: apiTypes.ConsensusEventTypeGovernanceVote,
RawBody: common.TryAsJSON(e.Governance.Vote),
Type: apiTypes.ConsensusEventTypeGovernanceVote,
}
}
ret.Height = e.Governance.Height
Expand Down

0 comments on commit 35fd167

Please sign in to comment.