Skip to content

Commit

Permalink
[Relay] Apply sub graph db of mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Apr 23, 2024
1 parent 3745b7d commit a11e2d9
Show file tree
Hide file tree
Showing 33 changed files with 979 additions and 111 deletions.
24 changes: 17 additions & 7 deletions packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ database:
connectionTimeoutMillis: 2000
max: 100

graph:
host: "${GRAPH_DATABASE_HOST}"
user: "${GRAPH_DATABASE_USER}"
password: "${GRAPH_DATABASE_PASSWORD}"
database: "${GRAPH_DATABASE_NAME}"
scheme: "${GRAPH_DATABASE_SCHEME}"
port: "${GRAPH_DATABASE_PORT}"
graph_sidechain:
host: "${GRAPH_SIDECHAIN_DATABASE_HOST}"
user: "${GRAPH_SIDECHAIN_DATABASE_USER}"
password: "${GRAPH_SIDECHAIN_DATABASE_PASSWORD}"
database: "${GRAPH_SIDECHAIN_DATABASE_NAME}"
scheme: "${GRAPH_SIDECHAIN_DATABASE_SCHEME}"
port: "${GRAPH_SIDECHAIN_DATABASE_PORT}"
connectionTimeoutMillis: 2000
max: 100

graph_mainchain:
host: "${GRAPH_MAINCHAIN_DATABASE_HOST}"
user: "${GRAPH_MAINCHAIN_DATABASE_USER}"
password: "${GRAPH_MAINCHAIN_DATABASE_PASSWORD}"
database: "${GRAPH_MAINCHAIN_DATABASE_NAME}"
scheme: "${GRAPH_MAINCHAIN_DATABASE_SCHEME}"
port: "${GRAPH_MAINCHAIN_DATABASE_PORT}"
connectionTimeoutMillis: 2000
max: 100

Expand Down
24 changes: 17 additions & 7 deletions packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ database:
connectionTimeoutMillis: 2000
max: 100

graph:
host: "${GRAPH_DATABASE_HOST}"
user: "${GRAPH_DATABASE_USER}"
password: "${GRAPH_DATABASE_PASSWORD}"
database: "${GRAPH_DATABASE_NAME}"
scheme: "${GRAPH_DATABASE_SCHEME}"
port: "${GRAPH_DATABASE_PORT}"
graph_sidechain:
host: "${GRAPH_SIDECHAIN_DATABASE_HOST}"
user: "${GRAPH_SIDECHAIN_DATABASE_USER}"
password: "${GRAPH_SIDECHAIN_DATABASE_PASSWORD}"
database: "${GRAPH_SIDECHAIN_DATABASE_NAME}"
scheme: "${GRAPH_SIDECHAIN_DATABASE_SCHEME}"
port: "${GRAPH_SIDECHAIN_DATABASE_PORT}"
connectionTimeoutMillis: 2000
max: 100

graph_mainchain:
host: "${GRAPH_MAINCHAIN_DATABASE_HOST}"
user: "${GRAPH_MAINCHAIN_DATABASE_USER}"
password: "${GRAPH_MAINCHAIN_DATABASE_PASSWORD}"
database: "${GRAPH_MAINCHAIN_DATABASE_NAME}"
scheme: "${GRAPH_MAINCHAIN_DATABASE_SCHEME}"
port: "${GRAPH_MAINCHAIN_DATABASE_PORT}"
connectionTimeoutMillis: 2000
max: 100

Expand Down
20 changes: 14 additions & 6 deletions packages/relay/env/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ DATABASE_PASSWORD=12345678
DATABASE_PORT=5432

# GRAPH DATABASE INFO
GRAPH_DATABASE_HOST=127.0.0.1
GRAPH_DATABASE_USER=agora
GRAPH_DATABASE_NAME=graph
GRAPH_DATABASE_SCHEME=sgd2
GRAPH_DATABASE_PASSWORD=12345678
GRAPH_DATABASE_PORT=5432
GRAPH_SIDECHAIN_DATABASE_HOST=127.0.0.1
GRAPH_SIDECHAIN_DATABASE_USER=agora
GRAPH_SIDECHAIN_DATABASE_NAME=graph
GRAPH_SIDECHAIN_DATABASE_SCHEME=sgd2
GRAPH_SIDECHAIN_DATABASE_PASSWORD=12345678
GRAPH_SIDECHAIN_DATABASE_PORT=5432

# GRAPH DATABASE INFO
GRAPH_MAINCHAIN_DATABASE_HOST=127.0.0.1
GRAPH_MAINCHAIN_DATABASE_USER=agora
GRAPH_MAINCHAIN_DATABASE_NAME=graph
GRAPH_MAINCHAIN_DATABASE_SCHEME=sgd3
GRAPH_MAINCHAIN_DATABASE_PASSWORD=12345678
GRAPH_MAINCHAIN_DATABASE_PORT=5432

# 0xDc245797409fb79446523Fa1A4ca97294eef22EE
DEPLOYER=0x2b5d5cc406b66c0398d0b8327d340cb4f6e30540621802e115506fe001398ba3
Expand Down
49 changes: 37 additions & 12 deletions packages/relay/src/DefaultServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { StorePurchaseRouter } from "./routers/StorePurchaseRouter";
import { TokenRouter } from "./routers/TokenRouter";
import { GraphStorage } from "./storage/GraphStorage";
import { RelayStorage } from "./storage/RelayStorage";
import { HistoryRouter } from "./routers/HistoryRouter";

export class DefaultServer extends WebService {
private readonly config: Config;
Expand All @@ -32,21 +33,24 @@ export class DefaultServer extends WebService {
public readonly paymentRouter: PaymentRouter;
public readonly relaySigners: RelaySigners;
public readonly storage: RelayStorage;
public readonly graph: GraphStorage;
public readonly graph_sidechain: GraphStorage;
public readonly graph_mainchain: GraphStorage;
private readonly sender: INotificationSender;
public readonly etcRouter: ETCRouter;
public readonly purchaseRouter: StorePurchaseRouter;
public readonly tokenRouter: TokenRouter;
public readonly phoneLinkRouter: PhoneLinkRouter;
public readonly bridgeRouter: BridgeRouter;
public readonly historyRouter: HistoryRouter;

private readonly metrics: Metrics;

constructor(
config: Config,
contractManager: ContractManager,
storage: RelayStorage,
graph: GraphStorage,
graph_sidechain: GraphStorage,
graph_mainchain: GraphStorage,
schedules?: Scheduler[],
handler?: INotificationEventHandler
) {
Expand Down Expand Up @@ -77,7 +81,8 @@ export class DefaultServer extends WebService {
this.config = config;
this.contractManager = contractManager;
this.storage = storage;
this.graph = graph;
this.graph_sidechain = graph_sidechain;
this.graph_mainchain = graph_mainchain;
this.sender = new NotificationSender(this.config, handler);
this.relaySigners = new RelaySigners(this.config);
this.defaultRouter = new DefaultRouter(this, this.config, this.contractManager, this.metrics);
Expand All @@ -87,7 +92,8 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners
);
this.shopRouter = new ShopRouter(
Expand All @@ -96,7 +102,8 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners,
this.sender
);
Expand All @@ -106,7 +113,8 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners,
this.sender
);
Expand All @@ -116,7 +124,8 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.sender
);
this.purchaseRouter = new StorePurchaseRouter(
Expand All @@ -125,15 +134,17 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph
this.graph_sidechain,
this.graph_mainchain
);
this.tokenRouter = new TokenRouter(
this,
this.config,
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners
);
this.phoneLinkRouter = new PhoneLinkRouter(
Expand All @@ -142,7 +153,8 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners
);

Expand All @@ -152,7 +164,19 @@ export class DefaultServer extends WebService {
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners
);

this.historyRouter = new HistoryRouter(
this,
this.config,
this.contractManager,
this.metrics,
this.storage,
this.graph_sidechain,
this.graph_mainchain,
this.relaySigners
);

Expand All @@ -164,7 +188,7 @@ export class DefaultServer extends WebService {
contractManager: this.contractManager,
storage: this.storage,
metrics: this.metrics,
graph: this.graph,
graph: this.graph_sidechain,
signers: this.relaySigners,
})
);
Expand Down Expand Up @@ -198,6 +222,7 @@ export class DefaultServer extends WebService {
this.tokenRouter.registerRoutes();
this.phoneLinkRouter.registerRoutes();
this.bridgeRouter.registerRoutes();
this.historyRouter.registerRoutes();

for (const m of this.schedules) await m.start();

Expand Down
12 changes: 8 additions & 4 deletions packages/relay/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class Config implements IConfig {

public database: DatabaseConfig;

public graph: DatabaseConfig;
public graph_sidechain: DatabaseConfig;
public graph_mainchain: DatabaseConfig;

public logging: LoggingConfig;

Expand All @@ -27,7 +28,8 @@ export class Config implements IConfig {
constructor() {
this.server = new ServerConfig();
this.database = new DatabaseConfig();
this.graph = new DatabaseConfig();
this.graph_sidechain = new DatabaseConfig();
this.graph_mainchain = new DatabaseConfig();
this.logging = new LoggingConfig();
this.scheduler = new SchedulerConfig();
this.relay = new RelayConfig();
Expand Down Expand Up @@ -70,7 +72,8 @@ export class Config implements IConfig {
}) as IConfig;
this.server.readFromObject(cfg.server);
this.database.readFromObject(cfg.database);
this.graph.readFromObject(cfg.graph);
this.graph_sidechain.readFromObject(cfg.graph_sidechain);
this.graph_mainchain.readFromObject(cfg.graph_mainchain);
this.logging.readFromObject(cfg.logging);
this.scheduler.readFromObject(cfg.scheduler);
this.relay.readFromObject(cfg.relay);
Expand Down Expand Up @@ -515,7 +518,8 @@ export interface IMetricsConfig {
export interface IConfig {
server: IServerConfig;
database: IDatabaseConfig;
graph: DatabaseConfig;
graph_sidechain: DatabaseConfig;
graph_mainchain: DatabaseConfig;
logging: ILoggingConfig;
scheduler: ISchedulerConfig;
relay: IRelayConfig;
Expand Down
5 changes: 3 additions & 2 deletions packages/relay/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async function main() {

await ContractUtils.delay(1000);
const storage = await RelayStorage.make(config.database);
const graph = await GraphStorage.make(config.graph);
const graph_sidechain = await GraphStorage.make(config.graph_sidechain);
const graph_mainchain = await GraphStorage.make(config.graph_mainchain);

const schedulers: Scheduler[] = [];
if (config.scheduler.enable) {
Expand Down Expand Up @@ -60,7 +61,7 @@ async function main() {

const contractManager = new ContractManager(config);
await contractManager.attach();
server = new DefaultServer(config, contractManager, storage, graph, schedulers);
server = new DefaultServer(config, contractManager, storage, graph_sidechain, graph_mainchain, schedulers);
return server.start().catch((error: any) => {
// handle specific listen errors with friendly messages
switch (error.code) {
Expand Down
9 changes: 6 additions & 3 deletions packages/relay/src/routers/BridgeRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ export class BridgeRouter {
private readonly metrics: Metrics;
private readonly relaySigners: RelaySigners;
private storage: RelayStorage;
private graph: GraphStorage;
private graph_sidechain: GraphStorage;
private graph_mainchain: GraphStorage;

constructor(
service: WebService,
config: Config,
contractManager: ContractManager,
metrics: Metrics,
storage: RelayStorage,
graph: GraphStorage,
graph_sidechain: GraphStorage,
graph_mainchain: GraphStorage,
relaySigners: RelaySigners
) {
this.web_service = service;
Expand All @@ -39,7 +41,8 @@ export class BridgeRouter {
this.metrics = metrics;

this.storage = storage;
this.graph = graph;
this.graph_sidechain = graph_sidechain;
this.graph_mainchain = graph_mainchain;
this.relaySigners = relaySigners;
}

Expand Down
9 changes: 6 additions & 3 deletions packages/relay/src/routers/ETCRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class ETCRouter {
private readonly contractManager: ContractManager;
private readonly metrics: Metrics;
private storage: RelayStorage;
private graph: GraphStorage;
private graph_sidechain: GraphStorage;
private graph_mainchain: GraphStorage;
private readonly sender: INotificationSender;

constructor(
Expand All @@ -28,15 +29,17 @@ export class ETCRouter {
contractManager: ContractManager,
metrics: Metrics,
storage: RelayStorage,
graph: GraphStorage,
graph_sidechain: GraphStorage,
graph_mainchain: GraphStorage,
sender: INotificationSender
) {
this.web_service = service;
this.config = config;
this.contractManager = contractManager;
this.metrics = metrics;
this.storage = storage;
this.graph = graph;
this.graph_sidechain = graph_sidechain;
this.graph_mainchain = graph_mainchain;
this.sender = sender;
}

Expand Down
Loading

0 comments on commit a11e2d9

Please sign in to comment.