-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'e35' into e35_mainnet_bodies_v2
- Loading branch information
Showing
32 changed files
with
488 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package handler | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/ledgerwatch/erigon/cl/beacon/beaconhttp" | ||
) | ||
|
||
func (a *ApiHandler) GetEthV2DebugBeaconHeads(w http.ResponseWriter, r *http.Request) (*beaconResponse, error) { | ||
if a.syncedData.Syncing() { | ||
return nil, beaconhttp.NewEndpointError(http.StatusServiceUnavailable, "beacon node is syncing") | ||
} | ||
hash, slotNumber, err := a.forkchoiceStore.GetHead() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return newBeaconResponse( | ||
[]interface{}{ | ||
map[string]interface{}{ | ||
"slot": slotNumber, | ||
"root": hash, | ||
"execution_optimistic": false, | ||
}, | ||
}), nil | ||
} | ||
|
||
func (a *ApiHandler) GetEthV1DebugBeaconForkChoice(w http.ResponseWriter, r *http.Request) { | ||
justifiedCheckpoint := a.forkchoiceStore.JustifiedCheckpoint() | ||
finalizedCheckpoint := a.forkchoiceStore.FinalizedCheckpoint() | ||
forkNodes := a.forkchoiceStore.ForkNodes() | ||
if err := json.NewEncoder(w).Encode(map[string]interface{}{ | ||
"justified_checkpoint": justifiedCheckpoint, | ||
"finalized_checkpoint": finalizedCheckpoint, | ||
"fork_choice_nodes": forkNodes, | ||
}); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
} |
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,80 @@ | ||
package handler | ||
|
||
import ( | ||
"io" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
libcommon "github.com/ledgerwatch/erigon-lib/common" | ||
"github.com/ledgerwatch/erigon/cl/clparams" | ||
"github.com/ledgerwatch/erigon/cl/cltypes/solid" | ||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetHeads(t *testing.T) { | ||
// find server | ||
_, _, _, _, p, handler, _, sm, fcu := setupTestingHandler(t, clparams.Phase0Version) | ||
sm.OnHeadState(p) | ||
s, cancel := sm.HeadState() | ||
s.SetSlot(789274827847783) | ||
cancel() | ||
|
||
fcu.HeadSlotVal = 128 | ||
fcu.HeadVal = libcommon.Hash{1, 2, 3} | ||
server := httptest.NewServer(handler.mux) | ||
defer server.Close() | ||
|
||
// get heads | ||
resp, err := server.Client().Get(server.URL + "/eth/v2/debug/beacon/heads") | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
|
||
require.Equal(t, 200, resp.StatusCode) | ||
out, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, `{"data":[{"execution_optimistic":false,"root":"0x0102030000000000000000000000000000000000000000000000000000000000","slot":128}]}`+"\n", string(out)) | ||
} | ||
|
||
func TestGetForkchoice(t *testing.T) { | ||
// find server | ||
_, _, _, _, p, handler, _, sm, fcu := setupTestingHandler(t, clparams.Phase0Version) | ||
sm.OnHeadState(p) | ||
s, cancel := sm.HeadState() | ||
s.SetSlot(789274827847783) | ||
cancel() | ||
|
||
fcu.HeadSlotVal = 128 | ||
fcu.HeadVal = libcommon.Hash{1, 2, 3} | ||
server := httptest.NewServer(handler.mux) | ||
defer server.Close() | ||
|
||
fcu.WeightsMock = []forkchoice.ForkNode{ | ||
{ | ||
BlockRoot: libcommon.Hash{1, 2, 3}, | ||
ParentRoot: libcommon.Hash{1, 2, 3}, | ||
Slot: 128, | ||
Weight: 1, | ||
}, | ||
{ | ||
BlockRoot: libcommon.Hash{1, 2, 2, 4, 5, 3}, | ||
ParentRoot: libcommon.Hash{1, 2, 5}, | ||
Slot: 128, | ||
Weight: 2, | ||
}, | ||
} | ||
|
||
fcu.FinalizedCheckpointVal = solid.NewCheckpointFromParameters(libcommon.Hash{1, 2, 3}, 1) | ||
fcu.JustifiedCheckpointVal = solid.NewCheckpointFromParameters(libcommon.Hash{1, 2, 3}, 2) | ||
|
||
// get heads | ||
resp, err := server.Client().Get(server.URL + "/eth/v1/debug/fork_choice") | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
|
||
require.Equal(t, 200, resp.StatusCode) | ||
out, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.Equal(t, `{"finalized_checkpoint":{"epoch":"1","root":"0x0102030000000000000000000000000000000000000000000000000000000000"},"fork_choice_nodes":[{"slot":"128","block_root":"0x0102030000000000000000000000000000000000000000000000000000000000","parent_root":"0x0102030000000000000000000000000000000000000000000000000000000000","justified_epoch":"0","finalized_epoch":"0","weight":"1","validity":"","execution_block_hash":"0x0000000000000000000000000000000000000000000000000000000000000000"},{"slot":"128","block_root":"0x0102020405030000000000000000000000000000000000000000000000000000","parent_root":"0x0102050000000000000000000000000000000000000000000000000000000000","justified_epoch":"0","finalized_epoch":"0","weight":"2","validity":"","execution_block_hash":"0x0000000000000000000000000000000000000000000000000000000000000000"}],"justified_checkpoint":{"epoch":"2","root":"0x0102030000000000000000000000000000000000000000000000000000000000"}}`+"\n", string(out)) | ||
} |
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,20 @@ | ||
package handler | ||
|
||
import "net/http" | ||
|
||
func (a *ApiHandler) GetEthV1NodeHealth(w http.ResponseWriter, r *http.Request) { | ||
syncingStatus, err := uint64FromQueryParams(r, "syncing_status") | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
syncingCode := http.StatusOK | ||
if syncingStatus != nil { | ||
syncingCode = int(*syncingStatus) | ||
} | ||
if a.syncedData.Syncing() { | ||
w.WriteHeader(syncingCode) | ||
return | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
} |
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,49 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/ledgerwatch/erigon/cl/clparams" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNodeSyncing(t *testing.T) { | ||
// i just want the correct schema to be generated | ||
_, _, _, _, _, handler, _, _, _ := setupTestingHandler(t, clparams.Phase0Version) | ||
|
||
// Call GET /eth/v1/node/health | ||
server := httptest.NewServer(handler.mux) | ||
defer server.Close() | ||
|
||
req, err := http.NewRequest("GET", server.URL+"/eth/v1/node/health?syncing_status=666", nil) | ||
require.NoError(t, err) | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
require.Equal(t, 666, resp.StatusCode) | ||
} | ||
|
||
func TestNodeSyncingTip(t *testing.T) { | ||
// i just want the correct schema to be generated | ||
_, _, _, _, post, handler, _, sm, _ := setupTestingHandler(t, clparams.Phase0Version) | ||
|
||
// Call GET /eth/v1/node/health | ||
server := httptest.NewServer(handler.mux) | ||
defer server.Close() | ||
|
||
req, err := http.NewRequest("GET", server.URL+"/eth/v1/node/health?syncing_status=666", nil) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, sm.OnHeadState(post)) | ||
s, cancel := sm.HeadState() | ||
s.SetSlot(999999999999999) | ||
cancel() | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
require.Equal(t, 200, resp.StatusCode) | ||
} |
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.