Skip to content

Commit

Permalink
Support tendermint 0.31
Browse files Browse the repository at this point in the history
A few small changes.

Fix create_empty_blocks and make sure we do not
submit duplicate validator (pubKey) entries to abci.

Related #184
  • Loading branch information
pinkiebell committed Mar 21, 2019
1 parent 064c284 commit b57cf68
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
33 changes: 24 additions & 9 deletions lotion/lib/abci-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ async function runTx(

function updateAndDiffValidators(validators, newValidators) {
const diffs = [];
const push = validator => {
const pubKeys = {};
const push = (validator) => {
diffs.push({
pubKey: {
type: validator.pubKey.type,
Expand All @@ -70,17 +71,31 @@ function updateAndDiffValidators(validators, newValidators) {
};

for (const key in newValidators) {
if (validators[key] === undefined) {
validators[key] = newValidators[key];
push(validators[key]);
} else if (
typeof newValidators[key] === 'number' &&
validators[key].power !== newValidators[key]
const numberOrObj = newValidators[key];
let validator = validators[key];

if (
typeof numberOrObj === 'number' &&
validator &&
validator.power !== numberOrObj
) {
validators[key].power = newValidators[key];
push(validators[key]);
validator.power = numberOrObj;
} else {
validator = numberOrObj;
validators[key] = validator;
}

// can also be 0
if (validator) {
pubKeys[validator.pubKey.data] = validator;
}
}

// why do we have different validator addrs with the same pubKey?
for (const key in pubKeys) {
push(pubKeys[key]);
}

return diffs;
}

Expand Down
2 changes: 1 addition & 1 deletion lotion/lib/node-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { join } = require('path');

module.exports = lotionPath => {
const validatorKeyInfo = JSON.parse(
fs.readFileSync(join(lotionPath, 'config/priv_validator.json'))
fs.readFileSync(join(lotionPath, 'config/priv_validator_key.json'))
);

const pubkeyAminoPrefix = Buffer.from('1624DE6220', 'hex');
Expand Down
4 changes: 2 additions & 2 deletions lotion/lib/tendermint.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = async ({
);
}
if (keys) {
const validatorJsonPath = join(lotionPath, 'config', 'priv_validator.json');
const validatorJsonPath = join(lotionPath, 'config', 'priv_validator_key.json');
const generatedValidatorJson = JSON.parse(
fs.readFileSync(validatorJsonPath, { encoding: 'utf8' })
);
Expand Down Expand Up @@ -62,7 +62,7 @@ module.exports = async ({
}
opts.consensus = {};
if (createEmptyBlocks === false) {
opts.consensus.createEmptyBlocks = false;
opts.consensus.create_empty_blocks = false;
}

if (!logTendermint) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/methods/getAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async (bridgeState, app) => {
const validatorKeyPath = path.join(
app.lotionPath(),
'config',
'priv_validator.json'
'priv_validator_key.json'
);
const validatorKey = JSON.parse(await readFile(validatorKeyPath, 'utf-8'));
const validatorID = Buffer.from(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cleanupLotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = async app => {
const lotionPath = app.lotionPath();
if (await exists(lotionPath)) {
const configPath = path.join(lotionPath, 'config');
const privValidatorPath = path.join(configPath, 'priv_validator.json');
const privValidatorPath = path.join(configPath, 'priv_validator_key.json');
const privValidator = JSON.parse(await readFile(privValidatorPath));
await writeFile(
privValidatorPath,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/printStartupInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = async (params, bridgeState) => {
const validatorKeyPath = path.join(
params.lotionPath,
'config',
'priv_validator.json'
'priv_validator_key.json'
);

const validatorKey = JSON.parse(await readFile(validatorKeyPath, 'utf-8'));
Expand Down

0 comments on commit b57cf68

Please sign in to comment.