-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: module allowlist #166
Changes from all commits
87ba4a6
d5fb39a
b43ff07
f11d420
34de49f
b93d9df
00a2914
1392fca
21bb3cc
c8bb757
9e9817e
44a7343
fecb2f1
ae89e7a
bffc8c9
4152d85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,11 @@ type JobOfferContainer struct { | |
State uint8 `json:"state"` | ||
JobOffer JobOffer `json:"job_offer"` | ||
} | ||
type EnabledModules struct { | ||
ModuleID string | ||
Version string | ||
Enabled bool | ||
} | ||
|
||
// posted to the solver by a resource provider | ||
type ResourceOffer struct { | ||
|
@@ -140,7 +145,8 @@ type ResourceOffer struct { | |
Spec MachineSpec `json:"spec"` | ||
// the module ID's that this resource provider can run | ||
// an empty list means ALL modules | ||
Modules []string `json:"modules"` | ||
Modules []EnabledModules `json:"modules"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename this to |
||
|
||
// tells the solver how to match these prices | ||
// for RP this will normally be FixedPrice | ||
// we expect the default pricing to be filled in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package jobcreator | |
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/lilypad-tech/lilypad/pkg/data" | ||
|
@@ -25,13 +26,19 @@ type JobCreatorController struct { | |
loop *system.ControlLoop | ||
log *system.ServiceLogger | ||
jobOfferSubscriptions []JobOfferSubscriber | ||
moduleAllowlist []string | ||
enableAllowlist bool | ||
} | ||
|
||
// the background "even if we have not heard of an event" loop | ||
// i.e. things will not wait 10 seconds - the control loop | ||
// reacts to events in the system - this 10 second background | ||
// loop is just for in case we miss any events | ||
const CONTROL_LOOP_INTERVAL = 10 * time.Second | ||
const ( | ||
ALLOWLIST_URL = "https://raw.githubusercontent.com/lilypad-tech/module-allowlist/main/allowlist.txt" | ||
|
||
// the background "even if we have not heard of an event" loop | ||
// i.e. things will not wait 10 seconds - the control loop | ||
// reacts to events in the system - this 10 second background | ||
// loop is just for in case we miss any events | ||
CONTROL_LOOP_INTERVAL = 10 * time.Second | ||
) | ||
|
||
func NewJobCreatorController( | ||
options JobCreatorOptions, | ||
|
@@ -141,6 +148,7 @@ func (controller *JobCreatorController) subscribeToWeb3() error { | |
controller.web3Events.Storage.SubscribeDealStateChange(func(ev storage.StorageDealStateChange) { | ||
deal, err := controller.solverClient.GetDeal(ev.DealId) | ||
if err != nil { | ||
err = fmt.Errorf("module allowlist error: %s", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks off, if that's the error then it should bubble up from where it happened no? The way this code reads it says any error during the |
||
controller.log.Error("error getting deal", err) | ||
return | ||
} | ||
|
@@ -156,6 +164,34 @@ func (controller *JobCreatorController) subscribeToWeb3() error { | |
|
||
func (controller *JobCreatorController) Start(ctx context.Context, cm *system.CleanupManager) chan error { | ||
errorChan := make(chan error) | ||
|
||
// Check the enableAllowlist flag to determine whether to manage the module allowlist | ||
if controller.enableAllowlist { | ||
// Initial fetch of the module allowlist | ||
err := controller.UpdateModuleAllowlist() | ||
if err != nil { | ||
controller.log.Error("failed to fetch module allowlist", err) | ||
} | ||
|
||
// Periodic update logic here using a time.Ticker | ||
ticker := time.NewTicker(1 * time.Hour) | ||
go func() { | ||
for { | ||
select { | ||
case <-ticker.C: | ||
err := controller.UpdateModuleAllowlist() | ||
if err != nil { | ||
controller.log.Error("periodic module allowlist update failed", err) | ||
} | ||
case <-ctx.Done(): | ||
ticker.Stop() | ||
return | ||
} | ||
} | ||
}() | ||
} | ||
|
||
// Setup subscriptions and other initialization tasks | ||
err := controller.subscribeToSolver() | ||
if err != nil { | ||
errorChan <- err | ||
|
@@ -166,6 +202,11 @@ func (controller *JobCreatorController) Start(ctx context.Context, cm *system.Cl | |
errorChan <- err | ||
return errorChan | ||
} | ||
err = controller.allowlistApproved() | ||
if err != nil { | ||
errorChan <- err | ||
return errorChan | ||
} | ||
|
||
// this connects the websocket client | ||
err = controller.solverClient.Start(ctx, cm) | ||
|
@@ -201,6 +242,38 @@ func (controller *JobCreatorController) Start(ctx context.Context, cm *system.Cl | |
return errorChan | ||
} | ||
|
||
func (controller *JobCreatorController) UpdateModuleAllowlist() error { | ||
// Call the new helper function with a 5-second timeout! | ||
body, err := http.GetRequestWithTimeout(ALLOWLIST_URL, 5*time.Second) | ||
if err != nil { | ||
return fmt.Errorf("failed to fetch module allowlist: %s", err) | ||
} | ||
|
||
// Update the internal cache of the allowlist | ||
controller.moduleAllowlist = strings.Split(strings.TrimSpace(string(body)), "\n") | ||
return nil | ||
} | ||
|
||
func (controller *JobCreatorController) allowlistApproved() error { | ||
controller.web3Events.Storage.SubscribeDealStateChange(func(ev storage.StorageDealStateChange) { | ||
deal, err := controller.solverClient.GetDeal(ev.DealId) | ||
if err != nil { | ||
|
||
controller.log.Error("module allowlist error", err) | ||
return | ||
} | ||
|
||
// error handling out of the allowlist function- this is a critical error!! | ||
if deal.JobCreator != controller.web3SDK.GetAddress().String() { | ||
return | ||
} | ||
controller.log.Debug("StorageDealStateChange", data.GetAgreementStateString(ev.State)) | ||
system.DumpObjectDebug(ev) | ||
controller.loop.Trigger() | ||
}) | ||
return nil | ||
} | ||
|
||
/* | ||
* | ||
* | ||
|
@@ -288,6 +361,7 @@ func (controller *JobCreatorController) agreeToDeals() error { | |
// list the deals that have results posted but we have not yet checked | ||
// we do this synchronously to prevent us racing with large result sets | ||
// also we are the client so have a lower chance of there being a chunky backlog | ||
|
||
noryev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (controller *JobCreatorController) checkResults() error { | ||
// load all deals in ResultsSubmitted state and don't have either results checked or accepted txs | ||
completedDeals, err := controller.solverClient.GetDealsWithFilter( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,11 +60,18 @@ type ResourceProviderPowOptions struct { | |
CudaBlockSize int | ||
} | ||
|
||
// Enabled Modules | ||
|
||
type ResourceProviderEnabledModules struct { | ||
EnableAllowlist bool | ||
} | ||
|
||
type ResourceProviderOptions struct { | ||
Bacalhau bacalhau.BacalhauExecutorOptions | ||
Offers ResourceProviderOfferOptions | ||
Web3 web3.Web3Options | ||
Pow ResourceProviderPowOptions | ||
Bacalhau bacalhau.BacalhauExecutorOptions | ||
Offers ResourceProviderOfferOptions | ||
Web3 web3.Web3Options | ||
Pow ResourceProviderPowOptions | ||
Allowlist ResourceProviderAllowlistOptions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, let's deprecate |
||
} | ||
|
||
type ResourceProvider struct { | ||
|
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 seems off, let's remove this.