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

Change objects to Maps #878

Merged
merged 8 commits into from
Jan 4, 2022
Merged

Change objects to Maps #878

merged 8 commits into from
Jan 4, 2022

Conversation

liayoo
Copy link
Contributor

@liayoo liayoo commented Jan 3, 2022

@liayoo liayoo added the enhancement New feature or request label Jan 3, 2022
this.hashToBlockInfo[currentBlockInfo.block.hash].notarized = true;
this.updateLongestNotarizedChains(this.hashToBlockInfo[currentBlockInfo.block.hash]);
currentBlockInfo.notarized = true;
this.updateLongestNotarizedChains();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: no need to pass an argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.. updateLongestNotarizedChains() expects no arguments. I think I updated the function a while ago and forgot to update some of the invocations of it. Thanks for noticing it though!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the explain.

@@ -467,29 +474,31 @@ class BlockPool {
currentBlockInfo.tallied >= totalAtStake * ConsensusConsts.MAJORITY) {
logger.info(`[${LOG_HEADER}] Notarized block: ${currentBlockInfo.block.hash} ` +
`(${currentBlockInfo.block.number} / ${currentBlockInfo.block.epoch})`);
this.hashToBlockInfo[blockHash].notarized = true;
this.updateLongestNotarizedChains(this.hashToBlockInfo[blockHash]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
}
if (!this.numberToBlockSet[blockNumber].size) {
delete this.numberToBlockSet[blockNumber];
if (!blockHashSet.size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor) what about === 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done~

@@ -148,10 +148,10 @@ class TransactionPool {
return null;
}

const addrToTxList = JSON.parse(JSON.stringify(this.transactions));
const addrToTxList = _.cloneDeep(this.transactions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

tx-pool/index.js Outdated
return !(addrToTxSet[address].has(tx.hash));
})
for (const [address, txList] of addrToTxSet.entries()) {
const sizeBefore = txList ? txList.length : 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: could txList be not a Set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed some bugs in the logic & updated the variable names to make them clearer, thanks!

@liayoo
Copy link
Contributor Author

liayoo commented Jan 4, 2022

Addressed all comments, PTAL @platfowner

if (this.transactions.has(address)) {
const txList = this.transactions.get(address);
const sizeBefore = txList.length;
this.transactions.set(address, txList.filter((tx) => !invalidTxSet.has(tx.hash)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@platfowner platfowner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for the nice refactoring!

@liayoo
Copy link
Contributor Author

liayoo commented Jan 4, 2022

Thanks for the review~ Now merging!

@liayoo liayoo merged commit 9c4eaa4 into develop Jan 4, 2022
@platfowner platfowner deleted the feature/liayoo/obj-to-map branch July 14, 2023 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants