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

agd export option for diagnosis #10344

Merged
merged 21 commits into from
Nov 21, 2024
Merged

agd export option for diagnosis #10344

merged 21 commits into from
Nov 21, 2024

Conversation

usmanmani1122
Copy link
Contributor

@usmanmani1122 usmanmani1122 commented Oct 28, 2024

closes: #8420
ref: #8152

Description

This PR adds a new optional flag --swing-store-export-mode to the agd export command which can be used to specify the nature of swing-store export

Security Considerations

None

Scaling Considerations

None

Documentation Considerations

An optional flag --swing-store-export-mode option is now supported for agd export to specify the kind of swing store export required:

  • operational (default) option will retain the existing behavior and export the swing-store artifacts using the latest height
  • skip option will not export any swing-store artifact
  • debug option will export all swing-store artifacts, starting from height 0

Testing Considerations

Tested manually

Upgrade Considerations

None

@usmanmani1122 usmanmani1122 self-assigned this Oct 28, 2024
Copy link

cloudflare-workers-and-pages bot commented Oct 28, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: cda65f9
Status: ✅  Deploy successful!
Preview URL: https://54559351.agoric-sdk.pages.dev
Branch Preview URL: https://usman-8420.agoric-sdk.pages.dev

View logs

}

// We don't have to launch VM in case the swing store export is not required
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mhofman since OnExportHook currently points to launchVM, is it okay to bypass this hook in case swing-store export is not needed? Or do you see us adding cosmic side future hook changes?

Copy link
Member

Choose a reason for hiding this comment

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

I think that's fine, but I'd like @michaelfig to confirm, especially with his upcoming changed for split brains. Basically export only needs to launch the VM if it will export the swing-store, which is decided by a command line config. Since OnExportHook is unconditionally set or not based on the entrypoint used, the only option we have is to ignore it here.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, my brain still struggles with distributing negations.

Suggested change
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
if swingStoreExportMode != swingsetkeeper.SwingStoreArtifactModeSkip && OnExportHook != nil {

@usmanmani1122 usmanmani1122 requested a review from mhofman October 31, 2024 12:07
@usmanmani1122 usmanmani1122 marked this pull request as ready for review October 31, 2024 12:07
@usmanmani1122 usmanmani1122 requested a review from a team as a code owner October 31, 2024 12:07
artifactsEnded = true
if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
err = nil
exportDataReader, err := getExportDataReader()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to close this reader in defer?
defer exportDataReader.Close()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought EncodeKVEntryReaderToJsonl function will close the reader passed to it at the end but it seems like it doesn't

Copy link
Member

Choose a reason for hiding this comment

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

Right, EncodeKVEntryReaderToJsonl doesn't close the reader. I think that was because I wanted the reader to be closed even if a read error occurred, and leave the caller in charge of handling potentially double errors. I'm not sure if that's the idiomatic golang thing to do, and would be open to reconsider if it's not.

Comment on lines 249 to 256
artifact = types.SwingStoreArtifact{
Data: encodedExportData.Bytes(),
Name: keeper.UntrustedExportDataArtifactName,
}
}
}
}
}
Copy link
Contributor

@Muneeb147 Muneeb147 Oct 31, 2024

Choose a reason for hiding this comment

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

So in-case exportMode is "debug", we are sending an extra artifact at the end which is a full export of swingStore (Kvstore)? Right? Assuming that caller iterates over ReadNextArtifact until gets io.EOF.

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Thanks for digging through this. The main issue is that we don't currently write out the "export data" as "untrusted copy" in debug mode, but instead we-write the cosmos DB copy.

golang/cosmos/app/app.go Show resolved Hide resolved
golang/cosmos/daemon/cmd/root.go Outdated Show resolved Hide resolved
}

// We don't have to launch VM in case the swing store export is not required
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that's fine, but I'd like @michaelfig to confirm, especially with his upcoming changed for split brains. Basically export only needs to launch the VM if it will export the swing-store, which is decided by a command line config. Since OnExportHook is unconditionally set or not based on the entrypoint used, the only option we have is to ignore it here.

}

// We don't have to launch VM in case the swing store export is not required
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
Copy link
Member

Choose a reason for hiding this comment

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

Btw, my brain still struggles with distributing negations.

Suggested change
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
if swingStoreExportMode != swingsetkeeper.SwingStoreArtifactModeSkip && OnExportHook != nil {

golang/cosmos/x/swingset/genesis.go Outdated Show resolved Hide resolved
golang/cosmos/x/swingset/genesis.go Outdated Show resolved Hide resolved
Comment on lines +244 to +253
err = agoric.EncodeKVEntryReaderToJsonl(
exportDataReader,
&encodedExportData,
)
if err == nil {
artifact = types.SwingStoreArtifact{
Data: encodedExportData.Bytes(),
Name: keeper.UntrustedExportDataArtifactName,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It really is a bit unfortunate we have to read, decode, re-encode it all in memory before finally writing it out, but streamlining this is definitely out of scope.

golang/cosmos/x/swingset/genesis.go Show resolved Hide resolved
golang/cosmos/x/swingset/genesis.go Outdated Show resolved Hide resolved
Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Assuming my final nit is addressed, feel free to merge this. Thanks for working on this.

Comment on lines 198 to 211
const (
// SwingStoreExportModeSkip indicates swing store data should be
// excluded from the export.
SwingStoreExportModeSkip = "skip"

// SwingStoreExportModeOperational (default) indicates export should
// have the minimal set of artifacts needed to operate a node.
SwingStoreExportModeOperational = "operational"

// SwingStoreExportModeDebug indicates export should have the maximal
// set of artifacts available in the JS swing-store.
SwingStoreExportModeDebug = "debug"
)

Copy link
Member

Choose a reason for hiding this comment

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

Let's move these to genesis.go as it's only applicable to that logic.

artifactsEnded = true
if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
err = nil
exportDataReader, err := getExportDataReader()
Copy link
Member

Choose a reason for hiding this comment

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

Right, EncodeKVEntryReaderToJsonl doesn't close the reader. I think that was because I wanted the reader to be closed even if a read error occurred, and leave the caller in charge of handling potentially double errors. I'm not sure if that's the idiomatic golang thing to do, and would be open to reconsider if it's not.

@usmanmani1122 usmanmani1122 added the automerge:squash Automatically squash merge label Nov 21, 2024
@mergify mergify bot merged commit 6112a8b into master Nov 21, 2024
91 checks passed
@mergify mergify bot deleted the usman/8420 branch November 21, 2024 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:squash Automatically squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

agd export option for diagnosis
3 participants