generated from opentensor/bittensor-subnet-template
-
Notifications
You must be signed in to change notification settings - Fork 35
Thykof/mod 1170 handle wrong response from a miner #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
Merged
parkhomenko
merged 6 commits into
main
from
thykof/mod-1170-handle-wrong-response-from-a-miner
Jan 16, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b5d787
introduce function validate_responses
Thykof 86f0253
reverse logic of validate_responses
Thykof c7ff01f
check json format and start time
Thykof 00e426f
add bt_venv into gitignore
Thykof dc428fd
validation method fixes
parkhomenko cd48020
formatted the file
parkhomenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,7 @@ bt_venv/ | |
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
| bt_venv | ||
|
|
||
| # Spyder project settings | ||
| .spyderproject | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import json | ||
| from datetime import datetime, timedelta | ||
|
|
||
|
|
||
| from simulation.simulation_input import SimulationInput | ||
|
|
||
|
|
||
| def validate_responses(response, simulation_input: SimulationInput) -> bool: | ||
| """ | ||
| Validate responses from miners. | ||
|
|
||
| Return False if response is incorrect. | ||
| """ | ||
| if response is None or len(response) == 0: | ||
| return False | ||
|
|
||
| # check the number of paths | ||
| if len(response) != simulation_input.num_simulations: | ||
| return False | ||
|
|
||
| for path in response: | ||
| # check the number of time points | ||
| if ( | ||
| len(path) | ||
| != ( | ||
| simulation_input.time_length // simulation_input.time_increment | ||
| ) | ||
| + 1 | ||
| ): | ||
| return False | ||
|
|
||
| # check the start time | ||
| if path[0]["time"] != simulation_input.start_time: | ||
| return False | ||
|
|
||
| for i in range(1, len(path)): | ||
| # check the time increment | ||
| i_minus_one_time = datetime.fromisoformat(path[i - 1]["time"]) | ||
| i_time = datetime.fromisoformat(path[i]["time"]) | ||
| expected_delta = timedelta(seconds=simulation_input.time_increment) | ||
| if i_time - i_minus_one_time != expected_delta: | ||
| return False | ||
|
|
||
| # check the price format | ||
| if not isinstance(path[i]["price"], (int, float)): | ||
| return False | ||
|
|
||
| return True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ah, I forgot about this! Good catch :)