Skip to content

Commit

Permalink
FullChain: Add optional argument for getAccountsTreeChunk
Browse files Browse the repository at this point in the history
- Add optional argument for `getAccountsTreeChunk` to set the block
  limit that will be used to determine if an accounts snapshot can be
  obtained.
- Only limit the snapshots if the block limit is set or is not `null`
  in the `getSnapshot` private method.
  • Loading branch information
jsdanielh committed Aug 23, 2023
1 parent dbfa255 commit 89f1364
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/generic/consensus/full/FullChain.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ class FullChain extends BaseChain {
* @param {string} startPrefix
* @returns {Promise.<?AccountsTreeChunk>}
*/
async getAccountsTreeChunk(blockHash, startPrefix) {
const snapshot = await this._getSnapshot(blockHash);
async getAccountsTreeChunk(blockHash, startPrefix, blockLimit = Policy.NUM_SNAPSHOTS_MAX) {
const snapshot = await this._getSnapshot(blockHash, blockLimit);
return snapshot && await snapshot.getAccountsTreeChunk(startPrefix);
}

Expand Down Expand Up @@ -649,12 +649,12 @@ class FullChain extends BaseChain {
* @param {Hash} blockHash
* @returns {Promise.<?Accounts>}
*/
_getSnapshot(blockHash) {
_getSnapshot(blockHash, blockLimit = Policy.NUM_SNAPSHOTS_MAX) {
// TODO Does this have to be synchronized with pushBlock() ?
return this._synchronizer.push(/*priority*/ 1, async () => {
const block = await this.getBlock(blockHash);
// Check if blockHash is a block on the main chain within the allowed window.
if (!block || this._mainChain.head.height - block.height > Policy.NUM_SNAPSHOTS_MAX) {
if (!block || (blockLimit && this._mainChain.head.height - block.height > Policy.NUM_SNAPSHOTS_MAX)) {
return null;
}

Expand Down

0 comments on commit 89f1364

Please sign in to comment.