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

After send sudt the sync process will stop with light client #184

Closed
yanguoyu opened this issue Jun 9, 2023 · 3 comments
Closed

After send sudt the sync process will stop with light client #184

yanguoyu opened this issue Jun 9, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@yanguoyu
Copy link

yanguoyu commented Jun 9, 2023

What happened

When Neuron fetches a transaction with an ACP address, it will check and save the sudt token and ACP lock args to asset-account. But after we update typeorm to 0.2.45, it will check whether the entity id has existed at https://github.com/typeorm/typeorm/blob/0.2.45/src/query-builder/ReturningResultsEntityUpdator.ts#L129. If we don't set entityId when saving an entity, the entity id query from https://github.com/typeorm/typeorm/blob/0.2.45/src/driver/sqlite/SqliteQueryRunner.ts#L74 and https://github.com/typeorm/typeorm/blob/0.2.45/src/driver/sqlite/SqliteQueryRunner.ts#L101 by https://github.com/TryGhost/node-sqlite3/wiki/API#runsql--param---callback, but the docs describe lastID that

lastID only contains valid information when the query was a successfully completed INSERT statement and changes only contains valid information when the query was a successfully completed UPDATE or DELETE statement. In all other cases, the content of these properties is inaccurate and should not be used. The .run() function is the only query method that sets these two values; all other query methods such as .all() or .get() don't retrieve these values.

After writing a demo to test, If we insert a conflicted entity after a successful insert. The lastID will be wrong, it will be the last insert statement's lastID.
And if we insert a conflicted entity without success inserting before, it will throw an error TypeORMError(Cannot update entity because entity id is not set in the entity.)
On the other hand, if send sudt at a full node, it will not affect the sync process, before inset into asset-account, it will insert a new item into indexer_tx_hash_cache at https://github.com/nervosnetwork/neuron/blob/v0.110.1/packages/neuron-wallet/src/block-sync-renderer/sync/indexer-cache-service.ts#L204.

  // It will throw `TypeORMError(`Cannot update entity because entity id is not set in the entity.` when `tokenID` and 
  // `blake160` exists.
  await connection
    .createQueryBuilder()
    .insert()
    .into(AssetAccountEntity)
    .values(assetAccount)
    .onConflict(`("tokenID", "blake160") DO NOTHING`)
    .execute()
// insert success
  await connection
    .createQueryBuilder()
    .insert()
    .into(User)
    .values(user)
    .execute()
// will run success even `tokenID` and `blake160` exists.
await connection
    .createQueryBuilder()
    .insert()
    .into(AssetAccountEntity)
    .values(assetAccount)
    .onConflict(`("tokenID", "blake160") DO NOTHING`)
    .execute()

How to replay this bug

After Neuron sync to 100% with light client, restart Neuron to avoid the effect of other inserts. Send sudt from the asset accounts page, then we can find that sync will stop before the sudt transaction block number. We can recover it by clean cache because after clean cache there will exist many successful inserts.

How to fixed

We can set the asset account id as null when insert, it will not affect the insert result with generated grown id.

@yanguoyu yanguoyu self-assigned this Jun 9, 2023
@yanguoyu yanguoyu changed the title After send sudt the sync process will stop After send sudt the sync process will stop with light client Jun 9, 2023
@yanguoyu
Copy link
Author

yanguoyu commented Jun 9, 2023

set the asset account id as null when insert will affect the id's type, so I check whether the entity exists before insert.

@yanguoyu
Copy link
Author

yanguoyu commented Jun 9, 2023

@littleLip520
Copy link

verified.
after sending sudt from the asset accounts page ,the block not stuck at height(9,696,823) of sudt transaction.
image

it continue snyc new block to 9,696,900
image

@github-project-automation github-project-automation bot moved this from 👀 Testing to ✅ Done in Neuron Jun 20, 2023
@yanguoyu yanguoyu moved this from ✅ Done to 🚩Pre Release in Neuron Jun 20, 2023
@FrederLu FrederLu moved this from 🚩Pre Release to ✅ Done in Neuron Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants