Conversation
bfacaac to
c24b031
Compare
66fa621 to
bcef559
Compare
hannahhoward
left a comment
There was a problem hiding this comment.
Left various comments, none blocking. Overall, really really nicely done. I have only minor quibbles.
Not marking any of my changes blocking since I'm headed out. But honestly, I would like to see the swear words removed. Sorry for being that bitch. :)
| aggregateSubmitterQueue := aws.NewSQSAggregateQueue(cfg.Config, cfg.SQSPDPPieceAggregatorURL) | ||
| aggregateSubmitter := aggregator.NewAggregateSubmitteer(cfg.PDPProofSet, aggregateStore, apiClient, aggregateSubmitterQueue) | ||
| aggregateSubmitter := aggregator.NewAggregateSubmitteer( | ||
| &aggregator.ConfiguredProofSetProvider{ID: cfg.PDPProofSet}, |
There was a problem hiding this comment.
why not just pass the ID direct?
There was a problem hiding this comment.
I had ideas around a different implementation of ProofSetProvider (ConfiguredProofSetProvider implements this interface) which lazily creates a proof set if one doesn't exist when it comes time to submit aggregates.
| } | ||
| } | ||
|
|
||
| func initLogging() { |
| switch { | ||
| case err != nil && g.level >= logger.Error: | ||
| // Always log SQL errors with call stack | ||
| // Skip logging "record not found" errors for pdp_piece_mh_to_commp table |
There was a problem hiding this comment.
Is it not useful altogether? Why not relegate to warning?
There was a problem hiding this comment.
The pdp_piece_mh_to_commp table is a mapping of (mostly) sha256 multihash to commp multihash. It's the table we frequently use to determine if a piece has been stored with us before. Therefore, we query this table a lot for existence checks, and it frequently doesn't find the cid when there is a new allocation - as expected. Returning an error or a warning here isn't appropriate since there isn't technically an error or a warning that the user needs to be made aware of - it's an in-actionable log message.
This log became spamy during my local testing/dev here, so I modified it to be less spamy.
|
|
||
| // Create SQLite database connection | ||
| db, err := sqlitedb.New(cfg.Replicator.DBPath) | ||
| db, err := sqlitedb.New(cfg.Replicator.DBPath, |
There was a problem hiding this comment.
again related to change or no?
There was a problem hiding this comment.
related to single process I mean
There was a problem hiding this comment.
The new options? Mostly yes.
| return s.aggregator | ||
| } | ||
|
|
||
| func ProvidePoorlyNamedPDPInterface(service types.API, agg aggregator.Aggregator, cfg app.AppConfig) (*Shit, error) { |
There was a problem hiding this comment.
OMG. man this is painful though I get it. look I don't want to make a big deal but sir this is a wendys. can we not use the actual S-word in the code? Just in case we forget to change it?
There was a problem hiding this comment.
🙈 sorry!!!! I'll fix this, didn't mean to push it.
| func (p *PDPService) FindPiece(ctx context.Context, piece types.Piece) (cid.Cid, bool, error) { | ||
| func (p *PDPService) FindPiece(ctx context.Context, piece types.Piece) (_ cid.Cid, _ bool, retErr error) { | ||
| log.Infow("finding piece", "request", piece) | ||
| defer func() { |
There was a problem hiding this comment.
Same here, retErr is not assigned to...I assume this is what @hannahhoward is also referring to? Maybe I don't know Go good enough...?
There was a problem hiding this comment.
same same but different: https://github.com/storacha/piri/pull/192/files#r2285712328
| start := time.Now() | ||
| log.Infow("uploading piece", "request", pieceUpload) | ||
| defer func() { | ||
| if retErr != nil { |
There was a problem hiding this comment.
I guess this will be a thing then :P
Question: all these logs are unrelated to the single process refactor yes? generally I would put those in a seperate PR. Not a big deal though.
| ) | ||
|
|
||
| // MarshalLogObject implements zapcore.ObjectMarshaler for ProofSetStatus | ||
| func (p ProofSetStatus) MarshalLogObject(enc zapcore.ObjectEncoder) error { |
There was a problem hiding this comment.
again nice refactor! again for the future I would leave this sort of thing out of an already large PR. but nb
There was a problem hiding this comment.
Yes sorry, did this for debugging. Will try to avoid things like this on big changes in the future.
alanshaw
left a comment
There was a problem hiding this comment.
I don't think I have any hard blocks here, but I do think it would be good to move the logging changes to a seperate PR since they're unrelated (also because I'm not sure they will actually do any logging).
I would really like piri serve full to just be piri serve though..."full" just screams legacy baggage IMHO.
| logging.SetLogLevel("auth", "error") | ||
| logging.SetLogLevel("rpcenc", "error") | ||
| logging.SetLogLevel("storage", "info") | ||
| logging.SetLogLevel("resources", "error") |
There was a problem hiding this comment.
The default is error right? Why not expicitly set all loggers to error and then just change the ones you want to change?
There was a problem hiding this comment.
ohh, yeah good point that would be a simpler change and easier to reason about - will address.
| Use: "full", | ||
| Short: "Start the full piri server!", | ||
| Args: cobra.NoArgs, | ||
| RunE: fullServer, |
There was a problem hiding this comment.
While I don't disagree - what becomes of piri serve ucan? Perhaps enabling the PDP mode ought to be a configuration value or flag on the serve command itself?
There was a problem hiding this comment.
or the other way around, as in piri serve --ucan-only
There was a problem hiding this comment.
Are we okay with merging this as is, and addressing this comment(s) in a follow on?
|
|
||
| FullCmd.Flags().String( | ||
| "contract-address", | ||
| "0x6170dE2b09b404776197485F3dc6c968Ef948505", // NB(forrest): default to calibration contract addrese |
There was a problem hiding this comment.
Do you think we should move this to presets?
There was a problem hiding this comment.
humm, yeah that would probably be a better place for this, will address.
| switch { | ||
| case err != nil && g.level >= logger.Error: | ||
| // Always log SQL errors with call stack | ||
| // Skip logging "record not found" errors for pdp_piece_mh_to_commp table |
There was a problem hiding this comment.
Is it not useful altogether? Why not relegate to warning?
| fx.As(new(aggregator.Aggregator)), | ||
| ), | ||
| aggregator.NewPieceAccepter, | ||
| aggregator.NewAggregateSubmitteer, |
There was a problem hiding this comment.
| aggregator.NewAggregateSubmitteer, | |
| aggregator.NewAggregateSubmitter, |
There was a problem hiding this comment.
Submitteer predates my changes, and I had kinda just assumed Submitteer was the british-english spelling. Will change!
|
|
||
| type PieceAccepter struct { | ||
| issuer ucan.Signer | ||
| issuer principal.Signer |
There was a problem hiding this comment.
Why the switch here and other places?
There was a problem hiding this comment.
Because the identity is provided and injected as a principal.Signer here: https://github.com/storacha/piri/blob/main/pkg/fx/identity/provider.go#L15
we could modify this fx code I linked to such that:
var Module = fx.Module("identity",
fx.Provide(
ProvideIdentity,
fx.Annotate(
fx.As(fx.Self()),
fx.As(new(ucan.Signer)),
),
),
)which will provide the identity as both interfaces - ucan.Signer and principal.Signer, allowing other methods to depend on either interface, but sticking with one here - principal.Signer because that feels simpler - fewer interfaces.
| LogStatus: true, | ||
| LogContentLength: true, | ||
| LogResponseSize: true, | ||
| LogHeaders: []string{"X-Agent-Message"}, |
There was a problem hiding this comment.
😮 wow are you skating to where the puck will be? ❤️
There was a problem hiding this comment.
⛸️ 🕺 Yup! Trying to align with storacha/go-ucanto#48 here
| } else { | ||
| log.Infow("allocated piece", "request", allocation, "response", res) | ||
| } | ||
| }() |
There was a problem hiding this comment.
Does this work? I don't think the function assigns to retErr anywhere?
There was a problem hiding this comment.
Yes because of the change in the function signature using named result parameters:
(res *types.AllocatedPiece, retErr error)
retErr will contain an error if this function returns an error, same for res containing *types.AllocatedPiece if the function executes successfully.
| func (p *PDPService) FindPiece(ctx context.Context, piece types.Piece) (cid.Cid, bool, error) { | ||
| func (p *PDPService) FindPiece(ctx context.Context, piece types.Piece) (_ cid.Cid, _ bool, retErr error) { | ||
| log.Infow("finding piece", "request", piece) | ||
| defer func() { |
There was a problem hiding this comment.
Same here, retErr is not assigned to...I assume this is what @hannahhoward is also referring to? Maybe I don't know Go good enough...?
| log.Infow("uploading piece", "request", pieceUpload) | ||
| defer func() { | ||
| if retErr != nil { | ||
| log.Errorw("failed to upload piece", "request", pieceUpload, "duration", time.Since(start), "error", retErr) |
There was a problem hiding this comment.
Is the duration useful in the log? Can it be added to telemetry instead? Maybe this is a seperate PR?
There was a problem hiding this comment.
Yes these should be metrics emitted from the node. I added in these logs while verifying that all APIs and their corresponding services were registered w/ fx. Should have been a separate change, but landed in here for my own convenience.
| func(svc *claims.ClaimService) claims.Claims { | ||
| return svc | ||
| }, | ||
| NewService, |
There was a problem hiding this comment.
can we now get rid of the NewService -> claims.NewV2 thing now?
There was a problem hiding this comment.
I'd like to do that in a follow on, where we also move a bunch of the fx provider codes closer to the types they are providing. Also, NewService is still used for the AWS setup iirc.
| func(svc *publisher.PublisherService) publisher.Publisher { | ||
| return svc | ||
| }, | ||
| NewService, |
There was a problem hiding this comment.
same here, I'd expect the logic in NewService to be part of publisher.New in the service/publisher package
There was a problem hiding this comment.
Fully agree, mentioned this here: https://github.com/storacha/piri/pull/192/files#r2285609301 would prefer to wait and do this in a follow on.
| var Module = fx.Module("root-handler", | ||
| fx.Provide( | ||
| fx.Annotate( | ||
| NewRootHandler, |
There was a problem hiding this comment.
maybe move this to the pkg/server package?
There was a problem hiding this comment.
Agreed, follow item: https://github.com/storacha/piri/pull/192/files#r2285609301
|
|
||
| "github.com/ipld/go-ipld-prime/datamodel" | ||
| "github.com/storacha/go-libstoracha/capabilities/types" | ||
| libtypes "github.com/storacha/go-libstoracha/capabilities/types" |
There was a problem hiding this comment.
this is usually aliased as captypes in other repos (just a convention)
| "github.com/storacha/piri/pkg/pdp/aggregator/aggregate" | ||
| "github.com/storacha/piri/pkg/pdp/aggregator/fns" | ||
| types2 "github.com/storacha/piri/pkg/pdp/types" | ||
| types "github.com/storacha/piri/pkg/pdp/types" |
There was a problem hiding this comment.
this is redundant now
| types "github.com/storacha/piri/pkg/pdp/types" | |
| "github.com/storacha/piri/pkg/pdp/types" |
| return db, nil | ||
| } | ||
|
|
||
| func ProviderAggregatorDB(lc fx.Lifecycle, cfg app.StorageConfig) (*sql.DB, error) { |
There was a problem hiding this comment.
| func ProviderAggregatorDB(lc fx.Lifecycle, cfg app.StorageConfig) (*sql.DB, error) { | |
| func ProvideAggregatorDB(lc fx.Lifecycle, cfg app.StorageConfig) (*sql.DB, error) { |
| } | ||
| blobStore := blobstore.NewTODO_DsBlobstore(namespace.Wrap(ds, datastore.NewKey("blobs"))) | ||
| stashStore, err := store.NewStashStore(path.Join(dataDir)) | ||
| stashStore, err := stashstore.NewStashStore(path.Join(dataDir)) |
There was a problem hiding this comment.
now that the store package is renamed to stashstore, stashstore.NewStashStore could be renamed to stashstore.New
There was a problem hiding this comment.
Agreed, saving this for a follow on where we do more mechanical cleanups.
| Use: "full", | ||
| Short: "Start the full piri server!", | ||
| Args: cobra.NoArgs, | ||
| RunE: fullServer, |
| // AsRouteRegistrar provides the Handler as a RouteRegistrar | ||
| func AsRouteRegistrar(h *Handler) echofx.RouteRegistrar { | ||
| return h | ||
| } | ||
|
|
There was a problem hiding this comment.
I thought this was what fx.As was for?
bcef559 to
bc0063a
Compare
required for full node when proof set isn't know at aggregator startup time. i.e allows lazy fetching and creating of a proofset.
bc0063a to
3df6a33
Compare
98916c2 to
fbd91a6
Compare
fbd91a6 to
2288012
Compare
Dependencies & Review
This PR builds on #190
I would recommend reviewing each commit of this PR on it's own - I have done my best to keep them well scoped.
What
This PR makes life easier by combining two servers into one. Instead of juggling
piri serve ucanandpiri server pdpin separate processes, you can now just runpiri serve fulland call it a day.The new command runs both UCAN and PDP servers in a single process. Don't worry if you're using an external PDP implementation (like Curio) -
piri serve ucanstill works standalone.Here's what the config looks like - notice how both UCAN and PDP settings live together:
How
This brings together work from several previous PRs (#187, #186, #169, #161, #144) to let both UCAN and PDP modules run in the same Piri process. Here's what changed under the hood:
Architecture Changes:
UCANModuleandPDPModule) that encapsulate their respective dependenciesThe Magic:
piri serve fullcommand uses fx (Uber's DI framework) to inject both modules at startupCommonModules(identity, HTTP server, databases)Backwards Compatibility:
piri serve ucanstill works for operators who want to run just the UCAN serverpiri server pdpcommand is gone (replaced by the full command)