Skip to content

Commit

Permalink
Merge branch 'main' into kiriyaga-txfusion-add-enable-eraVM-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga-txfusion authored Jan 24, 2025
2 parents 9c73c29 + 24aecc3 commit e3844d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
10 changes: 9 additions & 1 deletion packages/worker/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SystemContractService } from "./contract/systemContract.service";
@Injectable()
export class AppService implements OnModuleInit, OnModuleDestroy {
private readonly logger: Logger;
private isHandlingBlocksRevert = false;

public constructor(
private readonly counterService: CounterService,
Expand Down Expand Up @@ -43,14 +44,21 @@ export class AppService implements OnModuleInit, OnModuleDestroy {

@OnEvent(BLOCKS_REVERT_DETECTED_EVENT)
protected async handleBlocksRevert({ detectedIncorrectBlockNumber }: { detectedIncorrectBlockNumber: number }) {
if (this.isHandlingBlocksRevert) {
return;
}
this.isHandlingBlocksRevert = true;

this.logger.log("Stopping workers before blocks revert");
await this.stopWorkers();

this.logger.log("Reverting blocks");
await this.blocksRevertService.handleRevert(detectedIncorrectBlockNumber);

this.logger.log("Starting workers after blocks revert");
await this.startWorkers();
this.startWorkers();

this.isHandlingBlocksRevert = false;
}

private startWorkers() {
Expand Down
2 changes: 1 addition & 1 deletion packages/worker/src/block/block.watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class BlockWatcher implements OnModuleInit, OnModuleDestroy {
this.logger.debug(`Last block number is set to: ${this.lastBlockchainBlockNumber}`);

this.blockchainService.on("block", (blockNumber) => {
this.lastBlockchainBlockNumber = Math.max(this.lastBlockchainBlockNumber, blockNumber);
this.lastBlockchainBlockNumber = blockNumber || this.lastBlockchainBlockNumber;
this.blockchainBlocksMetric.set(this.lastBlockchainBlockNumber);
this.logger.debug(`Last block number is updated to: ${this.lastBlockchainBlockNumber}`);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/worker/src/contract/systemContract.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ describe("SystemContractService", () => {
SystemContractService.getSystemContracts().map((contract) => mock<Address>({ address: contract.address }))
);
await systemContractService.addSystemContracts();
expect(addressRepositoryMock.add).toBeCalledTimes(0);
expect(addressRepositoryMock.upsert).toBeCalledTimes(0);
});

it("adds all system contracts if none of them exist in the DB", async () => {
(addressRepositoryMock.find as jest.Mock).mockResolvedValue([]);
await systemContractService.addSystemContracts();
expect(addressRepositoryMock.add).toBeCalledTimes(systemContracts.length);
expect(addressRepositoryMock.upsert).toBeCalledTimes(systemContracts.length);
for (const systemContract of systemContracts) {
expect(addressRepositoryMock.add).toBeCalledWith({
expect(addressRepositoryMock.upsert).toBeCalledWith({
address: systemContract.address,
bytecode: `${systemContract.address}-code`,
});
Expand All @@ -69,10 +69,10 @@ describe("SystemContractService", () => {
existingContractAddresses.map((existingContractAddress) => mock<Address>({ address: existingContractAddress }))
);
await systemContractService.addSystemContracts();
expect(addressRepositoryMock.add).toBeCalledTimes(systemContracts.length - existingContractAddresses.length);
expect(addressRepositoryMock.upsert).toBeCalledTimes(systemContracts.length - existingContractAddresses.length);
for (const systemContract of systemContracts) {
if (!existingContractAddresses.includes(systemContract.address)) {
expect(addressRepositoryMock.add).toBeCalledWith({
expect(addressRepositoryMock.upsert).toBeCalledWith({
address: systemContract.address,
bytecode: `${systemContract.address}-code`,
});
Expand All @@ -93,10 +93,10 @@ describe("SystemContractService", () => {
return `${address}-code`;
});
await systemContractService.addSystemContracts();
expect(addressRepositoryMock.add).toBeCalledTimes(systemContracts.length - notDeployedSystemContracts.length);
expect(addressRepositoryMock.upsert).toBeCalledTimes(systemContracts.length - notDeployedSystemContracts.length);
for (const systemContract of systemContracts) {
if (!notDeployedSystemContracts.includes(systemContract.address)) {
expect(addressRepositoryMock.add).toBeCalledWith({
expect(addressRepositoryMock.upsert).toBeCalledWith({
address: systemContract.address,
bytecode: `${systemContract.address}-code`,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/worker/src/contract/systemContract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SystemContractService {
const bytecode = await this.blockchainService.getCode(contract.address);
// some contract might not exist on the environment yet
if (bytecode !== "0x") {
await this.addressRepository.add({
await this.addressRepository.upsert({
address: contract.address,
bytecode,
});
Expand Down

0 comments on commit e3844d6

Please sign in to comment.