Skip to content

Commit

Permalink
Updated version to deneb and tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
18aaddy committed Nov 5, 2024
1 parent cd03909 commit 1311e76
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
11 changes: 7 additions & 4 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,25 @@ func (in *Inner) Check_rpc() error {
func (in *Inner) get_execution_payload(slot *uint64) (*consensus_core.ExecutionPayload, error) {
errorChan := make(chan error, 1)
blockChan := make(chan consensus_core.BeaconBlock, 1)
versionChan := make(chan string , 1)
go func() {
var err error
block, err := in.RPC.GetBlock(*slot)
block,version, err := in.RPC.GetBlock(*slot)
if err != nil {
errorChan <- err
}
errorChan <- nil
blockChan <- block
versionChan <- version
}()

if err := <-errorChan; err != nil {
return nil, err
}

block := <-blockChan
Gethblock, err := beacon.BlockFromJSON("deneb", block.Hash)
version := <-versionChan
Gethblock, err := beacon.BlockFromJSON(version, block.Hash)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -340,7 +343,7 @@ func (in *Inner) Get_payloads(startSlot, endSlot uint64) ([]interface{}, error)
var payloads []interface{}

// Fetch the block at endSlot to get the initial parent hash
endBlock, err := in.RPC.GetBlock(endSlot)
endBlock,_, err := in.RPC.GetBlock(endSlot)
if err != nil {
return nil, err
}
Expand All @@ -357,7 +360,7 @@ func (in *Inner) Get_payloads(startSlot, endSlot uint64) ([]interface{}, error)
wg.Add(1)
go func(slot uint64) {
defer wg.Done()
block, err := in.RPC.GetBlock(slot)
block,_, err := in.RPC.GetBlock(slot)
if err != nil {
errorChan <- err
return
Expand Down
2 changes: 1 addition & 1 deletion consensus/rpc/consensus_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ConsensusRpc interface {
GetUpdates(period uint64, count uint8) ([]consensus_core.Update, error)
GetFinalityUpdate() (consensus_core.FinalityUpdate, error)
GetOptimisticUpdate() (consensus_core.OptimisticUpdate, error)
GetBlock(slot uint64) (consensus_core.BeaconBlock, error)
GetBlock(slot uint64) (consensus_core.BeaconBlock,string, error)
ChainId() (uint64, error)
}

Expand Down
8 changes: 4 additions & 4 deletions consensus/rpc/mock_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ func (m *MockRpc) GetOptimisticUpdate() (consensus_core.OptimisticUpdate, error)
}
return optimistic.Data, nil
}
func (m *MockRpc) GetBlock(slot uint64) (consensus_core.BeaconBlock, error) {
func (m *MockRpc) GetBlock(slot uint64) (consensus_core.BeaconBlock,string, error) {
path := filepath.Join(m.testdata, fmt.Sprintf("blocks/%d.json", slot))
res, err := os.ReadFile(path)
if err != nil {
return consensus_core.BeaconBlock{}, fmt.Errorf("failed to read file: %w", err)
return consensus_core.BeaconBlock{},"", fmt.Errorf("failed to read file: %w", err)
}
var block BeaconBlockResponse
err = json.Unmarshal(res, &block)
if err != nil {
return consensus_core.BeaconBlock{}, err
return consensus_core.BeaconBlock{},"", err
}
return block.Data.Message, nil
return block.Data.Message,block.Version, nil
}
func (m *MockRpc) ChainId() (uint64, error) {
return 0, fmt.Errorf("not implemented")
Expand Down
2 changes: 1 addition & 1 deletion consensus/rpc/mock_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestGetBlock(t *testing.T) {
}

mockRpc := NewMockRpc(tempDir)
block, err := mockRpc.GetBlock(4000)
block,_, err := mockRpc.GetBlock(4000)
if err != nil {
t.Fatalf("GetBlock failed: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions consensus/rpc/nimbus_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ func (n *NimbusRpc) GetOptimisticUpdate() (consensus_core.OptimisticUpdate, erro
}
return res.Data, nil
}
func (n *NimbusRpc) GetBlock(slot uint64) (consensus_core.BeaconBlock, error) {
func (n *NimbusRpc) GetBlock(slot uint64) (consensus_core.BeaconBlock,string, error) {
req := fmt.Sprintf("%s/eth/v2/beacon/blocks/%s", n.rpc, strconv.FormatUint(slot, 10))
var res BeaconBlockResponse
err := get(req, &res)
if err != nil {
return consensus_core.BeaconBlock{}, fmt.Errorf("block error: %w", err)
return consensus_core.BeaconBlock{},"", fmt.Errorf("block error: %w", err)
}
return res.Data.Message, nil
return res.Data.Message,res.Version, nil
}
func (n *NimbusRpc) ChainId() (uint64, error) {
req := fmt.Sprintf("%s/eth/v1/config/spec", n.rpc)
Expand All @@ -118,6 +118,7 @@ func (n *NimbusRpc) ChainId() (uint64, error) {
// BeaconBlock, Update,FinalityUpdate ,OptimisticUpdate,Bootstrap yet to be defined in consensus-core/src/types/mod.go
// For now defined in consensus/consensus_core.go
type BeaconBlockResponse struct {
Version string
Data BeaconBlockData
}
type BeaconBlockData struct {
Expand Down
2 changes: 1 addition & 1 deletion consensus/rpc/nimbus_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestNimbusGetBlock(t *testing.T) {
}))
defer server.Close()
nimbusRpc := NewNimbusRpc(server.URL)
block, err := nimbusRpc.GetBlock(4000)
block,_, err := nimbusRpc.GetBlock(4000)
assert.NoError(t, err)
assert.Equal(t, uint64(4000), block.Slot)
}
Expand Down

0 comments on commit 1311e76

Please sign in to comment.