Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added condition to avoid shard for INIT_DID trx #71

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/helpers/dbHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ END $$ LANGUAGE plpgsql;
body: Transaction
) {
const transactionObj = body.toObject()
if (ns == 'INIT_DID') {
shardId = -1
}
log.debug(`putValueInStorageTable() namespace=${ns}, namespaceShardId=${shardId}
, skey=${skey}, jsonValue=${transactionObj}`)
const sql = `INSERT INTO storage_node (namespace, namespace_shard_id, namespace_id, ts, skey, dataschema, payload)
Expand Down
24 changes: 11 additions & 13 deletions src/services/messaging/IndexStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export class IndexStorage {

This is POSTGRES
*/
public async unpackBlockToInboxes(mb: Block, shardSet: Set<number>) {
public async unpackBlockToTransactions(mb: Block, shardSet: Set<number>) {
// this is the list of shards that we support on this node
const nodeShards = this.storageContractState.getNodeShards()
this.log.debug('storage node supports %s shards: %o', nodeShards.size, nodeShards)
const shardsToProcess = Coll.intersectSet(shardSet, nodeShards)
this.log.debug('block %s has %d inboxes to unpack', mb.getTs(), shardsToProcess)
if (shardsToProcess.size == 0) {
this.log.debug('block %s has %d transactions to unpack', mb.getTs(), shardsToProcess)
if (shardsToProcess.size == 0 && !shardSet.has(-1)) {
this.log.debug('finished')
return
}
Expand All @@ -51,26 +51,24 @@ export class IndexStorage {
}
const currentNodeId = this.valContractState.nodeId
for (let i = 0; i < mb.getTxobjList().length; i++) {
const feedItem = mb.getTxobjList()[i]
const transaction = mb.getTxobjList()[i]
const targetWallets: string[] = MessageBlockUtil.calculateRecipients(mb, i)
for (let i1 = 0; i1 < targetWallets.length; i1++) {
const targetAddr = targetWallets[i1]
const targetShard = BlockUtil.calculateAffectedShard(
targetAddr,
this.storageContractState.shardCount
)
if (!shardsToProcess.has(targetShard)) {
const targetShard =
transaction.getTx().getCategory() == 'INIT_DID'
? -1
: BlockUtil.calculateAffectedShard(targetAddr, this.storageContractState.shardCount)
if (!shardsToProcess.has(targetShard) && transaction.getTx().getCategory() !== 'INIT_DID') {
continue
}
// const trx = feedItem.getTx()
// console.log(trx.toObject())
await this.putPayloadToInbox(
feedItem.getTx().getCategory(),
transaction.getTx().getCategory(),
targetShard,
targetAddr,
tsString,
currentNodeId,
feedItem.getTx()
transaction.getTx()
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/services/messaging/storageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default class StorageNode implements Consumer<QItem>, StorageContractList

// check for validation
const parsedBlock = BlockUtil.parseBlock(mb)
const blockObject = parsedBlock.toObject()
const validatorSet = new Set(this.valContractState.getAllNodesMap().keys())
const checkResult = await BlockUtil.checkBlockFinalized(
parsedBlock,
Expand All @@ -99,7 +98,7 @@ export default class StorageNode implements Consumer<QItem>, StorageContractList
return false
}
// send block
await this.indexStorage.unpackBlockToInboxes(parsedBlock, shardSet)
await this.indexStorage.unpackBlockToTransactions(parsedBlock, shardSet)
}

public async handleReshard(
Expand Down Expand Up @@ -147,7 +146,7 @@ export default class StorageNode implements Consumer<QItem>, StorageContractList
Coll.setToArray(shardsToAdd),
Coll.setToArray(shardsToAddFromBlock)
)
await this.indexStorage.unpackBlockToInboxes(mb, shardsToAddFromBlock)
await this.indexStorage.unpackBlockToTransactions(mb, shardsToAddFromBlock)
}
)
await this.blockStorage.saveNodeShards(newShards)
Expand Down