Skip to content

Commit

Permalink
Merge pull request #17 from chainstack/feature/talk_with_sonic
Browse files Browse the repository at this point in the history
Patch opera to talk with sonic
  • Loading branch information
agrevtsev authored Oct 24, 2024
2 parents 2fe594b + 975d82e commit 73a15be
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM golang:1.17-alpine as builder
WORKDIR /tmp
COPY opera-1.1.3-rc5.patch /tmp/

RUN apk add --no-cache make gcc musl-dev linux-headers git
RUN go clean -modcache
RUN git clone --depth 1 --branch release/1.1.3-rc.5 https://github.com/Fantom-foundation/go-opera.git && \
cd go-opera && \
RUN git clone --depth 1 --branch release/1.1.3-rc.5 https://github.com/Fantom-foundation/go-opera.git

RUN cd go-opera && \
git apply ../opera-1.1.3-rc5.patch && \
make

FROM golang:1.17-alpine
Expand All @@ -14,7 +17,7 @@ WORKDIR /root/.opera
COPY --from=builder /tmp/go-opera/build /usr/local/bin

RUN mkdir /opt/genesis
RUN wget -O /opt/genesis/mainnet.g https://opera.fantom.network/mainnet.g
RUN wget -O /opt/genesis/testnet.g https://opera.fantom.network/testnet.g
RUN wget -O /opt/genesis/mainnet.g https://storage.googleapis.com/fantom-opera-genesis/mainnet.g
RUN wget -O /opt/genesis/testnet.g https://storage.googleapis.com/fantom-opera-genesis/testnet.g

ENTRYPOINT ["opera"]
43 changes: 43 additions & 0 deletions opera-1.1.3-rc5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git forkSrcPrefix/gossip/handler.go forkDstPrefix/gossip/handler.go
index 1d5a48a183afdf92b6b2fe47f37397818e82e292..fcb134bd35da545947f16219ce56d8c41596c934 100644
--- forkSrcPrefix/gossip/handler.go
+++ forkDstPrefix/gossip/handler.go
@@ -3,6 +3,7 @@ package gossip
import (
"errors"
"fmt"
+ "github.com/ethereum/go-ethereum/p2p/enode"
"math"
"math/rand"
"strings"
@@ -773,6 +774,17 @@ func (h *handler) highestPeerProgress() PeerProgress {
return max
}

+// isUseless checks if the peer is banned from discovery and ban it if it should be
+func isUseless(node *enode.Node, name string) bool {
+ useless := discfilter.Banned(node.ID(), node.Record())
+ lowerName := strings.ToLower(name)
+ if !useless && !strings.Contains(lowerName, "opera") && !strings.Contains(lowerName, "sonic") {
+ useless = true
+ discfilter.Ban(node.ID())
+ }
+ return useless
+}
+
// handle is the callback invoked to manage the life cycle of a peer. When
// this function terminates, the peer is disconnected.
func (h *handler) handle(p *peer) error {
@@ -783,11 +795,7 @@ func (h *handler) handle(p *peer) error {
p.Log().Error("Snapshot extension barrier failed", "err", err)
return err
}
- useless := discfilter.Banned(p.Node().ID(), p.Node().Record())
- if !useless && (!eligibleForSnap(p.Peer) || !strings.Contains(strings.ToLower(p.Name()), "opera")) {
- useless = true
- discfilter.Ban(p.ID())
- }
+ useless := isUseless(p.Node(), p.Name())
if !p.Peer.Info().Network.Trusted && useless {
if h.peers.UselessNum() >= h.maxPeers/10 {
// don't allow more than 10% of useless peers

0 comments on commit 73a15be

Please sign in to comment.