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

feat: hash checksums + download urls for snapshot restore and create #201

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

BrendanCoughlan5
Copy link
Contributor

@BrendanCoughlan5 BrendanCoughlan5 commented Jan 27, 2025

hash checksums + download urls for snapshot restore and create, also cleaned up/ logs/ readme/ docs

@BrendanCoughlan5 BrendanCoughlan5 requested a review from a team as a code owner January 27, 2025 17:38
@BrendanCoughlan5 BrendanCoughlan5 changed the title feat: introduce hash checksums + download urls for snapshot restore a… feat: hash checksums + download urls for snapshot restore and create Jan 27, 2025
@BrendanCoughlan5 BrendanCoughlan5 force-pushed the hashes_and_snapshot_download branch from 1bac8ff to 43ca345 Compare January 27, 2025 17:41
README.md Outdated Show resolved Hide resolved
docs/snapshots_docs.md Outdated Show resolved Hide resolved
docs/snapshots_docs.md Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Outdated Show resolved Hide resolved
@BrendanCoughlan5 BrendanCoughlan5 force-pushed the hashes_and_snapshot_download branch from 17209f2 to 443cb30 Compare January 29, 2025 10:37
@BrendanCoughlan5 BrendanCoughlan5 self-assigned this Jan 29, 2025
@BrendanCoughlan5 BrendanCoughlan5 force-pushed the hashes_and_snapshot_download branch from acb5f62 to d215762 Compare January 30, 2025 19:59
@BrendanCoughlan5 BrendanCoughlan5 force-pushed the hashes_and_snapshot_download branch from d215762 to 28d5544 Compare January 30, 2025 20:02
docs/src/content/docs/running/snapshots.md Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
hashFileName := inputFileName + ".sha256sum"
hashFile, err := downloadFile(inputUrl+".sha256sum", hashFileName)
if err != nil {
return fmt.Errorf("failed to download snapshot hash: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to differentiate between an problem downloading the file and an error like a 404 where the file simply doesnt exist? If it doesnt exist, what do you think is the best thing to do?

Copy link
Contributor Author

@BrendanCoughlan5 BrendanCoughlan5 Jan 30, 2025

Choose a reason for hiding this comment

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

When using the repo_metadata/ manifest, if there's a 404 and you can't find the file, then you should go through older versions, i.e. curl -I through newest -> oldest, then download it, i think this would be handled no in the downloadFile but in a function interpreting the manifest to find the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also did the errors.Wrap and the downloadFile gives a 404 to be more explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

potentially you could give an error that the hash file isn't there, no verification happened and then proceed with restoring the snapshot, but i think that might be dangerous/ security wouldn't like that? Maybe for testnet that's fine to allow, i'm a bit hesitant to allow restore snapshot without

pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot_test.go Show resolved Hide resolved
docs/src/content/docs/running/snapshots.md Outdated Show resolved Hide resolved
docs/src/content/docs/running/snapshots.md Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
@seanmcgary seanmcgary self-requested a review February 3, 2025 14:49
Copy link
Member

@seanmcgary seanmcgary left a comment

Choose a reason for hiding this comment

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

Selected the wrong option on accident...see above feedback for changes needed.

@seanmcgary
Copy link
Member

seanmcgary commented Feb 3, 2025

Ran the restore-snapshot function and encountered a strange error. It seems to have downloaded the file completely, but then say's it received a 404 after the fact (which isnt possible):

downloading tmp/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump 100% [========================================] Error: failed to restore snapshot: Error downloading snapshot from 'https://eigenlayer-sidecar.s3.us-east-1.amazonaws.com/snapshots/testnet-holesky/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump': downloading error, received status code 404

It also didnt clean up the file that was created, which it probably should.

arguments:

go run main.go restore-snapshot
    --ethereum.rpc-url="https://winter-white-crater.ethereum-holesky.quiknode.pro/1b1d75c4ada73b7ad98e1488880649d4ea637733/" \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_test_restore" \
        --ethereum.use_native_batch_call=false \
        --snapshot.input=https://eigenlayer-sidecar.s3.us-east-1.amazonaws.com/snapshots/testnet-holesky/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump \
        --database.schema_name=public

As a sidenote, when we encounter an error during execution, can we change it so that the usage message isnt printed? It adds a lot of noise and should really only be printed if the inputs are incorrect.

@BrendanCoughlan5
Copy link
Contributor Author

BrendanCoughlan5 commented Feb 3, 2025

Ran the restore-snapshot function and encountered a strange error. It seems to have downloaded the file completely, but then say's it received a 404 after the fact (which isnt possible):

downloading tmp/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump 100% [========================================] Error: failed to restore snapshot: Error downloading snapshot from 'https://eigenlayer-sidecar.s3.us-east-1.amazonaws.com/snapshots/testnet-holesky/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump': downloading error, received status code 404

It also didnt clean up the file that was created, which it probably should.

arguments:

go run main.go restore-snapshot
    --ethereum.rpc-url="https://winter-white-crater.ethereum-holesky.quiknode.pro/1b1d75c4ada73b7ad98e1488880649d4ea637733/" \
    --chain="preprod" \
    --database.host="localhost" \
    --database.port="5432" \
    --database.user="seanmcgary" \
    --database.password="" \
    --database.db_name="sidecar_test_restore" \
        --ethereum.use_native_batch_call=false \
        --snapshot.input=https://eigenlayer-sidecar.s3.us-east-1.amazonaws.com/snapshots/testnet-holesky/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump \
        --database.schema_name=public

As a sidenote, when we encounter an error during execution, can we change it so that the usage message isnt printed? It adds a lot of noise and should really only be printed if the inputs are incorrect.

Fixed to be clear it's the filesum the hash that doesn't exist.

Try with the --snapshot.verify-input=false flag

It should now give something like : {"level":"fatal","ts":"2025-02-03T12:53:34.148-0800","caller":"cmd/restoreSnapshot.go:44","msg":"failed to restore snapshot","error":"snapshot hash file not found at 'https://eigenlayer-sidecar.s3.us-east-1.amazonaws.com/snapshots/testnet-holesky/sidecar-testnet-holesky_v3.0.0-rc.1_public_20250122.dump.sha256sum'. Ensure the file exists or set --verify-input=false to skip verification","stacktrace":"github.com/Layr-Labs/sidecar/cmd.init.func4\n\t/Users/brendan/Documents/GitHub/sidecar/cmd/restoreSnapshot.go:44\ngithub.com/spf13/cobra.(*Command).execute\n\t/Users/brendan/go/pkg/mod/github.com/spf13/[email protected]/command.go:985\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/brendan/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\t/Users/brendan/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041\ngithub.com/Layr-Labs/sidecar/cmd.Execute\n\t/Users/brendan/Documents/GitHub/sidecar/cmd/root.go:19\nmain.main\n\t/Users/brendan/Documents/GitHub/sidecar/main.go:8\nruntime.main\n\t/opt/homebrew/Cellar/go/1.23.4/libexec/src/runtime/proc.go:272"}

cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/createSnapshot.go Outdated Show resolved Hide resolved
cmd/restoreSnapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
}
}

// Download the snapshot file and assign to s.cfg.Input
Copy link
Member

Choose a reason for hiding this comment

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

except we're using inputUrl not s.cfg.Input. Comments should explain why, not what and/or clarify potentially complex code/edgecases

}

// Download the snapshot file and assign to s.cfg.Input
fileName, err := getFileNameFromURL(inputUrl)
Copy link
Member

Choose a reason for hiding this comment

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

Comment says we're downloading the file but this function is not downloading the file. Recommend removing the comment

if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to resolve input file path '%s'", s.cfg.Input))
}
s.cfg.Input = resolvedFilePath
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, we should not be overwriting config values

}

info, err := os.Stat(s.cfg.InputFile)
// s.cfg.input is resolved from a url in resolveAndDownloadRestoreInput()
Copy link
Member

Choose a reason for hiding this comment

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

if we're having to leave comments because the meaning of our config values changes during runtime, we need to modify the behavior to prevent that. config values should be immutable in nature

pkg/snapshot/snapshot_test.go Show resolved Hide resolved
@BrendanCoughlan5 BrendanCoughlan5 force-pushed the hashes_and_snapshot_download branch from f149b27 to 3929046 Compare February 6, 2025 07:07
@BrendanCoughlan5
Copy link
Contributor Author

#201 (comment)

downloadFile is intended to be used to download an individual file, like you downloadFile(snapshot), then downloadFile(snapshotHash)

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