@@ -29,6 +29,7 @@ import (
29
29
"github.com/ethereum/go-ethereum/common"
30
30
"github.com/ethereum/go-ethereum/common/mclock"
31
31
"github.com/ethereum/go-ethereum/core"
32
+ "github.com/ethereum/go-ethereum/core/forkid"
32
33
"github.com/ethereum/go-ethereum/core/types"
33
34
"github.com/ethereum/go-ethereum/eth"
34
35
"github.com/ethereum/go-ethereum/les/flowcontrol"
@@ -246,7 +247,7 @@ func (p *peerCommons) sendReceiveHandshake(sendList keyValueList) (keyValueList,
246
247
// network IDs, difficulties, head and genesis blocks. Besides the basic handshake
247
248
// fields, server and client can exchange and resolve some specified fields through
248
249
// two callback functions.
249
- func (p * peerCommons ) handshake (td * big.Int , head common.Hash , headNum uint64 , genesis common.Hash , sendCallback func (* keyValueList ), recvCallback func (keyValueMap ) error ) error {
250
+ func (p * peerCommons ) handshake (td * big.Int , head common.Hash , headNum uint64 , genesis common.Hash , forkID forkid. ID , forkFilter forkid. Filter , sendCallback func (* keyValueList ), recvCallback func (keyValueMap ) error ) error {
250
251
p .lock .Lock ()
251
252
defer p .lock .Unlock ()
252
253
@@ -262,6 +263,12 @@ func (p *peerCommons) handshake(td *big.Int, head common.Hash, headNum uint64, g
262
263
send = send .add ("headNum" , headNum )
263
264
send = send .add ("genesisHash" , genesis )
264
265
266
+ // If the protocol version is beyond les4, then pass the forkID
267
+ // as well. Check http://eips.ethereum.org/EIPS/eip-2124 for more
268
+ // spec detail.
269
+ if p .version >= lpv4 {
270
+ send = send .add ("forkID" , forkID )
271
+ }
265
272
// Add client-specified or server-specified fields
266
273
if sendCallback != nil {
267
274
sendCallback (& send )
@@ -295,6 +302,16 @@ func (p *peerCommons) handshake(td *big.Int, head common.Hash, headNum uint64, g
295
302
if int (rVersion ) != p .version {
296
303
return errResp (ErrProtocolVersionMismatch , "%d (!= %d)" , rVersion , p .version )
297
304
}
305
+ // Check forkID if the protocol version is beyond the les4
306
+ if p .version >= lpv4 {
307
+ var forkID forkid.ID
308
+ if err := recv .get ("forkID" , & forkID ); err != nil {
309
+ return err
310
+ }
311
+ if err := forkFilter (forkID ); err != nil {
312
+ return errResp (ErrForkIDRejected , "%v" , err )
313
+ }
314
+ }
298
315
if recvCallback != nil {
299
316
return recvCallback (recv )
300
317
}
@@ -561,10 +578,10 @@ func (p *serverPeer) updateHead(hash common.Hash, number uint64, td *big.Int) {
561
578
562
579
// Handshake executes the les protocol handshake, negotiating version number,
563
580
// network IDs and genesis blocks.
564
- func (p * serverPeer ) Handshake (genesis common.Hash ) error {
581
+ func (p * serverPeer ) Handshake (genesis common.Hash , forkid forkid. ID , forkFilter forkid. Filter ) error {
565
582
// Note: there is no need to share local head with a server but older servers still
566
583
// require these fields so we announce zero values.
567
- return p .handshake (common .Big0 , common.Hash {}, 0 , genesis , func (lists * keyValueList ) {
584
+ return p .handshake (common .Big0 , common.Hash {}, 0 , genesis , forkid , forkFilter , func (lists * keyValueList ) {
568
585
// Add some client-specific handshake fields
569
586
//
570
587
// Enable signed announcement randomly even the server is not trusted.
@@ -944,11 +961,11 @@ func (p *clientPeer) freezeClient() {
944
961
945
962
// Handshake executes the les protocol handshake, negotiating version number,
946
963
// network IDs, difficulties, head and genesis blocks.
947
- func (p * clientPeer ) Handshake (td * big.Int , head common.Hash , headNum uint64 , genesis common.Hash , server * LesServer ) error {
964
+ func (p * clientPeer ) Handshake (td * big.Int , head common.Hash , headNum uint64 , genesis common.Hash , forkID forkid. ID , forkFilter forkid. Filter , server * LesServer ) error {
948
965
// Note: clientPeer.headInfo should contain the last head announced to the client by us.
949
966
// The values announced in the handshake are dummy values for compatibility reasons and should be ignored.
950
967
p .headInfo = blockInfo {Hash : head , Number : headNum , Td : td }
951
- return p .handshake (td , head , headNum , genesis , func (lists * keyValueList ) {
968
+ return p .handshake (td , head , headNum , genesis , forkID , forkFilter , func (lists * keyValueList ) {
952
969
// Add some information which services server can offer.
953
970
if ! server .config .UltraLightOnlyAnnounce {
954
971
* lists = (* lists ).add ("serveHeaders" , nil )
0 commit comments