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

Problem: memiavl import API not implemented #941

Merged
merged 3 commits into from
Apr 3, 2023

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Mar 24, 2023

Solution:

  • implement Import function to convert state-sync snapshot to memiavl snapshot

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

@yihuang yihuang requested a review from a team as a code owner March 24, 2023 14:40
@yihuang yihuang requested review from calvinaco and thomas-nguy and removed request for a team March 24, 2023 14:40
Solution:
- implement Import function to convert state-sync snapshot to memiavl snapshot
node := &MemNode{
height: uint8(n.Height),
size: 1,
version: uint32(n.Version),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
memiavl/import.go Fixed Show fixed Hide fixed
i := w.nodeIndex
w.nodeIndex++
return i, nil
return w.writeBranch(node.Version(), uint32(node.Size()), node.Height(), leftIndex+1, node.Hash())

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
right: rightNode,
}
nodeHash := node.Hash()
idx, err := i.writeBranch(node.version, uint32(node.size), node.height, leftIndex+1, nodeHash)

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
rightNode := i.nodeStack[len(i.nodeStack)-1]

node := &MemNode{
height: uint8(n.Height),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
memiavl/import.go Fixed Show fixed Hide fixed
node := &MemNode{
height: uint8(n.Height),
size: leftNode.size + rightNode.size,
version: uint32(n.Version),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion

if n.Height == 0 {
node := &MemNode{
height: uint8(n.Height),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
memiavl/import.go Fixed Show fixed Hide fixed
memiavl/import.go Outdated Show resolved Hide resolved
memiavl/import.go Fixed Show fixed Hide fixed
memiavl/snapshot.go Fixed Show fixed Hide fixed
memiavl/import.go Fixed Show fixed Hide fixed
@yihuang
Copy link
Collaborator Author

yihuang commented Mar 25, 2023

@mmsqe sorry I did a force push to improve the code reuse, please review again

@yihuang yihuang requested a review from mmsqe March 25, 2023 03:08
if err := buildIndex(input, kvsIndexFile, snapshotDir, int(t.root.Size())); err != nil {
// N = 2L-1
leaves := (rootIndex + 2) / 2
if err := buildIndex(input, kvsIndexFile, dir, int(leaves)); err != nil {

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
return errors.New("version overflows uint32")
}

return writeSnapshot(dir, uint32(version), writeHashIndex, func(w *snapshotWriter) (uint32, error) {

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
Copy link
Collaborator

@mmsqe mmsqe left a comment

Choose a reason for hiding this comment

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

np, looks better now

memiavl/import.go Outdated Show resolved Hide resolved
Co-authored-by: mmsqe <tqd0800210105@gmail.com>
Signed-off-by: yihuang <huang@crypto.com>
@yihuang yihuang enabled auto-merge (squash) April 3, 2023 02:59
@yihuang yihuang merged commit 8004e02 into crypto-org-chain:main Apr 3, 2023
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