Skip to content

Commit

Permalink
Adding Boottime Feature
Browse files Browse the repository at this point in the history
Signed-off-by: Web-Dev-Manoj <manojbhargav.mv@gmail.com>
  • Loading branch information
Web-Dev-Manoj committed Oct 16, 2023
1 parent bed8e70 commit f2a7d03
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 47 deletions.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,73 @@ $ npm run build

## Run Hyperledger Explorer

### Bootup Mode

The Bootup Mode feature allows you to specify how many blocks should be loaded when starting the Hyperledger Explorer. You can choose from the below two modes:

- **ALL**: Load all available blocks.
- **CUSTOM**: Load a specific number of blocks as configured in the `config.json` file.

To set the Bootup Mode, update the `app/platform/fabric/config.json` file in your project with the desired mode.

- **ALL**
```json
{
"network-configs": {
"test-network": {
"name": "Test Network",
"profile": "./connection-profile/test-network.json",
"enableAuthentication": false,
"bootMode": "ALL",
"noOfBlocks": 0
}
},
"license": "Apache-2.0"
}
```
**Note:** In ALL Mode, Please make sure that `noOfBlocks` paramater is set to `0`

- **CUSTOM**

The `noOfBlocks` parameter allows you to specify the number of blocks that the Hyperledger Explorer will use when booting up. If you are using custom mode and want to control the number of blocks, make sure to pass your desired value to the `noOfBlocks` parameter.

```json
{
"network-configs": {
"test-network": {
"name": "Test Network",
"profile": "./connection-profile/test-network.json",
"enableAuthentication": false,
"bootMode": "CUSTOM",
"noOfBlocks": 5
}
},
"license": "Apache-2.0"
}
```

**Note:** Setting `noOfBlocks` to `0` will load Hyperledger Explorer with the latest block.

### Bootup Mode example for reference

Let's say your blockchain network consists of a total of 20 blocks, numbered from 1 to 20. You are interested in loading only the latest 5 blocks, which are blocks 20, 19, 18, 17, and 16.
Here is an example of how you can configure Hyperledger Explorer to achieve this:
```json
{
"network-configs": {
"test-network": {
"name": "Test Network",
"profile": "./connection-profile/test-network.json",
"enableAuthentication": false,
"bootMode": "CUSTOM",
"noOfBlocks": 5
}
},
"license": "Apache-2.0"
}
```
### Run Locally in the Same Location
* Modify `app/explorerconfig.json` to update sync settings.
Expand Down
74 changes: 59 additions & 15 deletions app/persistence/fabric/CRUDService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,36 @@ export class CRUDService {
let sqlTxList = ` select t.creator_msp_id,t.txhash,t.type,t.chaincodename,t.createdt,channel.name as channelName from transactions as t
inner join channel on t.channel_genesis_hash=channel.channel_genesis_hash and t.network_name = channel.network_name where t.blockid >= $1 and t.id >= $2 and
t.channel_genesis_hash = $3 and t.network_name = $4 and t.createdt between $5 and $6 `;
const values = [blockNum, txid, channel_genesis_hash, network_name, from, to, page, size];
const values = [
blockNum,
txid,
channel_genesis_hash,
network_name,
from,
to,
page,
size
];
if (page == 1) {
let sqlTxCount: string;
const filterValues = [blockNum, txid, channel_genesis_hash, network_name, from, to];
const filterValues = [
blockNum,
txid,
channel_genesis_hash,
network_name,
from,
to
];
sqlTxCount = ` select count(*) from transactions as t inner join channel on t.channel_genesis_hash=channel.channel_genesis_hash and t.network_name = channel.network_name
where t.blockid >= $1 and t.id >= $2 and t.channel_genesis_hash = $3 and t.network_name = $4 and t.createdt between $5 and $6 `
where t.blockid >= $1 and t.id >= $2 and t.channel_genesis_hash = $3 and t.network_name = $4 and t.createdt between $5 and $6 `;
if (orgs && orgs.length > 0) {
sqlTxCount += ' and t.creator_msp_id = ANY($7)';
filterValues.push(orgs);
}
countOfTxns = await this.sql.getRowsCountBySQlQuery(sqlTxCount, filterValues)
countOfTxns = await this.sql.getRowsCountBySQlQuery(
sqlTxCount,
filterValues
);
}
if (orgs && orgs.length > 0) {
sqlTxList += ' and t.creator_msp_id = ANY($9)';
Expand All @@ -124,7 +143,7 @@ export class CRUDService {
let response = {
txnsData: txnsData,
noOfpages: Math.ceil(countOfTxns / size)
}
};

return response;
}
Expand Down Expand Up @@ -162,7 +181,7 @@ export class CRUDService {
byOrgs = ' and creator_msp_id = ANY($7)';
}
let sqlBlockTxList;
if(orgs == null || orgs.length == 0 ) {
if (orgs == null || orgs.length == 0) {
sqlBlockTxList = `SELECT a.* FROM (
SELECT (SELECT c.name FROM channel c WHERE c.channel_genesis_hash =$1 AND c.network_name = $2)
as channelname, blocks.blocknum,blocks.txcount ,blocks.datahash ,blocks.blockhash ,blocks.prehash,blocks.createdt, blocks.blksize, (
Expand All @@ -188,18 +207,18 @@ export class CRUDService {
filterValues.push(orgs);
byOrgs = ' and creator_msp_id = ANY($5)';
}
if(orgs == null || orgs.length == 0 ) {
if (orgs == null || orgs.length == 0) {
sqlBlockTxCount = `SELECT COUNT(DISTINCT blocks.blocknum) FROM blocks
JOIN transactions ON blocks.blocknum = transactions.blockid
WHERE blockid = blocks.blocknum ${byOrgs} AND
blocknum >= 0 AND blocks.channel_genesis_hash = $1 AND blocks.network_name = $2 AND
blocks.createdt between $3 AND $4`
blocks.createdt between $3 AND $4`;
} else {
sqlBlockTxCount = `SELECT COUNT(DISTINCT blocks.blocknum) FROM blocks
JOIN transactions ON blocks.blocknum = transactions.blockid
WHERE blockid = blocks.blocknum ${byOrgs}
AND blocks.channel_genesis_hash = $1 and blocks.network_name = $2 AND blocks.createdt between $3 AND $4
AND transactions.creator_msp_id IS NOT NULL AND transactions.creator_msp_id != ' ' AND length(creator_msp_id) > 0`
AND transactions.creator_msp_id IS NOT NULL AND transactions.creator_msp_id != ' ' AND length(creator_msp_id) > 0`;
}
countOfBlocks = await this.sql.getRowsCountBySQlQuery(
sqlBlockTxCount,
Expand Down Expand Up @@ -326,7 +345,12 @@ export class CRUDService {
await this.sql.saveRow('transactions', transaction);
await this.sql.updateBySql(
'update chaincodes set txcount =txcount+1 where channel_genesis_hash=$1 and network_name = $2 and name=$3 and version=$4',
[transaction.channel_genesis_hash, network_name, transaction.chaincodename, chaincodeversion]
[
transaction.channel_genesis_hash,
network_name,
transaction.chaincodename,
chaincodeversion
]
);
await this.sql.updateBySql(
'update channel set trans =trans+1 where channel_genesis_hash=$1 and network_name = $2 ',
Expand Down Expand Up @@ -540,6 +564,21 @@ export class CRUDService {
}
// Orderer BE-303

/**
* Returns whether the block is available in the DB or not
*
* @param {*} blockHeight
* @returns
* @memberof CRUDService
*/
async isBlockAvailableInDB(channel_genesis_hash: string, blockHeight: number) {
const count: any = await this.sql.getRowsBySQlCase(
`SELECT COUNT(*) FROM blocks WHERE channel_genesis_hash= $1 AND blocknum = $2`,
[channel_genesis_hash, blockHeight]
);
return count.count > 0;
}

/**
*
* Returns the block by block number.
Expand All @@ -549,20 +588,25 @@ export class CRUDService {
* @returns
* @memberof CRUDService
*/
async getBlockByBlocknum(network_name: any, channel_genesis_hash: any, blockNo: any) {
async getBlockByBlocknum(
network_name: any,
channel_genesis_hash: any,
blockNo: any
) {
const sqlBlockTxList = `select a.* from (
select (select c.name from channel c where c.channel_genesis_hash =$1 and c.network_name = $2)
as channelname, blocks.blocknum,blocks.txcount ,blocks.datahash ,blocks.blockhash ,blocks.prehash,blocks.createdt, blocks.blksize, (
SELECT array_agg(txhash) as txhash FROM transactions where blockid = $3 and
channel_genesis_hash = $1 and network_name = $2) from blocks where
blocks.channel_genesis_hash =$1 and blocks.network_name = $2 and blocknum = $3) a where a.txhash IS NOT NULL`;

const row: any = await this.sql.getRowsBySQlCase(
sqlBlockTxList,
[channel_genesis_hash, network_name, blockNo]);
const row: any = await this.sql.getRowsBySQlCase(sqlBlockTxList, [
channel_genesis_hash,
network_name,
blockNo
]);
return row;
}

}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/platform/fabric/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"network-configs": {
"test-network": {
"name": "Test Network",
"profile": "./connection-profile/test-network.json"
"profile": "./connection-profile/test-network.json",
"bootMode": "ALL",
"noOfBlocks": 0
}
},
"license": "Apache-2.0"
Expand Down
Loading

0 comments on commit f2a7d03

Please sign in to comment.