Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/api-development/source/controllers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

return {
data: {
constants: this.configuration.getMilestone(this.stateStore.getHeight()),
constants: this.configuration.getMilestone(this.stateStore.getBlockNumber()),

Check warning on line 33 in packages/api-development/source/controllers/node.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-development/source/controllers/node.ts#L33

Added line #L33 was not covered by tests
core: {
version: this.app.version(),
},
Expand Down
6 changes: 3 additions & 3 deletions packages/api-development/source/controllers/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
(_, index) => roundValidators[this.proposerCalculator.getValidatorIndex(index)],
);

const height = this.stateStore.getHeight();
const blockNumber = this.stateStore.getBlockNumber();

Check warning on line 26 in packages/api-development/source/controllers/round.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-development/source/controllers/round.ts#L26

Added line #L26 was not covered by tests

return {
height,
...this.roundCalculator.calculateRound(height),
blockNumber,
...this.roundCalculator.calculateRound(blockNumber),

Check warning on line 30 in packages/api-development/source/controllers/round.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-development/source/controllers/round.ts#L29-L30

Added lines #L29 - L30 were not covered by tests
// Map the round validator set (static, vote-weighted, etc.) to actual proposal order
validators: orderedValidators.map((validator) => ({
// rank: validator.getVoteBalance().toFixed(),
Expand Down
2 changes: 1 addition & 1 deletion packages/api-evm/source/actions/eth-block-number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe<{

beforeEach(async (context) => {
context.store = {
getHeight() {
getBlockNumber() {
return height;
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/api-evm/source/actions/eth-block-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export class EthBlockNumberAction implements Contracts.Api.RPC.Action {
};

public async handle(parameters: []): Promise<string> {
return `0x${this.stateStore.getHeight().toString(16)}`;
return `0x${this.stateStore.getBlockNumber().toString(16)}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
};

public async handle(parameters: [string]): Promise<null> {
if (this.stateStore.getHeight() < Number(parameters[0])) {
if (this.stateStore.getBlockNumber() < Number(parameters[0])) {

Check warning on line 21 in packages/api-evm/source/actions/eth-get-uncle-by-block-number-and-index.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-evm/source/actions/eth-get-uncle-by-block-number-and-index.ts#L21

Added line #L21 was not covered by tests
throw new Exceptions.RpcError("Block not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
};

public async handle(parameters: [string]): Promise<string> {
if (this.stateStore.getHeight() < Number(parameters[0])) {
if (this.stateStore.getBlockNumber() < Number(parameters[0])) {

Check warning on line 21 in packages/api-evm/source/actions/eth-get-uncle-count-by-block-number.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-evm/source/actions/eth-get-uncle-count-by-block-number.ts#L21

Added line #L21 was not covered by tests
throw new Exceptions.RpcError("Block not found");
}

Expand Down
2 changes: 1 addition & 1 deletion packages/api-evm/source/utils/resolve-block-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
case "finalized":
case "latest":
case "safe": {
return stateStore.getHeight();
return stateStore.getBlockNumber();

Check warning on line 15 in packages/api-evm/source/utils/resolve-block-tag.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-evm/source/utils/resolve-block-tag.ts#L15

Added line #L15 was not covered by tests
}
default: {
throw new Error("invalid blockTag:" + tag);
Expand Down
2 changes: 1 addition & 1 deletion packages/api-evm/source/validation/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

export const makeKeywords = (stateStore: Contracts.State.Store) => {
const currentHeight: FuncKeywordDefinition = {
compile: (schema) => (data) => Number(data) === stateStore.getHeight(),
compile: (schema) => (data) => Number(data) === stateStore.getBlockNumber(),

Check warning on line 6 in packages/api-evm/source/validation/keywords.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-evm/source/validation/keywords.ts#L6

Added line #L6 was not covered by tests
errors: false,
keyword: "currentHeightHex",
metaSchema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
public async configuration(request: Hapi.Request) {
return {
data: {
blockNumber: this.stateStore.getBlockNumber(),

Check warning on line 19 in packages/api-transaction-pool/source/controllers/configuration.ts

View check run for this annotation

Codecov / codecov/patch

packages/api-transaction-pool/source/controllers/configuration.ts#L19

Added line #L19 was not covered by tests
core: {
version: this.app.version(),
},
height: this.stateStore.getHeight(),
transactionPool: {
maxTransactionAge: this.pluginConfiguration.get("maxTransactionAge"),
maxTransactionBytes: this.pluginConfiguration.get("maxTransactionBytes"),
Expand Down
4 changes: 2 additions & 2 deletions packages/bootstrap/source/bootstrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
this.state.setBootstrap(false);

this.validatorRepository.printLoadedValidators();
await this.txPoolWorker.start(this.stateStore.getHeight());
await this.evmWorker.start(this.stateStore.getHeight());
await this.txPoolWorker.start(this.stateStore.getBlockNumber());
await this.evmWorker.start(this.stateStore.getBlockNumber());

Check warning on line 73 in packages/bootstrap/source/bootstrapper.ts

View check run for this annotation

Codecov / codecov/patch

packages/bootstrap/source/bootstrapper.ts#L72-L73

Added lines #L72 - L73 were not covered by tests

void this.runConsensus();

Expand Down
2 changes: 1 addition & 1 deletion packages/consensus/source/consensus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe<Context>("Consensus", ({ it, beforeEach, assert, stub, spy, clock, each

context.state = {
getLastBlock: () => {},
getHeight: () => 1,
getBlockNumber: () => 1,
};

context.cryptoConfiguration = {
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/source/contracts/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface Store extends CommitHandler {
getLastBlock(): Block;
setLastBlock(block: Block): void;

setHeight(height: number): void;
getHeight(): number;
setBlockNumber(blockNumber: number): void;
getBlockNumber(): number;

setTotalRound(totalRound: number): void;
getTotalRound(): number;
Expand Down
4 changes: 2 additions & 2 deletions packages/evm-api-worker/source/handlers/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@inject(Identifiers.Services.Log.Service)
protected readonly logger!: Contracts.Kernel.Logger;

public async handle(height: number): Promise<void> {
this.stateStore.setHeight(height);
public async handle(blockNumber: number): Promise<void> {
this.stateStore.setBlockNumber(blockNumber);

Check warning on line 13 in packages/evm-api-worker/source/handlers/commit.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm-api-worker/source/handlers/commit.ts#L12-L13

Added lines #L12 - L13 were not covered by tests
}
}
4 changes: 2 additions & 2 deletions packages/evm-api-worker/source/handlers/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
@tagged("plugin", "api-evm")
private readonly configuration!: Providers.PluginConfiguration;

public async handle(height: number): Promise<void> {
this.store.setHeight(height);
public async handle(blockNumber: number): Promise<void> {
this.store.setBlockNumber(blockNumber);

Check warning on line 18 in packages/evm-api-worker/source/handlers/start.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm-api-worker/source/handlers/start.ts#L17-L18

Added lines #L17 - L18 were not covered by tests

if (this.configuration.get("server.http.enabled")) {
await this.app.get<Contracts.Api.Server>(Identifiers.Evm.API.HTTP).boot();
Expand Down
8 changes: 4 additions & 4 deletions packages/p2p/source/downloader/block-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#getLastRequestedBlockNumber(): number {
const latestJob = this.#downloadJobs.at(-1);
if (latestJob === undefined) {
return this.stateStore.getHeight();
return this.stateStore.getBlockNumber();

Check warning on line 96 in packages/p2p/source/downloader/block-downloader.ts

View check run for this annotation

Codecov / codecov/patch

packages/p2p/source/downloader/block-downloader.ts#L96

Added line #L96 was not covered by tests
}

return latestJob.blockNumberTo;
Expand Down Expand Up @@ -210,7 +210,7 @@
}

#handleMissingBlocks(job: DownloadJob): void {
const configuration = this.configuration.getMilestone(this.stateStore.getHeight() + 1);
const configuration = this.configuration.getMilestone(this.stateStore.getBlockNumber() + 1);

Check warning on line 213 in packages/p2p/source/downloader/block-downloader.ts

View check run for this annotation

Codecov / codecov/patch

packages/p2p/source/downloader/block-downloader.ts#L213

Added line #L213 was not covered by tests

const size = job.blocks.reduce((size, block) => size + block.length, 0);

Expand All @@ -233,13 +233,13 @@
}

const isFirstJob = index === 0;
const blockNumberFrom = isFirstJob ? this.stateStore.getHeight() + 1 : job.blockNumberFrom;
const blockNumberFrom = isFirstJob ? this.stateStore.getBlockNumber() + 1 : job.blockNumberFrom;

Check warning on line 236 in packages/p2p/source/downloader/block-downloader.ts

View check run for this annotation

Codecov / codecov/patch

packages/p2p/source/downloader/block-downloader.ts#L236

Added line #L236 was not covered by tests

// Skip if next job is higher than current block number
if (
isFirstJob &&
this.#downloadJobs.length > 1 &&
this.#downloadJobs[1].blockNumberFrom > this.stateStore.getHeight()
this.#downloadJobs[1].blockNumberFrom > this.stateStore.getBlockNumber()

Check warning on line 242 in packages/p2p/source/downloader/block-downloader.ts

View check run for this annotation

Codecov / codecov/patch

packages/p2p/source/downloader/block-downloader.ts#L242

Added line #L242 was not covered by tests
) {
this.#downloadJobs.shift();
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/p2p/source/downloader/message-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
public initialize(): void {
this.events.listen(Events.BlockEvent.Applied, {
handle: () => {
this.#downloadsByBlockNumber.delete(this.stateStore.getHeight());
this.#fullDownloadsByBlockNumber.delete(this.stateStore.getHeight());
this.#downloadsByBlockNumber.delete(this.stateStore.getBlockNumber());
this.#fullDownloadsByBlockNumber.delete(this.stateStore.getBlockNumber());

Check warning on line 74 in packages/p2p/source/downloader/message-downloader.ts

View check run for this annotation

Codecov / codecov/patch

packages/p2p/source/downloader/message-downloader.ts#L73-L74

Added lines #L73 - L74 were not covered by tests
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe<{
const database = { findCommitBuffers: () => {} };
const store = {
getLastDownloadedBlock: () => {},
getHeight: () => {},
getBlockNumber: () => {},
};

beforeEach((context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe<{
const database = { findCommitBuffers: () => {} };
const store = {
getLastDownloadedBlock: () => {},
getHeight: () => {},
getBlockNumber: () => {},
};

beforeEach((context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class GetBlocksController implements Contracts.P2P.Controller {
const requestBlockNumber: number = request.payload.fromBlockNumber;
const requestBlockLimit: number = request.payload.limit;

const lastBlockNumber: number = this.stateStore.getHeight();
const lastBlockNumber: number = this.stateStore.getBlockNumber();
if (requestBlockNumber > lastBlockNumber) {
return { blocks: [] };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("getHeaders", ({ it, assert }) => {
let port = 4007;
const version = "3.0.9";
const height = 387;
const store = { getHeight: () => height, isStarted: () => true };
const store = { getBlockNumber: () => height, isStarted: () => true };
const appGet = {
[Identifiers.State.Store]: store,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/p2p/source/socket-server/utils/get-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getHeaders = (app: Contracts.Kernel.Application) => {
version: app.version(),
};

headers.height = app.get<Contracts.State.Store>(Identifiers.State.Store).getHeight();
headers.height = app.get<Contracts.State.Store>(Identifiers.State.Store).getBlockNumber();

return headers;
};
2 changes: 1 addition & 1 deletion packages/state/source/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe<{
});

it("#initialize - should set height and totalRound", ({ store }) => {
assert.equal(store.getHeight(), 0);
assert.equal(store.getBlockNumber(), 0);
assert.equal(store.getTotalRound(), 0);
});

Expand Down
16 changes: 8 additions & 8 deletions packages/state/source/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Store implements Contracts.State.Store {

#genesisCommit?: Contracts.Crypto.Commit;
#lastBlock?: Contracts.Crypto.Block;
#height = 0;
#blockNumber = 0;
#totalRound = 0;

public setGenesisCommit(block: Contracts.Crypto.Commit): void {
Expand All @@ -30,27 +30,27 @@ export class Store implements Contracts.State.Store {

public setLastBlock(block: Contracts.Crypto.Block): void {
this.#lastBlock = block;
this.setHeight(block.data.number);
this.setBlockNumber(block.data.number);
}

public getLastBlock(): Contracts.Crypto.Block {
assert.defined(this.#lastBlock);
return this.#lastBlock;
}

// Set height is used on workers, because last block is not transferred
public setHeight(height: number): void {
this.#height = height;
this.configuration.setHeight(height + 1);
// Set blockNumber is used on workers, because last block is not transferred
public setBlockNumber(blockNumber: number): void {
this.#blockNumber = blockNumber;
this.configuration.setHeight(blockNumber + 1);

if (this.configuration.isNewMilestone()) {
this.logger.notice(`Milestone change: ${JSON.stringify(this.configuration.getMilestoneDiff())}`);
void this.events.dispatch(Events.CryptoEvent.MilestoneChanged);
}
}

public getHeight(): number {
return this.#height;
public getBlockNumber(): number {
return this.#blockNumber;
}

public setTotalRound(totalRound: number): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/test-framework/source/utils/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
});

export const getLastHeight = (app: Contracts.Kernel.Application): number =>
app.get<Contracts.State.Store>(Identifiers.State.Store).getHeight();
app.get<Contracts.State.Store>(Identifiers.State.Store).getBlockNumber();

Check warning on line 16 in packages/test-framework/source/utils/generic.ts

View check run for this annotation

Codecov / codecov/patch

packages/test-framework/source/utils/generic.ts#L16

Added line #L16 was not covered by tests

export const getWalletNonce = async (app: Contracts.Kernel.Application, publicKey: string): Promise<BigNumber> =>
BigNumber.ZERO;
8 changes: 4 additions & 4 deletions packages/test-transaction-builders/source/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@
export const waitBlock = async (sandbox: Sandbox, count: number = 1) => {
const state = sandbox.app.get<Contracts.State.Store>(Identifiers.State.Store);

let currentHeight = state.getHeight();
const targetHeight = currentHeight + count;
let currentBlockNumber = state.getBlockNumber();
const targetBlockNumber = currentBlockNumber + count;

Check warning on line 167 in packages/test-transaction-builders/source/utilities.ts

View check run for this annotation

Codecov / codecov/patch

packages/test-transaction-builders/source/utilities.ts#L166-L167

Added lines #L166 - L167 were not covered by tests

do {
await sleep(200);
currentHeight = state.getHeight();
} while (currentHeight < targetHeight);
currentBlockNumber = state.getBlockNumber();
} while (currentBlockNumber < targetBlockNumber);

Check warning on line 172 in packages/test-transaction-builders/source/utilities.ts

View check run for this annotation

Codecov / codecov/patch

packages/test-transaction-builders/source/utilities.ts#L171-L172

Added lines #L171 - L172 were not covered by tests
};

export const getRandomFundedWallet = async (
Expand Down
6 changes: 3 additions & 3 deletions packages/transaction-pool-service/source/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
}

this.storage.addTransaction({
blockNumber: this.stateStore.getHeight(),
blockNumber: this.stateStore.getBlockNumber(),

Check warning on line 87 in packages/transaction-pool-service/source/service.ts

View check run for this annotation

Codecov / codecov/patch

packages/transaction-pool-service/source/service.ts#L87

Added line #L87 was not covered by tests
hash: transaction.hash,
senderPublicKey: transaction.data.senderPublicKey,
serialized: transaction.serialized,
Expand Down Expand Up @@ -121,7 +121,7 @@
let previouslyStoredFailures = 0;

const maxTransactionAge: number = this.pluginConfiguration.getRequired<number>("maxTransactionAge");
const lastBlockNumber: number = this.stateStore.getHeight();
const lastBlockNumber: number = this.stateStore.getBlockNumber();

Check warning on line 124 in packages/transaction-pool-service/source/service.ts

View check run for this annotation

Codecov / codecov/patch

packages/transaction-pool-service/source/service.ts#L124

Added line #L124 was not covered by tests
const expiredBlockNumber: number = lastBlockNumber - maxTransactionAge;

for (const { blockNumber, hash, serialized } of this.storage.getAllTransactions()) {
Expand Down Expand Up @@ -179,7 +179,7 @@

async #removeOldTransactions(): Promise<void> {
const maxTransactionAge: number = this.pluginConfiguration.getRequired<number>("maxTransactionAge");
const lastBlockNumber: number = this.stateStore.getHeight();
const lastBlockNumber: number = this.stateStore.getBlockNumber();

Check warning on line 182 in packages/transaction-pool-service/source/service.ts

View check run for this annotation

Codecov / codecov/patch

packages/transaction-pool-service/source/service.ts#L182

Added line #L182 was not covered by tests
const expiredBlockNumber: number = lastBlockNumber - maxTransactionAge;

for (const { senderPublicKey, hash } of this.storage.getOldTransactions(expiredBlockNumber)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/transaction-pool-worker/source/handlers/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
@inject(Identifiers.Services.Log.Service)
protected readonly logger!: Contracts.Kernel.Logger;

public async handle(height: number, sendersAddresses: string[]): Promise<void> {
public async handle(blockNumber: number, sendersAddresses: string[]): Promise<void> {

Check warning on line 18 in packages/transaction-pool-worker/source/handlers/commit.ts

View check run for this annotation

Codecov / codecov/patch

packages/transaction-pool-worker/source/handlers/commit.ts#L18

Added line #L18 was not covered by tests
try {
this.stateStore.setHeight(height);
this.stateStore.setBlockNumber(blockNumber);

Check warning on line 20 in packages/transaction-pool-worker/source/handlers/commit.ts

View check run for this annotation

Codecov / codecov/patch

packages/transaction-pool-worker/source/handlers/commit.ts#L20

Added line #L20 was not covered by tests

if (this.configuration.isNewMilestone()) {
void this.transactionPoolService.reAddTransactions();
Expand Down
4 changes: 2 additions & 2 deletions packages/transaction-pool-worker/source/handlers/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
@tagged("plugin", "api-transaction-pool")
private readonly configuration!: Providers.PluginConfiguration;

public async handle(height: number): Promise<void> {
this.store.setHeight(height);
public async handle(blockNumber: number): Promise<void> {
this.store.setBlockNumber(blockNumber);

Check warning on line 21 in packages/transaction-pool-worker/source/handlers/start.ts

View check run for this annotation

Codecov / codecov/patch

packages/transaction-pool-worker/source/handlers/start.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
await this.transactionPoolService.reAddTransactions();

if (this.configuration.get("server.http.enabled")) {
Expand Down
Loading
Loading