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

Bug/is 1083 catchup snapshot priority archive #2032

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions skaled/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ int main( int argc, char** argv ) try {

std::string urlToDownloadSnapshotFrom = "";
if ( vm.count( "no-snapshot-majority" ) ) {
downloadSnapshotFlag = true;
urlToDownloadSnapshotFrom = vm["no-snapshot-majority"].as< string >();
clog( VerbosityInfo, "main" )
<< "Manually set url to download snapshot from: " << urlToDownloadSnapshotFrom;
Expand All @@ -1601,27 +1602,10 @@ int main( int argc, char** argv ) try {
std::vector< std::string > coreVolumes = { BlockChain::getChainDirName( chainParams ),
"filestorage", "prices_" + chainParams.nodeInfo.id.str() + ".db",
"blocks_" + chainParams.nodeInfo.id.str() + ".db" };
std::vector< std::string > archiveVolumes = {};
if ( chainParams.nodeInfo.archiveMode ) {
#ifdef HISTORIC_STATE
archiveVolumes.insert( archiveVolumes.end(), { "historic_roots", "historic_state" } );
#endif
}
snapshotManager.reset( new SnapshotManager(
chainParams, getDataDir(), sharedSpace ? sharedSpace->getPath() : "" ) );
}

bool downloadGenesisForSyncNode = false;
if ( chainParams.nodeInfo.syncNode ) {
auto bc = BlockChain( chainParams, getDataDir() );
if ( bc.number() == 0 ) {
downloadSnapshotFlag = true;
if ( chainParams.nodeInfo.syncFromCatchup ) {
downloadGenesisForSyncNode = true;
}
}
}

if ( downloadSnapshotFlag ) {
statusAndControl->setExitState( StatusAndControl::StartAgain, true );
statusAndControl->setExitState( StatusAndControl::StartFromSnapshot, true );
Expand All @@ -1632,18 +1616,8 @@ int main( int argc, char** argv ) try {
sharedSpace_lock.reset( new std::lock_guard< SharedSpace >( *sharedSpace ) );

try {
if ( !downloadGenesisForSyncNode )
downloadAndProccessSnapshot(
snapshotManager, chainParams, urlToDownloadSnapshotFrom, true );
else {
try {
downloadAndProccessSnapshot(
snapshotManager, chainParams, urlToDownloadSnapshotFrom, false );
snapshotManager->restoreSnapshot( 0 );
} catch ( SnapshotManager::SnapshotAbsent& ) {
clog( VerbosityWarning, "main" ) << "Snapshot for 0 block is not found";
}
}
downloadAndProccessSnapshot(
snapshotManager, chainParams, urlToDownloadSnapshotFrom, true );

// if we dont have 0 snapshot yet
try {
Expand All @@ -1669,6 +1643,26 @@ int main( int argc, char** argv ) try {

} // if --download-snapshot

// download 0 snapshot if needed
if ( chainParams.nodeInfo.syncNode ) {
auto bc = BlockChain( chainParams, getDataDir() );
if ( bc.number() == 0 ) {
if ( chainParams.nodeInfo.syncFromCatchup && !downloadSnapshotFlag ) {
statusAndControl->setExitState( StatusAndControl::StartAgain, true );
statusAndControl->setExitState( StatusAndControl::StartFromSnapshot, true );
statusAndControl->setSubsystemRunning( StatusAndControl::SnapshotDownloader, true );

try {
downloadAndProccessSnapshot(
snapshotManager, chainParams, urlToDownloadSnapshotFrom, false );
snapshotManager->restoreSnapshot( 0 );
} catch ( SnapshotManager::SnapshotAbsent& ) {
clog( VerbosityWarning, "main" ) << "Snapshot for 0 block is not found";
}
}
}
}

statusAndControl->setSubsystemRunning( StatusAndControl::SnapshotDownloader, false );

statusAndControl->setExitState( StatusAndControl::StartAgain, true );
Expand Down
Loading