2022-09-30 17:07:13 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2022-10-06 12:34:39 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel/communication"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel/communication/p2p"
|
2022-09-30 17:07:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/utils"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
// These below are the handlers for heartbeat functions
|
|
|
|
|
2022-10-06 12:34:39 +00:00
|
|
|
func (c *ConsensusHandlers) goodbyeHandler(ctx *communication.StreamContext, dat *p2p.Goodbye) error {
|
2022-09-30 17:07:13 +00:00
|
|
|
//log.Info("[Lightclient] Received", "goodbye", dat.Reason)
|
2022-10-06 20:53:24 +00:00
|
|
|
defer c.peers.DisconnectPeer(ctx.Stream.Conn().RemotePeer())
|
2022-10-07 12:38:12 +00:00
|
|
|
_, err := ctx.Codec.WritePacket(dat, SuccessfullResponsePrefix)
|
2022-09-30 17:07:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// type safe handlers which all have access to the original stream & decompressed data
|
|
|
|
// ping handler
|
2022-10-06 12:34:39 +00:00
|
|
|
func pingHandler(ctx *communication.StreamContext, dat *p2p.Ping) error {
|
2022-09-30 17:07:13 +00:00
|
|
|
// since packets are just structs, they can be resent with no issue
|
2022-10-07 12:38:12 +00:00
|
|
|
_, err := ctx.Codec.WritePacket(dat, SuccessfullResponsePrefix)
|
2022-09-30 17:07:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-10-06 20:53:24 +00:00
|
|
|
func (c *ConsensusHandlers) metadataHandlerV1(ctx *communication.StreamContext, dat *communication.EmptyPacket) error {
|
2022-10-07 16:40:18 +00:00
|
|
|
_, err := ctx.Codec.WritePacket(c.metadataV1, SuccessfullResponsePrefix)
|
2022-10-06 20:53:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-30 17:07:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-10-07 16:40:18 +00:00
|
|
|
// TODO: Actually respond with proper status
|
2022-10-06 12:34:39 +00:00
|
|
|
func statusHandler(ctx *communication.StreamContext, dat *p2p.Status) error {
|
2022-10-06 09:01:56 +00:00
|
|
|
log.Debug("[ReqResp] Status",
|
2022-09-30 17:07:13 +00:00
|
|
|
"epoch", dat.FinalizedEpoch,
|
|
|
|
"final root", utils.BytesToHex(dat.FinalizedRoot),
|
|
|
|
"head root", utils.BytesToHex(dat.HeadRoot),
|
|
|
|
"head slot", dat.HeadSlot,
|
|
|
|
"fork digest", utils.BytesToHex(dat.ForkDigest),
|
|
|
|
)
|
2022-10-07 16:40:18 +00:00
|
|
|
_, err := ctx.Codec.WritePacket(dat, SuccessfullResponsePrefix)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-30 17:07:13 +00:00
|
|
|
return nil
|
|
|
|
}
|