Skip to content

feat: add parent hash in the block event #6294

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

clarkchen
Copy link

What does this PR do?
Adds parent hash information to BlockLogTrigger to include this data in the block streaming output.

Why are these changes required?
This enhancement helps users easily identify forked blockchain scenarios by providing the parent hash information in the block logs, which is crucial for blockchain analysis and troubleshooting.

This PR has been tested by:

  • Manual Testing

Follow up
NO

Extra details
The implementation adds a parentHash field to BlockLogTrigger and populates it in BlockLogTriggerCapsule by retrieving the parent hash from the block data.

@waynercheung
Copy link
Contributor

Hi @clarkchen , the block event is used in the eventplugin.

So, do you want to check the parent hash when you fetch the block info from the event service, such as kafka and mongoDB?

@clarkchen
Copy link
Author

@waynercheung good point.

I have checked the the code, the new parent hash will also be compatible with the event plugin, because java_tron passes objects to the plugin in string format.

EventPluginLoader.java

  • parent hash will be appened to the return toJsonString(trigger)

public void postBlockTrigger(BlockLogTrigger trigger) {
if (useNativeQueue) {
NativeMessageQueue.getInstance()
.publishTrigger(toJsonString(trigger), trigger.getTriggerName());
} else {
eventListeners.forEach(listener ->
listener.handleBlockEvent(toJsonString(trigger)));
}
}

Plugins

the Plugin Interface, e.g. KafkaEventListener.java, MongodbEventListener.java, will handle string smoothly and push to clients new message, which format is "[oldmsg], parentHash: xxxxxx"

https://github.com/tronprotocol/event-plugin/blob/97bea8cc200ee2a1b6abf61860b33782794fb192/plugins/kafkaplugin/src/main/java/org/tron/eventplugin/KafkaEventListener.java#L40-L45

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

Successfully merging this pull request may close these issues.

2 participants