Skip to content

Commit

Permalink
fix: 🐛 function for bgtask_calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
waynewyang committed Jan 2, 2024
1 parent d2c93f7 commit 05f8c8e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lerna-debug.log*
/coverage
/.nyc_output

/dist-test
# IDEs and editors
/.idea
.project
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://github.com/dataswap/messagehub#readme",
"dependencies": {
"@dataswapjs/dataswapjs": "^0.4.0",
"@dataswapjs/dataswapjs": "^0.5.2",
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/backgroundTask/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export class Context implements IContext {
replayStrategyOptions: {
replay: true,
//TODO:add all evm address
replayStrategy: new AddressesFilterReplayStrategy([]),
replayStrategy: new AddressesFilterReplayStrategy([
'f410fai7exftlsq6igc35jsxij7twcza3feadlmtrjla',
]),
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/backgroundTask/decoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export class Decoder implements IDecoder {
*/
getPendingDataswapMessages(pendingChainInfo: Chain): DataswapMessage[] {
try {
let res: DataswapMessage[];
const res: DataswapMessage[] = [];
pendingChainInfo.messages.forEach((msg) => {
//TODO:To check address format ,add toEthaddress function
switch (msg.Msg.To) {
case this.context.evm.datasetMetadata.getContractAddress():
case 'f410fai7exftlsq6igc35jsxij7twcza3feadlmtrjla':
res.push(this.context.evm.datasetMetadata.decodeMessage(msg).data);
break;

Expand Down
35 changes: 20 additions & 15 deletions src/backgroundTask/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,29 @@ export class BackgroundTask implements IBackgroundTask {
const chainInfo = await this.syncer.getPendingChainInfo(
this.syncHeight,
);
if (chainInfo !== null) {
//step 2.1: decode the dataswapMessages from the chainInfo
const dataswapMessages =
this.decoder.getPendingDataswapMessages(chainInfo);

//step 2.1: decode the dataswapMessages from the chainInfo
const dataswapMessages =
this.decoder.getPendingDataswapMessages(chainInfo);
if (dataswapMessages) {
//step 2.2: select the special params from the dataswapMessages
const selectedParams =
this.decoder.getPendingSelectedParams(dataswapMessages);

//step 2.2: select the special params from the dataswapMessages
const selectedParams =
this.decoder.getPendingSelectedParams(dataswapMessages);
console.log(selectedParams);
//step 3.1 store selectedParams
await this.storager.storeSelectedParams(selectedParams);

//step 3.1 store selectedParams
await this.storager.storeSelectedParams(selectedParams);

//step 3.2 store dataswapMessages
await this.storager.storeDataswapMessages(dataswapMessages);

//step 3.3 store chainInfo
await this.storager.storeChainInfo(chainInfo);
//step 3.2 store dataswapMessages
await this.storager.storeDataswapMessages(dataswapMessages);
}
//step 3.3 store chainInfo
await this.storager.storeChainInfo(chainInfo);
} else if (this.syncHeight < chainHeadHeight) {
this.syncHeight++;
} else {
delay(3000);
}
} else if (this.syncHeight < chainHeadHeight) {
this.syncHeight++;
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/backgroundTask/provider/backgroundTask.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
********************************************************************************/

import { Injectable, OnModuleInit } from '@nestjs/common';
import { mainBgTask, calibrationBgTask } from '../../config/backgroundTask';
import { calibrationBgTask } from '../../config/backgroundTask';
// import { mainBgTask, calibrationBgTask } from '../../config/backgroundTask';

/**
* Service responsible for synchronizing with the blockchain.
Expand All @@ -38,9 +39,9 @@ export class BackgroundTaskService implements OnModuleInit {
*/
private async startBackgroundTask() {
try {
const mainBgTaskPromise = mainBgTask.start();
// const mainBgTaskPromise = mainBgTask.start();
const calibrationBgTaskPromise = calibrationBgTask.start();
await Promise.all([mainBgTaskPromise, calibrationBgTaskPromise]);
await Promise.all([calibrationBgTaskPromise]);
} catch (error) {
throw new Error(`Error in the background task:${error}`);
}
Expand Down
4 changes: 3 additions & 1 deletion src/backgroundTask/storager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export class Storager implements IStorager {
conditions: [{ Height: height }],
});
if (!syncedTipsetsRes.ok) {
throw new Error(`isHeightAlreadySynced error:${syncedTipsetsRes.error}`);
return false;
//TODO
// throw new Error(`isHeightAlreadySynced error:${syncedTipsetsRes.error}`);
}
if (syncedTipsetsRes.data.length === 0) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/backgroundTask/syncer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export class Syncer implements ISyncer {
if (!res.ok) {
throw new Error(res.error);
}
if (res.data.tipset.Height < height) {
res.data = null as Chain;
}
return res.data;
}
}
2 changes: 1 addition & 1 deletion src/config/backgroundTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const calibrationConfig: Config = {
apiAddress: process.env.CALIBRATION_LOTUS_API_ENDPOINT as string,
token: process.env.CALIBRATION_LOTUS_TOKEN as string,
mongoUrl: process.env.CALIBRATION_MONGO_URL as string,
startHeight: 1210900,
startHeight: 1213437,
evm: {
datasetMetadata: datasetMetadataEvm_Calibration,
},
Expand Down

0 comments on commit 05f8c8e

Please sign in to comment.