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

[Neo Plugin New Feature] Rollback ledger #3313

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Jun 9, 2024

Description

Problem:

Neo nodes support various plugins that provide a wide range of services, such as applicationlogs, stateservice, and more. However, these plugins sometimes crash or pause, causing them to miss critical block execution information. This desynchronization between the plugins and the blockchain can lead to inconsistencies and outdated information.

Currently, the only way to resynchronize these plugins is to reprocess the entire blockchain from the genesis block, which is inefficient and time-consuming. This process also increases the risk of further errors and delays in service restoration.

Solution:

To address this issue, we propose implementing a rollback mechanism in the Neo node. This mechanism will allow the blockchain to roll back to a specified block height, enabling plugins to resynchronize their data starting from that point. By rolling back to a known good state and reapplying blocks, plugins can catch up with the latest block execution information without the need for a full blockchain resynchronization.

Proposed Implementation:

Monitor and Record State Changes:

Implement a system to monitor and record state changes of the blockchain during block commits.
Save these state changes to a persistent store indexed by block height.
Rollback Command:

Introduce a new command (fallback ledger) that allows users to specify a target block height to roll back to.
When executed, the command will revert the blockchain state to the specified height by applying the recorded state changes in reverse order.
Reapply Blocks:

After rolling back to the specified height, the node will reprocess blocks from that height onward, ensuring that plugins can update their state with the latest block execution information.

Fixes # #3312

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • TBD

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y Jim8y marked this pull request as draft June 9, 2024 18:21
@Jim8y Jim8y linked an issue Jun 9, 2024 that may be closed by this pull request
@@ -34,7 +34,7 @@ public sealed record StorageKey

public StorageKey() { }

internal StorageKey(byte[] cache)
public StorageKey(byte[] cache)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be reverted by setting neo internal accessable to plugin

@cschuchardt88
Copy link
Member

cschuchardt88 commented Jun 16, 2024

@roman-khimov @Jim8y

Can't we use SPV packets? To reset the node? To rebuild the MerkleRoot

#region SPV protocol
/// <summary>
/// Sent to load the <see cref="BloomFilter"/>.
/// </summary>
[ReflectionCache(typeof(FilterLoadPayload))]
FilterLoad = 0x30,
/// <summary>
/// Sent to update the items for the <see cref="BloomFilter"/>.
/// </summary>
[ReflectionCache(typeof(FilterAddPayload))]
FilterAdd = 0x31,
/// <summary>
/// Sent to clear the <see cref="BloomFilter"/>.
/// </summary>
FilterClear = 0x32,
/// <summary>
/// Sent to send a filtered block.
/// </summary>
[ReflectionCache(typeof(MerkleBlockPayload))]
MerkleBlock = 0x38,
#endregion

@roman-khimov
Copy link
Contributor

No, that's different.

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.

Implement Rollback Mechanism for Neo Node to Sync Plugin Information
3 participants