Skip to content

Commit

Permalink
Merge pull request #2032 from skalenetwork/bug/IS-1083-catchup-snapsh…
Browse files Browse the repository at this point in the history
…ot-priority-archive

Bug/is 1083 catchup snapshot priority archive
  • Loading branch information
olehnikolaiev authored Oct 25, 2024
2 parents 73dc77e + c358786 commit 7e333f5
Showing 1 changed file with 23 additions and 29 deletions.
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

0 comments on commit 7e333f5

Please sign in to comment.