Skip to content
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

Avail Integration + Generic interface extension for Plasma #10614

Closed
wants to merge 13 commits into from

Conversation

rac-sri
Copy link

@rac-sri rac-sri commented May 22, 2024

Description

PR introduces generic commitment extension. Now on calling put on DA Server, commitment generated by DA Service is returned in the function call, rather than having to precompute it, which is a hurdle when we talk in terms of DA chains, whose block hash is an important data to be included in commitment.
Alongside that, there is a DA server as part of this pr, to interact with Avail chain.

Tests

The tests for DA service are updated to comply with the new interface introduced.

@rac-sri rac-sri marked this pull request as ready for review May 29, 2024 11:01
@rac-sri rac-sri requested a review from a team as a code owner May 29, 2024 11:01
@rac-sri rac-sri requested a review from ajsutton May 29, 2024 11:01
Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

This update introduces a new avail-da-server target and related functionalities for handling data availability within the op-plasma project. Key additions include new Makefile targets, a DA service interface, and CLI configurations for the Plasma Avail DA Server. It also includes new methods and structures for interacting with availability data, test cases, and utility functions to support these features.

Changes

Files/Paths Change Summaries
.gitignore Added vendor directory to the exclusion list.
op-plasma/Makefile Added avail-da-server and test-avail targets.
op-plasma/cmd/adapters/dastore.go Introduced DAService interface and DAServiceAdapter struct.
op-plasma/cmd/adapters/kvstore.go Introduced KVStore interface and KVStoreAdapter struct.
op-plasma/cmd/avail/README.md Added documentation for Plasma Avail DA Server.
op-plasma/cmd/avail/entrypoint.go Defined StartDAServer function.
op-plasma/cmd/avail/flags.go Defined flags and configurations for avail service binary.
op-plasma/cmd/avail/main.go Set up CLI application for Plasma Avail DA Service.
op-plasma/cmd/avail/scripts/get_block_data.go Introduced functions for retrieving and extracting extrinsic data from a block.
op-plasma/cmd/avail/scripts/submit_and_watch.go Introduced functions for submitting data, signing extrinsics, and monitoring extrinsic finalization.
op-plasma/cmd/avail/service/avail_service.go Introduced AvailService struct with methods for interacting with availability data.
op-plasma/cmd/avail/types/avail_block_ref.go Introduced types and functions related to Avail block references and specifications.
op-plasma/cmd/avail/utils/utils.go Provided utility functions for handling account nonces, Substrate API interactions, and more.
op-plasma/cmd/daserver/entrypoint.go Modified to use adapters.KVStore and adapters.KVStoreAdapter.
op-plasma/daclient.go Renamed setInput to setInputs and added a blank line after DecodeGenericCommitment(b).
op-plasma/daclient_avail_test.go Introduced test functions for DAClient service availability in the Plasma package.
op-plasma/daclient_test.go Updated to use DAServiceStore instead of MemStore and modified NewDAServer calls.
op-plasma/damgr.go Renamed NewPlasmaDAWithState to NewPlasmaWithState and adjusted error handling in DecodeResolvedInput.
op-plasma/daserver.go Renamed KVStore to UnifiedStore and updated related methods and struct fields.
op-plasma/params.go Updated comment for MaxInputSize constant for clarity.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Comment on lines +13 to +14
go run ./cmd/avail --addr=localhost --port=8000 --avail.rpc=<Avail RPC URL> --avail.seed="<seed phrase>" --avail.appid=<APP ID> --avail.timeout=<Timeout>
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the language for the fenced code block to enable syntax highlighting.

- ```
+ ```bash
  go run ./cmd/avail  --addr=localhost --port=8000 --avail.rpc=<Avail RPC URL> --avail.seed="<seed phrase>" --avail.appid=<APP ID> --avail.timeout=<Timeout>

<!-- This is an auto-generated comment by CodeRabbit -->

Comment on lines +18 to +19
func (adapter DAServiceAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) {
return adapter.DAService.Put(ctx, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the method signature to match the interface.

- func (adapter DAServiceAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) {
+ func (adapter DAServiceAdapter) Put(ctx context.Context, value []byte) ([]byte, error) {
  return adapter.DAService.Put(ctx, value)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (adapter DAServiceAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) {
return adapter.DAService.Put(ctx, value)
func (adapter DAServiceAdapter) Put(ctx context.Context, value []byte) ([]byte, error) {
return adapter.DAService.Put(ctx, value)
}

Comment on lines +20 to +26
func (adapter KVStoreAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) {
err := adapter.KVStore.Put(ctx, key, value)
if err != nil {
return nil, err
}
return key, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the return type of the Put method to match typical key-value store operations.

- func (adapter KVStoreAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) {
+ func (adapter KVStoreAdapter) Put(ctx context.Context, key []byte, value []byte) error {
  err := adapter.KVStore.Put(ctx, key, value)
  if err != nil {
    return err
  }
  return nil
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (adapter KVStoreAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) {
err := adapter.KVStore.Put(ctx, key, value)
if err != nil {
return nil, err
}
return key, nil
}
func (adapter KVStoreAdapter) Put(ctx context.Context, key []byte, value []byte) error {
err := adapter.KVStore.Put(ctx, key, value)
if err != nil {
return err
}
return nil
}

Comment on lines +16 to +34
func SubmitDataAndWatch(specs *types.AvailDASpecs, ctx context.Context, data []byte) (types.AvailBlockRef, error) {
call, err := createDataAvailabilityCall(specs, data)

if err != nil {

return types.AvailBlockRef{}, fmt.Errorf("creating data availability call: %w", err)
}

signedExt, sender, nonce, err := prepareAndSignExtrinsic(specs, call)
if err != nil {
fmt.Println(err)
return types.AvailBlockRef{}, fmt.Errorf("preparing and signing extrinsic: %w", err)
}

dataCommitment := crypto.Keccak256(data)

return waitForExtrinsicFinalization(specs, signedExt, sender, nonce, dataCommitment)

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure consistent error handling and logging in the SubmitDataAndWatch function. Specifically, replace the fmt.Println statement with fmt.Errorf for logging and returning errors.

  • Line 26: Replace fmt.Println(err) with fmt.Errorf("preparing and signing extrinsic: %w", err)
Analysis chain

The function SubmitDataAndWatch has been updated to handle the data submission and watching for finalization on the Avail chain. Ensure that error handling and logging are consistent and comprehensive throughout the function to facilitate debugging and maintenance.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling and logging in `SubmitDataAndWatch`.

# Test: Search for error handling patterns. Expect: Consistent error handling and logging.
rg --type go $'SubmitDataAndWatch'

Length of output: 313



Script:

#!/bin/bash
# Extract the full implementation of the SubmitDataAndWatch function to analyze error handling and logging.
ast-grep --lang go --pattern $'func SubmitDataAndWatch($_, $_, $_) ($_ , $_) {
  $$$
}' > submit_and_watch_function.txt

# Display the extracted function for review.
cat submit_and_watch_function.txt

Length of output: 1741

server := plasma.NewDAServer(cliCtx.String(ListenAddrFlagName), cliCtx.Int(PortFlagName), adapters.DAServiceAdapter{DAService: availService}, l)

if err := server.Start(); err != nil {
return fmt.Errorf("failed to start the DA server")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance the error message to provide more context about the failure.

- return fmt.Errorf("failed to start the DA server")
+ return fmt.Errorf("failed to start the DA server: %v", err)

Committable suggestion was skipped due low confidence.

Comment on lines +28 to +38
func Check() error {
if RPC == "" {
return errors.New("no rpc url provided")
}
if APPID == 0 {
return errors.New("no app id provided")
}
if SEED == "" {
return errors.New("seedphrase not provided")
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Check function is used to validate the configuration before tests run. Consider handling these errors more gracefully than using panic in the test setup.

- panic(err)
+ t.Fatalf("Configuration check failed: %v", err)

Committable suggestion was skipped due low confidence.


ctx := context.Background()

server := NewDAServer("127.0.0.1", 0, adapters.DAServiceAdapter{DAService: store}, logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The NewDAServer function does not match the expected signature with adapters.DAServiceAdapter. Instead, it uses a UnifiedStore type. Additionally, the DAServiceAdapter struct is defined in op-plasma/cmd/adapters/dastore.go, but it is not used in the NewDAServer function.

  • NewDAServer function signature: func NewDAServer(host string, port int, store UnifiedStore, log log.Logger) *DAServer
  • DAServiceAdapter struct definition: type DAServiceAdapter struct { DAService DAService }

Please review the usage of NewDAServer and ensure that the correct types are being used in the test.

Analysis chain

The instantiation of NewDAServer within the test uses an adapter. Ensure that the NewDAServer function and the adapters.DAServiceAdapter are correctly implemented to support this usage.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `NewDAServer` function and `adapters.DAServiceAdapter` in test context.

# Test: Search for the `NewDAServer` function and `adapters.DAServiceAdapter` implementation. Expect: Correct implementation to support test usage.
ast-grep --lang go --pattern $'func NewDAServer($_, $_, adapters.DAServiceAdapter, $_) $_ {
  $$$
}'

Length of output: 101



Script:

#!/bin/bash
# Description: Verify the `NewDAServer` function and `adapters.DAServiceAdapter` in test context.

# Search for the `NewDAServer` function definition.
ast-grep --lang go --pattern $'func NewDAServer($_, $_, $_, $_) $_ {
  $$$
}'

# Search for the `DAServiceAdapter` struct definition in the adapters package.
ast-grep --lang go --pattern $'type DAServiceAdapter struct {
  $$$
}' --search-dir adapters

Length of output: 959



Script:

#!/bin/bash
# Description: Verify the `DAServiceAdapter` struct definition in the adapters package.

# Search for the `DAServiceAdapter` struct definition.
ast-grep --lang go --pattern $'type DAServiceAdapter struct {
  $$$
}' adapters

Length of output: 136



Script:

#!/bin/bash
# Description: Locate and verify the `DAServiceAdapter` struct definition.

# Locate the file containing `DAServiceAdapter`.
fd DAServiceAdapter

# Verify the `DAServiceAdapter` struct definition.
ast-grep --lang go --pattern $'type DAServiceAdapter struct {
  $$$
}'

Length of output: 264

Comment on lines +20 to +34
func NewAvailService(apiURL string, seed string, appID int, timeout time.Duration) *AvailService {

availSpecs, err := types.NewAvailDASpecs(apiURL, appID, seed, timeout)

if err != nil {
panic("failed avail initialisation")
}

return &AvailService{
Seed: seed,
ApiURL: apiURL,
AppID: appID,
Timeout: timeout,
Specs: availSpecs,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NewAvailService function initializes an AvailService instance. Ensure that the error from types.NewAvailDASpecs is handled appropriately instead of using panic.

- panic("failed avail initialisation")
+ return nil, fmt.Errorf("failed avail initialisation: %w", err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func NewAvailService(apiURL string, seed string, appID int, timeout time.Duration) *AvailService {
availSpecs, err := types.NewAvailDASpecs(apiURL, appID, seed, timeout)
if err != nil {
panic("failed avail initialisation")
}
return &AvailService{
Seed: seed,
ApiURL: apiURL,
AppID: appID,
Timeout: timeout,
Specs: availSpecs,
}
func NewAvailService(apiURL string, seed string, appID int, timeout time.Duration) (*AvailService, error) {
availSpecs, err := types.NewAvailDASpecs(apiURL, appID, seed, timeout)
if err != nil {
return nil, fmt.Errorf("failed avail initialisation: %w", err)
}
return &AvailService{
Seed: seed,
ApiURL: apiURL,
AppID: appID,
Timeout: timeout,
Specs: availSpecs,
}, nil

@ajsutton ajsutton requested review from axelKingsley and removed request for ajsutton June 2, 2024 21:25
Copy link
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jun 17, 2024
@github-actions github-actions bot closed this Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant