Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #119 from mappum/tendermint-0.19.2
Browse files Browse the repository at this point in the history
Tendermint 0.19.2
  • Loading branch information
keppel authored May 5, 2018
2 parents a5474c8 + 7a3d3e6 commit 6ef018b
Show file tree
Hide file tree
Showing 16 changed files with 1,044 additions and 3,926 deletions.
6 changes: 3 additions & 3 deletions bin/binaries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports.tendermint = {
darwin: 'https://tendermint.nyc3.digitaloceanspaces.com/darwin-tendermint-v0.15.0.zip',
win32: 'https://tendermint.nyc3.digitaloceanspaces.com/windows-tendermint-v0.15.0.zip',
linux: 'https://tendermint.nyc3.digitaloceanspaces.com/linux-tendermint-v0.15.0.zip'
darwin: 'https://github.com/tendermint/tendermint/releases/download/v0.19.2/tendermint_0.19.2_darwin_386.zip',
win32: 'https://github.com/tendermint/tendermint/releases/download/v0.19.2/tendermint_0.19.2_windows_386.zip',
linux: 'https://github.com/tendermint/tendermint/releases/download/v0.19.2/tendermint_0.19.2_linux_386.zip'
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function Lotion(opts = {}) {
GCI = getGCIFromGenesis(genesisJson)
serveGenesisGCI(GCI, genesisJson)
}

await tendermint.synced
if (!lite) {
announceSelfAsFullNode({ GCI, tendermintPort })
Expand Down
66 changes: 28 additions & 38 deletions lib/abci-app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let abci = require('./abci/')
let createABCIServer = require('abci')
let decodeTx = require('./tx-encoding.js').decode
let jsondiffpatch = require('jsondiffpatch')
let getRoot = require('./get-root.js')
Expand All @@ -15,8 +15,6 @@ async function runTx(txMiddleware, store, tx, chainInfo, allowMutation = false){
get: (target, name) => {
if (typeof target[name] === 'object' && target[name] !== null) {
return new Proxy(target[name], proxy)
} else {
return target[name]
}
return target[name]
},
Expand All @@ -34,7 +32,7 @@ async function runTx(txMiddleware, store, tx, chainInfo, allowMutation = false){
// run middleware stack
try {
for (let txHandler of txMiddleware) {
await txHandler(hookedState, tx, hookedChainInfo);
await txHandler(hookedState, tx, hookedChainInfo)
}
} catch (e) {
return [false, e.toString()]
Expand All @@ -53,12 +51,6 @@ async function runTx(txMiddleware, store, tx, chainInfo, allowMutation = false){

class AbciApp {
constructor() {}
beginBlock(req, cb) {
cb({})
}
setOption(req, cb) {
cb({})
}
}

module.exports = function configureABCIServer({
Expand All @@ -73,89 +65,87 @@ module.exports = function configureABCIServer({
}
let lastValidatorState = {}
let abciApp = new AbciApp()
abciApp.checkTx = async function(req, cb) {
let rawTx = req.check_tx.tx
abciApp.checkTx = async function(req) {
let rawTx = req.tx
try {
let tx = decodeTx(rawTx)
let [isValid, log] = await runTx(txMiddleware, store, tx, chainInfo, false)
let code = isValid ? 0 : 2
cb({ code, log })
return { code, log }
} catch (e) {
cb({ code: 2, log: 'Invalid tx encoding for checkTx' })
return { code: 2, log: 'Invalid tx encoding for checkTx' }
}
}

abciApp.deliverTx = async function(req, cb) {
let rawTx = req.deliver_tx.tx
abciApp.deliverTx = async function(req) {
let rawTx = req.tx
try {
let tx = decodeTx(rawTx)
let [isValid, log] = await runTx(txMiddleware, store, tx, chainInfo, true)
if (isValid) {
cb({ code: 0 })
return { code: 0 }
} else {
cb({ code: 2, log })
return { code: 2, log }
}
} catch (e) {
cb({ code: 2, log: 'Invalid tx encoding for deliverTx' })
return { code: 2, log: 'Invalid tx encoding for deliverTx' }
}
}

abciApp.commit = async function(req, cb) {
abciApp.commit = async function() {
chainInfo.height++
blockMiddleware.forEach(blockHandler => {
blockHandler(store, chainInfo)
})
let appHash = await getRoot(store)
cb({ data: appHash })
return { data: appHash }
}

abciApp.initChain = function(req, cb) {
let validators = req.init_chain.validators
abciApp.initChain = function({ validators }) {
validators.forEach(tmValidator => {
let pubKey = tmValidator.pub_key.toString('hex')
let pubKey = tmValidator.pubKey.toString('hex')
let power = tmValidator.power.toNumber()
chainInfo.validators[pubKey] = power
})
Object.assign(lastValidatorState, chainInfo.validators)
cb({})
return {}
}

abciApp.endBlock = function(req, cb) {
abciApp.endBlock = function() {
let diffs = []
for (let key in chainInfo.validators) {
if (lastValidatorState[key] !== chainInfo.validators[key]) {
diffs.push({
pub_key: Buffer.from(key, 'hex'),
pubKey: Buffer.from(key, 'hex'),
power: { low: chainInfo.validators[key], high: 0 }
})
}
}
lastValidatorState = Object.assign({}, chainInfo.validators)
cb({ validator_updates: diffs })
return { validatorUpdates: diffs }
}

abciApp.query = async function(req, cb) {
abciApp.query = function() {
try {
let queryResponse = {
return {
value: stringify(store),
height: { low: chainInfo.height - 1, high: 0 },
height: chainInfo.height - 1,
proof: '',
key: '',
index: { low: 0, high: 0 },
index: 0,
code: 0,
log: ''
}
cb(queryResponse)
} catch (e) {
cb({ code: 2, log: 'invalid query: ' + e.message })
return { code: 2, log: 'invalid query: ' + e.message }
}
}

abciApp.info = async function(req, cb) {
abciApp.info = async function() {
let rootHash = await getRoot(store)
cb({ last_block_app_hash: rootHash })
return { lastBlockAppHash: rootHash }
}
let abciServer = new abci.Server(abciApp)

return abciServer.server
let abciServer = createABCIServer(abciApp)
return abciServer
}
179 changes: 0 additions & 179 deletions lib/abci/client.js

This file was deleted.

Loading

0 comments on commit 6ef018b

Please sign in to comment.