Skip to content

Commit

Permalink
fix(bc): fixup headerIndexCache, surprised this didn't come up before
Browse files Browse the repository at this point in the history
  • Loading branch information
danwbyrne committed Jan 20, 2021
1 parent df2cf5a commit 495a959
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/neo-one-node-blockchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
"@types/leveldown": "^4.0.0",
"@types/lodash": "^4.14.138",
"@types/lru-cache": "^5.1.0",
"@types/memdown": "^3.0.0",
"leveldown": "^5.1.1",
"levelup": "4.1.0",
"gulp": "~4.0.2",
"memdown": "^5.0.0",
"tslib": "^1.10.0"
}
}
2 changes: 1 addition & 1 deletion packages/neo-one-node-blockchain/src/HeaderIndexCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class HeaderIndexCache {
return this.getHeaderHashIndexFromCurrent(hashListHashIndex);
}

const hashListIndex = (index - hashListHashIndex) / 2000;
const hashListIndex = index - hashListHashIndex;
const headerHashList = await this.getHeaderHashList(hashListIndex);
if (headerHashList === undefined) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// tslint:disable: readonly-keyword no-object-mutation
import { crypto } from '@neo-one/client-common';
import { Storage } from '@neo-one/node-core';
import { storage as levelStorage } from '@neo-one/node-storage-levelup';
import { randomBytes } from 'crypto';
import LevelUp from 'levelup';
import _ from 'lodash';
import MemDown from 'memdown';
import { HeaderIndexCache } from '../HeaderIndexCache';

const getUInt = () => crypto.hash256(randomBytes(32));
const getUInts = (n: number) => _.range(n).map(getUInt);

describe('headerIndexCache tests', () => {
const context = { messageMagic: 1951352142, validatorsCount: 7 };

let storage: Storage;
let db: any;
beforeEach(() => {
db = new LevelUp(new MemDown());
storage = levelStorage({ db, context });
});

test('headerCacheIndex push 2500 hashes -- retrieves something from different headerHashLists', async () => {
const cache = new HeaderIndexCache({ storage, initCurrentHeaderHashes: [], initStorageCount: 0 });
const testHashes = getUInts(2500);
// tslint:disable-next-line: no-loop-statement
for (const hash of testHashes) {
await cache.push(hash);
}

const [listZeroHash, listTwoThousandHash] = await Promise.all([cache.get(11), cache.get(2005)]);

expect(listZeroHash.equals(testHashes[11])).toEqual(true);
expect(listTwoThousandHash.equals(testHashes[2005])).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Creates the environment for compiling smart contracts, which is then used in the

### neo-one-smart-contract-lib

Defines NEP17 tokens and ICOs.
Defines NEP5 tokens and ICOs.

### neo-one-smart-contract-test

Expand Down

0 comments on commit 495a959

Please sign in to comment.