Check SHAMapV2 ledger close flag

This commit is contained in:
wilsonianb
2016-12-01 13:41:28 -08:00
parent 11528eff92
commit fd640cd65e
2 changed files with 10 additions and 7 deletions

View File

@@ -30,7 +30,7 @@ Then see the [documentation](https://github.com/ripple/ripple-lib/blob/develop/d
##Generating Documentation
The continuous integration tests require that the documentation stays up-to-date. If you make changes the the JSON schemas, fixtures, or documentation sources, you must update the documentation by running `npm run docgen`.
The continuous integration tests require that the documentation stays up-to-date. If you make changes to the JSON schemas, fixtures, or documentation sources, you must update the documentation by running `npm run docgen`.
##More Information

View File

@@ -27,7 +27,7 @@ function hashLedgerHeader(ledgerHeader) {
return hashes.computeLedgerHash(header)
}
function computeTransactionHash(ledger) {
function computeTransactionHash(ledger, version) {
if (ledger.rawTransactions === undefined) {
return ledger.transactionHash
}
@@ -38,7 +38,7 @@ function computeTransactionHash(ledger) {
tx.meta ? {metaData: tx.meta} : {})
return renameMeta
})
const transactionHash = hashes.computeTransactionTreeHash(txs)
const transactionHash = hashes.computeTransactionTreeHash(txs, version)
if (ledger.transactionHash !== undefined
&& ledger.transactionHash !== transactionHash) {
throw new common.errors.ValidationError('transactionHash in header'
@@ -47,12 +47,12 @@ function computeTransactionHash(ledger) {
return transactionHash
}
function computeStateHash(ledger) {
function computeStateHash(ledger, version) {
if (ledger.rawState === undefined) {
return ledger.stateHash
}
const state = JSON.parse(ledger.rawState)
const stateHash = hashes.computeStateTreeHash(state)
const stateHash = hashes.computeStateTreeHash(state, version)
if (ledger.stateHash !== undefined && ledger.stateHash !== stateHash) {
throw new common.errors.ValidationError('stateHash in header'
+ ' does not match computed hash of state')
@@ -60,10 +60,13 @@ function computeStateHash(ledger) {
return stateHash
}
const sLCF_SHAMapV2 = 0x02
function computeLedgerHash(ledger: Object): string {
const version = ((ledger.closeFlags & sLCF_SHAMapV2) === 0) ? 1 : 2
const subhashes = {
transactionHash: computeTransactionHash(ledger),
stateHash: computeStateHash(ledger)
transactionHash: computeTransactionHash(ledger, version),
stateHash: computeStateHash(ledger, version)
}
return hashLedgerHeader(_.assign({}, ledger, subhashes))
}