Skip to content

Commit

Permalink
Merge pull request #1056 from nervosnetwork/fix-syn-cellbase
Browse files Browse the repository at this point in the history
Skip get previous tx when cellbase
  • Loading branch information
ashchan authored Nov 8, 2019
2 parents f579950 + aeeb464 commit e1064d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/neuron-wallet/src/services/indexer/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default class IndexerQueue {

private url: string

private emptyTxHash = '0x' + '0'.repeat(64)

constructor(url: string, lockHashInfos: LockHashInfo[], tipNumberSubject: Subject<string | undefined>) {
this.lockHashInfos = lockHashInfos
this.url = url
Expand Down Expand Up @@ -213,6 +215,9 @@ export default class IndexerQueue {
if (!txEntity || !txEntity.blockHash) {
if (!txEntity) {
for (const input of transaction.inputs!) {
if (input.previousOutput!.txHash === this.emptyTxHash) {
continue
}
const previousTxWithStatus = await this.getBlocksService.getTransaction(input.previousOutput!.txHash)
const previousTx = TypeConvert.toTransaction(previousTxWithStatus.transaction)
const previousOutput = previousTx.outputs![+input.previousOutput!.index]
Expand Down
27 changes: 15 additions & 12 deletions packages/neuron-wallet/src/services/sync/get-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,25 @@ export default class GetBlocks {
const cachedPreviousTxs = new Map()
for (const block of blocks) {
logger.debug(`checking block #${block.header.number}, ${block.transactions.length} txs`)
for (const tx of block.transactions) {
for (let i = 0; i < block.transactions.length; ++i) {
const tx = block.transactions[i]
const checkTx = new CheckTx(tx, this.url)
const addresses = await checkTx.check(lockHashes)
if (addresses.length > 0) {
for (const input of tx.inputs!) {
const previousTxHash = input.previousOutput!.txHash
let previousTxWithStatus = cachedPreviousTxs.get(previousTxHash)
if (!previousTxWithStatus) {
previousTxWithStatus = await this.getTransaction(previousTxHash)
cachedPreviousTxs.set(previousTxHash, previousTxWithStatus)
if (i > 0) {
for (const input of tx.inputs!) {
const previousTxHash = input.previousOutput!.txHash
let previousTxWithStatus = cachedPreviousTxs.get(previousTxHash)
if (!previousTxWithStatus) {
previousTxWithStatus = await this.getTransaction(previousTxHash)
cachedPreviousTxs.set(previousTxHash, previousTxWithStatus)
}
const previousTx = TypeConvert.toTransaction(previousTxWithStatus.transaction)
const previousOutput = previousTx.outputs![+input.previousOutput!.index]
input.lock = previousOutput.lock
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
}
const previousTx = TypeConvert.toTransaction(previousTxWithStatus.transaction)
const previousOutput = previousTx.outputs![+input.previousOutput!.index]
input.lock = previousOutput.lock
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
}
await TransactionPersistor.saveFetchTx(tx)
addressesUsedSubject.next({
Expand Down

0 comments on commit e1064d4

Please sign in to comment.