-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(event): correct fork rollback handling in solidity event maps #6718
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1377,6 +1377,7 @@ public void pushBlock(final BlockCapsule block) | |
| } catch (Throwable throwable) { | ||
| logger.error(throwable.getMessage(), throwable); | ||
| khaosDb.removeBlk(block.getBlockId()); | ||
| clearSolidityContractTriggerCache(block.getNum()); | ||
| throw throwable; | ||
| } | ||
| long newSolidNum = getDynamicPropertiesStore().getLatestSolidifiedBlockNum(); | ||
|
|
@@ -2378,6 +2379,16 @@ private void reOrgContractTrigger() { | |
| getDynamicPropertiesStore().getLatestBlockHeaderHash()); | ||
| } | ||
| } | ||
| clearSolidityContractTriggerCache(getHeadBlockNum()); | ||
| } | ||
|
|
||
| private void clearSolidityContractTriggerCache(long blockNum) { | ||
| if (eventPluginLoaded | ||
| && (EventPluginLoader.getInstance().isSolidityEventTriggerEnable() | ||
| || EventPluginLoader.getInstance().isSolidityLogTriggerEnable())) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SHOULD] outer condition Subtler still: the consumer Suggestion (preferred): simply drop the guard. private void clearSolidityContractTriggerCache(long blockNum) {
Args.getSolidityContractLogTriggerMap().remove(blockNum);
Args.getSolidityContractEventTriggerMap().remove(blockNum);
}
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enabling only |
||
| Args.getSolidityContractLogTriggerMap().remove(blockNum); | ||
| Args.getSolidityContractEventTriggerMap().remove(blockNum); | ||
| } | ||
| } | ||
|
|
||
| private void postContractTrigger(final TransactionTrace trace, boolean remove, String blockHash) { | ||
|
|
@@ -2397,9 +2408,14 @@ private void postContractTrigger(final TransactionTrace trace, boolean remove, S | |
| .getLatestSolidifiedBlockNum()); | ||
| contractTriggerCapsule.setBlockHash(blockHash); | ||
|
|
||
| if (!triggerCapsuleQueue.offer(contractTriggerCapsule)) { | ||
| logger.info("Too many triggers, contract log trigger lost: {}.", | ||
| trigger.getTransactionId()); | ||
| // Process synchronously to avoid race condition between async queue and | ||
| // reOrgContractTrigger cache clearing. Performance is not impacted because | ||
| // processTrigger() only enqueues events into the plugin's internal queue | ||
|
yanghang8612 marked this conversation as resolved.
|
||
| // without blocking on actual I/O. | ||
| try { | ||
| contractTriggerCapsule.processTrigger(); | ||
| } catch (Throwable throwable) { | ||
| logger.warn("Post contract trigger failed.", throwable); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[SHOULD]
switchForkhas twoapplyBlockfailure paths that don't clear the cache.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated chain switching is a historical oversight and will not be addressed in this PR. It can be discussed separately in a later issue.