Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Chain Event Types #3 #3044

Merged
merged 91 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
76d9437
from event-types client side
timolegros Dec 6, 2022
40ef656
move chain + network to event -> working chain activity dashboard
timolegros Dec 6, 2022
eb00def
switch ce commands to ts-node-dev
timolegros Dec 6, 2022
8aa9c25
chain + network added to event in ChainEventConsumer
timolegros Dec 6, 2022
cbaae3b
save
timolegros Dec 6, 2022
df44f65
filter out non entity creation/completion events for notifications
timolegros Dec 21, 2022
a4053f4
Merge branch 'master' into tim.remove-event-types
timolegros Dec 21, 2022
2587dd9
remove EventTypeCUD RabbitMQ types + config + pub/sub calls
timolegros Dec 21, 2022
8907f7b
remove ChainEventType model
timolegros Dec 21, 2022
ee05e1f
remove chain-event-type migration
timolegros Dec 21, 2022
0aac144
CET model removal fixes
timolegros Dec 21, 2022
d2230f6
CW remove CET migration
timolegros Dec 21, 2022
66feb57
CW remove CET model
timolegros Dec 21, 2022
892ccba
CET removal migrations + model update
timolegros Dec 26, 2022
374e1e0
Merge branch 'master' into tim.remove-event-types
timolegros Dec 26, 2022
05bd075
migration fixes
timolegros Dec 26, 2022
b503daa
migration fixes
timolegros Dec 26, 2022
f4d925e
chain subscriptions + chain-event notification settings + subscribedC…
timolegros Dec 27, 2022
3fcd13a
add full chain to createSubscription route result + fix UI
timolegros Dec 27, 2022
c4beca2
turn off sourceMap, use proper tsconfig when building ce, and fixed s…
timolegros Jan 21, 2023
11a836d
add type check to CI + fix type errors
timolegros Jan 22, 2023
a5eb796
add type check to CI + fix type errors + remove format in CE repo
timolegros Jan 22, 2023
6b036f4
Merge branch 'master' into tim.fix_ce
timolegros Jan 22, 2023
0499dab
set allowJs: false in tsconfig so sourceMap files don't interrupt ts-…
timolegros Jan 22, 2023
491c8ee
Merge branch 'master' into tim.remove-event-types
timolegros Jan 23, 2023
8466b5b
RabbitMQ merge fixes
timolegros Jan 23, 2023
bd5a5b9
Make CI lint only the changes in the branch rather than everything
timolegros Jan 23, 2023
f6e44b4
fix tsconfig + run prettier
timolegros Jan 23, 2023
d7ca704
merge fixes
timolegros Jan 23, 2023
144699b
Merge branch 'tim.fix_ce' into tim.remove-event-types
timolegros Jan 23, 2023
ae04ae6
merge fixes
timolegros Jan 23, 2023
751a303
discoverReconnectRange fix
timolegros Jan 23, 2023
83c0103
consumer erc20 notification handler bug fix
timolegros Jan 23, 2023
621cc20
load-env-var fix
timolegros Jan 23, 2023
56a2c6b
Procfile fix
timolegros Jan 23, 2023
b064ac9
Merge branch 'master' into tim.remove-event-types
timolegros Jan 25, 2023
ba3ce09
master merge fixes
timolegros Jan 25, 2023
98432e5
fix chain-event notifications
timolegros Jan 25, 2023
069a1b5
fix chain-event email notifications
timolegros Jan 25, 2023
ab255a7
format
timolegros Jan 25, 2023
3472824
format
timolegros Jan 25, 2023
974c1f2
CE css fix
timolegros Jan 27, 2023
89d4d30
remove subscriptions count for chain-events
timolegros Jan 27, 2023
6c13aba
Merge branch 'master' into tim.remove-event-types
timolegros Feb 2, 2023
c46860b
fix getSubscribedChains call
timolegros Feb 2, 2023
0b1f2b0
notification settings page fixes + remove unnecessary logs
timolegros Feb 2, 2023
3c76bd3
format
timolegros Feb 2, 2023
d0d01d8
Merge branch 'master' into tim.remove-event-types
timolegros Feb 2, 2023
6e4cde5
Merge branch 'master' into tim.remove-event-types
jnaviask Feb 3, 2023
34aa104
Merge master into tim.remove-event-types
github-actions[bot] Feb 3, 2023
f38a057
Merge master into tim.remove-event-types
github-actions[bot] Feb 3, 2023
209c44a
Merge master into tim.remove-event-types
github-actions[bot] Feb 3, 2023
a84e298
delete script
timolegros Feb 3, 2023
1703d01
Merge remote-tracking branch 'origin/tim.remove-event-types' into tim…
timolegros Feb 3, 2023
41a3c09
migration script fix
timolegros Feb 3, 2023
6ef41af
prettier format
timolegros Feb 3, 2023
22005b1
publishCustomRabbitMQMessage.ts improvements
timolegros Feb 3, 2023
ebeff18
prettier format
timolegros Feb 3, 2023
4e136cf
more script improvements for testing/QA
timolegros Feb 3, 2023
a55446d
Merge branch 'master' into tim.remove-event-types
timolegros Feb 18, 2023
97b605f
add dump file to gitignore
timolegros Mar 3, 2023
0351acc
8 min local
timolegros Mar 3, 2023
9850859
15 seconds local
timolegros Mar 3, 2023
3b69468
add fkey from NR to Sub
timolegros Mar 3, 2023
d71bfad
Merge branch 'master' into tim.remove-event-types-2
timolegros Mar 3, 2023
64b736d
format
timolegros Mar 3, 2023
16c14a5
eslint + format + .prettierignore update
timolegros Mar 3, 2023
175635a
Ensure CET Removal Backwards Compatibility. (#2765)
jnaviask Feb 10, 2023
5679fe8
fixed type errors
timolegros Mar 3, 2023
cda8767
fix lint
timolegros Mar 3, 2023
81df4f1
fix lint
timolegros Mar 3, 2023
50cc65d
format
timolegros Mar 3, 2023
4e0da6a
small logging fix
timolegros Mar 5, 2023
7577ab5
Merge branch 'master' into tim.remove-event-types-2
CowMuon Mar 6, 2023
615a2b3
Merge branch 'master' into tim.remove-event-types-2
timolegros Mar 7, 2023
398a42a
Merge remote-tracking branch 'origin/tim.remove-event-types-2' into t…
timolegros Mar 7, 2023
ef95667
migration log improvement
timolegros Mar 7, 2023
dacc062
ce procfile fix
timolegros Mar 7, 2023
60594fd
add missing index to notif table
timolegros Mar 7, 2023
f54e0f9
Subscriptions pkey + not null
timolegros Mar 7, 2023
c54278f
Merge branch 'master' into tim.remove-event-types-2
timolegros Mar 9, 2023
ebda16b
Merge branch 'master' into tim.remove-event-types-2
CowMuon Mar 10, 2023
e8aec80
Merge branch 'master' into tim.remove-event-types-2
timolegros Mar 13, 2023
7cad764
Merge remote-tracking branch 'origin/tim.remove-event-types-2' into t…
timolegros Mar 13, 2023
fdda7f5
Merge branch 'master' into tim.remove-event-types-2
CowMuon Mar 15, 2023
a5e7540
fix type
timolegros Mar 16, 2023
a49bab8
test improved CE queries
timolegros Mar 16, 2023
b4d0c88
Procfile fix
timolegros Mar 16, 2023
65ee13f
heroku test
timolegros Mar 16, 2023
1e521a5
heroku test 2
timolegros Mar 16, 2023
5a22fb3
cleaup
timolegros Mar 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/build
**/dist
**/.github
**/*.env
**/node_modules
Expand All @@ -16,6 +17,7 @@ packages/chain-events/.eslintrc.js
**/contractTypes
**/factories
**/eth/types
**/eth/artifacts
**/.eslintrc.js
**/ios/App/App

10 changes: 5 additions & 5 deletions packages/chain-events/Procfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
web: node --max_old_space_size=$(../../../../scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/app/Server.js
subscriber1: CHAIN_SUBSCRIBER_INDEX=0 node --max_old_space_size=$(../../../../scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainSubscriber/chainSubscriber.js run-as-script
subscriber2: CHAIN_SUBSCRIBER_INDEX=1 node --max_old_space_size=$(../../../../scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainSubscriber/chainSubscriber.js run-as-script
subscriber3: CHAIN_SUBSCRIBER_INDEX=2 node --max_old_space_size=$(../../../../scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainSubscriber/chainSubscriber.js run-as-script
consumer: node --max_old_space_size=$(../../../../scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainEventsConsumer/chainEventsConsumer.js run-as-script
web: node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/app/Server.js
subscriber1: CHAIN_SUBSCRIBER_INDEX=0 node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainSubscriber/chainSubscriber.js run-as-script
subscriber2: CHAIN_SUBSCRIBER_INDEX=1 node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainSubscriber/chainSubscriber.js run-as-script
subscriber3: CHAIN_SUBSCRIBER_INDEX=2 node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainSubscriber/chainSubscriber.js run-as-script
consumer: node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/chain-events/build/chain-events/services/ChainEventsConsumer/chainEventsConsumer.js run-as-script
release: cd packages/chain-events && npx sequelize-cli db:migrate --config services/database/sequelize.json
7 changes: 4 additions & 3 deletions packages/chain-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"batch-poll": "ts-node -T ./scripts/batchPoller.ts",
"preyalcpublish": "yarn build",
"emit-events": "ts-node --project tsconfig.json ./scripts/emitChainEvents.ts",
"start-app": "ts-node --project tsconfig.services.json services/app/Server.ts",
"start-consumer": "ts-node --project tsconfig.services.json services/ChainEventsConsumer/chainEventsConsumer.ts run-as-script",
"start-subscriber": "ts-node --project tsconfig.services.json services/ChainSubscriber/chainSubscriber.ts run-as-script",
"start-app": "ts-node-dev --max-old-space-size=4096 --respawn --transpile-only --project tsconfig.services.json services/app/Server.ts",
"start-consumer": "ts-node-dev --max-old-space-size=4096 --respawn --transpile-only --project tsconfig.services.json services/ChainEventsConsumer/chainEventsConsumer.ts run-as-script",
"start-subscriber": "ts-node-dev --max-old-space-size=4096 --respawn --transpile-only --project tsconfig.services.json services/ChainSubscriber/chainSubscriber.ts run-as-script",
"start-all": "concurrently -p '{name}' -c yellow,blue,magenta -n app,consumer,subscriber 'yarn start-app' 'yarn start-consumer' 'yarn start-subscriber'",
"create-db": "npx sequelize db:create",
"migrate-db": "npx sequelize db:migrate",
Expand Down Expand Up @@ -80,6 +80,7 @@
"pg-format": "^1.0.4",
"rollbar": "^2.25.2",
"sleep-promise": "^8.0.1",
"ts-node-dev": "^2.0.0",
"typescript-logging": "^0.6.4",
"underscore": "^1.10.2",
"web3": "^1.3.1",
Expand Down
14 changes: 13 additions & 1 deletion packages/chain-events/scripts/migrateChainEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import type { BrokerConfig } from 'rascal';
import { RABBITMQ_URI } from '../../commonwealth/server/config';
import { constructSubstrateUrl } from '../../commonwealth/shared/substrate';
import { CHAIN_EVENT_SERVICE_SECRET, CW_SERVER_URL } from '../services/config';
import NotificationsHandler from '../services/ChainEventsConsumer/ChainEventHandlers/notification';
import models from '../services/database/database';
import { EventKind } from '../src/chains/substrate/types';

const log = factory.getLogger(formatFilename(__filename));

Expand Down Expand Up @@ -95,6 +98,14 @@ async function migrateChainEntity(
rmqController,
chain
);

const excludedNotificationEvents = [EventKind.DemocracyTabled];
const notificationsHandler = new NotificationsHandler(
models,
rmqController,
excludedNotificationEvents
);

let fetcher: IStorageFetcher<any>;
const range: IDisconnectedRange = { startBlock: 0 };
if (chainInstance.base === ChainBase.Substrate) {
Expand Down Expand Up @@ -153,7 +164,8 @@ async function migrateChainEntity(
try {
// eslint-disable-next-line no-await-in-loop
const dbEvent = await migrationHandler.handle(event);
await entityArchivalHandler.handle(event, dbEvent);
const ceEvent = await entityArchivalHandler.handle(event, dbEvent);
await notificationsHandler.handle(event, ceEvent);
} catch (e) {
log.error(`Event handle failure: ${e.message}`);
}
Expand Down
83 changes: 83 additions & 0 deletions packages/chain-events/scripts/publishCustomRabbitMQMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { IEventData } from '../src/chains/aave/types';
import type { CWEvent } from '../src';
import { SupportedNetwork } from '../src';
import { publishRmqMsg } from 'common-common/src/rabbitmq/util';
import { RABBITMQ_API_URI } from '../services/config';
import { RascalExchanges, RascalRoutingKeys } from 'common-common/src/rabbitmq';
import models from 'chain-events/services/database/database';

async function main() {
const ceData = {
id: 10,
kind: 'proposal-created',
values: ['0'],
targets: ['0xE710CEd57456D3A16152c32835B5FB4E72D9eA5b'],
endBlock: 16203604,
executor: '0x64c7d40c07EFAbec2AafdC243bF59eaF2195c6dc',
ipfsHash:
'0x3876d28a014bc20432dcc3549ba95710446b98431d84c7f84fde6abe1baf527f',
proposer: '0xb55a948763e0d386b6dEfcD8070a522216AE42b1',
strategy: '0x90Dfd35F4a0BB2d30CDf66508085e33C353475D9',
calldatas: [
'0x00000000000000000000000092d6c1e31e14520e676a687f0a93788b716beff5000000000000000000000000a8541f948411b3f95d9e89e8d339a56a9ed3d00b000000000000000000000000000000000000000000002fa54641bae8aaa00000',
],
signatures: ['transfer(address,address,uint256)'],
startBlock: 16177324,
};
const chainEvent: CWEvent<IEventData> = {
blockNumber: 16170754,
data: <any>ceData,
network: SupportedNetwork.Aave,
chain: 'dydx',
};

const publishJson = await publishRmqMsg(
RABBITMQ_API_URI,
RascalExchanges.ChainEvents,
RascalRoutingKeys.ChainEvents,
chainEvent
);

console.log(publishJson);
}

async function clear() {
try {
let eventsDeleted = 0,
entitiesDeleted = 0;
await models.sequelize.transaction(async (t) => {
const entityId = (
await models.ChainEntity.findOne({
where: { chain: 'dydx', type_id: '10' },
transaction: t,
})
)?.id;

if (entityId) {
eventsDeleted = await models.ChainEvent.destroy({
where: { entity_id: entityId },
transaction: t,
});

entitiesDeleted = await models.ChainEntity.destroy({
where: { id: entityId },
transaction: t,
});
} else {
console.log('Entity does not exist.');
}
});

console.log(
`Events deleted: ${eventsDeleted}\nEntities deleted: ${entitiesDeleted}`
);
} catch (e) {
console.log('Failed to clear - reverted.');
console.error(e);
}

process.exit(1);
}

if (process.argv[2] === 'clear') clear();
else main();
21 changes: 0 additions & 21 deletions packages/chain-events/scripts/testSequelizeQuery.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RascalPublications } from 'common-common/src/rabbitmq/types';

import type { DB } from '../../database/database';

import type { ChainEventInstance } from 'chain-events/services/database/models/chain_event';
import type {
CWEvent,
IChainEntityKind,
Expand Down Expand Up @@ -40,7 +41,10 @@ export default class extends IEventHandler {
* `dbEvent` is the database entry corresponding to the `event`.
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public async handle(event: CWEvent<IChainEventData>, dbEvent) {
public async handle(
event: CWEvent<IChainEventData>,
dbEvent: ChainEventInstance
) {
// eslint-disable-next-line @typescript-eslint/no-shadow
const log = factory.getLogger(
addPrefix(__filename, [event.network, event.chain])
Expand Down Expand Up @@ -173,5 +177,7 @@ export default class extends IEventHandler {
break;
}
}

return dbEvent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@
* Processes events during migration, upgrading from simple notifications to entities.
*/
import type { WhereOptions } from 'sequelize';
import type {
RabbitMQController,
RmqCENotificationCUD,
RmqCETypeCUD,
} from 'common-common/src/rabbitmq';
import { RascalPublications } from 'common-common/src/rabbitmq';
import type { RabbitMQController } from 'common-common/src/rabbitmq';
import { factory, formatFilename } from 'common-common/src/logging';

import type { CWEvent } from '../../../src';
import {
IEventHandler,
EntityEventKind,
eventToEntity,
getUniqueEntityKey,
EntityEventKind,
IEventHandler,
} from '../../../src';
import type { DB } from '../../database/database';
import type {
ChainEventAttributes,
ChainEventInstance,
} from '../../database/models/chain_event';

const log = factory.getLogger(formatFilename(__filename));

export default class extends IEventHandler<ChainEventInstance> {
Expand All @@ -47,48 +43,18 @@ export default class extends IEventHandler<ChainEventInstance> {
fieldValue: string,
eventType: EntityEventKind
) => {
const [dbEventType, created] =
await this._models.ChainEventType.findOrCreate({
where: {
id: `${chain}-${event.data.kind.toString()}`,
chain,
event_network: event.network,
event_name: event.data.kind.toString(),
},
});
log.trace(
`${created ? 'created' : 'found'} chain event type: ${dbEventType.id}`
);

if (created) {
const publishData: RmqCETypeCUD.RmqMsgType = {
chainEventTypeId: dbEventType.id,
cud: 'create',
};

await this._rmqController.safePublish(
publishData,
dbEventType.id,
RascalPublications.ChainEventTypeCUDMain,
{
sequelize: this._models.sequelize,
model: this._models.ChainEventType,
}
);
}

const queryFieldName = `event_data.${fieldName}`;
const queryArgs: WhereOptions<ChainEventAttributes> =
eventType === EntityEventKind.Vote
? {
chain_event_type_id: dbEventType.id,
[queryFieldName]: fieldValue,
// votes will be unique by data rather than by type
event_data: event.data as any,
chain,
}
: {
chain_event_type_id: dbEventType.id,
[queryFieldName]: fieldValue,
chain,
};
const existingEvent = await this._models.ChainEvent.findOne({
where: queryArgs,
Expand All @@ -101,31 +67,12 @@ export default class extends IEventHandler<ChainEventInstance> {
}

log.info('No existing event found, creating new event in db!');
const dbEvent = await this._models.ChainEvent.create({
chain_event_type_id: dbEventType.id,
return await this._models.ChainEvent.create({
block_number: event.blockNumber,
event_data: event.data,
network: event.network,
chain,
});

const formattedEvent: ChainEventAttributes = dbEvent.toJSON();
formattedEvent.ChainEventType = dbEventType.toJSON();

const publishData: RmqCENotificationCUD.RmqMsgType = {
ChainEvent: formattedEvent,
event,
cud: 'create',
};

await this._rmqController.safePublish(
publishData,
dbEvent.id,
RascalPublications.ChainEventNotificationsCUDMain,
{
sequelize: this._models.sequelize,
model: this._models.ChainEvent,
}
);
return dbEvent;
};

const entity = eventToEntity(event.network, event.data.kind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import type { RmqCENotificationCUD } from 'common-common/src/rabbitmq/types';
import { RascalPublications } from 'common-common/src/rabbitmq/types';

import { addPrefix, factory } from '../../../src/logging';
import type { ChainEventAttributes } from '../../database/models/chain_event';
import type { ChainEventInstance } from '../../database/models/chain_event';
import type { DB } from '../../database/database';

import type { CWEvent, IChainEventKind } from 'chain-events/src';
import { IEventHandler } from 'chain-events/src';
import {
EntityEventKind,
eventToEntity,
IEventHandler,
} from 'chain-events/src';

export default class extends IEventHandler {
public readonly name = 'Notification Producer';
Expand All @@ -21,7 +25,7 @@ export default class extends IEventHandler {
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public async handle(event: CWEvent, dbEvent) {
public async handle(event: CWEvent, dbEvent: ChainEventInstance) {
const log = factory.getLogger(
addPrefix(__filename, [event.network, event.chain])
);
Expand All @@ -36,25 +40,24 @@ export default class extends IEventHandler {
return dbEvent;
}

let dbEventType;
try {
dbEventType = await dbEvent.getChainEventType();
if (!dbEventType) {
log.error(`Failed to fetch event type! Ignoring.`);
return;
}
} catch (e) {
log.error(
`Failed to get chain-event type for event: ${JSON.stringify(event)}`
);
if (!dbEvent.entity_id) {
log.info(`No related entity, skipping!`);
return dbEvent;
}

const formattedEvent: ChainEventAttributes = dbEvent.toJSON();
formattedEvent.ChainEventType = dbEventType.toJSON();
const [, eventEntityKind] = eventToEntity(event.network, event.data.kind);
if (
eventEntityKind != EntityEventKind.Create &&
eventEntityKind != EntityEventKind.Complete
) {
log.trace(
`Event does not mark the creation or completion of an entity. Skipping event!`
);
return dbEvent;
}

const publishData: RmqCENotificationCUD.RmqMsgType = {
ChainEvent: formattedEvent,
ChainEvent: dbEvent.toJSON(),
event,
cud: 'create',
};
Expand Down
Loading