Skip to content

Commit

Permalink
Merge pull request #740 from wilsonianb/shamapv2
Browse files Browse the repository at this point in the history
Check SHAMapV2 ledger close flag
  • Loading branch information
clark800 committed Dec 2, 2016
2 parents 11528ef + fd640cd commit c0101cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions src/offline/ledgerhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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'
Expand All @@ -47,23 +47,26 @@ 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')
}
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))
}
Expand Down

0 comments on commit c0101cb

Please sign in to comment.