Skip to content

Commit

Permalink
fix: re-register resource offers after runJob (#396)
Browse files Browse the repository at this point in the history
* fix: re-register resource offers after runJob

* chore: go mod tidy
  • Loading branch information
walkah authored Oct 9, 2024
1 parent 85f92b9 commit 1cc64f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-libp2p v0.36.5 // indirect
github.com/libp2p/go-libp2p v0.36.4 // indirect
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
github.com/libp2p/go-libp2p-kad-dht v0.26.1 // indirect
github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ github.com/libp2p/go-doh-resolver v0.4.0 h1:gUBa1f1XsPwtpE1du0O+nnZCUqtG7oYi7Bb+
github.com/libp2p/go-doh-resolver v0.4.0/go.mod h1:v1/jwsFusgsWIGX/c6vCRrnJ60x7bhTiq/fs2qt0cAg=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro=
github.com/libp2p/go-libp2p v0.36.5 h1:DoABsaHO0VXwH6pwCs2F6XKAXWYjFMO4HFBoVxTnF9g=
github.com/libp2p/go-libp2p v0.36.5/go.mod h1:CpszAtXxHYOcyvB7K8rSHgnNlh21eKjYbEfLoMerbEI=
github.com/libp2p/go-libp2p v0.36.4 h1:ZaKyKSHBFbzs6CnAYMhaMc5QgV1UoCN+9WXrg8SEwI4=
github.com/libp2p/go-libp2p v0.36.4/go.mod h1:4Y5vFyCUiJuluEPmpnKYf6WFx5ViKPUYs/ixe9ANFZ8=
github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94=
github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8=
github.com/libp2p/go-libp2p-kad-dht v0.26.1 h1:AazV3LCImYVkDUGAHx5lIEgZ9iUI2QQKH5GMRQU8uEA=
Expand Down
17 changes: 14 additions & 3 deletions pkg/resourceprovider/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (controller *ResourceProviderController) Start(ctx context.Context, cm *sys
ctx,
CONTROL_LOOP_INTERVAL,
func() error {
err := controller.ensureResourceOffers()
err := controller.checkResourceoffers()
if err != nil {
errorChan <- err
}
Expand Down Expand Up @@ -248,12 +248,22 @@ func (controller *ResourceProviderController) getResourceOffer(index int, spec d
}
}

func (controller *ResourceProviderController) ensureResourceOffers() error {
func (controller *ResourceProviderController) checkResourceoffers() error {
// We only want to run this every RESOURCE_OFFER_INTERVAL
if !lastResourceOfferPost.IsZero() && time.Since(lastResourceOfferPost) < RESOURCE_OFFER_INTERVAL {
return nil
}

err := controller.ensureResourceOffers()
if err != nil {
return err
}

lastResourceOfferPost = time.Now()
return nil
}

func (controller *ResourceProviderController) ensureResourceOffers() error {
// load the resource offers that are currently active and so should not be replaced
activeResourceOffers, err := controller.solverClient.GetResourceOffers(store.GetResourceOffersQuery{
ResourceProvider: controller.web3SDK.GetAddress().String(),
Expand Down Expand Up @@ -302,7 +312,6 @@ func (controller *ResourceProviderController) ensureResourceOffers() error {
}
}

lastResourceOfferPost = time.Now()
return err
}

Expand Down Expand Up @@ -546,5 +555,7 @@ func (controller *ResourceProviderController) runJob(ctx context.Context, deal d
}
span.AddEvent("solver.transaction_hash.added")

controller.ensureResourceOffers()

span.AddEvent("done")
}

0 comments on commit 1cc64f2

Please sign in to comment.