- 
                Notifications
    
You must be signed in to change notification settings  - Fork 286
 
Remove Global State #1146
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
base: master
Are you sure you want to change the base?
Remove Global State #1146
Conversation
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.
NACK
This doesn't address the issue with the dependancies between these components and main and in fact just makes a lot of this harder to eventually test.
What needs to be done is asic.h, for instance, needs to no longer know about global state.
On top of that this is far too large of a change to go in without any additional tests being written.
          
 the thing is that the GLOBAL_STATE is static in main but not accessible without routing it through methods, in fact its static^^ ESP-Miner/main/tasks/stratum_task.c Lines 343 to 346 in d47275b 
 like this this makes sure that every struct with extern flag can exists only once. i can also move the structs into own headers, then they can get included as needed  | 
    
…s from process work that they match the header declaration
          
 Ok, this might be worthwhile and I might agree, but you called the PR splitt modules but there wasn't any change in dependencies. You need to work on the commit and PR clarity here. It changes 1000 lines of code. Lets be clearer on the intent  | 
    
          
 Not everything in the struct will cause memory leaks. Only the alloc'd values like the strings. That is unavoidable. we need to free the dynamically allocated strings regardless of if GLOBAL_STATE holds the pointer or some other module.  | 
    
          
 i did not say it will, it can. but its now more safe because its using the same memory location and make the free obsolete. 
 I probably have to, if you have a good title feel free to change it  | 
    
# Conflicts: # main/global_state.h # main/tasks/asic_result_task.c # main/tasks/power_management_task.c
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.
i rechecked everything requested
| #include "device_config.h" | ||
| #include "wifi_module.h" | ||
| #include "pool_module.h" | ||
| #include "state_module.h" | 
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.
All these includes is a sign that we need to overhaul this class as well. But that's outside the scope of this PR.
| // static bm_job ** active_jobs; is required to keep track of the active jobs since the | ||
| const double NONCE_SPACE = 4294967296.0; // 2^32 | ||
| 
               | 
          ||
| double ASIC_get_asic_job_frequency_ms(float frequency) | 
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.
Interesting to see this moved here. Kinda makes sense, at least in the current version.
| #include "system_module.h" | ||
| #include "device_config.h" | ||
| #include "pool_module.h" | ||
| #include "state_module.h" | 
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.
Similar commend to http_server, this file might need to be broken up as well. But not for this PR.
        
          
                main/system_module.h
              
                Outdated
          
        
      | 
               | 
          ||
| typedef struct | ||
| { | ||
| // The starting time for a certain period of mining activity. | 
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.
This comment is not correct I think. AFAIK it has something to do with the statistics. Maybe those can be moved into a Statistics_module?
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.
its correct^^
Line 213 in 27c8dc4
| double duration = (double) (esp_timer_get_time() - module->duration_start) / 1000000; | 
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.
its only used in system.c it dont have to be global
…rate_time_stamps historical_hashrate historical_hashrate_init into own struct
6d88748    to
    b801cf5      
    Compare
  
    # Conflicts: # main/http_server/http_server.c # main/http_server/http_server.h # main/tasks/power_management_task.c # main/tasks/power_management_task.h # main/thermal/thermal.h
b801cf5    to
    ce7f0f9      
    Compare
  
    # Conflicts: # components/asic/asic.c # components/asic/bm1397.c # components/asic/include/bm1366.h # components/asic/include/bm1368.h # components/asic/include/bm1370.h # components/asic/include/bm1397.h # main/http_server/http_server.c # main/self_test/self_test.c # main/tasks/create_jobs_task.c # main/tasks/power_management_task.c
| 
           As an exercise to the reader (me) I tried to only make  My try is in https://github.com/mutatrum/ESP-Miner/tree/static-global-state. Some stuff could be done further, f.e. the  Having said that, I think the changes on how the modules are separated do make sense. Maybe a better way would be to indeed remove GlobalState, have the modules live in   | 
    
| 
           this is only the top of the iceberg^^ https://github.com/KillerInk/ESP-Miner/blob/8f43e63d151c35542534d4719d2a6153c4e7ddc5/main/tasks/asic_task.h#L12-L13 https://github.com/KillerInk/ESP-Miner/blob/8f43e63d151c35542534d4719d2a6153c4e7ddc5/main/tasks/stratum_task.h#L8  | 
    
# Conflicts: # components/asic/asic.c # components/asic/bm1397.c # components/asic/include/bm1366.h # components/asic/include/bm1368.h # components/asic/include/bm1370.h # components/asic/include/bm1397.h # main/global_state.h # main/http_server/http_server.c # main/main.c # main/screen.c # main/self_test/self_test.c # main/system.c # main/tasks/create_jobs_task.c # main/tasks/power_management_task.c # main/tasks/statistics_task.c # main/tasks/stratum_task.c # main/thermal/thermal.c # main/thermal/thermal.h
…dule2 # Conflicts: # components/asic/asic.c # main/self_test/self_test.c # main/tasks/create_jobs_task.c # main/tasks/power_management_task.c
pool switch refactor mvp
fix build error
This PR removes reliance on the GlobalState structure to improve readability, maintainability, and functionality.
Removed the GlobalState parameter from most functions, simplifying function signatures.
Extracted relevant data directly where needed instead of relying on a global state.
These changes aim to streamline the ASIC management code while ensuring all ASIC types are properly supported and making the codebase more modular.