Skip to content

Commit

Permalink
introduce engine_getCapabilities (#6695)
Browse files Browse the repository at this point in the history
Implementation of ethereum/execution-apis#364
  • Loading branch information
hexoscott authored Jan 25, 2023
1 parent 82c478a commit d9e1782
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion cmd/rpcdaemon/commands/engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"math/big"

"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/gointerfaces"
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
types2 "github.com/ledgerwatch/erigon-lib/gointerfaces/types"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/hexutil"
Expand Down Expand Up @@ -388,6 +389,47 @@ func (e *EngineImpl) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64
return convertExecutionPayloadV1(apiRes), nil
}

var ourCapabilities = []string{
"engine_forkchoiceUpdatedV1",
"engine_forkchoiceUpdatedV2",
"engine_newPayloadV1",
"engine_newPayloadV2",
"engine_getPayloadV1",
"engine_getPayloadV2",
"engine_exchangeTransitionConfigurationV1",
"engine_getPayloadBodiesByHashV1",
"engine_getPayloadBodiesByRangeV1",
}

func (e *EngineImpl) ExchangeCapabilities(fromCl []string) []string {
missingOurs := compareCapabilities(fromCl, ourCapabilities)
missingCl := compareCapabilities(ourCapabilities, fromCl)

if len(missingCl) > 0 || len(missingOurs) > 0 {
log.Debug("ExchangeCapabilities mismatches", "cl_unsupported", missingCl, "erigon_unsupported", missingOurs)
}

return ourCapabilities
}

func compareCapabilities(from []string, to []string) []string {
result := make([]string, 0)
for _, f := range from {
found := false
for _, t := range to {
if f == t {
found = true
break
}
}
if !found {
result = append(result, f)
}
}

return result
}

func convertExecutionPayloadV1(response *remote.EngineGetPayloadBodiesV1Response) []*ExecutionPayloadBodyV1 {
result := make([]*ExecutionPayloadBodyV1, len(response.Bodies))
for idx, body := range response.Bodies {
Expand Down

0 comments on commit d9e1782

Please sign in to comment.