Skip to content

Commit

Permalink
Workaround for BSC nodes not propagating new block hashes and blocks (#…
Browse files Browse the repository at this point in the history
…6777)

It turns out that "standard" BSC nodes based on Geth, do not propagate
new block hashes and blocks, at least towards Erigon nodes. This is a
workaround

---------

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
  • Loading branch information
AlexeyAkhunov and Alexey Sharp authored Feb 5, 2023
1 parent 03f737c commit 52aef48
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
30 changes: 30 additions & 0 deletions cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/temporal/historyv2"
"github.com/ledgerwatch/erigon-lib/recsplit"
"github.com/ledgerwatch/erigon-lib/recsplit/eliasfano32"
librlp "github.com/ledgerwatch/erigon-lib/rlp"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon/turbo/debug"
Expand Down Expand Up @@ -1345,6 +1346,33 @@ func dumpState(chaindata string) error {
return nil
}

type NewPooledTransactionHashesPacket68 struct {
Types []byte
Sizes []uint32
Hashes []libcommon.Hash
}

func rlptest() error {
var p = NewPooledTransactionHashesPacket68{
Types: []byte{44, 200},
Sizes: []uint32{56, 57680},
Hashes: []libcommon.Hash{{}, {}},
}
b, err := rlp.EncodeToBytes(&p)
if err != nil {
return err
}
fmt.Printf("%x\n", b)
var hashes []byte
for _, h := range p.Hashes {
hashes = append(hashes, h[:]...)
}
b = make([]byte, librlp.AnnouncementsLen(p.Types, p.Sizes, hashes))
l := librlp.EncodeAnnouncements(p.Types, p.Sizes, hashes, b)
fmt.Printf("%x\n%d %d\n", b, len(b), l)
return nil
}

func main() {
debug.RaiseFdLimit()
flag.Parse()
Expand Down Expand Up @@ -1476,6 +1504,8 @@ func main() {
err = readSeg(*chaindata)
case "dumpState":
err = dumpState(*chaindata)
case "rlptest":
err = rlptest()
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,5 +1323,5 @@ func initConsensusEngine(cc *chain2.Config, datadir string, db kv.RwDB) (engine
} else {
consensusConfig = &config.Ethash
}
return ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallgRPCAddress, config.HeimdallURL, config.WithoutHeimdall, datadir, snapshots, db.ReadOnly(), db)
return ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, HeimdallgRPCAddress, HeimdallURL, config.WithoutHeimdall, datadir, snapshots, db.ReadOnly(), db)
}
8 changes: 1 addition & 7 deletions cmd/sentry/sentry/sentry_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,13 @@ func (cs *MultiClient) SendHeaderRequest(ctx context.Context, req *headerdownloa
}
minBlock := req.Number

var maxPeers uint64
if cs.sendHeaderRequestsToMultiplePeers {
maxPeers = 5
} else {
maxPeers = 1
}
outreq := proto_sentry.SendMessageByMinBlockRequest{
MinBlock: minBlock,
Data: &proto_sentry.OutboundMessageData{
Id: proto_sentry.MessageId_GET_BLOCK_HEADERS_66,
Data: bytes,
},
MaxPeers: maxPeers,
MaxPeers: 5,
}
sentPeers, err1 := cs.sentries[i].SendMessageByMinBlock(ctx, &outreq, &grpc.EmptyCallOption{})
if err1 != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/sentry/sentry/sentry_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ func runPeer(
if _, err := io.ReadFull(msg.Payload, b); err != nil {
log.Error(fmt.Sprintf("%s: reading msg into bytes: %v", peerID, err))
}
//log.Debug("NewBlockHashesMsg from", "peerId", fmt.Sprintf("%x", peerID)[:20], "name", peerInfo.peer.Name())
send(eth.ToProto[protocol][msg.Code], peerID, b)
case eth.NewBlockMsg:
if !hasSubscribers(eth.ToProto[protocol][msg.Code]) {
Expand All @@ -463,6 +464,7 @@ func runPeer(
if _, err := io.ReadFull(msg.Payload, b); err != nil {
log.Error(fmt.Sprintf("%s: reading msg into bytes: %v", peerID, err))
}
//log.Debug("NewBlockMsg from", "peerId", fmt.Sprintf("%x", peerID)[:20], "name", peerInfo.peer.Name())
send(eth.ToProto[protocol][msg.Code], peerID, b)
case eth.NewPooledTransactionHashesMsg:
if !hasSubscribers(eth.ToProto[protocol][msg.Code]) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ func (c *Bor) CommitStates(
to := time.Unix(int64(chain.Chain.GetHeaderByNumber(number-c.config.CalculateSprint(number)).Time), 0)
lastStateID := _lastStateID.Uint64()

log.Info(
log.Debug(
"Fetching state updates from Heimdall",
"fromID", lastStateID+1,
"to", to.Format(time.RFC3339))
Expand Down
2 changes: 1 addition & 1 deletion consensus/bor/heimdall/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h *HeimdallClient) StateSyncEvents(ctx context.Context, fromID uint64, to
return nil, err
}

log.Info("Fetching state sync events", "queryParams", url.RawQuery)
log.Debug("Fetching state sync events", "queryParams", url.RawQuery)

ctx = withRequestType(ctx, stateSyncRequest)

Expand Down
2 changes: 1 addition & 1 deletion tests/testdata
Submodule testdata updated 616 files
11 changes: 8 additions & 3 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,19 @@ func (hd *HeaderDownload) RequestSkeleton() *HeaderRequest {
hd.lock.RLock()
defer hd.lock.RUnlock()
log.Debug("[Downloader] Request skeleton", "anchors", len(hd.anchors), "highestInDb", hd.highestInDb)
stride := uint64(192)
var stride uint64
if hd.initialCycle {
stride = 192
}
var length uint64 = 192
// Include one header that we have already, to make sure the responses are not empty and do not get penalised when we are at the tip of the chain
from := hd.highestInDb
if from == 0 {
if from <= 1 {
from = 1
} else {
from--
}
return &HeaderRequest{Number: from, Length: length, Skip: stride - 1, Reverse: false}
return &HeaderRequest{Number: from, Length: length, Skip: stride, Reverse: false}
}

func (hd *HeaderDownload) VerifyHeader(header *types.Header) error {
Expand Down

0 comments on commit 52aef48

Please sign in to comment.