Skip to content

Commit

Permalink
no auto block in manual mode
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Sep 4, 2024
1 parent 56a1cc4 commit 2ef08a9
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions packages/core/src/blockchain/txpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,27 @@ export class TxPool {
unsafeBlockHeight,
})

// with the latest message queue, messages are processed in the upcoming block
if (!this.#chain.processQueuedMessages) return
// if block was built without horizontal or downward messages then skip
if (_.isEmpty(horizontalMessages) && _.isEmpty(downwardMessages)) return

// messageQueue.bookStateFor
const prefix = '0xb8753e9383841da95f7b8871e5de326954e062a2cf8df68178ee2e5dbdf00bff'
const meta = await this.#chain.head.meta
const keys = await this.#chain.head.getKeysPaged({ prefix, pageSize: 1000 })
for (const key of keys) {
const rawValue = await this.#chain.head.get(key)
if (!rawValue) continue
const message = meta.registry.createType('PalletMessageQueueBookState', hexToU8a(rawValue)).toJSON() as any
if (message.size > 0) {
logger.info('Queued messages detected, building a new block')
// build a new block to process the queued messages
await this.#chain.newBlock()
return
// try to process queued messages if not in manual mode
if (this.#mode !== BuildBlockMode.Manual) {
// with the latest message queue, messages could be processed in the upcoming block
if (!this.#chain.processQueuedMessages) return
// if block was built without horizontal or downward messages then skip
if (_.isEmpty(horizontalMessages) && _.isEmpty(downwardMessages)) return

// messageQueue.bookStateFor
const prefix = '0xb8753e9383841da95f7b8871e5de326954e062a2cf8df68178ee2e5dbdf00bff'
const meta = await this.#chain.head.meta
const keys = await this.#chain.head.getKeysPaged({ prefix, pageSize: 1000 })
for (const key of keys) {
const rawValue = await this.#chain.head.get(key)
if (!rawValue) continue
const message = meta.registry.createType('PalletMessageQueueBookState', hexToU8a(rawValue)).toJSON() as any
if (message.size > 0) {
logger.info('Queued messages detected, building a new block')
// build a new block to process the queued messages
await this.#chain.newBlock()
return
}
}
}
} catch (err) {
Expand Down

0 comments on commit 2ef08a9

Please sign in to comment.