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

getHeadBlockId abnormal return #5389

Closed
xxo1shine opened this issue Aug 1, 2023 · 2 comments · Fixed by #5403
Closed

getHeadBlockId abnormal return #5389

xxo1shine opened this issue Aug 1, 2023 · 2 comments · Fixed by #5403
Assignees
Labels

Comments

@xxo1shine
Copy link
Contributor

System information

Java-tron version: v4.7.2
OS & Version: Linux & macOS

Expected behavior

The getHeadBlockId function should return the correct block header information.

Actual behavior

When synchronizing blocks, an abnormal block ID appears, as shown in the following log:
image

This ID: 00000000032b9cc50deb2777f7e751ade0245ace23c2cc8579d733af34401832 is composed of two parts, the number of block 53189829 and the hash of block 53189830. The reason for this phenomenon is that there is a concurrency problem in this function. The function definition is as follows:

public synchronized BlockId getHeadBlockId() {
    return new BlockId(
        dynamicPropertiesStore.getLatestBlockHeaderHash(),
        dynamicPropertiesStore.getLatestBlockHeaderNumber());
  }

When calling this function, if only the block hash is written at this time, and the block number has not been written in time, the above-mentioned situation will occur.

@jwrct
Copy link
Contributor

jwrct commented Aug 2, 2023

@wubin01 Do you have any good solutions for how to solve this concurrency problem?

@xxo1shine
Copy link
Contributor Author

@chengtx01 Just use dynamicPropertiesStore.getLatestBlockHeaderHash() to construct, The function implementation is as follows.

public synchronized BlockId getHeadBlockId() {
    return new BlockId(dynamicPropertiesStore.getLatestBlockHeaderHash());
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants