-
Notifications
You must be signed in to change notification settings - Fork 165
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
Style: improve api clients comments #780
Open
samlaf
wants to merge
2
commits into
master
Choose a base branch
from
style--improve-api-clients-comments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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 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 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 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 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 |
---|---|---|
|
@@ -16,13 +16,19 @@ import ( | |
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
// IEigenDAClient is a wrapper around the DisperserClient interface which | ||
// encodes blobs before dispersing them, and decodes them after retrieving them. | ||
type IEigenDAClient interface { | ||
GetBlob(ctx context.Context, batchHeaderHash []byte, blobIndex uint32) ([]byte, error) | ||
PutBlob(ctx context.Context, txData []byte) (*grpcdisperser.BlobInfo, error) | ||
GetCodec() codecs.BlobCodec | ||
} | ||
|
||
// EigenDAClient is a wrapper around the DisperserClient which | ||
// encodes blobs before dispersing them, and decodes them after retrieving them. | ||
type EigenDAClient struct { | ||
// TODO: all of these should be private, to prevent users from using them directly, | ||
// which breaks encapsulation and makes it hard for us to do refactors or changes | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this I personally think is a refactor worth doing... but it might break some client code... :\ |
||
Config EigenDAClientConfig | ||
Log log.Logger | ||
Client DisperserClient | ||
|
@@ -46,6 +52,7 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien | |
if len(config.SignerPrivateKeyHex) == 64 { | ||
signer = auth.NewLocalBlobRequestSigner(config.SignerPrivateKeyHex) | ||
} else if len(config.SignerPrivateKeyHex) == 0 { | ||
// noop signer is used when we need a read-only eigenda client | ||
signer = auth.NewLocalNoopSigner() | ||
} else { | ||
return nil, fmt.Errorf("invalid length for signer private key") | ||
|
@@ -74,6 +81,8 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien | |
}, nil | ||
} | ||
|
||
// Deprecated: do not rely on this function. Do not use m.Codec directly either. | ||
// These will eventually be removed and not exposed. | ||
func (m EigenDAClient) GetCodec() codecs.BlobCodec { | ||
return m.Codec | ||
} | ||
|
@@ -84,27 +93,30 @@ func (m EigenDAClient) GetCodec() codecs.BlobCodec { | |
// data, which is necessary for generating KZG proofs for data's correctness. | ||
// The function handles potential errors during blob retrieval, data length | ||
// checks, and decoding processes. | ||
// TODO: should we use a pointer receiver instead, to prevent unnecessary copying of the EigenDAClient struct? | ||
func (m EigenDAClient) GetBlob(ctx context.Context, batchHeaderHash []byte, blobIndex uint32) ([]byte, error) { | ||
data, err := m.Client.RetrieveBlob(ctx, batchHeaderHash, blobIndex) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("could not retrieve blob: %w", err) | ||
} | ||
|
||
if len(data) == 0 { | ||
// TODO: explain when/why/how this can happen | ||
return nil, fmt.Errorf("blob has length zero") | ||
} | ||
Comment on lines
103
to
106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bxue-l2 do you know? |
||
|
||
decodedData, err := m.Codec.DecodeBlob(data) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting blob: %w", err) | ||
return nil, fmt.Errorf("error decoding blob: %w", err) | ||
} | ||
|
||
return decodedData, nil | ||
} | ||
|
||
// PutBlob encodes and writes a blob to EigenDA, waiting for it to be finalized | ||
// before returning. This function is resiliant to transient failures and | ||
// before returning. This function is resilient to transient failures and | ||
// timeouts. | ||
// TODO: should we use a pointer receiver instead, to prevent unnecessary copying of the EigenDAClient struct? | ||
func (m EigenDAClient) PutBlob(ctx context.Context, data []byte) (*grpcdisperser.BlobInfo, error) { | ||
resultChan, errorChan := m.PutBlobAsync(ctx, data) | ||
select { // no timeout here because we depend on the configured timeout in PutBlobAsync | ||
|
@@ -115,6 +127,7 @@ func (m EigenDAClient) PutBlob(ctx context.Context, data []byte) (*grpcdisperser | |
} | ||
} | ||
|
||
// TODO: should we use a pointer receiver instead, to prevent unnecessary copying of the EigenDAClient struct? | ||
func (m EigenDAClient) PutBlobAsync(ctx context.Context, data []byte) (resultChan chan *grpcdisperser.BlobInfo, errChan chan error) { | ||
resultChan = make(chan *grpcdisperser.BlobInfo, 1) | ||
errChan = make(chan error, 1) | ||
|
@@ -137,11 +150,13 @@ func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan c | |
return | ||
} | ||
|
||
// TODO: should we just use uint8s directly in the config? | ||
customQuorumNumbers := make([]uint8, len(m.Config.CustomQuorumIDs)) | ||
for i, e := range m.Config.CustomQuorumIDs { | ||
customQuorumNumbers[i] = uint8(e) | ||
} | ||
// disperse blob | ||
// TODO: can we consider passing a requestID directly to requests, to get idempotency and tracing? | ||
blobStatus, requestID, err := m.Client.DisperseBlobAuthenticated(ctx, data, customQuorumNumbers) | ||
if err != nil { | ||
errChan <- fmt.Errorf("error initializing DisperseBlobAuthenticated() client: %w", err) | ||
|
@@ -150,13 +165,12 @@ func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan c | |
|
||
// process response | ||
if *blobStatus == disperser.Failed { | ||
m.Log.Error("Unable to disperse blob to EigenDA, aborting", "err", err) | ||
errChan <- fmt.Errorf("reply status is %d", blobStatus) | ||
errChan <- fmt.Errorf("unable to disperse blob to eigenda (reply status %d): %w", blobStatus, err) | ||
return | ||
} | ||
|
||
base64RequestID := base64.StdEncoding.EncodeToString(requestID) | ||
m.Log.Info("Blob dispersed to EigenDA, now waiting for confirmation", "requestID", base64RequestID) | ||
m.Log.Info("Blob accepted by EigenDA disperser, now polling for status updates", "requestID", base64RequestID) | ||
|
||
ticker := time.NewTicker(m.Config.StatusQueryRetryInterval) | ||
defer ticker.Stop() | ||
|
@@ -175,25 +189,23 @@ func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan c | |
case <-ticker.C: | ||
statusRes, err := m.Client.GetBlobStatus(ctx, requestID) | ||
if err != nil { | ||
m.Log.Error("Unable to retrieve blob dispersal status, will retry", "requestID", base64RequestID, "err", err) | ||
m.Log.Warn("Unable to retrieve blob dispersal status, will retry", "requestID", base64RequestID, "err", err) | ||
continue | ||
} | ||
|
||
switch statusRes.Status { | ||
case grpcdisperser.BlobStatus_PROCESSING, grpcdisperser.BlobStatus_DISPERSING: | ||
// to prevent log clutter, we only log at info level once | ||
if alreadyWaitingForDispersal { | ||
m.Log.Debug("Blob submitted, waiting for dispersal from EigenDA", "requestID", base64RequestID) | ||
m.Log.Debug("Blob is being processed by the EigenDA network", "requestID", base64RequestID) | ||
} else { | ||
m.Log.Info("Blob submitted, waiting for dispersal from EigenDA", "requestID", base64RequestID) | ||
m.Log.Info("Blob is being processed by the EigenDA network", "requestID", base64RequestID) | ||
alreadyWaitingForDispersal = true | ||
} | ||
case grpcdisperser.BlobStatus_FAILED: | ||
m.Log.Error("EigenDA blob dispersal failed in processing", "requestID", base64RequestID, "err", err) | ||
errChan <- fmt.Errorf("EigenDA blob dispersal failed in processing, requestID=%s: %w", base64RequestID, err) | ||
return | ||
case grpcdisperser.BlobStatus_INSUFFICIENT_SIGNATURES: | ||
m.Log.Error("EigenDA blob dispersal failed in processing with insufficient signatures", "requestID", base64RequestID, "err", err) | ||
errChan <- fmt.Errorf("EigenDA blob dispersal failed in processing with insufficient signatures, requestID=%s: %w", base64RequestID, err) | ||
return | ||
case grpcdisperser.BlobStatus_CONFIRMED: | ||
|
@@ -212,11 +224,12 @@ func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan c | |
} | ||
case grpcdisperser.BlobStatus_FINALIZED: | ||
batchHeaderHashHex := fmt.Sprintf("0x%s", hex.EncodeToString(statusRes.Info.BlobVerificationProof.BatchMetadata.BatchHeaderHash)) | ||
m.Log.Info("Successfully dispersed blob to EigenDA", "requestID", base64RequestID, "batchHeaderHash", batchHeaderHashHex) | ||
m.Log.Info("EigenDA blob finalized", "requestID", base64RequestID, "batchHeaderHash", batchHeaderHashHex) | ||
resultChan <- statusRes.Info | ||
return | ||
default: | ||
errChan <- fmt.Errorf("EigenDA blob dispersal failed in processing with reply status %d", statusRes.Status) | ||
// this should never happen. If it does, the blob is in a heisenberg state... it could either eventually get confirmed or fail | ||
errChan <- fmt.Errorf("unknown reply status %d. ask for assistance from EigenDA team, using requestID %s", statusRes.Status, base64RequestID) | ||
return | ||
} | ||
} | ||
|
This file contains 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 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 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
Oops, something went wrong.
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.
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.
@bxue-l2 you prob know this