Skip to content

Commit 1d2f5cf

Browse files
authored
les/catalyst/api: add support for ExchangeTransitionConfigurationV1 (#25752)
This method is missing in light client mode and breaks consensus clients that require a valid response.
1 parent 3db4a13 commit 1d2f5cf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

les/catalyst/api.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323

2424
"github.com/ethereum/go-ethereum/common"
25+
"github.com/ethereum/go-ethereum/common/hexutil"
2526
"github.com/ethereum/go-ethereum/core/beacon"
2627
"github.com/ethereum/go-ethereum/les"
2728
"github.com/ethereum/go-ethereum/log"
@@ -189,3 +190,31 @@ func (api *ConsensusAPI) setCanonical(newHead common.Hash) error {
189190
}
190191
return nil
191192
}
193+
194+
// ExchangeTransitionConfigurationV1 checks the given configuration against
195+
// the configuration of the node.
196+
func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.TransitionConfigurationV1) (*beacon.TransitionConfigurationV1, error) {
197+
log.Trace("Engine API request received", "method", "ExchangeTransitionConfiguration", "ttd", config.TerminalTotalDifficulty)
198+
if config.TerminalTotalDifficulty == nil {
199+
return nil, errors.New("invalid terminal total difficulty")
200+
}
201+
202+
ttd := api.les.BlockChain().Config().TerminalTotalDifficulty
203+
if ttd == nil || ttd.Cmp(config.TerminalTotalDifficulty.ToInt()) != 0 {
204+
log.Warn("Invalid TTD configured", "geth", ttd, "beacon", config.TerminalTotalDifficulty)
205+
return nil, fmt.Errorf("invalid ttd: execution %v consensus %v", ttd, config.TerminalTotalDifficulty)
206+
}
207+
208+
if config.TerminalBlockHash != (common.Hash{}) {
209+
if hash := api.les.BlockChain().GetCanonicalHash(uint64(config.TerminalBlockNumber)); hash == config.TerminalBlockHash {
210+
return &beacon.TransitionConfigurationV1{
211+
TerminalTotalDifficulty: (*hexutil.Big)(ttd),
212+
TerminalBlockHash: config.TerminalBlockHash,
213+
TerminalBlockNumber: config.TerminalBlockNumber,
214+
}, nil
215+
}
216+
return nil, fmt.Errorf("invalid terminal block hash")
217+
}
218+
219+
return &beacon.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil
220+
}

0 commit comments

Comments
 (0)