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

Fix some snap sync issues #6802

Merged
merged 8 commits into from
Mar 26, 2024
Merged

Conversation

matkt
Copy link
Contributor

@matkt matkt commented Mar 25, 2024

PR description

The purpose of this PR is to fix some bugs detected in the snap sync. This should allow for greater stability with the snap sync and the healing of the flat DB.

Fixed Issue(s)

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

matkt added 4 commits March 5, 2024 09:24
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
@matkt matkt force-pushed the feature/snap-fix-test branch from 99c9a1c to 11405c2 Compare March 25, 2024 09:22
@matkt matkt marked this pull request as ready for review March 25, 2024 09:26
Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

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

LGTM, a couple suggestions regarding doc and dedupe, 🚢 when ready

Comment on lines 155 to 174

public static boolean isInRange(
final Bytes location, final Bytes startKeyPath, final Bytes endKeyPath) {
final MutableBytes path = MutableBytes.create(Bytes32.SIZE * 2);
path.set(0, location);
return !location.isEmpty()
&& Arrays.compare(path.toArrayUnsafe(), startKeyPath.toArrayUnsafe()) >= 0
&& Arrays.compare(path.toArrayUnsafe(), endKeyPath.toArrayUnsafe()) <= 0;
}

public static Bytes createPath(final Bytes bytes) {
final MutableBytes path = MutableBytes.create(bytes.size() * 2);
int j = 0;
for (int i = 0; i < bytes.size(); i += 1, j += 2) {
final byte b = bytes.get(i);
path.set(j, (byte) ((b >>> 4) & 0x0f));
path.set(j + 1, (byte) (b & 0x0f));
}
return path;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

both of these could use javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 80 to 86
public static boolean isInRange(
final Bytes location, final Bytes startKeyPath, final Bytes endKeyPath) {
final MutableBytes path = MutableBytes.create(Bytes32.SIZE * 2);
path.set(0, location);
return Arrays.compare(path.toArrayUnsafe(), startKeyPath.toArrayUnsafe()) >= 0
&& Arrays.compare(path.toArrayUnsafe(), endKeyPath.toArrayUnsafe()) <= 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not use the range manager implementation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a modified version where location.isEmpty is removed in the check . I can create another PR to check if we can merge the two range methods

Comment on lines 40 to 74
@Override
public void visit(final Bytes location, final ExtensionNode<V> extensionNode) {
if (!extensionNode.isDirty()) {
return;
}

final Node<V> child = extensionNode.getChild();
if (child.isDirty()) {
child.accept(Bytes.concatenate(location, extensionNode.getPath()), this);
}
if (child.isHealNeeded()
|| !isInRange(
Bytes.concatenate(location, extensionNode.getPath()), startKeyPath, endKeyPath)) {
extensionNode.markHealNeeded(); // not save an incomplete node
}

maybeStoreNode(location, extensionNode);
}

@Override
public void visit(final Bytes location, final BranchNode<V> branchNode) {
if (!branchNode.isDirty()) {
return;
}

for (int i = 0; i < branchNode.maxChild(); ++i) {
Bytes index = Bytes.of(i);
final Node<V> child = branchNode.child((byte) i);
if (child.isDirty()) {
child.accept(Bytes.concatenate(location, index), this);
}
if (child.isHealNeeded()
|| !isInRange(Bytes.concatenate(location, index), startKeyPath, endKeyPath)) {
branchNode.markHealNeeded(); // not save an incomplete node
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add javadoc on these too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added javadoc

matkt added 3 commits March 26, 2024 11:24
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
@matkt matkt enabled auto-merge (squash) March 26, 2024 13:10
@matkt matkt merged commit 15cbd84 into hyperledger:main Mar 26, 2024
42 checks passed
jflo pushed a commit to jflo/besu that referenced this pull request Mar 26, 2024
The purpose of this commit is to fix some bugs detected in the snap sync. This should allow for greater stability with the snap sync and the healing of the flat DB.

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
amsmota pushed a commit to Citi/besu that referenced this pull request Apr 16, 2024
The purpose of this commit is to fix some bugs detected in the snap sync. This should allow for greater stability with the snap sync and the healing of the flat DB.

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: amsmota <antonio.mota@citi.com>
amsmota pushed a commit to Citi/besu that referenced this pull request Apr 16, 2024
The purpose of this commit is to fix some bugs detected in the snap sync. This should allow for greater stability with the snap sync and the healing of the flat DB.

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: amsmota <antonio.mota@citi.com>
matthew1001 pushed a commit to kaleido-io/besu that referenced this pull request Jun 7, 2024
The purpose of this commit is to fix some bugs detected in the snap sync. This should allow for greater stability with the snap sync and the healing of the flat DB.

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
@matkt matkt deleted the feature/snap-fix-test branch November 28, 2024 15:43
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