-
Notifications
You must be signed in to change notification settings - Fork 90
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
app/eth2wrap: fix error comparison for synthetic blocks #2702
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,11 @@ | |
"github.com/attestantio/go-eth2-client/spec/capella" | ||
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" | ||
shuffle "github.com/protolambda/eth2-shuffle" | ||
"go.uber.org/zap" | ||
|
||
"github.com/obolnetwork/charon/app/errors" | ||
"github.com/obolnetwork/charon/app/log" | ||
"github.com/obolnetwork/charon/app/z" | ||
) | ||
|
||
const ( | ||
|
@@ -149,10 +151,8 @@ | |
} | ||
signed, err := h.Client.SignedBeaconBlock(ctx, opts) | ||
if err != nil { | ||
if apiErr := new(eth2api.Error); errors.As(err, apiErr) { // Continue if block is not found in the given slot. | ||
if apiErr.StatusCode == http.StatusNotFound { | ||
continue | ||
} | ||
if fieldExists(err, zap.Int("status_code", http.StatusNotFound)) { | ||
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 was needed as the returned error will be a wrapped error from eth2wrap.Multi struct |
||
continue | ||
} | ||
|
||
return nil, err | ||
|
@@ -204,6 +204,34 @@ | |
return proposal, nil | ||
} | ||
|
||
// fieldExists checks if the given field exists as part of the given error. | ||
func fieldExists(err error, field zap.Field) bool { | ||
dB2510 marked this conversation as resolved.
Show resolved
Hide resolved
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. I wonder if instead of declaring this function here, we should create a The casting logic seems to be a 1:1 copy off |
||
type structErr interface { | ||
Fields() []z.Field | ||
} | ||
|
||
sterr, ok := err.(structErr) //nolint:errorlint | ||
if !ok { | ||
return false | ||
} | ||
|
||
zfs := sterr.Fields() | ||
var zapFs []zap.Field | ||
for _, field := range zfs { | ||
field(func(zp zap.Field) { | ||
zapFs = append(zapFs, zp) | ||
}) | ||
} | ||
|
||
for _, zaps := range zapFs { | ||
if zaps.Equals(field) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// fraction returns a fraction of the transactions in the block. | ||
// This is used to reduce the size of synthetic blocks to manageable levels. | ||
func fraction(transactions []bellatrix.Transaction) []bellatrix.Transaction { | ||
|
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.
Seems like this was not working at all until now :(
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.
There must be a linter somewhere that checks for this...