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

IS-450 Reload rotation timestamp on each isExitTime request #1757

Merged
merged 11 commits into from
Jan 9, 2024

Conversation

badrogger
Copy link
Contributor

@badrogger badrogger commented Dec 15, 2023

Problem

The solution for https://github.com/skalenetwork/internal-support/issues/450 making skale-admin will write it to corresponding file directly instead of sending rpc call. The issue is that InstanceMonitor.cpp loads this file once during startup, which effectively says that timestamp won't be passed to skaled at all.

Changes

isExitTime will check the content of rotation.txt file and compare it to current block timestamp instead on relaying on m_finishTimestamp field.

Performance

Since rotation.txt file is only 4 bytes and reading is happening in background performance should not be affected.

Unit tests

Modified tests in InstanceMonitorTest.cpp.

Testing

Tested by running rotation procedure on local network.

@badrogger badrogger marked this pull request as ready for review December 15, 2023 15:34
}

bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) {
if ( !fs::exists( m_rotationInfoFilePath ) ) {
return false;
}
return m_finishTimestamp <= _finishTimestamp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to write information about rotation into logs

@@ -46,23 +46,20 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) {
std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() );
rotationInfoFile << rotationJson;

m_finishTimestamp = _finishTimestamp;
LOG( m_logger ) << "Set rotation time to " << m_finishTimestamp;
LOG( m_logger ) << "Set rotation time to " << _finishTimestamp;
}

bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to rename the parameter to currentTimestamp/blockTimestamp or sth like this

Copy link
Collaborator

@kladkogex kladkogex left a comment

Choose a reason for hiding this comment

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

Change .txt to .json

uint64_t InstanceMonitor::rotationTimestamp() const {
std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() );
auto rotationJson = nlohmann::json::parse( rotationInfoFile );
auto timestamp = rotationJson["timestamp"].get< uint64_t >();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add try catch to handle the case of corrupt file

@@ -46,23 +46,22 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) {
std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() );
rotationInfoFile << rotationJson;

m_finishTimestamp = _finishTimestamp;
LOG( m_logger ) << "Set rotation time to " << m_finishTimestamp;
LOG( m_logger ) << "Set rotation time to " << _finishTimestamp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add try catch

@@ -61,5 +56,5 @@ class InstanceMonitor {
void reportExitTimeReached( bool _reached );

private:
dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) };
mutable dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) };
Copy link
Collaborator

Choose a reason for hiding this comment

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

mutable is not needed here

dimalit
dimalit previously approved these changes Dec 28, 2023
Copy link

codecov bot commented Jan 3, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (6183faf) 45.52% compared to head (53ecf1e) 45.61%.
Report is 1 commits behind head on v3.18.0.

❗ Current head 53ecf1e differs from pull request most recent head 9ce9d5c. Consider uploading reports for the commit 9ce9d5c to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           v3.18.0    #1757      +/-   ##
===========================================
+ Coverage    45.52%   45.61%   +0.08%     
===========================================
  Files          356      356              
  Lines        51709    51727      +18     
===========================================
+ Hits         23542    23593      +51     
+ Misses       28167    28134      -33     

@kladkogex kladkogex self-requested a review January 4, 2024 17:06
kladkogex
kladkogex previously approved these changes Jan 4, 2024
@badrogger badrogger changed the title Reload rotation timestamp on each isExitTime request IS-450 Reload rotation timestamp on each isExitTime request Jan 4, 2024
dimalit
dimalit previously approved these changes Jan 4, 2024
Comment on lines 73 to 74
mutable dev::Logger m_info_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) };
mutable dev::Logger m_error_logger{ createLogger( dev::VerbosityError, "instance-monitor" ) };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change to camelCase

@olehnikolaiev olehnikolaiev self-requested a review January 8, 2024 13:22
@DmytroNazarenko DmytroNazarenko merged commit bfa5a20 into v3.18.0 Jan 9, 2024
7 checks passed
@DmytroNazarenko DmytroNazarenko deleted the reload-rotation-timestamp branch January 9, 2024 13:16
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants