-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
SUGGESTIONS BEFORE MERGE:
|
} | ||
|
||
bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) { | ||
if ( !fs::exists( m_rotationInfoFilePath ) ) { | ||
return false; | ||
} | ||
return m_finishTimestamp <= _finishTimestamp; |
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.
It's better to write information about rotation into logs
libethereum/InstanceMonitor.cpp
Outdated
@@ -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 ) { |
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.
Better to rename the parameter to currentTimestamp
/blockTimestamp
or sth like 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.
Change .txt to .json
libethereum/InstanceMonitor.cpp
Outdated
uint64_t InstanceMonitor::rotationTimestamp() const { | ||
std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); | ||
auto rotationJson = nlohmann::json::parse( rotationInfoFile ); | ||
auto timestamp = rotationJson["timestamp"].get< uint64_t >(); |
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.
Add try catch to handle the case of corrupt file
libethereum/InstanceMonitor.cpp
Outdated
@@ -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; |
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.
Add try catch
libethereum/InstanceMonitor.h
Outdated
@@ -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" ) }; |
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.
mutable is not needed here
Codecov ReportAttention:
Additional details and impacted files@@ 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 |
libethereum/InstanceMonitor.h
Outdated
mutable dev::Logger m_info_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; | ||
mutable dev::Logger m_error_logger{ createLogger( dev::VerbosityError, "instance-monitor" ) }; |
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.
Change to camelCase
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 onm_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.