-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
feat: add avail tests, remove debug statements
WalkthroughThis update introduces a new Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 8
go run ./cmd/avail --addr=localhost --port=8000 --avail.rpc=<Avail RPC URL> --avail.seed="<seed phrase>" --avail.appid=<APP ID> --avail.timeout=<Timeout> | ||
``` |
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.
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 -->
func (adapter DAServiceAdapter) Put(ctx context.Context, key []byte, value []byte) ([]byte, error) { | ||
return adapter.DAService.Put(ctx, value) |
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.
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.
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) | |
} |
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 | ||
} |
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.
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.
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 | |
} |
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) | ||
|
||
} |
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.
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)
withfmt.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") |
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.
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.
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 |
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.
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.
op-plasma/daclient_avail_test.go
Outdated
|
||
ctx := context.Background() | ||
|
||
server := NewDAServer("127.0.0.1", 0, adapters.DAServiceAdapter{DAService: store}, logger) |
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.
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
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, | ||
} |
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.
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.
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 |
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. |
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.