Skip to content

Commit

Permalink
Merge pull request #379 from mantlenetworkio/release/v0.8.8
Browse files Browse the repository at this point in the history
Release/v0.8.8
  • Loading branch information
dennisloh95 authored Aug 17, 2023
2 parents 19c8195 + c3ce469 commit 42d4b02
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
6 changes: 3 additions & 3 deletions data-sync-service/src/l1Ingestion/l1Ingestion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ export class L1IngestionService {
.insert()
.into(DaBatches)
.values(insertBatchData)
.onConflict(`("da_hash") DO NOTHING`)
.orIgnore()
.execute().catch(e => {
console.log({
type: 'ERROR',
Expand Down Expand Up @@ -1128,7 +1128,7 @@ export class L1IngestionService {
if (upgrade_data_store_id && upgrade_data_store_id !== 0) {
number += upgrade_data_store_id
}
const dataStoreData = await this.eigenlayerService.getDataStore(fromStoreNumber);
const dataStoreData = await this.eigenlayerService.getDataStore(number);
console.log({
type: 'log',
time: new Date().getTime(),
Expand Down Expand Up @@ -1603,7 +1603,7 @@ export class L1IngestionService {
if (upgrade_data_store_id && upgrade_data_store_id !== 0) {
number += upgrade_data_store_id
}
const dataStoreData = await this.eigenlayerService.getDataStore(fromStoreNumber);
const dataStoreData = await this.eigenlayerService.getDataStore(number);
console.log({
type: 'log',
time: new Date().getTime(),
Expand Down
4 changes: 2 additions & 2 deletions data-sync-service/src/l2Ingestion/l2Ingestion.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { L2IngestionService } from './l2Ingestion.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { L2RelayedMessageEvents, L2SentMessageEvents, L2ToL1 } from 'src/typeorm';
import { L2RelayedMessageEvents, L2SentMessageEvents, L2ToL1, Addresses } from 'src/typeorm';
import { HttpModule } from '@nestjs/axios';
import {
makeGaugeProvider,
Expand All @@ -10,7 +10,7 @@ import {
@Module({
imports: [
HttpModule,
TypeOrmModule.forFeature([L2RelayedMessageEvents, L2SentMessageEvents, L2ToL1]),
TypeOrmModule.forFeature([L2RelayedMessageEvents, L2SentMessageEvents, L2ToL1, Addresses]),
],
providers: [
L2IngestionService,
Expand Down
33 changes: 33 additions & 0 deletions data-sync-service/src/l2Ingestion/l2Ingestion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
L2RelayedMessageEvents,
L2SentMessageEvents,
L2ToL1,
Addresses
} from 'src/typeorm';
import { EntityManager, getConnection, getManager, Repository } from 'typeorm';
import Web3 from 'web3';
Expand Down Expand Up @@ -34,6 +35,8 @@ export class L2IngestionService {
private readonly sentEventsRepository: Repository<L2SentMessageEvents>,
@InjectRepository(L2ToL1)
private readonly l2ToL1Repository: Repository<L2ToL1>,
@InjectRepository(Addresses)
private readonly addressesRepo: Repository<Addresses>,
private readonly httpService: HttpService,
@InjectMetric('msg_nonce')
public metricMsgNonce: Gauge<string>,
Expand Down Expand Up @@ -530,6 +533,36 @@ export class L2IngestionService {
await queryRunner.release();
}
}
async syncFeeVaultBalance() {
const BVM_SequencerFeeVault = '0x4200000000000000000000000000000000000011'
const currentBlockNumber = await this.web3.eth.getBlockNumber()
const balance = await this.web3.eth.getBalance(BVM_SequencerFeeVault, currentBlockNumber);
const dataSource = getConnection();
const queryRunner = dataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
await queryRunner.manager
.createQueryBuilder()
.update(Addresses)
.set({
fetched_coin_balance_block_number: currentBlockNumber,
fetched_coin_balance: balance
})
.where({ hash: Buffer.from(BVM_SequencerFeeVault.slice(2), 'hex') })
.execute()
await queryRunner.commitTransaction();
} catch (error) {
console.log({
type: 'ERROR',
time: new Date().getTime(),
msg: `syncFeeVaultBalance error ${error?.message}`
})
await queryRunner.rollbackTransaction();
} finally {
await queryRunner.release();
}
}
async initMetrics() {
const l2ToL1Item = await this.l2ToL1Repository.findOne({
select: ['msg_nonce'],
Expand Down
5 changes: 5 additions & 0 deletions data-sync-service/src/schedule/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@ export class TasksService {
});
}
}
@Interval(60000)
async syncFeeVaultBalance() {
// BVM_SequencerFeeVault: 0x4200000000000000000000000000000000000011
await this.l2IngestionService.syncFeeVaultBalance();
}

@Interval(3150)
async updateTransactionStats() {
Expand Down
19 changes: 19 additions & 0 deletions data-sync-service/src/typeorm/addresses.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';

@Entity()
export class Addresses {
@PrimaryColumn({ type: 'bytea' })
hash: string;

@Column({ type: 'numeric', precision: 100 })
fetched_coin_balance: string;

@Column({ type: 'int8' })
fetched_coin_balance_block_number: number;

@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
inserted_at: Date;

@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
updated_at: Date;
}
3 changes: 3 additions & 0 deletions data-sync-service/src/typeorm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DaBatches } from './da_batches.entity';
import { DaBatchTransactions } from './da_batch_transactions.entity';
import { TokenPriceHistory } from './token_price_history.entity';
import { TokenPriceRealTime } from './token_price_real_time.entity';
import { Addresses } from './addresses.entity';
import { Last24HrsStats } from './last_24hrs_stats.entity';

const entities = [
Expand All @@ -31,6 +32,7 @@ const entities = [
DaBatchTransactions,
TokenPriceHistory,
TokenPriceRealTime,
Addresses,
Blocks,
TransactionStats,
Last24HrsStats,
Expand All @@ -51,6 +53,7 @@ export {
DaBatchTransactions,
TokenPriceHistory,
TokenPriceRealTime,
Addresses,
Blocks,
TransactionStats,
Last24HrsStats,
Expand Down

0 comments on commit 42d4b02

Please sign in to comment.