diff --git a/consensus/consensus.go b/consensus/consensus.go index 4449629..863fc12 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -295,14 +295,16 @@ 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 { @@ -310,7 +312,8 @@ func (in *Inner) get_execution_payload(slot *uint64) (*consensus_core.ExecutionP } block := <-blockChan - Gethblock, err := beacon.BlockFromJSON("deneb", block.Hash) + version := <-versionChan + Gethblock, err := beacon.BlockFromJSON(version, block.Hash) if err != nil { return nil, err } @@ -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 } @@ -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 diff --git a/consensus/rpc/consensus_rpc.go b/consensus/rpc/consensus_rpc.go index f31ac85..5968a48 100644 --- a/consensus/rpc/consensus_rpc.go +++ b/consensus/rpc/consensus_rpc.go @@ -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) } diff --git a/consensus/rpc/mock_rpc.go b/consensus/rpc/mock_rpc.go index 2fbee22..f2562c5 100644 --- a/consensus/rpc/mock_rpc.go +++ b/consensus/rpc/mock_rpc.go @@ -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") diff --git a/consensus/rpc/mock_rpc_test.go b/consensus/rpc/mock_rpc_test.go index 8215bb9..4fff58a 100644 --- a/consensus/rpc/mock_rpc_test.go +++ b/consensus/rpc/mock_rpc_test.go @@ -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) } diff --git a/consensus/rpc/nimbus_rpc.go b/consensus/rpc/nimbus_rpc.go index 49b66fa..7b59852 100644 --- a/consensus/rpc/nimbus_rpc.go +++ b/consensus/rpc/nimbus_rpc.go @@ -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) @@ -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 { diff --git a/consensus/rpc/nimbus_rpc_test.go b/consensus/rpc/nimbus_rpc_test.go index 05cd0cd..d64e1fd 100644 --- a/consensus/rpc/nimbus_rpc_test.go +++ b/consensus/rpc/nimbus_rpc_test.go @@ -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) }