lisk-framework
Version:
Lisk blockchain application platform
46 lines • 2.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BFTModule = void 0;
const method_1 = require("./method");
const constants_1 = require("./constants");
const schemas_1 = require("./schemas");
const bft_votes_1 = require("./bft_votes");
const bft_params_1 = require("./bft_params");
class BFTModule {
constructor() {
this.name = constants_1.MODULE_NAME_BFT;
this.method = new method_1.BFTMethod();
}
async init(batchSize, blockTime) {
this._batchSize = batchSize;
this.method.init(this._batchSize, blockTime);
this._maxLengthBlockBFTInfos = 3 * this._batchSize;
}
async initGenesisState(stateStore, header) {
const votesStore = stateStore.getStore(constants_1.MODULE_STORE_PREFIX_BFT, constants_1.STORE_PREFIX_BFT_VOTES);
await votesStore.setWithSchema(constants_1.EMPTY_KEY, {
maxHeightPrevoted: header.height,
maxHeightPrecommitted: header.height,
maxHeightCertified: header.height,
blockBFTInfos: [],
activeValidatorsVoteInfo: [],
}, schemas_1.bftVotesSchema);
}
async beforeTransactionsExecute(stateStore, header, maxRemovalHeight) {
const votesStore = stateStore.getStore(constants_1.MODULE_STORE_PREFIX_BFT, constants_1.STORE_PREFIX_BFT_VOTES);
const paramsStore = stateStore.getStore(constants_1.MODULE_STORE_PREFIX_BFT, constants_1.STORE_PREFIX_BFT_PARAMETERS);
const paramsCache = new bft_params_1.BFTParametersCache(paramsStore);
const bftVotes = await votesStore.getWithSchema(constants_1.EMPTY_KEY, schemas_1.bftVotesSchema);
(0, bft_votes_1.insertBlockBFTInfo)(bftVotes, header, this._maxLengthBlockBFTInfos);
await paramsCache.cache(bftVotes.blockBFTInfos[bftVotes.blockBFTInfos.length - 1].height, bftVotes.blockBFTInfos[0].height);
await (0, bft_votes_1.updatePrevotesPrecommits)(bftVotes, paramsCache);
await (0, bft_votes_1.updateMaxHeightPrevoted)(bftVotes, paramsCache);
await (0, bft_votes_1.updateMaxHeightPrecommitted)(bftVotes, paramsCache);
(0, bft_votes_1.updateMaxHeightCertified)(bftVotes, header);
await votesStore.setWithSchema(constants_1.EMPTY_KEY, bftVotes, schemas_1.bftVotesSchema);
const minHeightBFTParametersRequired = Math.min(bftVotes.blockBFTInfos[bftVotes.blockBFTInfos.length - 1].height, maxRemovalHeight);
await (0, bft_params_1.deleteBFTParameters)(paramsStore, minHeightBFTParametersRequired);
}
}
exports.BFTModule = BFTModule;
//# sourceMappingURL=module.js.map
;