-
Notifications
You must be signed in to change notification settings - Fork 21
Add PDP scheduling API boundary interfaces #616
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,63 @@ | ||
| package dealpusher | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "math/big" | ||
| "time" | ||
|
|
||
| "github.com/data-preservation-programs/singularity/model" | ||
| "github.com/ipfs/go-cid" | ||
| ) | ||
|
|
||
| // PDPSchedulingConfig holds PDP-specific scheduling knobs for on-chain operations. | ||
| type PDPSchedulingConfig struct { | ||
| BatchSize int | ||
| GasLimit uint64 | ||
| ConfirmationDepth uint64 | ||
| PollingInterval time.Duration | ||
| } | ||
|
|
||
| // Validate validates PDP scheduling configuration. | ||
anjor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func (c PDPSchedulingConfig) Validate() error { | ||
| if c.BatchSize <= 0 { | ||
| return errors.New("pdp batch size must be greater than 0") | ||
| } | ||
| if c.GasLimit == 0 { | ||
| return errors.New("pdp gas limit must be greater than 0") | ||
| } | ||
| if c.ConfirmationDepth == 0 { | ||
| return errors.New("pdp confirmation depth must be greater than 0") | ||
| } | ||
| if c.PollingInterval <= 0 { | ||
| return errors.New("pdp polling interval must be greater than 0") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // PDPProofSetManager defines proof set lifecycle operations needed by scheduling. | ||
| type PDPProofSetManager interface { | ||
| // EnsureProofSet returns an existing proof set ID or creates one for this client/provider pair. | ||
| EnsureProofSet(ctx context.Context, wallet model.Wallet, provider string) (uint64, error) | ||
| // QueueAddRoots submits root additions for a proof set and returns the queued tx reference. | ||
| QueueAddRoots(ctx context.Context, proofSetID uint64, pieceCIDs []cid.Cid, cfg PDPSchedulingConfig) (*PDPQueuedTx, error) | ||
| } | ||
|
|
||
| // PDPTransactionConfirmer defines confirmation checks for queued on-chain transactions. | ||
| type PDPTransactionConfirmer interface { | ||
| WaitForConfirmations(ctx context.Context, txHash string, depth uint64, pollInterval time.Duration) (*PDPTransactionReceipt, error) | ||
| } | ||
|
|
||
| // PDPQueuedTx represents an on-chain transaction submitted by PDP scheduling. | ||
| type PDPQueuedTx struct { | ||
| Hash string | ||
| } | ||
|
|
||
| // PDPTransactionReceipt represents a confirmed on-chain transaction result. | ||
| type PDPTransactionReceipt struct { | ||
| Hash string | ||
| BlockNumber uint64 | ||
| GasUsed uint64 | ||
| Status uint64 | ||
| CostAttoFIL *big.Int | ||
| } | ||
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,36 @@ | ||
| package dealpusher | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestPDPSchedulingConfigValidate(t *testing.T) { | ||
| t.Run("valid", func(t *testing.T) { | ||
| cfg := PDPSchedulingConfig{ | ||
| BatchSize: 100, | ||
| GasLimit: 5000000, | ||
| ConfirmationDepth: 5, | ||
| PollingInterval: 30 * time.Second, | ||
| } | ||
| require.NoError(t, cfg.Validate()) | ||
| }) | ||
|
|
||
| t.Run("invalid", func(t *testing.T) { | ||
| cfg := PDPSchedulingConfig{} | ||
| require.Error(t, cfg.Validate()) | ||
| }) | ||
|
|
||
| t.Run("invalid gas limit", func(t *testing.T) { | ||
| cfg := PDPSchedulingConfig{ | ||
| BatchSize: 100, | ||
| ConfirmationDepth: 5, | ||
| PollingInterval: 30 * time.Second, | ||
| } | ||
| err := cfg.Validate() | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "pdp gas limit must be greater than 0") | ||
| }) | ||
| } |
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,60 @@ | ||
| package dealpusher | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/data-preservation-programs/singularity/model" | ||
| "github.com/ipfs/go-cid" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| type noopPDPProofSetManager struct{} | ||
|
|
||
| func (noopPDPProofSetManager) EnsureProofSet(_ context.Context, _ model.Wallet, _ string) (uint64, error) { | ||
| return 1, nil | ||
| } | ||
|
|
||
| func (noopPDPProofSetManager) QueueAddRoots(_ context.Context, _ uint64, _ []cid.Cid, _ PDPSchedulingConfig) (*PDPQueuedTx, error) { | ||
| return &PDPQueuedTx{Hash: "0x1"}, nil | ||
| } | ||
|
|
||
| type noopPDPTransactionConfirmer struct{} | ||
|
|
||
| func (noopPDPTransactionConfirmer) WaitForConfirmations(_ context.Context, txHash string, _ uint64, _ time.Duration) (*PDPTransactionReceipt, error) { | ||
| return &PDPTransactionReceipt{Hash: txHash}, nil | ||
| } | ||
|
|
||
| func TestDealPusher_ResolveScheduleDealType_DefaultsToMarket(t *testing.T) { | ||
| d := &DealPusher{} | ||
| require.Equal(t, model.DealTypeMarket, d.resolveScheduleDealType(&model.Schedule{})) | ||
| } | ||
|
|
||
| func TestDealPusher_RunSchedule_PDPWithoutDependenciesReturnsConfiguredError(t *testing.T) { | ||
| d := &DealPusher{ | ||
| scheduleDealTypeResolver: func(_ *model.Schedule) model.DealType { | ||
| return model.DealTypePDP | ||
| }, | ||
| } | ||
|
|
||
| state, err := d.runSchedule(context.Background(), &model.Schedule{}) | ||
| require.Error(t, err) | ||
| require.Equal(t, model.ScheduleError, state) | ||
| require.Contains(t, err.Error(), "pdp scheduling dependencies are not configured") | ||
| } | ||
|
|
||
| func TestDealPusher_RunSchedule_PDPWithDependenciesReturnsNotImplemented(t *testing.T) { | ||
| d := &DealPusher{ | ||
| pdpProofSetManager: noopPDPProofSetManager{}, | ||
| pdpTxConfirmer: noopPDPTransactionConfirmer{}, | ||
| scheduleDealTypeResolver: func(_ *model.Schedule) model.DealType { | ||
| return model.DealTypePDP | ||
| }, | ||
| } | ||
|
|
||
| state, err := d.runSchedule(context.Background(), &model.Schedule{}) | ||
| require.Error(t, err) | ||
| require.Equal(t, model.ScheduleError, state) | ||
| require.Contains(t, err.Error(), "pdp scheduling path is not implemented") | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.