-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle errors as no-op for execution requests (#14826)
* Update electra core processing error handling * Add test for IsExecutionRequestError * Add TestProcessOperationsWithNilRequests * gazelle --------- Co-authored-by: Preston Van Loon <[email protected]>
- Loading branch information
1 parent
f9c2021
commit 910609a
Showing
8 changed files
with
151 additions
and
5 deletions.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package electra | ||
|
||
import "github.com/pkg/errors" | ||
|
||
type execReqErr struct { | ||
error | ||
} | ||
|
||
// IsExecutionRequestError returns true if the error has `execReqErr`. | ||
func IsExecutionRequestError(e error) bool { | ||
if e == nil { | ||
return false | ||
} | ||
var d execReqErr | ||
return errors.As(e, &d) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package electra | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestIsExecutionRequestError(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
want bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
want: false, | ||
}, | ||
{ | ||
name: "random error", | ||
err: errors.New("some error"), | ||
want: false, | ||
}, | ||
{ | ||
name: "execution request error", | ||
err: execReqErr{errors.New("execution request failed")}, | ||
want: true, | ||
}, | ||
{ | ||
name: "wrapped execution request error", | ||
err: errors.Wrap(execReqErr{errors.New("execution request failed")}, "wrapped"), | ||
want: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := IsExecutionRequestError(tt.err) | ||
if got != tt.want { | ||
t.Errorf("IsExecutionRequestError(%v) = %v, want %v", tt.err, got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
beacon-chain/core/electra/transition_no_verify_sig_test.go
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package electra_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/electra" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
) | ||
|
||
func TestProcessOperationsWithNilRequests(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
modifyBlk func(blockElectra *ethpb.SignedBeaconBlockElectra) | ||
errMsg string | ||
}{ | ||
{ | ||
name: "Nil deposit request", | ||
modifyBlk: func(blk *ethpb.SignedBeaconBlockElectra) { | ||
blk.Block.Body.ExecutionRequests.Deposits = []*enginev1.DepositRequest{nil} | ||
}, | ||
errMsg: "nil deposit request", | ||
}, | ||
{ | ||
name: "Nil withdrawal request", | ||
modifyBlk: func(blk *ethpb.SignedBeaconBlockElectra) { | ||
blk.Block.Body.ExecutionRequests.Withdrawals = []*enginev1.WithdrawalRequest{nil} | ||
}, | ||
errMsg: "nil withdrawal request", | ||
}, | ||
{ | ||
name: "Nil consolidation request", | ||
modifyBlk: func(blk *ethpb.SignedBeaconBlockElectra) { | ||
blk.Block.Body.ExecutionRequests.Consolidations = []*enginev1.ConsolidationRequest{nil} | ||
}, | ||
errMsg: "nil consolidation request", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
st, ks := util.DeterministicGenesisStateElectra(t, 128) | ||
blk, err := util.GenerateFullBlockElectra(st, ks, util.DefaultBlockGenConfig(), 1) | ||
require.NoError(t, err) | ||
|
||
tc.modifyBlk(blk) | ||
|
||
b, err := blocks.NewSignedBeaconBlock(blk) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, st.SetSlot(1)) | ||
|
||
_, err = electra.ProcessOperations(context.Background(), st, b.Block()) | ||
require.ErrorContains(t, tc.errMsg, err) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Update electra core processing to not mark block bad if execution request error. |