diff --git a/lotion/lib/abci-app.js b/lotion/lib/abci-app.js index 54c85c4c..54a1214b 100644 --- a/lotion/lib/abci-app.js +++ b/lotion/lib/abci-app.js @@ -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, @@ -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; } diff --git a/lotion/lib/node-info.js b/lotion/lib/node-info.js index b4663e63..786b134e 100644 --- a/lotion/lib/node-info.js +++ b/lotion/lib/node-info.js @@ -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'); diff --git a/lotion/lib/tendermint.js b/lotion/lib/tendermint.js index 5f7f7761..ef126cb3 100644 --- a/lotion/lib/tendermint.js +++ b/lotion/lib/tendermint.js @@ -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' }) ); @@ -62,7 +62,7 @@ module.exports = async ({ } opts.consensus = {}; if (createEmptyBlocks === false) { - opts.consensus.createEmptyBlocks = false; + opts.consensus.create_empty_blocks = false; } if (!logTendermint) { diff --git a/src/api/methods/getAddress.js b/src/api/methods/getAddress.js index 792c82fa..c061bdad 100644 --- a/src/api/methods/getAddress.js +++ b/src/api/methods/getAddress.js @@ -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( diff --git a/src/utils/cleanupLotion.js b/src/utils/cleanupLotion.js index 439f7ac6..94f87253 100644 --- a/src/utils/cleanupLotion.js +++ b/src/utils/cleanupLotion.js @@ -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, diff --git a/src/utils/printStartupInfo.js b/src/utils/printStartupInfo.js index 991a24df..029dc578 100644 --- a/src/utils/printStartupInfo.js +++ b/src/utils/printStartupInfo.js @@ -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'));