-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
liayoo
commented
Jan 3, 2022
- Updated objects in BlockPool and TransactionPool to Maps
- Related: Use Map instead of Object when additions and removals are frequent #797
this.hashToBlockInfo[currentBlockInfo.block.hash].notarized = true; | ||
this.updateLongestNotarizedChains(this.hashToBlockInfo[currentBlockInfo.block.hash]); | ||
currentBlockInfo.notarized = true; | ||
this.updateLongestNotarizedChains(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
block-pool/index.js
Outdated
} | ||
} | ||
if (!this.numberToBlockSet[blockNumber].size) { | ||
delete this.numberToBlockSet[blockNumber]; | ||
if (!blockHashSet.size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor) what about === 0?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this 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!
Thanks for the review~ Now merging! |