-
Notifications
You must be signed in to change notification settings - Fork 80
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
public archive sdk #2426
public archive sdk #2426
Conversation
# Conflicts: # pkg/node/local.go
@@ -490,6 +498,9 @@ func UpsizeLocalNode( | |||
nodeConfig = map[string]interface{}{} | |||
} | |||
nodeConfig[config.NetworkAllowPrivateIPsKey] = true | |||
if network.Kind == models.Fuji { | |||
nodeConfig[config.IndexEnabledKey] = false // disable index for Fuji |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does it mean if this flag is disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataset for avalanchego created with index and without are not interchangeable
sdk/publicarchive/downloader.go
Outdated
} | ||
|
||
// NewDownloader returns a new Downloader | ||
// network: the network to download from ( fuji or mainnet). todo: add mainnet support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets remove this mainnet support part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
sdk/publicarchive/downloader.go
Outdated
}, nil | ||
} | ||
default: | ||
return Downloader{}, fmt.Errorf("unsupported network ID: %d", network.ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just print currently public archive is only supported on fuji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
return nil | ||
} | ||
|
||
func (d Downloader) UnpackTo(targetDir string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no library for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also have code for this
switch header.Typeflag { | ||
case tar.TypeDir: | ||
d.logger.Debug("Creating directory", zap.String("path", targetPath)) | ||
if err := os.MkdirAll(targetPath, os.FileMode(header.Mode)); err != nil { | ||
d.logger.Error("Failed to create directory", zap.Error(err)) | ||
return fmt.Errorf("failed to create directory: %w", err) | ||
} | ||
case tar.TypeReg: | ||
d.logger.Debug("Ensure parent directory exists for ", zap.String("path", targetPath)) | ||
if err := os.MkdirAll(filepath.Dir(targetPath), os.FileMode(0o755)); err != nil { | ||
d.logger.Error("Failed to create parent directory for file", zap.Error(err)) | ||
return fmt.Errorf("failed to create parent directory for file: %w", err) | ||
} | ||
d.logger.Debug("Creating file", zap.String("path", targetPath)) | ||
outFile, err := os.Create(targetPath) | ||
if err != nil { | ||
d.logger.Error("Failed to create file", zap.Error(err)) | ||
return fmt.Errorf("failed to create file: %w", err) | ||
} | ||
defer outFile.Close() | ||
copied, err := io.CopyN(outFile, tarReader, header.Size) | ||
if err != nil { | ||
d.logger.Error("Failed to write file", zap.Error(err)) | ||
return fmt.Errorf("failed to write file: %w", err) | ||
} | ||
if copied < header.Size { | ||
d.logger.Error("Incomplete file write", zap.String("path", targetPath)) | ||
return fmt.Errorf("incomplete file write for %s", targetPath) | ||
} | ||
extractedSize += header.Size | ||
d.logger.Debug("Written bytes", zap.Int64("bytes", extractedSize)) | ||
default: | ||
d.logger.Debug("Skipping file", zap.String("path", targetPath)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be better for us to use library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't find one that I liked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open for the suggestions
pkg/node/helper.go
Outdated
if err := publicArcDownloader.Download(); err != nil { | ||
return fmt.Errorf("failed to download public archive: %w", err) | ||
} | ||
// defer publicArcDownloader.CleanUp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. it should be enabled and was commented out for the debug
|
||
wg := sync.WaitGroup{} | ||
mu := sync.Mutex{} | ||
var firstErr error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should rename this err var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err is used in
if firstErr == nil {
firstErr = fmt.Errorf("failed to unpack public archive: %w", err)
so it should be some other name
ux.Logger.Info("unpacking public archive to %s", target) | ||
|
||
// Skip if target already exists | ||
if _, err := os.Stat(target); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we override data instead of skip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no we should skip as data is already there
sdk/publicarchive/downloader.go
Outdated
"github.com/cavaliergopher/grab/v3" | ||
"go.uber.org/zap" | ||
|
||
sdkConstants "github.com/ava-labs/avalanche-cli/sdk/constants" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inside sdk I shall call this one constants, and the other one cliConstants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
sdk/publicarchive/downloader.go
Outdated
// logLevel: the log level | ||
func NewDownloader( | ||
network network.Network, | ||
logLevel logging.Level, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it receive a logger instead of log level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is to have full control on the logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
return nil | ||
} | ||
|
||
func (d Downloader) UnpackTo(targetDir string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also have code for this
sdk/constants/constants.go
Outdated
@@ -10,5 +10,6 @@ const ( | |||
APIRequestLargeTimeout = 2 * time.Minute | |||
|
|||
// node | |||
WriteReadUserOnlyPerms = 0o600 | |||
WriteReadUserOnlyPerms = 0o600 | |||
WriteReadUserOnlyDirPerms = 0o700 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserOnlyReadWriteExecPerms ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
pkg/node/helper.go
Outdated
return nil | ||
} | ||
|
||
func CleanUpClusterNodeData(rootDir string, nodesNames []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this is not needed to be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. fixed
pkg/node/helper.go
Outdated
@@ -555,3 +560,75 @@ func GetNodeData(endpoint string) ( | |||
"0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:]), | |||
nil | |||
} | |||
|
|||
func SeedClusterData( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it have another name. Something related to downloading blockchain db for the cluster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to DownloadPublicArchive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Why this should be merged
resolves #2425
it provides sdk pkg to access public archive data for fuji to speedup
avalanchego
bootstrap if connected to fujicurrent timing
How this works
only fuji is supported for now.
sdk provides a functionality to Download public archive data into tmp file. This data can be un-tar into destination folder.
this sdk is used inside of the CLI. In case of the error all downloaded data is cleaned and bootstrap continues on like nothing happened.
How this was tested
How is this documented
n/a