Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use parent block's utxo root for the inclusion reference logic #376

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/core/src/validator/offchain/offchain-tx-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,22 @@ export class OffchainTxValidator extends OffchainValidatorContext
// TODO: use index when booleans are supported
if (finalized.find(p => p.finalized === true)) return true
// Or check the recent precedent blocks has that utxo tree root
let currentBlockHash: string = blockHash.toString()
let childBlockHash: string = blockHash.toString()
for (let i = 0; i < this.layer2.config.referenceDepth; i += 1) {
const hash = currentBlockHash
const currentBlock = await this.layer2.db.findOne('Block', {
where: { hash },
const childBlockHeader = await this.layer2.db.findOne('Header', {
where: { hash: childBlockHash },
})
const parentBlock = await this.layer2.db.findOne('Block', {
where: { hash: childBlockHeader.parentBlock },
include: { header: true, slash: true },
})
if (currentBlock === null || currentBlock.slash !== null) {
if (parentBlock === null || parentBlock.slash !== null) {
return false
}
if (inclusionRef.eq(Uint256.from(currentBlock.header.utxoRoot))) {
if (inclusionRef.eq(Uint256.from(parentBlock.header.utxoRoot))) {
return true
}
currentBlockHash = currentBlock.header.parentBlock
childBlockHash = childBlockHeader.parentBlock
}
return false
}
Expand Down