Skip to content
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

fix(core-snapshots): also fix the genesis block id during verify #2809

Merged
merged 1 commit into from
Jul 15, 2019
Merged
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
13 changes: 9 additions & 4 deletions packages/core-snapshots/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import { canImportRecord, verifyData } from "./verification";
const logger = app.resolvePlugin<Logger.ILogger>("logger");
const emitter = app.resolvePlugin<EventEmitter.EventEmitter>("event-emitter");

const fixData = (table, data) => {
if (table === "blocks" && data.height === 1) {
data.id = Managers.configManager.get("genesisBlock").id;
}
}

export const exportTable = async (table, options) => {
const snapFileName = utils.getFilePath(table, options.meta.folder);
const gzip = zlib.createGzip();
Expand Down Expand Up @@ -89,9 +95,7 @@ export const importTable = async (table, options) => {
for await (const record of readStream) {
counter++;

if (table === "blocks" && record.height === 1) {
record.id = Managers.configManager.get("genesisBlock").id;
}
fixData(table, record);

if (!verifyData(table, record, prevData, options.verifySignatures)) {
app.forceExit(`Error verifying data. Payload ${JSON.stringify(record, undefined, 2)}`);
Expand Down Expand Up @@ -129,14 +133,15 @@ export const verifyTable = async (table, options) => {
let prevData;

decodeStream.on("data", data => {
fixData(table, data);
if (!verifyData(table, data, prevData, options.verifySignatures)) {
app.forceExit(`Error verifying data. Payload ${JSON.stringify(data, undefined, 2)}`);
}
prevData = data;
});

readStream.on("finish", () => {
logger.info(`Snapshot file ${sourceFile} succesfully verified`);
logger.info(`Snapshot file ${sourceFile} successfully verified`);
});
};

Expand Down